<!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 class="content_wrapper">
    <div class="container-fluid">
        <aside>
            <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" id="goodForm"
                  action="#" style="margin-top: 20px">
                <header><i class="fa fa-fw fa-file"></i>首充礼包配置</header>
                <section>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
<!--                                <button type="button" class="btn btn-success" data-toggle="modal"-->
<!--                                        data-target="#goodsAddBtn">增加-->
<!--                                </button>-->
                                <button type="button" class="btn btn-success" id="goodsSubmitBtn">提交</button>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <?php foreach ($shopList as $key => $vl) { ?>
                            <div class="row AllTypeControl"
                                 style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                                <div class="form-group">
                                    <label class="col-sm-1 control-label">商品GID*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control" readonly
                                               name="good[<?php echo $vl['id']; ?>][gid]"
                                               value="<?php echo $vl['gid']; ?>">
                                    </div>
                                    <label class="col-sm-1 control-label">等级下限*: </label>
                                    <div class="col-sm-1">
                                        <input type="number" class="form-control"
                                               name="good[<?php echo $vl['id']; ?>][min_level]"
                                               value="<?php echo $vl['min_level']; ?>">
                                    </div>
                                    <label class="col-sm-1 control-label">等级上限*: </label>
                                    <div class="col-sm-1">
                                        <input type="number" class="form-control"
                                               name="good[<?php echo $vl['id']; ?>][max_level]"
                                               value="<?php echo $vl['max_level']; ?>">
                                    </div>
                                    <label class="col-sm-2 control-label">存在时间（小时）*: </label>
                                    <div class="col-sm-1">
                                        <input type="number" class="form-control"
                                               name="good[<?php echo $vl['id']; ?>][life_time]"
                                               value="<?php echo $vl['life_time']; ?>">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-1 control-label">商品折扣*: </label>
                                    <div class="col-sm-1">
                                        <input type="number" class="form-control"
                                               name="good[<?php echo $vl['id']; ?>][discount]"
                                               value="<?php echo $vl['discount']; ?>">
                                    </div>
                                    <label class="col-sm-1 control-label">配图*: </label>
                                    <div class="col-sm-1">
                                        <select class="form-control" name="good[<?php echo $vl['id']; ?>][skin_dir]">
                                            <?php foreach ($imgSkinList as $k1 => $v1) { ?>
                                                <option value="<?php echo $k1; ?>" <?php if ($vl['skin_dir'] == $k1) echo 'selected'; ?>><?php echo $v1; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                    <label class="col-sm-1 control-label">上下架*: </label>
                                    <div class="col-sm-1">
                                        <select class="form-control" name="good[<?php echo $vl['id']; ?>][status]">
                                            <option value="0" <?php if ($vl['status'] == 0) echo 'selected'; ?>>下架
                                            </option>
                                            <option value="1" <?php if ($vl['status'] == 1) echo 'selected'; ?>>上架
                                            </option>
                                        </select>
                                    </div>
                                    <label class="col-sm-2 control-label">商品价格（美元）*: </label>
                                    <div class="col-sm-1">
                                        <select class="form-control" name="good[<?php echo $vl['id']; ?>][price]">
                                            <?php foreach ($skuList as $oneSku) { ?>
                                                <option value="<?php echo $oneSku['price']; ?>" <?php if ($vl['price'] == $oneSku['price']) echo 'selected'; ?>><?php echo $oneSku['price']; ?></option>
                                            <?php } ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group propsList propsList2" id="<?php echo $vl['id']; ?>"
                                     data-value='<?php echo $vl['prize_json']; ?>'>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </section>
            </form>
        </aside>
    </div>
</div>
</body>


<div class="modal" id="goodsAddBtn" 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="addGoods"
                  action="">
                <div class="modal-body">
                    <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="ID" value="601" disabled name="id">
                        </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">
                            <input type="number" class="form-control" placeholder="存在时间（小时）" name="life_time">
                        </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-3">
                            <label class="select-inline">
                                <select class="form-control" name="skin_dir">
                                    <?php foreach ($imgSkinList as $k2 => $v2) { ?>
                                        <option value="<?php echo $k2; ?>"><?php echo $v2; ?></option>
                                    <?php } ?>
                                </select>
                            </label>
                        </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="discount">
                        </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="goodsAddBtn2">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="<?php echo base_url(); ?>static/common/js/props.js"></script>
<script>
    propsClass.Init(JSON.parse('<?php echo json_encode([]);?>'), 'prizeJson');
</script>
<script>
    $('.propsList2').each(function () {
        propsClass.Init($(this).data('value'), this.id);
    })
</script>
<script>
    $(function () {
        $('#goodsSubmitBtn').click(function () {
            var data = new FormData(document.getElementById("goodForm"));
            data.append('img_name', 'firstPay')
            $.ajax({
                url: rootPath + 'newShop/firstPayGoodsUpdate',
                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);
                }
            });
        });


        $('#goodsAddBtn2').click(function () {
            var data = new FormData($("#addGoods")[0]);
            data.append('img_name', 'firstPay')

            $.ajax({
                url: rootPath + 'newShop/firstPayGoodsAdd',
                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);
                }
            });
        });

    });
</script>