<div class="content_wrapper">
    <style>
        .btn-name {
            white-space: nowrap;
        }
    </style>
    <div class="container-fluid">
        <div id="msg-tip"></div>
        <div class="row">

            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>奖励转盘配置</header>
                    <section>
                        <div class="container-fluid">
                            <a class="btn btn-primary"  href="/export/adSlotGroupRewards" target="_blank">导出</a>
                            <button type="button" class="btn btn-outline btn-success" onclick="$('#import-file').click()"  >导入</button>
                            <input type="file" style="display: none" id="import-file">
                        </div>
                        <hr>
                        <div class="container-fluid">
                            <?php foreach ($list as $item){ ?>
                                <div class="">
                                    <table class=" table table-bordered"  id=""  style="margin:10px;padding:5px;border:solid 1px goldenrod;">
                                        <tr>
                                            <th width="100">等级区间</th>
                                            <th width="300">
                                                <div class="input-group">

                                                    <input class="form-control" readonly value="<?=$item['condition']['level']['start']?>" style="width: 45%">
                                                    <input class="form-control" readonly value="<?=$item['condition']['level']['end']?>" style="width: 45%">
                                                </div>
                                            </th>
                                            <th width="300">数数分组</th>
                                            <th width="300">
                                                <select class="form-control select2" multiple>
                                                    <?php  foreach ($ssGroups as $id => $group){?>
                                                        <option value='<?=$id?>' <?php if(in_array($id, $item['condition']['shushu']['shushu']))echo 'selected'?> ><?=$group?></option>";
                                                    <?php }?>
                                                </select>
                                            </th>
                                            <th style="vertical-align: middle;text-align: center;">
                                                <span style="cursor: pointer" data-id="<?=$item['group_id']?>" data-status="show" onclick="$('#adRewards-<?=$item['group_id']?>').slideToggle()">+/-</span>
                                            </th>
                                        </tr>

                                        <tbody id="adRewards-<?=$item['group_id']?>">
                                            <?php foreach ($item['reward_list'] as $rewardList){ ?>
                                                <tr>
                                                    <th style="vertical-align: middle;text-align: center;background: #7A7A7A" colspan="5">
                                                        层级：<?=$rewardList['stage']?>
                                                    </th>
                                                </tr>
                                                <tr>
                                                    <th>ID</th>
                                                    <th>权重</th>
                                                    <th>是否是最终大奖</th>
                                                    <th>最低旋转次数</th>
                                                    <th>奖品</th>
                                                </tr>
                                                <?php foreach ($rewardList['info'] as $rewardItem){ ?>
                                                    <tr>
                                                        <td>
                                                            <input readonly class="form-control" value="<?=$rewardItem['id']?>" >
                                                        </td>
                                                        <td>
                                                            <input readonly class="form-control" value="<?=$rewardItem['pro']?>" >
                                                        </td>
                                                        <td>
                                                            <select readonly class="form-control" value="<?=$rewardItem['pro']?>" >
                                                                <option value="0" <?php if($rewardItem['isMax'] == 0) echo 'selected';?> >否</option>
                                                                <option value="1" <?php if($rewardItem['isMax'] == 1) echo 'selected';?> >是</option>
                                                            </select>
                                                        </td>
                                                        <td>
                                                            <input readonly class="form-control" value="<?=$rewardItem['lowestSpend']?>" >
                                                        </td>
                                                        <td class="formPropsRewardsTag" data-value='<?= json_encode($rewardItem["prize"]) ?>' data-name="props"></td>
                                                    </tr>
                                                <?php } ?>
                                            <?php } ?>
                                        </tbody>
                                    </table>
                                </div>
                            <?php }?>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>
</div>
<script src="<?php echo base_url(); ?>public/js/common.js"></script>
<!--select2-->
<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/select2/select2.min.css">
<script src="<?php echo base_url();?>public/js/vendor/select2/select2.full.min.js"></script>
<script>
    propsJs.initTag('formPropsRewardsTag')
    $('.select2').select2({})

    $('#import-file').change(function () {
        let _this = $(this)
        let filePath = _this.val();
        let href = '/import/adSlotGroupRewards'
        if (filePath) {
            let formData = new FormData();
            formData.append("file",document.getElementById('import-file').files[0]);
            showLoading()
            $.ajax({
                type: "POST", // 数据提交类型
                url: href,  // 发送地址
                data: formData, //发送数据
                async: true, // 是否异步
                processData: false, //processData 默认为false，当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
                contentType: false, //
                success: function(data) { // 成功回调
                    hideLoading()
                    _this.val('');
                    if(typeof data == 'string')data = JSON.parse(data);
                    console.log(data)
                    alert(data.msg)
                    if(data.ret == 0){
                        window.location.reload();
                    }
                },
                error:function(e,x,h){
                    hideLoading()
                    _this.val('');
                    alert(h)
                }
            });
        } else {
            _this.val('');
            return false
        }
    })
</script>