<!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">
        <aside>
            <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data"  id="goodForm" action="#" style="margin-top: 20px">
                <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>
                                <button type="button" class="btn btn-danger" id="addChest">新增宝箱</button>
                                <button type="button" class="btn btn-info importBtn" data-href="/import/chestSkinBasic">导入宝箱基础配置</button>
                                <button type="button" class="btn btn-info importBtn" data-href="/import/chestSkinRewards/14">导入宝箱金币配置</button>
                                <button type="button" class="btn btn-info importBtn" data-href="/import/chestSkinRewards/15">导入宝箱体力配置</button>
                                <button type="button" class="btn btn-info importBtn" data-href="/import/chestSkinRewards/8">导入宝箱宠物经验配置</button>
                                <button type="button" class="btn btn-info importBtn" data-href="/import/chestSkinProbs">导入宝箱概率配置</button>

                                <button type="button" class="btn btn-primary exportBtn" data-href="/export/chestSkinBasic">导出宝箱基础配置</button>
                                <button type="button" class="btn btn-primary exportBtn" data-href="/export/chestSkinRewards/14">导出宝箱金币配置</button>
                                <button type="button" class="btn btn-primary exportBtn" data-href="/export/chestSkinRewards/15">导出宝箱体力配置</button>
                                <button type="button" class="btn btn-primary exportBtn" data-href="/export/chestSkinRewards/8">导出宝箱宠物经验配置</button>
                                <button type="button" class="btn btn-primary exportBtn" data-href="/export/chestSkinProbs">导出宝箱概率配置</button>
                            </div>
                        </div>
                    </div>
                    <input type="file"  id="importFiles" name="files" style="display: none">
                    <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="good[<?php echo $vl['id'];?>][id]" value="<?php echo $vl['id'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">宝箱皮肤资源ID*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="good[<?php echo $vl['id'];?>][skinResourceId]" value="<?php echo $vl['skinResourceId'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">宝箱名称*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="good[<?php echo $vl['id'];?>][name]" value="<?php echo $vl['name'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">卡片数量*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="good[<?php echo $vl['id'];?>][card]" value="<?php echo $vl['reward'][17]['num'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">小丑卡兑换数量: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="good[<?php echo $vl['id'];?>][joker]" value="<?php echo $vl['reward'][18]['num'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">宠物粮食: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="good[<?php echo $vl['id'];?>][food]" value="<?php echo $vl['reward'][9]['num']??0;?>">
                                    </div>
                                </div>
                                <div class="form-group" >

                                </div>
                                <div class="form-group">
<!--                                    <label class="col-sm-1 control-label"><button type="button" class="btn btn-success showHide">金币配置</button></label>-->
<!--                                    <div class="col-sm-5" style="display: none">-->
<!--                                        <div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">-->
<!--                                            --><?php //foreach ($vl['reward'][14]['pro'] as $k => $reward) { ?>
<!--                                                <div class="form-group">-->
<!--                                                    <label class="col-sm-2 control-label">数量*: </label>-->
<!--                                                    <div class="col-sm-2">-->
<!--                                                        <input type="text" class="form-control"  name="good[--><?php //echo $vl['id'];?><!--][coins][num][]" value="--><?php //echo $reward['num'];?><!--">-->
<!--                                                    </div>-->
<!--                                                    <label class="col-sm-2 control-label">概率*: </label>-->
<!--                                                    <div class="col-sm-2">-->
<!--                                                        <input type="text" class="form-control"  name="good[--><?php //echo $vl['id'];?><!--][coins][v][]" value="--><?php //echo $reward['v'];?><!--">-->
<!--                                                    </div>-->
<!--                                                    <button type="button" class="btn btn-danger deleteParent" >删除</button>-->
<!--                                                </div>-->
<!--                                            --><?php //} ?>
<!--                                            <button type="button" class="btn btn-success addParent" id="--><?php //echo $vl['id'];?><!--" style="margin-left: 12px;margin-bottom: 10px;">增加</button>-->
<!--                                        </div>-->
<!--                                    </div>-->

                                    <label class="col-sm-1 control-label"><a href="/#config/chestWeight/2/14/<?php echo $vl['id'];?>" target="_blank" type="button" class="btn btn-success">金币奖励配置</a></label>
                                    <label class="col-sm-1 control-label"><a href="/#config/chestWeight/2/15/<?php echo $vl['id'];?>" target="_blank" type="button" class="btn btn-success">体力奖励配置</a></label>
                                    <label class="col-sm-1 control-label"><a href="/#config/chestWeight/2/8/<?php echo $vl['id'];?>" target="_blank" type="button" class="btn btn-success">宠物经验配置</a></label>
                                    <label class="col-sm-1 control-label"><a href="/#config/cardTypePro/<?php echo $vl['id'];?>" target="_blank" type="button" class="btn btn-success">宝箱概率配置</a></label>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </section>
            </form>
        </aside>
    </div>
</div>
</body>

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

        $('.addParent').on("click",function(){
            var id = $(this).attr('id');
            var str = "";
            str += '<div class="form-group"><label class="col-sm-2 control-label">数量*: </label><div class="col-sm-2"><input type="text" class="form-control"  name="good['+id+'][coins][num][]" value="1">'
            str += '</div><label class="col-sm-2 control-label">概率*: </label><div class="col-sm-2"><input type="text" class="form-control" name="good['+id+'][coins][v][]" value="1"></div><button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).before(str);
        });

        $('.spinsNum').on("click",function(){
            var id = $(this).attr('id');
            var str = "";
            str += '<div class="form-group"><label class="col-sm-2 control-label">数量*: </label><div class="col-sm-2"><input type="text" class="form-control"  name="good['+id+'][spins][num][]" value="1">'
            str += '</div><label class="col-sm-2 control-label">概率*: </label><div class="col-sm-2"><input type="text" class="form-control" name="good['+id+'][spins][v][]" value="1"></div><button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).before(str);
        });

        $('.petExp').on("click",function(){
            var id = $(this).attr('id');
            var str = "";
            str += '<div class="form-group"><label class="col-sm-2 control-label">数量*: </label><div class="col-sm-2"><input type="text" class="form-control"  name="good['+id+'][exp][num][]" value="1">'
            str += '</div><label class="col-sm-2 control-label">概率*: </label><div class="col-sm-2"><input type="text" class="form-control" name="good['+id+'][exp][v][]" value="1"></div><button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).before(str);
        });

        $('.showHide').on("click",function(){
            if($(this).parent().next().css("display") == "block"){
                $(this).parent().next().hide(300);
            }else{
                $(this).parent().next().show(300);
            }
        });

        $('#goodsubmitBtn').click(function () {
            var data = new FormData(document.getElementById("goodForm"));
            $.ajax({
                url: rootPath + 'config/actionChestSkin',
                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);
                }
            });
        });
        $('#addChest').click(function () {
            var name = prompt("请输入新增宝箱的名字","测试宝箱");
            if(name) {
                $.post('/config/actionAddChestSkin',{
                    name:name
                },function (data) {
                    data = JSON.parse(data);
                    alert(data.msg);
                    window.location.reload();
                });
            }
        });



    });
    $('.importBtn').click(function(){
        $('#importFiles').click()
        $('#importFiles').data('href', $(this).data('href'))
    })
    $('#importFiles').change(function(){
        var url = $(this).data('href');
        console.log(url)
        var formData = new FormData();
        formData.append("file",document.getElementById("importFiles").files[0]);
        $(this).val('');
        showLoading()
        $.ajax({
            type: "POST", // 数据提交类型
            url: url, // 发送地址
            data: formData, //发送数据
            async: true, // 是否异步
            processData: false, //processData 默认为false，当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
            contentType: false, //
            success: function(data) { // 成功回调
                hideLoading()
                data = JSON.parse(data);
                alert(data.msg);
                if(data.ret > 0){
                    window.location.reload();
                }
            }
            ,error: function(xhr,err) { // 成功回调
                hideLoading()
                console.log(xhr,err)
                alert('上传失败');
            }
        });
    })

    $('.exportBtn').click(function(){
        window.open( $(this).data('href'))
    })

</script>
</html>
