<!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="form2" 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="submitBtn2">提交</button>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <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" style="color: red">购买刷新（钻石）*: </label>
                                <div class="col-sm-1">
                                    <input type="text" class="form-control"  name="refreshTimeDiamond" value="<?php echo $miningGameReward['refreshTimeDiamond']??10;?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label" style="color: red">转换比例*: </label>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label">金币*: </label>
                                <div class="col-sm-1">
                                    <input type="text" class="form-control"  name="reward[coins]" value="<?php echo $miningGameReward['reward']['coins'];?>">
                                </div>
                                <label class="col-sm-1 control-label">钱袋*: </label>
                                <div class="col-sm-1">
                                    <input type="text" class="form-control"  name="reward[purse]" value="<?php echo $miningGameReward['reward']['purse'];?>">
                                </div>
                                <label class="col-sm-1 control-label">石头*: </label>
                                <div class="col-sm-1">
                                    <input type="text" class="form-control"  name="reward[stone]" value="<?php echo $miningGameReward['reward']['stone'];?>">
                                </div>
                                <label class="col-sm-1 control-label">老鼠*: </label>
                                <div class="col-sm-1">
                                    <input type="text" class="form-control"  name="reward[mouse]" value="<?php echo $miningGameReward['reward']['mouse'];?>">
                                </div>
                                <label class="col-sm-1 control-label">体力*: </label>
                                <div class="col-sm-1">
                                    <input type="text" class="form-control"  name="reward[spins]" value="<?php echo $miningGameReward['reward']['spins'];?>">
                                </div>
                                <label class="col-sm-1 control-label">钻石*: </label>
                                <div class="col-sm-1">
                                    <input type="text" class="form-control"  name="reward[diamond]" value="<?php echo $miningGameReward['reward']['diamond']??0;?>">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label" style="color: red">等级倍率*: </label>
                                <div class="col-sm-8">
                                    <div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                        <?php foreach ($miningGameReward['rewardBet'] as $k => $row) { ?>
                                            <div class="form-group">
                                                <label class="col-sm-2 control-label">等级（min）*: </label>
                                                <div class="col-sm-2">
                                                    <input type="text" class="form-control" name="rewardBet[minLv][]" value="<?php echo $row['minLv'];?>">
                                                </div>
                                                <label class="col-sm-2 control-label">等级（max）*: </label>
                                                <div class="col-sm-2">
                                                    <input type="text" class="form-control" name="rewardBet[maxLv][]" value="<?php echo $row['maxLv'];?>">
                                                </div>
                                                <label class="col-sm-2 control-label">倍率*: </label>
                                                <div class="col-sm-1">
                                                    <input type="text" class="form-control"  name="rewardBet[bet][]" value="<?php echo $row['bet'];?>">
                                                </div>
                                                <button type="button" class="btn btn-danger deleteParent" >删除</button>
                                            </div>
                                        <?php } ?>
                                        <button type="button" class="btn btn-success addParent2" style="margin-left: 12px;margin-bottom: 10px;">增加</button>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group" >
                                <label class="col-sm-1 control-label" style="color: red">阶段奖励*: </label>
                                <div class="col-sm-8">
                                    <div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                        <div class="form-group">
                                            <?php foreach ($miningGameReward['rewardStage'] as $k => $row) { ?>
                                                <div class="container-fluid" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                                    <label class="col-sm-1 control-label">关卡*: </label>
                                                    <div class="col-sm-1">
                                                        <input type="text" class="form-control" name="rewardStage[<?php echo $row['levelId'];?>][levelId]" value="<?php echo $row['levelId'];?>">
                                                    </div>
                                                    <div class="col-sm-10">
                                                        <?php foreach ($row['props'] as $p) { ?>
                                                            <div class="form-group">
                                                                <label class="col-sm-1 control-label">道具: </label>
                                                                <div class="col-sm-3">
                                                                    <select class="form-control" name="rewardStage[<?php echo $row['levelId'];?>][propsId][]">
                                                                        <?php foreach ($idData as $propsId=>$props) { ?>
                                                                            <option value="<?php echo $propsId;?>" <?php if($p['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="rewardStage[<?php echo $row['levelId'];?>][num][]" value="<?php echo $p['num'];?>">
                                                                </div>
                                                                <button type="button" class="btn btn-danger deleteParent" >删除</button>
                                                            </div>
                                                        <?php } ?>
                                                        <button type="button" class="btn btn-success addParentStage" sid="<?php echo $row['levelId'];?>" style="margin-left: 12px;margin-bottom: 10px;">增加</button>
                                                    </div>
                                                </div>
                                            <?php } ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>
            </form>
        </aside>
    </div>

    <div class="container-fluid">
        <aside>
            <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data"  id="form" 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">
                                <a href="/#Config/miningGameConfig"><button type="button" class="btn btn-info">1-5关</button></a>
                                <a href="/#Config/miningGameConfig/1"><button type="button" class="btn btn-info">6-10关</button></a>
                                <a href="/#Config/miningGameConfig/2"><button type="button" class="btn btn-info">11-15关</button></a>
                                <a href="/#Config/miningGameConfig/3"><button type="button" class="btn btn-info">16-20关</button></a>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12">
                                <button type="button" class="btn btn-success" id="submitBtn">提交</button>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <?php foreach ($miningGameConfig as $key => $vl) {if($key < $pageMax && $pageMin <= $key){  ?>
                            <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">关卡*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control" readonly name="config[<?php echo $key;?>][lv]" value="<?php echo $vl['lv'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">目标值*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control" name="config[<?php echo $key;?>][target]" value="<?php echo $vl['target'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">游戏时长*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="config[<?php echo $key;?>][duration]" value="<?php echo $vl['duration'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">下钩速度*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="config[<?php echo $key;?>][hookDownSpeed]" value="<?php echo $vl['hookDownSpeed'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">钩子旋转速度*: </label>
                                    <div class="col-sm-1">
                                        <input type="number" placeholder="1.5-4" max="4" min="1.3" step="0.1" class="form-control"  name="config[<?php echo $key;?>][hookSpinSpeed]" value="<?php echo $vl['hookSpinSpeed'];?>">
                                    </div>
                                </div>
                                <div class="form-group" >
                                    <label class="col-sm-1 control-label">过关钻石价格*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control" name="config[<?php echo $key;?>][upLevelDiamond]" value="<?php echo $vl['upLevelDiamond'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">过关金币数量*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control" name="config[<?php echo $key;?>][diamondCoins]" value="<?php echo $vl['diamondCoins'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">复活价格(钻石)*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control" name="config[<?php echo $key;?>][resurrectionDiamond]" value="<?php echo $vl['resurrectionDiamond'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">复活时长(秒)*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control" name="config[<?php echo $key;?>][resurrectionTime]" value="<?php echo $vl['resurrectionTime'];?>">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-1 control-label" style="color: red">上钩速度*: </label>
                                </div>
                                <div class="form-group">
                                    <?php foreach ($mineralType as $x => $y) { ?>
                                        <label class="col-sm-1 control-label"><?php echo $y['name'];?>*: </label>
                                        <div class="col-sm-1">
                                            <input type="hidden" class="form-control"  name="config[<?php echo $key;?>][hookUpSpeed][<?php echo $x;?>][id]"    value="<?php echo $y['id'];?>">
                                            <input type="text"   class="form-control"  name="config[<?php echo $key;?>][hookUpSpeed][<?php echo $x;?>][speed]" value="<?php echo $vl['hookUpSpeed'][$y['id']]??0;?>">
                                        </div>
                                    <?php } ?>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-1 control-label" style="color: red">矿物数据*: </label>
                                    <div class="col-sm-8">
                                        <div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                            <?php foreach ($vl['mineralData'] as $k => $mineral) { ?>
                                                <div class="form-group">
                                                    <label class="col-sm-1 control-label">矿物*: </label>
                                                    <div class="col-sm-3">
                                                        <select class="form-control" name="config[<?php echo $key;?>][mineralData][<?php echo $k;?>][id]"">
                                                            <?php foreach ($mineralType as $x => $y) { ?>
                                                                <option value="<?php echo $y['id'];?>" <?php if($mineral['id'] == $y['id']) echo 'selected'; ?>><?php echo $y['name'];?></option>
                                                            <?php } ?>
                                                        </select>
                                                    </div>
                                                    <label class="col-sm-1 control-label">矿层*: </label>
                                                    <div class="col-sm-3">
                                                        <input type="text" class="form-control"  name="config[<?php echo $key;?>][mineralData][<?php echo $k;?>][floor]" value="<?php echo $mineral['floor'];?>">
                                                    </div>
                                                    <label class="col-sm-1 control-label">数量*: </label>
                                                    <div class="col-sm-2">
                                                        <input type="text" class="form-control"  name="config[<?php echo $key;?>][mineralData][<?php echo $k;?>][num]" value="<?php echo $mineral['num'];?>">
                                                    </div>
                                                    <button type="button" class="btn btn-danger deleteParent" >删除</button>
                                                </div>
                                            <?php } ?>
                                            <button type="button" class="btn btn-success addParent" pro="<?php echo $key;?>" k="<?php echo count($vl['mineralData']);?>" 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($mineralType); ?>');

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

        $('.addParent').on("click",function(){
            var pro = $(this).attr('pro');
            var k   = $(this).attr('k');
            var str = '';
            str += '<div class="form-group"><label class="col-sm-1 control-label">矿物*: </label><div class="col-sm-3"><select class="form-control" name="config['+pro+'][mineralData]['+k+'][id]">';
            for(var x in idData) {
                str += '<option value="'+idData[x]['id']+'">'+idData[x]['name']+'</option>';
            }
            str += '</select></div><label class="col-sm-1 control-label">矿层*: </label><div class="col-sm-3"><input type="text" class="form-control" name="config['+pro+'][mineralData]['+k+'][floor]" value="1">';
            str += '</div><label class="col-sm-1 control-label">数量*: </label><div class="col-sm-2"><input type="text" class="form-control"  name="config['+pro+'][mineralData]['+k+'][num]" value="1">'+
                '</div><button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).before(str);
            $(this).attr('k',Number(k)+1);
        });

        var propsData = JSON.parse('<?php echo json_encode($idData); ?>');
        $('.addParentStage').on("click",function(){
            var sid = $(this).attr('sid');
            var str = '';
            str += '<div class="form-group"><label class="col-sm-1 control-label">道具: </label><div class="col-sm-3"><select class="form-control" name="rewardStage['+sid+'][propsId][]">';
            for(var x in propsData) {
                str += '<option value="'+propsData[x]['id']+'">'+propsData[x]['name']+'</option>';
            }
            str += '</select></div><label class="col-sm-1 control-label">数量: </label><div class="col-sm-2"><input type="text" class="form-control"  name="rewardStage['+sid+'][num][]" value="1"></div><button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).before(str);
        });


        $('.addParent2').on("click",function(){
            var str = '<div class="form-group"><label class="col-sm-2 control-label">等级（min）*: </label><div class="col-sm-2"><input type="text" class="form-control" name="rewardBet[minLv][]" value=""></div><label class="col-sm-2 control-label">等级（max）*: </label><div class="col-sm-2"><input type="text" class="form-control" name="rewardBet[maxLv][]" value=""></div><label class="col-sm-2 control-label">倍率*: </label><div class="col-sm-1"><input type="text" class="form-control"  name="rewardBet[bet][]" value="1"></div><button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).before(str);
        });

        $('#submitBtn').click(function () {
            var data = new FormData(document.getElementById("form"));
            $.ajax({
                url: rootPath + 'Config/actionMiningGameConfig',
                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);
                }
            });
        });

        $('#submitBtn2').click(function () {
            var data = new FormData(document.getElementById("form2"));
            $.ajax({
                url: rootPath + 'Config/actionMiningGameRewardConfig',
                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>
