<head>
<title>配置</title>
<link rel="stylesheet" href="<?php echo base_url();?>public/css/vendor/bootstrap/bootstrap-table.css">
<link rel="stylesheet" href="<?php echo base_url();?>public/css/vendor/bootstrap/table-fix-column.css">

<script src="<?php echo base_url();?>public/js/vendor/bootstrap/src/bootstrap-table.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap/src/table-fix-column.js"></script>

<!-- 最新版本的 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;
        }
        table {
            table-layout:fixed !important;
        }

        th{
            background: rgb(146, 208, 80);
        }

        td,th{
            max-width: 400px;
            word-wrap: break-word;
        }

        .table-hover > tbody > tr:hover {
            background-color: #c8bd6d;
        }

        input {
            width:60px;
        }

        #roleTable tr:nth-child(5n){
            background:rgb(198, 239, 206);
        } /**隔五行*/

        .fixed-table-toolbar {
            display: none;
        }
        .fileinput-button {
            position: relative;
            top: -5px;
        }

        .fileinput-button input{
            position:absolute;
            right: 0px;
            top: 0px;
            opacity: 0;
            -ms-filter: 'alpha(opacity=0)';
        }

    </style>
</head>

<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="form1" 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="submitBtn1">提交</button>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <?php if(!empty($list['gameProNew'])){ ?>
                        <?php foreach ($list['gameProNew'] as $k => $one) { ?>
                        <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="gameProNew[<?php echo $k;?>][id]" value="<?php echo $one['id'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">类型</label>
                                    <div class="col-sm-2">
                                        <select class="form-control" name="gameProNew[<?php echo $k;?>][type]">
                                        <?php foreach ($slotResult as $t=>$tname){?>
                                            <option value="<?php echo $t;?>" <?php if($t == $one['type']) echo 'selected'; ?>><?php echo $tname;?></option>
                                        <?php }?>
                                        </select>
                                    </div>
                                    <label class="col-sm-1 control-label">权重</label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control" name="gameProNew[<?php echo $k;?>][weight]" value="<?php echo $one['weight'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">倍率</label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control" readonly name="gameProNew[<?php echo $k;?>][bet]" value="1">
                                    </div>
                                </div>

                                <div class="form-group">
                                    <label class="col-sm-4 control-label">奖励</label>
                                    <div class="col-sm-12"><div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                    <?php if(!empty($one['ext'])){ ?>
                                        <?php foreach ($one['ext'] as $key => $reward) { ?>
                                        <div class="form-group speProps">
                                                <label class="col-sm-1 control-label">道具*: </label>
                                                <div class="col-sm-2">
                                                    <select class="form-control" name="gameProNew[<?php echo $k;?>][ext][<?php echo $key;?>][propsId]">
                                                        <?php foreach ($idData as $propsId=>$props) { ?>
                                                            <option value="<?php echo $propsId;?>" <?php if($reward['propsId'] == $propsId) 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="gameProNew[<?php echo $k;?>][ext][<?php echo $key;?>][num]" value="<?php echo $reward['num'];?>">
                                                </div>
                                                <label class="col-sm-1 control-label">取值类型*: </label>
                                                <div class="col-sm-2">
                                                    <select class="form-control" name="gameProNew[<?php echo $k;?>][ext][<?php echo $key;?>][rtype]">
                                                        <option value="1" <?php if($reward['rtype'] == 1) echo 'selected'; ?>>直接取值/金卡(不支持)</option>
                                                        <option value="2" <?php if($reward['rtype'] == 2) echo 'selected'; ?>>等级取值(仅支持金币)/随机金卡</option>
                                                    </select>
                                                </div>
                                                <label class="col-sm-1 control-label">皮肤id: </label>
                                                <div class="col-sm-2">
                                                    <select class="form-control" name="gameProNew[<?php echo $k;?>][ext][<?php echo $key;?>][skin]">
                                                        <option value="0">无</option>
                                                        <?php foreach ($chestSkin as $skin=>$name) { ?>
                                                            <option value="<?php echo $skin;?>" <?php if($reward['skin'] == $skin) echo 'selected'; ?>><?php echo $name;?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <button type="button" class="btn btn-danger deleteParent" >删除</button>
                                        </div>

                                        <?php } ?>
                                    <?php } ?>
                                     <button type="button" class="btn btn-success addParent" id="<?php echo $one['id'];?>" extlen="<?php echo count($one['ext']);?>" style="margin-left: 12px;margin-bottom: 10px;">增加</button>
                                    </div></div>
                                </div>

                        </div>
                        <?php } ?>
                        <?php } ?>

                    </div>
                </section>
            </form>
        </aside>
    </div>

    <!--    权重配置-->
    <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">
                        <?php if(!empty($list['gameProNewPay'])){ ?>
                            <?php foreach ($list['gameProNewPay'] as $k => $one) { ?>
                                <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="gameProNewPay[<?php echo $k;?>][id]" value="<?php echo $one['id'];?>">
                                        </div>
                                        <label class="col-sm-1 control-label">类型</label>
                                        <div class="col-sm-2">
                                            <select class="form-control" name="gameProNewPay[<?php echo $k;?>][type]">
                                                <?php foreach ($slotResult as $t=>$tname){?>
                                                    <option value="<?php echo $t;?>" <?php if($t == $one['type']) echo 'selected'; ?>><?php echo $tname;?></option>
                                                <?php }?>
                                            </select>
                                        </div>
                                        <label class="col-sm-1 control-label">权重</label>
                                        <div class="col-sm-1">
                                            <input type="text" class="form-control" name="gameProNewPay[<?php echo $k;?>][weight]" value="<?php echo $one['weight'];?>">
                                        </div>
                                        <label class="col-sm-1 control-label">倍率</label>
                                        <div class="col-sm-1">
                                            <input type="text" class="form-control" readonly name="gameProNewPay[<?php echo $k;?>][bet]" value="1">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">奖励</label>
                                        <div class="col-sm-12"><div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                                <?php if(!empty($one['ext'])){ ?>
                                                    <?php foreach ($one['ext'] as $key => $reward) { ?>
                                                        <div class="form-group speProps">
                                                            <label class="col-sm-1 control-label">道具*: </label>
                                                            <div class="col-sm-2">
                                                                <select class="form-control" name="gameProNewPay[<?php echo $k;?>][ext][<?php echo $key;?>][propsId]">
                                                                    <?php foreach ($idData as $propsId=>$props) { ?>
                                                                        <option value="<?php echo $propsId;?>" <?php if($reward['propsId'] == $propsId) 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="gameProNewPay[<?php echo $k;?>][ext][<?php echo $key;?>][num]" value="<?php echo $reward['num'];?>">
                                                            </div>
                                                            <label class="col-sm-1 control-label">取值类型*: </label>
                                                            <div class="col-sm-2">
                                                                <select class="form-control" name="gameProNewPay[<?php echo $k;?>][ext][<?php echo $key;?>][rtype]">
                                                                    <option value="1" <?php if($reward['rtype'] == 1) echo 'selected'; ?>>直接取值/金卡(不支持)</option>
                                                                    <option value="2" <?php if($reward['rtype'] == 2) echo 'selected'; ?>>等级取值(仅支持金币)/随机金卡</option>
                                                                </select>
                                                            </div>
                                                            <label class="col-sm-1 control-label">皮肤id: </label>
                                                            <div class="col-sm-2">
                                                                <select class="form-control" name="gameProNewPay[<?php echo $k;?>][ext][<?php echo $key;?>][skin]">
                                                                    <option value="0">无</option>
                                                                    <?php foreach ($chestSkin as $skin=>$name) { ?>
                                                                        <option value="<?php echo $skin;?>" <?php if($reward['skin'] == $skin) echo 'selected'; ?>><?php echo $name;?></option>
                                                                    <?php } ?>
                                                                </select>
                                                            </div>
                                                            <button type="button" class="btn btn-danger deleteParent2" >删除</button>
                                                        </div>

                                                    <?php } ?>
                                                <?php } ?>
                                                <button type="button" class="btn btn-success addParent2" id="<?php echo $one['id'];?>" extlen="<?php echo count($one['ext']);?>" style="margin-left: 12px;margin-bottom: 10px;">增加</button>
                                            </div></div>
                                    </div>

                                </div>
                            <?php } ?>
                        <?php } ?>

                    </div>
                </section>
            </form>
        </aside>
    </div>

    <!--    商品配置-->
    <div class="container-fluid">
        <aside>
            <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data"  id="form3" 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="submitBtn3">提交</button>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <?php if(!empty($goodsList)){ ?>
                        <?php foreach ($goodsList as $k => $one) { ?>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">gid</label>
                            <div class="col-sm-1">
                                <input type="text" class="form-control" readonly name="goodsListNew[<?php echo $one['gid'];?>][gid]" value="<?php echo $one['gid'];?>">
                                <input type="hidden" class="form-control" name="goodsListNew[<?php echo $one['gid'];?>][gtype]" value="113">
                            </div>
                            <label class="col-sm-1 control-label">价格/sku</label>
                            <div class="col-sm-3">
                                <select class="form-control skuListSel" name="goodsListNew[<?php echo $one['gid'];?>][price]">
                                    <?php foreach ($skuList as $tname){?>
                                        <option value="<?php echo $tname['price'];?>" <?php if($tname['sku'] == $one['sku']) echo 'selected'; ?>><?php echo $tname['price'];?></option>
                                    <?php }?>
                                </select>
                                <input type="text" class="form-control" readonly name="goodsListNew[<?php echo $one['gid'];?>][sku]" value="<?php echo $one['sku'];?>">
                            </div>
                            <label class="col-sm-1 control-label">奖励倍数</label>
                            <div class="col-sm-1">
                                <input type="text" class="form-control" name="goodsListNew[<?php echo $one['gid'];?>][bet]" value="<?php echo $one['bet'];?>">
                            </div>
                        </div>
                        <?php } ?>
                        <?php } ?>
                    </div>
                </section>
            </form>
        </aside>
    </div>
    <!--    等级金币配置-->
    <div class="container-fluid">
        <div class="row">
        <div class="col-sm-12">
        <aside>
            <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data"  id="form4" action="#" style="margin-top: 20px">
            <header><i class="fa fa-fw fa-file"></i>等级金币配置</header>
            <section>
                <div class="container-fluid">
                    <div class="row" style="padding-left: 15px;">
                        <span id="upfile_a" class="btn btn-success fileinput-button">
                            <span>导入</span>
                            <input type="file" id="upfile1">
                        </span>
                        <input type="button" style="display: none;margin-bottom: 10px;width: 80px;" class="btn btn-success" value="上传" id="upfileBtn1"/>
                        <a type="button" href="/Export/lvFruitBaseCoinsOut" style="margin-bottom: 10px;width: 80px;" class="btn btn-success">导出</a>
                    </div>
                </div>
                <div class="row">
                    <div class="col-sm-12">
                        <div class="table-responsive">
                            <table id="roleTable2" class="table table-bordered table-hover"
                                   data-toggle="table"
                                   data-classes="table table-hover"
                                   data-show-columns="true"
                                   data-striped="true"
                                   data-height="500">
                                <thead>
                                <tr>
                                    <th>用户等级</th>
                                    <th>金币</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                if(is_array($list['baseCoins'])  && !empty($list['baseCoins'])){
                                    foreach ($list['baseCoins'] as $key => $vl) { ?>
                                        <tr>
                                            <td><?php echo $vl['lv'];?></td>
                                            <td><?php echo $vl['coins'];?></td>

                                        </tr>
                                    <?php } } else{?>
                                    <tr>
                                        <td colspan="14">暂无数据</td>
                                    </tr>
                                <?php } ?>
                                </tbody>
                            </table>
                        </div>
                        <nav>
                            <ul class="pagination">
                                <li class="disabled"><a href="#">共<span class="pagetotal"><?php echo count($list['baseCoins']);?></span>条</a></li>
                            </ul>
                        </nav>
                    </div>
                </div>
            </section>
            </form>
        </aside>
        </div></div>
    </div>

    <div class="modal inmodal fade in" id="myModal5" tabindex="-1" role="dialog" aria-hidden="true" style="display: none;">
        <div class="modal-dialog modal-lg" style="width:1000px">
            <div class="modal-content" style="width: 100%;left: -15%;">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" onclick="closePrize()"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">奖励配置</h4>
                </div>
                <div class="modal-body" style="height: 600px;">
                    <!--                <from id="prize_from">-->
                    <table class="table table-bordered" id="prize_table">
                        <thead><tr class="ths"><th>奖励类型</th><th>是否固定</th><th>奖励值</th><th>皮肤</th></tr></thead>
                        <tbody id="prize_body">

                        </tbody>
                        <tbody>
                        <tr>
                            <td colspan="4" id="tds">
                                <div class="text-center">
                                    <botton class="btn btn-primary" id="addPrize" onclick="addPrize()">添加</botton>
                                    <botton class="btn btn-danger del-tr" onclick="delPrize()">删除</botton>
                                </div>
                            </td>
                        </tr>
                        </tbody></table>
                    <!--                </from>-->
                </div>
                <hr><hr>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal" onclick="closePrize()">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="scheduleSubmit()">保存</button>
                </div>
            </div>
        </div>
    </div>

</div>
<script src="<?php echo base_url();?>public/js/common.js"></script>
<script>
    var idData = JSON.parse('<?php echo json_encode($idData); ?>');
    // console.log(idData);
    var chestSkin = JSON.parse('<?php echo json_encode($chestSkin); ?>');
    var lvConfig = JSON.parse('<?php echo json_encode($lvList); ?>');
    var goodSku = JSON.parse('<?php echo json_encode($skuList); ?>');
    $('.addOrDelControl').on("click",'.deleteParent',function(){
        $(this).parent().remove();
    });
    $(document).on('change', '.skuListSel', function(e) {
        var this_selSku = e.currentTarget.parentElement;
        // $(this_selSku).empty();
        var tds = e.currentTarget.parentElement;
        var price = e.currentTarget.value;
        $.each(goodSku, function (k, v) {
            if (price == v["price"]) {
                sku = v["sku"];
            }
        });
        tds.children[1].value = sku;

        // console.log(this_selSku);
    });

    $('.addParent').on("click",function(){
        var id = $(this).attr('id')-1;
        var len =$(this).parent(".addOrDelControl").children('.speProps').length;
        var typ = $('select[name="gameProNew['+id+'][type]"]').val();
        if (typ!=3){
            alert("特殊奖励才支持配置");
            return
        }
        var str = "";
        str += '<div class="form-group speProps">';
        str +='<label class="col-sm-1 control-label">道具*: </label><div class="col-sm-2"><select class="form-control" name="gameProNew['+id+'][ext]['+len+'][propsId]"">';
        for(var x in idData) {
            str += '<option value="'+x+'">'+idData[x]['name']+'</option>';
        }
        str += '</select></div>';

        str +='<label class="col-sm-1 control-label">数量*: </label><div class="col-sm-1"><input type="text" class="form-control"  name="gameProNew['+id+'][ext]['+len+'][num]" value="1"></div>';

        str +='<label class="col-sm-1 control-label">取值类型*: </label><div class="col-sm-1">';
        str +='<select class="form-control" name="gameProNew['+id+'][ext]['+len+'][rtype]"><option value="1" >直接取值/金卡(不支持)</option><option value="2">等级取值(仅支持金币)/随机金卡</option></select>';
        str +='</div>';

        str +='<label class="col-sm-1 control-label">皮肤id*: </label><div class="col-sm-2"><select class="form-control" name="gameProNew['+id+'][ext]['+len+'][skin]"">';
        str +='<option value="0">无</option>';
        for(var x in chestSkin) {
            str += '<option value="'+x+'">'+chestSkin[x]+'</option>';
        }
        str += '</select></div>';

        str +='<button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
        // $(this).attr("extlen",len);
        $(this).before(str);
    });

    $('.addParent2').on("click",function(){
        var id = $(this).attr('id')-1;
        var len =$(this).parent(".addOrDelControl2").children('.speProps').length;
        var typ = $('select[name="gameProNewPay['+id+'][type]"]').val();
        if (typ!=3){
            alert("特殊奖励才支持配置");
            return
        }
        var str = "";
        str += '<div class="form-group speProps">';
        str +='<label class="col-sm-1 control-label">道具*: </label><div class="col-sm-2"><select class="form-control" name="gameProNewPay['+id+'][ext]['+len+'][propsId]"">';
        for(var x in idData) {
            str += '<option value="'+x+'">'+idData[x]['name']+'</option>';
        }
        str += '</select></div>';

        str +='<label class="col-sm-1 control-label">数量*: </label><div class="col-sm-1"><input type="text" class="form-control"  name="gameProNewPay['+id+'][ext]['+len+'][num]" value="1"></div>';

        str +='<label class="col-sm-1 control-label">取值类型*: </label><div class="col-sm-1">';
        str +='<select class="form-control" name="gameProNewPay['+id+'][ext]['+len+'][rtype]"><option value="1" >直接取值/金卡(不支持)</option><option value="2">等级取值(仅支持金币)/随机金卡</option></select>';
        str +='</div>';

        str +='<label class="col-sm-1 control-label">皮肤id*: </label><div class="col-sm-2"><select class="form-control" name="gameProNewPay['+id+'][ext]['+len+'][skin]"">';
        str +='<option value="0">无</option>';
        for(var x in chestSkin) {
            str += '<option value="'+x+'">'+chestSkin[x]+'</option>';
        }
        str += '</select></div>';

        str +='<button type="button" class="btn btn-danger deleteParent2" >删除</button></div>';
        // $(this).attr("extlen",len);
        $(this).before(str);
    });


    $('#submitBtn1').click(function () {
        var data = new FormData(document.getElementById("form1"));
        $.ajax({
            url: rootPath + 'Config/SaveFruitNewCfg/gameProNew',
            type: 'POST',
            data: data,
            dataType: 'json',
            contentType: false, //必须
            processData: false, //必须
            success: function (data) {
                console.log(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/SaveFruitNewCfg/gameProNewPay',
            type: 'POST',
            data: data,
            dataType: 'json',
            contentType: false, //必须
            processData: false, //必须
            success: function (data) {
                console.log(data);
                alert(data.msg);
                // window.location.reload();
            },
            error: function (msg) {
                alert(data.msg);
            }
        });
    });


    $('#submitBtn3').click(function () {
        var data = new FormData(document.getElementById("form3"));
        $.ajax({
            url: rootPath + 'Config/SaveFruitNewCfg/goodsListNew',
            type: 'POST',
            data: data,
            dataType: 'json',
            contentType: false, //必须
            processData: false, //必须
            success: function (data) {
                // console.log(data);
                alert(data.msg);
                window.location.reload();
            },
            error: function (msg) {
                alert(data.msg);
            }
        });
    });
    // ========================等级配置=========================
    var prize_num=0;
    var this_index=1;
    var this_lv=0;
    initLvConfig();
    function initLvConfig(){
        var html="";
        $.each(lvConfig,function(k,v){
            html+='<tr class="lvcfgTr">';
            html+='<td readonly class="thislv">'+v["lv"]+'</td>';
            html+="<td>"+v["maxExp"]+"</td>";
            $.each(v["upCeCfg"],function(key,val){
                html+="<td>"+val["ce"]+"</td>";
            });
            html+='<td class="rewardshow_'+v["lv"]+'">';
            html+=getRewardShowHtml(v["lvRewardCfg"]);
            $.each(v["lvRewardCfg"],function(key,val){
                v["lvRewardCfg"][key]["id"]=key+1;
            });
            html+="</td>";
            dataStr=JSON.stringify(v["lvRewardCfg"]);
            console.log(dataStr);
            html+='<td><input name="lvRewardCfg" type="hidden" id="reward_'+v["lv"]+'" value="'+escape(dataStr)+'"><button type="button" class="btn btn-danger" onclick="showReward('+v["lv"]+')">编辑</button></td>';
            html+="</tr>";
        });
        $(".lvConfig").html(html)
    }
    function closePrize() {
        $('#myModal5').removeClass('in');
        $('#myModal5').hide();
    }
    function showReward(lv){
        this_lv = lv;
        prize_num=0;
        prizeStr=$("#reward_"+this_lv).val();
        console.log(prizeStr);
        if (prizeStr!=null&&prizeStr!=""){
            str =unescape(prizeStr);
            prize = JSON.parse(str);
            console.log(11111,prize);
            // prize = eval('(' + str + ')');
            // console.log(22222,prize);
            $('#myModal5').addClass('in');
            $('#myModal5').show();
            $('#prize_body').children("tr").remove();
            for(var i=0;i<prize.length;i++){
                prize_num++;
                d = prize[i];
                // console.log(prize[i]);
                var html = prizeInfoTR(d);
                $("#prize_body").append(html);
            }
        }
    }
    // 等级奖励配置
    function prizeInfoTR(data,index=0){
        var w ='';
        if(index>0){
            var w = 'style="width: 100%"';
        }
        var html='';
        var sel2 ='';
        var sel3 ='';
        html+='<tr id="prize_'+data['id']+'">';
        html+='<input type="hidden" name="id" value="'+data['id']+'">';
        html +='<td><select class="form-control"  name="propsId">';//prize['+data['prize']['id']+']
        $.each(idData,function(k,v){
            if(data['propsId']==v["id"]){
                sel = "selected";
            }else{
                sel = "";
            }
            html +='<option value="'+v["id"]+'" '+sel+'>'+v["name"]+'</option>';
        });
        html +='</select></td>';
        html +='<td><select class="form-control" name="rtype">';
        if(data['rtype']==1){
            sel2 = "selected";
        }else{
            sel3 = "selected";
        }
        html +='<option value="1" '+sel2+'>固定值</option>';
        html +='<option value="2" '+sel3+'>等级取值</option>';
        html +='</select></td>';
        html +='<td><input type="text" class="form-control" name="num" value="'+data['num']+'" '+w+'></td>';
        html +='<td><select class="form-control" name="skin"><option  value="0">无</option>';
        $.each(chestSkin,function(k,v){
            if(data['skin']==k){
                var sel = "selected";
            }else{
                var sel = "";
            }
            html +='<option '+sel+' value="'+k+'">'+v+'</option>';
        });
        html +='</select></td>';
        html +='</tr>';
        return html;
    }
    function getRewardShowHtml(prize_show_arr) {
        var html="";
        $.each(prize_show_arr,function(key,val){
            if (val["skin"]!=0){
                text = "皮肤"+val["skin"];
            }else if(val["rtype"]==2&&val["propsId"]==14){
                text = val["num"]+"倍"
            }else{
                text = val["num"]
            }
            html+='<span class="btn btn-outline btn-success btn-xl">'+idData[val["propsId"]]["name"]+':'+text+'</span>';
        });
        return html;
    }
    function addPrize() {
        stage = 1;
        prize_num++;
        var data ={"id":prize_num,"propsId":0,"num":1,"rtype":1,"skin":0};
        console.log(stage);
        var html = prizeInfoTR(data,this_index);
        $("#prize_body").append(html);
    }
    function delPrize() {
        if(prize_num>0){
            // console.log(prize_num);
            $("#prize_body").children("tr:last-child").remove();
            prize_num--;
        }
    }
    function scheduleSubmit() {
        var str = '';
        // console.log(prize_num);
        for(var i=1;i<=prize_num;i++){
            data = serializeForm("prize_"+i);
            // console.log(data);
            str +=data+",";
        }
        str="["+str.slice(0,str.length-1)+"]";
        var prize_show_arr = JSON.parse(str);
        dataStr=JSON.stringify(prize_show_arr);
        console.log("prize_show_arr:",prize_show_arr);
        $("#reward_"+this_lv).val(dataStr);
        //todo 设置显示
        html = getRewardShowHtml(prize_show_arr);
        console.log(html);
        $(".rewardshow_"+this_lv).html(html);

        $('.lvcfgTr').css("background","#fff");
        $(".rewardshow_"+this_lv).parent('.lvcfgTr').css("background","#fdf59a");
        selLv = this_lv
        closePrize();
        if($('#commitBtn').prop('disabled')){
            $('#commitBtn').attr('disabled', false);
        }
    }
    //============================================================
    $("#upfile_a").on("change", "input[type='file']", function() {
        var filePath = $(this).val();
        //如果仅上传图片 if(filePath.indexOf("jpg") != -1 || filePath.indexOf("png") != -1) {
        if (filePath) {
            $('#upfile_a').hide();
            $("#upfileBtn1").show();
        } else {
            return false
        }
    });
    $("#upfile_b").on("change", "input[type='file']", function() {
        var filePath = $(this).val();
        //如果仅上传图片 if(filePath.indexOf("jpg") != -1 || filePath.indexOf("png") != -1) {
        if (filePath) {
            $('#upfile_b').hide();
            $("#upfileBtn").show();
        } else {
            return false
        }
    });
    //导入金币配置
    $("#upfileBtn1").click(function(){
        var formData = new FormData();
        formData.append("file",document.getElementById("upfile1").files[0]);
        $.ajax({
            type: "POST", // 数据提交类型
            url: "Import/lvFruitBaseCoinsIn", // 发送地址
            data: formData, //发送数据
            async: true, // 是否异步
            processData: false, //processData 默认为false，当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
            contentType: false, //
            success: function(data) { // 成功回调
                data = JSON.parse(data);
                if(data.ret == 0){
                    // console.log(data)
                    alert(data.msg);
                    window.location.reload();
                }else {
                    // msgTip = $('#msg-tip');
                    alert(data.msg);
                    // window.location.reload();
                }
            }
        });
    });

    $("#upfile_b").on("change", "input[type='file']", function() {
        var filePath = $(this).val();
        //如果仅上传图片 if(filePath.indexOf("jpg") != -1 || filePath.indexOf("png") != -1) {
        if (filePath) {
            $('#upfile_a').hide();
            $("#upfileBtn1").show();
        } else {
            return false
        }
    });
    //导入等级配置
    $("#upfileBtn").click(function(){
        var formData = new FormData();
        formData.append("file",document.getElementById("upfile").files[0]);
        $.ajax({
            type: "POST", // 数据提交类型
            url: "Import/lvFruitGameCfgIn", // 发送地址
            data: formData, //发送数据
            async: true, // 是否异步
            processData: false, //processData 默认为false，当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
            contentType: false, //
            success: function(data) { // 成功回调
                data = JSON.parse(data);
                if(data.ret == 0){
                    // console.log(data)
                    alert(data.msg);
                    window.location.reload();
                }else {
                    alert(data.msg);
                    // window.location.reload();
                }
            }
        });
    });

</script>

<script type="text/javascript">

    //获取指定form中的所有的<input>对象
    function getElements(formId) {
        var form = document.getElementById(formId);
        var elements = new Array();
        var tagElements = form.getElementsByTagName('input');
        var tagElements2 = form.getElementsByTagName('select');
        for (var j = 0; j < tagElements.length; j++){
            elements.push(tagElements[j]);
        }
        for (var i = 0; i < tagElements2.length; i++){
            elements.push(tagElements2[i]);
        }
        return elements;
    }

    //获取单个input中的【name,value】数组
    function inputSelector(element) {
        if (element.checked)
            return [element.name, element.value];
    }

    function input(element) {
        switch (element.type.toLowerCase()) {
            case 'submit':
            case 'hidden':
            case 'password':
            case 'text':
                return [element.name, element.value];
            case 'checkbox':
            case 'select-one':
                return [element.name, element.value];
            case 'radio':
                return inputSelector(element);
        }
        return false;
    }

    //组合URL
    function serializeElement(element) {
        var parameter = input(element);

        if (parameter) {
            var key = encodeURIComponent(parameter[0]);
            if (key.length == 0) return;

            if (parameter[1].constructor != Array)
                parameter[1] = [parameter[1]];

            var values = parameter[1];
            var results ='';
            for (var i=0; i<values.length; i++) {
                results +='"'+parameter[0]+'":"'+encodeURIComponent(values[i])+'",';
                // results[parameter[0]] = encodeURIComponent(values[i]);
            }
            return results;

        }
    }

    //调用方法
    function serializeForm(formId) {
        var elements = getElements(formId);
        // var queryComponents = new Array();
        var queryComponents ='';
        for (var i = 0; i < elements.length; i++) {
            var queryComponent = serializeElement(elements[i]);
            if (queryComponent)
                queryComponents += queryComponent;
            // queryComponents.push(queryComponent);
        }
        queryComponents = queryComponents.slice(0,queryComponents.length-1);
        queryComponents = '{'+queryComponents+'}';
        return queryComponents;
    }
</script>

<script>
    var selLv=0;
    $('#roleTable').on('dblclick','td',function(){
        // console.log(111111);
        selLv = parseInt($(this).parent('.lvcfgTr').find('.thislv').html());
        $('.lvcfgTr').css("background","#fff");
        $(this).parent('.lvcfgTr').css("background","#fdf59a");

        var _this = $(this),//保存td
            tdText = _this.text();
        var  cellIndex =  _this[0].cellIndex;
        if(cellIndex == 0) {return false;} //点击操作列不可编辑
        if(!_this.is('.input')){
            _this.addClass('input').html('<input type="text" value="'+ tdText +'" />').find('input').focus().blur(function(){
                var _input = $(this); //保存input对象
                var thisvalue = $(this).val();
                _input.parent().removeClass('input').html(thisvalue || '');
                if($('#commitBtn').prop('disabled')){
                    $('#commitBtn').attr('disabled', false);
                }
            });
        }

    });


    $('#roleTable').on('blur', '.add-row', function () {
        // console.log(22222);
        var _that = $(this);
        var thisval = _that.find('input').val();
        _that.removeClass('input').html(thisval || 0);
    });
    //提交表格数据
    $('#commitBtn').click(function () {
        var tableContent = $('#roleTable').html(),
            msgTip = $('#msg-tip');
        //如果还有添加未编辑的，则不能提交
        if($('#roleTable td').hasClass('input')){
            msgTip.messager().warn('列表中还有未编辑的');
            return;
        }

        var tr = $('#roleTable tr');
        var arr = [];
        // for (var i = 1; i < tr.length; i++) {
            var tempData = {};
            var arrayTemp =[];
            td = $(tr[selLv]).find('td');
            // lv=parseInt($(td[0]).html());
            // console.log(lv,selLv);
            for (var j = 0; j < td.length; j++) {
                switch (j) {
                    case 0:
                        tempData['lv'] = parseInt($(td[j]).html());
                        break;
                    case 1:
                        tempData['maxExp'] = parseInt($(td[j]).html());
                        break;
                    case 2:
                        one ={"id":1,"ce":parseFloat($(td[j]).html())};
                        arrayTemp.push(one);
                        break;
                    case 3:
                        one ={"id":2,"ce":parseFloat($(td[j]).html())};
                        arrayTemp.push(one);
                        break;
                    case 4:
                        one ={"id":3,"ce":parseFloat($(td[j]).html())};
                        arrayTemp.push(one);
                        // arrayTemp['3'] = parseFloat($(td[j]).html());
                        break;
                    case 5:
                        one ={"id":4,"ce":parseFloat($(td[j]).html())};
                        arrayTemp.push(one);
                        // arrayTemp['4'] = parseFloat($(td[j]).html());
                        break;
                    case 6:
                        one ={"id":5,"ce":parseFloat($(td[j]).html())};
                        arrayTemp.push(one);
                        // arrayTemp['5'] = parseFloat($(td[j]).html());
                        break;
                    case 7:
                        one ={"id":6,"ce":parseFloat($(td[j]).html())};
                        arrayTemp.push(one);
                        // arrayTemp['6'] = parseFloat($(td[j]).html());
                        break;
                    case 8:
                        one ={"id":7,"ce":parseFloat($(td[j]).html())};
                        arrayTemp.push(one);
                        // arrayTemp['7'] = parseFloat($(td[j]).html());
                        break;
                    case 9:
                        one ={"id":8,"ce":parseFloat($(td[j]).html())};
                        arrayTemp.push(one);
                        // arrayTemp['8'] = parseFloat($(td[j]).html());
                        break;
                    case 10:
                        one ={"id":9,"ce":parseFloat($(td[j]).html())};
                        arrayTemp.push(one);
                        // arrayTemp['9'] = parseFloat($(td[j]).html());
                        break;
                    case 11:
                        one ={"id":10,"ce":parseFloat($(td[j]).html())};
                        arrayTemp.push(one);
                        // arrayTemp['10'] = parseFloat($(td[j]).html());
                        break;
                    case 12:
                        one ={"id":11,"ce":parseFloat($(td[j]).html())};
                        arrayTemp.push(one);
                        // arrayTemp['11'] = parseFloat($(td[j]).html());
                        break;
                    case 13:
                        one ={"id":12,"ce":parseFloat($(td[j]).html())};
                        arrayTemp.push(one);
                        // arrayTemp['12'] = parseFloat($(td[j]).html());
                        break;
                }
                tempData['reward'] =JSON.parse(unescape($("#reward_"+tempData['lv']).val()));
            }
            tempData['data'] = arrayTemp;
            // arr.push(tempData);
        // }
        console.log(tempData);
        $.ajaxSetup({
            async: true
        });


        $.ajax({
            type: 'POST',
            dataType: 'json',
            data:{
                data: JSON.stringify(tempData)
            },
            url:'config/SaveFruitLvCfg',
            success: function(data){
                if(data.ret == 0){
                    // console.log(data)
                    alert(data.msg);
                    // window.location.reload();
                    // $('#commitBtn').attr('disabled', true);
                }else{
                    alert(data.msg);
                }
            }
        });
    });
</script>