<!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="content_wrapper">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <a style="margin:5px;" class="btn btn-primary" href="#activity/config/16" role="button">任务配置(旧)</a>
                                    <a style="margin:5px;" class="btn btn-primary" href="#activity/config/16/1.6.9" role="button">任务配置(新)</a>
                                    <a style="margin:5px;" class="btn btn-primary " href="#config/treasurepro/" role="button">概率倍率配置</a>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>
    <div class="container-fluid">
        <aside>
            <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data"  id="goodForm" action="#" style="margin-top: 20px">
                <input type="hidden" class="form-control" name="id" value="<?php echo $id;?>">
                <input type="hidden" class="form-control" name="version" value="<?php echo $version;?>">
                <header><i class="fa fa-fw fa-file"></i>宝藏活动</header>
                <section>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
                                <button type="button" class="btn btn-success" id="goodsubmitBtn">提交</button>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <?php foreach ($list as $key => $vl) { ?>
                            <div class="row AllTypeControl" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                                <div class="form-group" >
                                    <label class="col-sm-1 control-label">任务ID*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control" readonly name="config[<?php echo $vl['id'];?>][id]" value="<?php echo $vl['id'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">任务类型*: </label>
                                    <div class="col-sm-2">
                                        <select class="form-control typeControl" name="config[<?php echo $vl['id'];?>][taskType]">
                                            <option value="1" <?php if($vl['taskType'] == "1") echo 'selected'; ?>>下注次数</option>
                                            <option value="2" <?php if($vl['taskType'] == "2") echo 'selected'; ?>>获得金币</option>
                                            <option value="3" <?php if($vl['taskType'] == "3") echo 'selected'; ?>>Bonus Wheel</option>
                                        </select>
                                    </div>
                                    <label class="col-sm-1 control-label">任务值*: </label>
                                    <div class="col-sm-2">
                                        <input type="text" class="form-control" placeholder="除了下注次数，其他都是倍率" name="config[<?php echo $vl['id'];?>][target]" value="<?php echo $vl['target'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">金卡*: </label>
                                    <div class="col-sm-2">
                                        <select class="form-control typeControl" name="config[<?php echo $vl['id'];?>][special]">
                                            <option value="0" <?php if($vl['special'] == "0") echo 'selected'; ?>>无</option>
                                            <option value="1" <?php if($vl['special'] == "1") echo 'selected'; ?>>随机5星金卡</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-1 control-label">道具奖励*: </label>
                                    <div class="col-sm-7">
                                        <div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">金币*: </label>
                                                <div class="col-sm-4">
                                                    <input type="text" class="form-control"  name="config[<?php echo $vl['id'];?>][coins]" value="<?php echo $vl['coins'];?>">
                                                </div>
                                                <label class="col-sm-2 control-label">体力*: </label>
                                                <div class="col-sm-4">
                                                    <input type="text" class="form-control"  name="config[<?php echo $vl['id'];?>][spins]" value="<?php echo $vl['spins'];?>">
                                                </div>
                                            </div>
                                            <?php foreach ($vl['props'] as $k => $reward) { ?>
                                                <div class="form-group">
                                                    <label class="col-sm-1 control-label">道具*: </label>
                                                    <div class="col-sm-2">
                                                        <select class="form-control" name="config[<?php echo $vl['id'];?>][props][propsId][<?php echo $k;?>]">
                                                            <?php foreach ($idData as $propsId=>$props) { ?>
                                                                <option value="<?php echo $propsId;?>" <?php if($reward['propsId'] == $propsId) echo 'selected'; ?>><?php echo $props['msg'];?></option>
                                                            <?php } ?>
                                                        </select>
                                                    </div>
                                                    <label class="col-sm-1 control-label">数量*: </label>
                                                    <div class="col-sm-2">
                                                        <input type="text" class="form-control"  name="config[<?php echo $vl['id'];?>][props][num][<?php echo $k;?>]" value="<?php echo $reward['num'];?>">
                                                    </div>
                                                    <?php
                                                        if($reward['propsId'] == 13){
                                                    ?>
                                                    <label class="col-sm-1 control-label">类型*: </label>
                                                    <div class="col-sm-2">
                                                        <select class="form-control" name="config[<?php echo $vl['id'];?>][props][type][<?php echo $k;?>]">
                                                            <option value="1" <?php if($reward['type'] == 1) echo 'selected'; ?>>固定金卡</option>
                                                            <option value="0" <?php if($reward['type'] == 0) echo 'selected'; ?>>随机金卡</option>
                                                        </select>
                                                    </div>
                                                    <?php
                                                        }
                                                    ?>
                                                    <button type="button" class="btn btn-danger deleteParent" >删除</button>
                                                </div>
                                            <?php } ?>
                                            <button type="button" class="btn btn-success addParent" gid="<?php echo $vl['id'];?>" style="margin-left: 12px;margin-bottom: 10px;">增加</button>
                                        </div>
                                    </div>
                                    <label class="col-sm-1 control-label">下注值*: </label>
                                    <div class="col-sm-3">
                                        <div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                            <?php foreach ($vl['bet'] as $k => $reward) { ?>
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label">下注*: </label>
                                                    <div class="col-sm-6">
                                                        <input type="text" class="form-control"  name="config[<?php echo $vl['id'];?>][bet][]" value="<?php echo $reward;?>">
                                                    </div>
                                                    <button type="button" class="btn btn-danger deleteParent" >删除</button>
                                                </div>
                                            <?php } ?>
                                            <button type="button" class="btn btn-success addBet" gid="<?php echo $vl['id'];?>" style="margin-left: 12px;margin-bottom: 10px;">增加</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </section>
            </form>
        </aside>
    </div>
</div>
</body>

<script>
    $(function () {
        var idData = JSON.parse('<?php echo json_encode($idData); ?>');

        $('.addOrDelControl').on("click",'.deleteParent',function(){
            $(this).parent().remove();
        });

        $('.addParent').on("click",function(){
            var gid = $(this).attr('gid');
            var str = "";
            str += '<div class="form-group"><label class="col-sm-2 control-label">道具*: </label><div class="col-sm-4"><select class="form-control" name="config['+gid+'][props][propsId][]"">';
            for(var x in idData) {
                str += '<option value="'+x+'">'+idData[x]['msg']+'</option>';
            }
            str += '</select></div><label class="col-sm-2 control-label">数量*: </label><div class="col-sm-2"><input type="text" class="form-control"  name="config['+gid+'][props][num][]" value="1">'+
                '</div><button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).before(str);
        });

        $('.addBet').on("click",function(){
            var gid = $(this).attr('gid');
            var str = "";
            str += '<div class="form-group"><label class="col-sm-2 control-label">下注*: </label><div class="col-sm-8"><input type="text" class="form-control"  name="config['+gid+'][bet][]" value="1"></div>';
            str += '<button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).before(str);
        });


        $('#goodsubmitBtn').click(function () {
            var data = new FormData(document.getElementById("goodForm"));
            $.ajax({
                url: rootPath + 'activity/actionConfig',
                type: 'POST',
                data: data,
                dataType: 'json',
                contentType: false, //必须
                processData: false, //必须
                success: function (data) {
                    alert(data.msg);
                    window.location.reload();
                },
                error: function (msg) {
                    alert(data.msg);
                }
            });
        });
    });
</script>
</html>
