<!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">
    <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">
    <link rel="stylesheet" href="<?php echo base_url(); ?>public/node_modules/bootstrap-select/dist/css/bootstrap-select.min.css">
    <script src="<?php echo base_url(); ?>public/node_modules/bootstrap-select/dist/js/bootstrap-select.min.js"></script>

    <style type="text/css">
        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>

<body>
<div class="content_wrapper">
    <div id="msg-tip"></div>
    <div class="container-fluid ">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>体力不足礼包配置</header>
                    <section>
                        <div class="container-fluid">
                            <div>
                                <button type="button" class="btn btn-success" onclick="openAddEdit()"
                                        data-toggle="modal"
                                        data-target="#goodsEditBtn">增加
                                </button>
                                <!--                                <span id="filespanXml" class="btn btn-success fileinput-button">-->
                                <!--                                    <span>导入</span>-->
                                <!--                                    <input type="file" id="uploadXml">-->
                                <!--                                </span>-->
                                <!--                                <input type="button" style="display: none;margin-bottom: 10px;width: 80px;"-->
                                <!--                                       class="btn btn-success" value="上传" id="uploadConfigFileBtn"/>-->
                                <!--                                <a type="button" href="/Export/skucoin" style="margin-bottom: 10px;width: 80px;"-->
                                <!--                                   class="btn btn-success">导出</a>-->
                            </div>

                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="table-responsive ">
                                        <table id="roleTable" class="table table-bordered table-hover"
                                               data-toggle="table"
                                               data-classes="table table-hover"
                                               data-show-columns="true"
                                               data-striped="true"

                                               data-height="700">
                                            <thead>
                                            <tr>
                                                <th>ID</th>
                                                <th>等级下限</th>
                                                <th>等级上限</th>
                                                <th>数数分组</th>
                                                <th>价格</th>
                                                <th>上下架</th>
                                                <th>奖励配置</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <?php
                                            if (is_array($shopList) && !empty($shopList)) {
                                                foreach ($shopList as $key => $vl) { ?>
                                                    <tr>
                                                        <td><?php echo $vl['id']; ?></td>
                                                        <td><?php echo $vl['min_level']; ?></td>
                                                        <td><?php echo $vl['max_level']; ?></td>
                                                        <td><?php echo implode(',', $vl['ssGroup']); ?></td>
                                                        <td><?php echo $vl['price']; ?></td>
                                                        <td><?php echo $statusList[$vl['status']]; ?></td>
                                                        <td><?php echo $vl['prizeJson']; ?></td>

                                                        <td>
                                                            <button type="button" class="btn btn-primary active"
                                                                    onclick="openEdit(this)"
                                                                    data-toggle="modal"
                                                                    data-target="#goodsEditBtn"
                                                                    data-value='<?php echo json_encode($vl); ?>'>编辑
                                                            </button>
                                                        </td>
                                                    </tr>
                                                <?php }
                                            } else { ?>
                                                <tr>
                                                    <td colspan="14">暂无数据</td>
                                                </tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>
</div>
</body>

<div class="modal" id="goodsEditBtn" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width: 60%">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                            class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">修改配置</h4>
            </div>
            <form class="form-horizontal" method="post" id="goodForm" action="">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">ID:</label>
                        <div class="col-sm-2">
                            <input readonly type="text" placeholder="ID不需要填写" class="form-control" name="id">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">GID:</label>
                        <div class="col-sm-2">
                            <input type="text" class="form-control" placeholder="GID" readonly name="gid">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">上下架:</label>
                        <div class="col-sm-3">
                            <select class="form-control typeControl" name="status">
                                <option value="0">下架</option>
                                <option value="1">上架</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">开放等级:</label>
                        <div class="col-sm-3">
                            <input type="number" class="form-control" placeholder="开放等级" name="min_level">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">关闭等级:</label>
                        <div class="col-sm-3">
                            <input type="number" class="form-control" placeholder="关闭等级" name="max_level">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">价格（美元）:</label>
                        <div class="col-sm-3">
                            <label class="select-inline">
                                <select class="form-control" name="price">
                                    <?php foreach ($skuList as $oneSku) { ?>
                                        <option value="<?php echo $oneSku['price']; ?>"><?php echo $oneSku['price']; ?></option>
                                    <?php } ?>
                                </select>
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">数数分组：</label>
                        <div class="col-sm-6">
                            <label class="select-inline">
                                <select id="usertype" name="ss_group[]" class="selectpicker show-tick form-control"
                                        multiple data-live-search="false">
                                    <?php foreach ($ssGroupList as $key => $val) { ?>
                                        <option value="<?php echo $key; ?>"><?php echo $val; ?></option>
                                    <?php } ?>
                                </select>
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="propsList" id="prizeJson">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="goodsSubmitBtn">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="<?php echo base_url(); ?>static/common/js/props.js"></script>
<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>

<script src="<?php echo base_url(); ?>static/common/js/props.js"></script>
<script>
    propsClass.Init(JSON.parse('<?php echo json_encode([]);?>'), 'prizeJson');
</script>

<script>
    $(function () {
        $('#usertype').selectpicker('val', []);
        $('#goodsSubmitBtn').click(function () {
            var data = new FormData(document.getElementById("goodForm"));
            data.append('img_name', 'unfitnessPay')

            $.ajax({
                url: rootPath + 'newShop/unfitnessPayGoodsUpdate',
                type: 'POST',
                data: data,
                dataType: 'json',
                contentType: false, //必须
                processData: false, //必须
                success: function (data) {
                    alert(data.msg);
                    // confirm(data.msg);
                    window.location.reload();
                },
                error: function (data) {
                    alert(data.msg);
                }
            });
        });

    });

    function openEdit(even) {
        let formData = $(even).data('value')

        for (let key in formData) {
            if (formData.hasOwnProperty(key)) {
                if (key === 'ss_group') {
                    console.log(formData[key])
                    $('#usertype').selectpicker('val', formData[key]);
                    // $("[name=" + key + "\[\]]").val(formData[key]);
                } else {
                    $("[name=" + key + "]").val(formData[key]);
                }
            }
        }
        propsClass.Init(JSON.parse(formData['prize_json']), 'prizeJson');
    }

    function openAddEdit() {
        key = 'id'
        $("[name=" + key + "]").val('');
    }

</script>
