<link href="<?php echo base_url();?>public/h5/css/bootstrap.min14ed.css" rel="stylesheet">
<link href="<?php echo base_url();?>public/h5/css/font-awesome.min93e3.css" rel="stylesheet">
<link href="<?php echo base_url();?>public/h5/css/animate.min.css" rel="stylesheet">
<link href="<?php echo base_url();?>public/h5/css/style.min862f.css" rel="stylesheet">
<div id="msg-tip">
</div>
<div class="content_wrapper">
    <div class="container-fluid">
        <aside>
        <form method="post" class="form-horizontal" id="editForm" action="/fans/edit.php">
            <input type="hidden" value="<?php echo $id?>" name="id">
            <div class="ibox float-e-margins">
                <div class="ibox-title" style="border-top: 0;">
                    <h3 style="font-weight: bold">粉丝页配置</h3>
                </div>
                <div class="ibox-content" style="padding:25px 0;">
                    <div class="col-sm-8">
                        <div class="form-group ">
                            <label class="col-sm-2 control-label m-b">弹出群组：</label>
                            <div class="col-sm-4">
                                <select class="form-control m-b" id="open_channel" name="info[open_channel]">
                                    <option value="1" <?php if(!empty($info['open_channel']) && $info['open_channel'] == 1) echo 'selected';?>>全部</option>
                                    <option value="2" <?php if(!empty($info['open_channel']) && $info['open_channel'] == 2) echo 'selected';?>>fb</option>
                                    <option value="3" <?php if(!empty($info['open_channel']) && $info['open_channel'] == 3) echo 'selected';?>>游客</option>
                                    <option value="4" <?php if(!empty($info['open_channel']) && $info['open_channel'] == 4) echo 'selected';?>>群组</option>
                                    <option value="5" <?php if(!empty($info['open_channel']) && $info['open_channel'] == 5) echo 'selected';?>>关闭</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group ">
                            <div id="open_group" <?php if(empty($info['open_channel']) || $info['open_channel'] != 4) echo 'style="display:none;"';?>>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label" style="line-height: 7px;">分组:</label>
                                    <div class="an-checkbox-div col-sm-9 android-package">
                                        <label>
                                            <input type="checkbox" id="checkall"> 【全选】
                                        </label>
                                        <?php foreach ($groups as $k => $v) { ?>
                                            <label>
                                                <input type="checkbox" class="android-check" name="info[open_group][]" value="<?php echo $k;?>" <?php if(!empty($info['open_group'])&&in_array($k, $info['open_group'])) {echo 'checked'; }?> > <?php echo $v;?>
                                            </label>
                                        <?php }?>
                                        <br/>
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="form-group ">
                            <div class="form-group">
                                <label class="col-sm-2 control-label" style="line-height: 7px;">弹出时机:</label>
                                <div class="an-checkbox-div col-sm-9 android-package">
                                    <?php foreach ($showTypes as $k => $v) { ?>
                                        <label>
                                            <input type="checkbox" class="android-check" name="configJson[showType][]" value="<?php echo $k;?>" <?php if(in_array($k, $configJson['showType'])) {echo 'checked'; }?> > <?php echo $v;?>
                                        </label>
                                    <?php }?>
                                    <br/>
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                </div>
                            </div>
                        </div>

                        <div class="col-sm-12">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">弹出类型：</label>
                                <div class="col-sm-6">
                                <select class="form-control m-b open_type" name="info[open_type]">
                                    <?php foreach ($types as $k => $v) { ?>
                                    <option value="<?php echo $k;?>" <?php if(isset($info['open_type']) && $info['open_type'] == $k) echo 'selected';?>><?php echo $v;?></option>
                                    <?php }?>
                                </select>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">当日最大次数：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" name="configJson[maxEveryDay]" value="<?php echo !empty($configJson['maxEveryDay']) ? $configJson['maxEveryDay'] : 0;?>">
                            </div>
                            <label class="col-sm-2 control-label">最大弹出次数：</label>
                            <div class="col-sm-3">
                                <input type="text" class="form-control" name="configJson[maxTotal]" value="<?php echo !empty($configJson['maxTotal']) ? $configJson['maxTotal'] : 0;?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">配置：</label>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-2"> </div>
                            <div class="col-sm-10">
                                <?php foreach ($types as $k => $v) { ?>
                                <?php if(empty($configJson[$k])){ continue;}?>
                                <div class="col-sm-12" style="display: none">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label"><?php echo $v?> 图片：</label>
                                        <div class="col-sm-6">
                                        <input type="text" class="form-control" name="configJson[<?php echo $k; ?>][imgUrl]" value="<?php echo isset($configJson[$k], $configJson[$k]['imgUrl']) ? $configJson[$k]['imgUrl'] : 0;?>">
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-12" style="display: none">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label"><?php echo $v?> 背景：</label>
                                        <div class="col-sm-6">
                                        <input type="text" class="form-control" name="configJson[<?php echo $k; ?>][btnBgUrl]" value="<?php echo isset($configJson[$k], $configJson[$k]['btnBgUrl']) ? $configJson[$k]['btnBgUrl'] : 0;?>">
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-12" style="display: none">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label"><?php echo $v?> icon：</label>
                                        <div class="col-sm-6">
                                        <input type="text" class="form-control" name="configJson[<?php echo $k; ?>][btnIconUrl]" value="<?php echo isset($configJson[$k], $configJson[$k]['btnIconUrl']) ? $configJson[$k]['btnIconUrl'] : 0;?>">
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-12">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label"><?php echo $v?>方式：</label>
                                        <div class="col-sm-6">
                                        <select class="form-control m-b open_type" name="configJson[<?php echo $k; ?>][btnAction]">
                                            <option value="1" <?php if(isset($configJson[$k]['btnAction']) && $configJson[$k]['btnAction'] == 1) echo 'selected';?>>关闭</option>
                                            <option value="2" <?php if(isset($configJson[$k]['btnAction']) && $configJson[$k]['btnAction'] != 1) echo 'selected';?>>网址</option>
                                        </select>
                                        <input type="text" <?php
                                        if(isset($configJson[$k]['btnAction']) && $configJson[$k]['btnAction'] == 1) echo 'style="display:none;"';?> class="form-control type_address" name="configJson[<?php echo $k; ?>][btnAction2]" placeholder="跳转地址" value="<?php echo (isset($configJson[$k], $configJson[$k]['btnAction']) && $configJson[$k]['btnAction'] != 1) ? $configJson[$k]['btnAction'] : 1;?>">
                                        </div>
                                    </div>
                                </div>
                            <?php }?>
                            </div>
                        </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-3">
                                <button type="button" class="btn btn-primary" id="submitBtn">提交</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
        <aside>
    </div>
</div>

<script src="<?php echo base_url();?>public/h5/js/jquery.min.js"></script>
<script src="<?php echo base_url();?>public/h5/js/bootstrap.min.js"></script>
<script src="<?php echo base_url();?>public/h5/js/content.min.js"></script>
<script>
    //全选/全不选
    $('#open_channel').change(function () {
        var val = $(this).children('option:selected').val();
        if(val == 4){
            $('#open_group').show();       
        }else{
            $('#open_group').hide();
        }
    });
    //全选/全不选
    $('#checkall').change(function () {
        if($(this).is(':checked')) {//已经是全选的状态
            $('.android-check').prop('checked', true);
        }else {
            $('.android-check').prop('checked', false);
        }
    });
    var msgTip = $('#msg-tip');
    //提交
    $('#submitBtn').click(function () {
        var data = new FormData(document.getElementById("editForm"));
        $.ajax({
            url: rootPath + 'fans/edit',
            type: 'POST',
            data: data,
            dataType: 'json',
            contentType: false, //必须
            processData: false, //必须
            success: function (data) {
                if (data.ret != 0) {//新增失败
                    msgTip.messager().error(data.msg);
                } else {
                    window.location.reload();
                    //location.href=rootPath + '#fans/index';
                }
            },
            error: function (msg) {
                msgTip.messager().error('网络错误，请刷新后重试');
            }
        });
    });


    //全选/全不选
    $('.open_type').change(function () {
        var val = $(this).children('option:selected').val();
        if(val == 1){
            $(this).parent('div').find('.type_address').hide();
        }else{
            var val = $(this).parent('div').find('.type_address').val();
            $(this).parent('div').find('.type_address').show();
            $(this).parent('div').find('.type_address').val(val != 1 ? val : '');
        }
    });

</script>
