<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改广告</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="<?php echo base_url();?>public/js/bootstrap/bootstrap.min.css" >
    <link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.css">
    <link rel="stylesheet" href="<?php echo base_url();?>public/css/jquery.timepicker.min.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/select2/select2.min.css">

    <style type="text/css">
        .thumbnail {
            margin:10px;
        }

        .lang-name {
            margin-left:42px;
        }

        .upimg {
            cursor: pointer;
        }

    </style>
</head>
<body>
<div id="msg-tip">

</div>
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>修改广告</header>
                    <hr/>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <form class="form-horizontal J_ajaxForm" role="form" method="post" action="Config/actionPolymerization" data-callBack="message">
                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">广告ID*: </label>
                                            <div class="col-sm-2">
                                                <input type="text" readonly class="form-control"  name="id" value="<?php echo $info['id'];?>">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">真实ID*: </label>
                                            <div class="col-sm-3">
                                                <input type="text"  class="form-control"  name="trueId" value="<?php echo $info['trueId'];?>">
                                            </div>
                                            <label class="col-sm-1 control-label">(ios)*: </label>
                                            <div class="col-sm-3">
                                                <input type="text"  class="form-control"  name="trueId_ios" value="<?php echo $info['trueId_ios'];?>">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">场景ID*: </label>
                                            <div class="col-sm-3">
                                                <input type="text"  class="form-control"  name="sceneId" value="<?php echo $info['sceneId'];?>">
                                            </div>
                                            <label class="col-sm-1 control-label">场景(ios)*: </label>
                                            <div class="col-sm-3">
                                                <input type="text"  class="form-control"  name="sceneId_ios" value="<?php echo $info['sceneId_ios'];?>">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">名称*: </label>
                                            <div class="col-sm-3">
                                                <input type="text" class="form-control"  name="name" value="<?php echo $info['name'];?>">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">奖励*: </label>
                                            <div class="col-sm-3">
                                                <?php
                                                    if($info['reward']['specialReward'] && $info['id'] != 19 && $info['id'] != 12){
                                                        echo '<input type="text" readonly class="form-control"  name="" value="'.$info['reward']['tips'].'">';
                                                    }else{
                                                        if(isset($info['reward']['reward']['coins'])){
                                                            $select = '<select class="form-control" name="coins">';
                                                            for ($i=1;$i<=6;$i++){
                                                                $t = "";
                                                                if($info['reward']['reward']['coins']['coins'] == 'coins0'.$i){
                                                                    $t = "selected";
                                                                }
                                                                $select .= '<option value="coins0'.$i.'" '.$t.'>coins0'.$i.'</option>';
                                                            }
                                                            $select.= '</select>';
                                                            echo '<label class="col-sm-3 control-label">金币 </label><div class="col-sm-9">'.$select.'</div><label class="col-sm-3 control-label">倍率</label><div class="col-sm-9"><input type="text" class="form-control"  name="bet" value="'.$info['reward']['reward']['coins']['bet'].'"></div>';
                                                        }
                                                        if(isset($info['reward']['reward']['spins'])){
                                                            echo '<label class="col-sm-3 control-label">体力 </label><div class="col-sm-9"><input type="text" class="form-control"  name="spins" value="'.$info['reward']['reward']['spins'].'"></div></div';
                                                        }
                                                        if(isset($info['reward']['reward']['shield'])){
                                                            echo '<label class="col-sm-3 control-label">盾牌 </label><div class="col-sm-9"><input type="text" class="form-control"  name="shield" value="'.$info['reward']['reward']['shield'].'"></div></div';
                                                        }
                                                        if(isset($info['reward']['reward']['chestId'])){
                                                            $select = '<select class="form-control" name="chestId">';
                                                            foreach (['木质宝箱','白银宝箱','黄金宝箱','魔幻宝箱'] as $key=>$item) {
                                                                $t = "";
                                                                if($info['reward']['reward']['chestId'] == ($key+1)){
                                                                    $t = "selected";
                                                                }
                                                                $select .= '<option value="'.($key+1).'" '.$t.'>'.$item.'</option>';
                                                            }
                                                            $select.= '</select>';
                                                            echo '<label class="col-sm-3 control-label">道具 </label><div class="col-sm-9">'.$select.'</div>';
                                                        }
                                                        if(isset($info['reward']['config'])){
                                                            echo '<label class="col-sm-2 control-label">盾牌 </label><div class="col-sm-5"><input type="text" class="form-control" name="config[shield][num]" value="'.$info['reward']['config']['shield']['num'].'"></div>';
                                                            echo '<label class="col-sm-2 control-label">概率 </label><div class="col-sm-3"><input type="text" class="form-control" name="config[shield][v]"   value="'.$info['reward']['config']['shield']['v'].'"></div>';
                                                            echo '<label class="col-sm-2 control-label">金币 </label><div class="col-sm-5"><input type="text" class="form-control" name="config[coins][num]"  value="'.$info['reward']['config']['coins']['num'].'"></div>';
                                                            echo '<label class="col-sm-2 control-label">概率 </label><div class="col-sm-3"><input type="text" class="form-control" name="config[coins][v]"    value="'.$info['reward']['config']['coins']['v'].'"></div>';
                                                            echo '<label class="col-sm-2 control-label">体力 </label><div class="col-sm-5"><input type="text" class="form-control" name="config[spins][num]"  value="'.$info['reward']['config']['spins']['num'].'"></div>';
                                                            echo '<label class="col-sm-2 control-label">概率 </label><div class="col-sm-3"><input type="text" class="form-control" name="config[spins][v]"    value="'.$info['reward']['config']['spins']['v'].'"></div>';
                                                        }
                                                    }
                                                ?>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">最大数量*:</label>
                                            <div class="col-sm-1">
                                                <input type="text" class="form-control" placeholder="最大数量" name="max" value="<?php echo $info['max'];?>">
                                            </div>
                                            <label class="col-sm-2 control-label">CD(秒)*:</label>
                                            <div class="col-sm-1">
                                                <input type="number" class="form-control" placeholder="间隔时间" min="0" name="cd" value="<?php echo $info['cd'];?>">
                                            </div>
                                            <?php if(isset($info['reward']['bet'])) { ?>
                                                <label class="col-sm-1 control-label">奖励倍率*:</label>
                                                <div class="col-sm-1">
                                                    <input type="text" class="form-control" placeholder="奖励倍率" name="bet" value="<?php echo $info['reward']['bet'];?>">
                                                </div>
                                            <?php }?>
                                            <?php if(isset($info['reward']['time'])) { ?>
                                                <label class="col-sm-1 control-label">奖励有效时长(秒)*:</label>
                                                <div class="col-sm-1">
                                                    <input type="text" class="form-control" placeholder="奖励有效时长" name="time" value="<?php echo $info['reward']['time'];?>">
                                                </div>
                                            <?php }?>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">广告状态*:</label>
                                            <div class="col-sm-2">
                                                <label class="radio-inline">
                                                    <input type="radio" name="status"  value="3" <?php if($info['status'] == 3) { ?>checked <?php }?> /> 全开
                                                </label>
                                                <label class="radio-inline">
                                                    <input type="radio" name="status"  value="2" <?php if($info['status'] == 2) { ?>checked <?php }?> /> 安卓开
                                                </label>
                                                <label class="radio-inline">
                                                    <input type="radio" name="status"  value="1" <?php if($info['status'] == 1) { ?>checked <?php }?> /> IOS开
                                                </label>
                                                <label class="radio-inline">
                                                    <input type="radio" name="status"  value="0" <?php if($info['status'] == 0) { ?>checked <?php }?> /> 关
                                                </label>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-sm-2 control-label">目标群组*:</label>
                                        </div>

                                        <div class="form-group addOrDelControl">
                                            <div class="col-sm-12">
                                                <?php foreach ($info['group_pro'] as $pro) { ?>
                                                    <div class="form-group line-group">
                                                        <label class="col-sm-1 control-label">群组类型*: </label>
                                                        <div class="col-sm-1">
                                                            <select class="form-control groupTypeId" name="group_pro[type][]">
                                                                <?php foreach ($userGroupTypes as $typeId=>$typeText) { ?>
                                                                    <option value="<?php echo $typeId;?>" <?php if($typeId == $pro['type']) echo 'selected'; ?>><?php echo $typeText;?></option>
                                                                <?php } ?>
                                                            </select>
                                                        </div>
                                                        <label class="col-sm-1 control-label">群组*: </label>
                                                        <div class="col-sm-2">
                                                            <select class="form-control groupId select2" name="group_pro[id][]">
                                                                <?php foreach ($userGroups[$pro['type']] as $propsId=>$props) { ?>
                                                                    <option value="<?php echo $props['id'];?>" <?php if($props['id'] == $pro['id']) echo 'selected'; ?>><?php echo $props['name'];?></option>
                                                                <?php } ?>
                                                            </select>
                                                        </div>
                                                        <label class="col-sm-1 control-label">概率*: </label>
                                                        <div class="col-sm-1">
                                                            <input type="text" class="form-control"  name="group_pro[v][]" value="<?php echo $pro['v'];?>">
                                                        </div>
                                                        <label class="col-sm-1 control-label">开放等级*: </label>
                                                        <div class="col-sm-1">
                                                            <input type="text" class="form-control"  name="group_pro[levelId][]" value="<?php echo $pro['levelId'];?>">
                                                        </div>
                                                        <label class="col-sm-1 control-label">广告次数*: </label>
                                                        <div class="col-sm-1">
                                                            <input type="text" class="form-control"  name="group_pro[num][]" value="<?php echo $pro['num'];?>">
                                                        </div>
                                                        <button type="button" class="btn btn-danger deleteParent" >删除</button>
                                                    </div>
                                                <?php } ?>
                                                <button type="button" class="btn btn-success addParent" style="margin-left: 3rem;margin-bottom: 10px;">增加分组</button>
                                                <button type="button" class="btn btn-success addAll" style="margin-left: 3rem;margin-bottom: 10px;">增加所有分组</button>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <div class="col-sm-offset-2 col-sm-3">
                                                <button type="button" class="btn btn-info goback">返回</button>
                                                <button type="button" class="btn btn-primary J_ajaxSubmitBtn">提交</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</body>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<script src="<?php echo base_url();?>public/plugins/validate/jquery.validate-1.15.0.min.js"></script>
<script src="<?php echo base_url();?>public/plugins/validate/jaquery.validate.messages_zh.js"></script>
<script src="<?php echo base_url();?>public/js/common.js"></script>
<!--select2-->
<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/select2/select2.min.css">
<script src="<?php echo base_url();?>public/js/vendor/select2/select2.full.min.js"></script>
<script>
    var userGroups = JSON.parse('<?php echo json_encode($userGroups);?>');
    var userGroupTypes = JSON.parse('<?php echo json_encode($userGroupTypes);?>');
    var idData = userGroups[1];

    $('.select2').select2({})
    $('.addOrDelControl').on("click",'.deleteParent',function(){
        $(this).parent().remove();
    });
    $('.addOrDelControl').on("change",'.groupTypeId',function(){
        var type = $(this).val();
        console.log($(this).parents('.line-group'))
        var selector = $(this).parents('.line-group').find('.groupId')
        selector.empty();
        var tmpGroups = userGroups[type]
        for( i in tmpGroups){
            selector.append('<option value="'+tmpGroups[i].id+'">'+tmpGroups[i].name+'</option>')
        }
        $('.select2').select2({})
    });

    $('.addAll').on("click",function(){
        for(var j in idData) {

            var str = "";
            str += '<div class="form-group"><label class="col-sm-1 control-label">群组*: </label><div class="col-sm-2"><select class="form-control" name="group_pro[id][]">';
            for(var x in idData) {
                if(idData[x]['id'] == idData[j]['id']){
                    var selected = 'selected';
                }else{
                    var selected = "";
                }
                str += '<option value="'+idData[x]['id']+'" '+selected+'>'+idData[x]['name']+'</option>';
            }
            str += '</select></div><label class="col-sm-1 control-label">概率*: </label><div class="col-sm-1"><input type="text" class="form-control"  name="group_pro[v][]" value="1"></div><label class="col-sm-1 control-label">开放等级*: </label><div class="col-sm-1"><input type="text" class="form-control"  name="group_pro[levelId][]" value="1">\</div><label class="col-sm-1 control-label">广告次数*: </label><div class="col-sm-1"><input type="text" class="form-control"  name="group_pro[num][]" value="1"></div><button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).prev().before(str);
        }
    });

    $('.addParent').on("click",function(){
        var str = "";
        var defaultType = 1;
        str += '<div class="form-group line-group">' +
            '<label class="col-sm-1 control-label">群组类型*: </label>' +
            '<div class="col-sm-1">' +
            '<select class="form-control groupTypeId" name="group_pro[type][]">';
        for(var x in userGroupTypes) {
            str += '<option value="'+x+'">'+userGroupTypes[x]+'</option>';
        }
        str+=   '</select>'+
            '</div>'+
            '<label class="col-sm-1 control-label">群组*: </label>' +
            '<div class="col-sm-2">' +
            '<select class="form-control groupId select2" name="group_pro[id][]">';
        for(var x in userGroups[defaultType]) {
            str += '<option value="'+userGroups[defaultType][x]['id']+'">'+userGroups[defaultType][x]['name']+'</option>';
        }
        str += '</select></div><label class="col-sm-1 control-label">概率*: </label><div class="col-sm-1"><input type="text" class="form-control"  name="group_pro[v][]" value="1"></div><label class="col-sm-1 control-label">开放等级*: </label><div class="col-sm-1"><input type="text" class="form-control"  name="group_pro[levelId][]" value="1">\</div><label class="col-sm-1 control-label">广告次数*: </label><div class="col-sm-1"><input type="text" class="form-control"  name="group_pro[num][]" value="1"></div><button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
        $(this).before(str);
        $('.select2').select2({})
    });


    $('.goback').click(function(){
        history.go(-1);
    });

    function message(returnData, $from) {
        alert(returnData.msg);
        if(returnData.state!= 'success'){
            alert(returnData.msg);
        }else{
            // window.location.reload();
        }
    }
</script>
</html>