<script type="text/html" template lay-done="layui.data.sendParams(d);">
    <div class="layui-form coreshop-form layui-form-pane" lay-filter="LAY-app-CoreCmsPinTuanRule-editForm" id="LAY-app-CoreCmsPinTuanRule-editForm">
        <input type="hidden" name="id" id="id" value="{{d.params.data.model.id || '' }}" />

        <div class="layui-form-item">
            <label for="name" class="layui-form-label">活动名称</label>
            <div class="layui-input-inline">
                <input name="name" id="name" lay-verType="tips" lay-verify="required|verifyname" class="layui-input" placeholder="请输入活动名称" lay-reqText="请输入活动名称" value="{{d.params.data.model.name || '' }}" />
            </div>
            <div class="layui-form-mid layui-word-aux">请输入不超过255个字符内容</div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">商品id：</label>
            <div class="layui-input-block">

                <div id="goods_box" class="select_seller_goods_box">
                    <div>
                        <button class="layui-btn" style="margin-left: 10px;" lay-active="goods_show"><i class="layui-icon layui-icon-ok"></i>选择商品</button>
                    </div>
                    <input type="hidden" name="goods" id="goods" value="">
                    <ul id="goods_list" class="sellect_seller_goods_list">
                    </ul>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="startTime" class="layui-form-label">起止时间</label>
            <div class="layui-input-inline layui-inline-6">
                <input name="startTime" id="editTime-CoreCmsPinTuanRule-startTime" type="text" lay-verType="tips" lay-verify="required|datetime" class="layui-input" placeholder="请输入开始时间" lay-reqText="请输入开始时间" value="{{d.params.data.model.startTime}} 到 {{d.params.data.model.endTime}}" />
            </div>
        </div>

        <div class="layui-form-item">
            <label for="maxNums" class="layui-form-label">限购数量</label>
            <div class="layui-input-inline layui-inline-1">
                <input type="number" min="0" max="999999" name="maxNums" id="maxNums" lay-verType="tips" lay-verify="required|number" class="layui-input" value="{{d.params.data.model.maxNums  }}" placeholder="请输入每人限购数量" lay-reqText="请输入每人限购数量并为数字" />
            </div>
            <div class="layui-form-mid layui-word-aux">每人限购数量，0为不限制</div>
        </div>

        <div class="layui-form-item">
            <label for="maxGoodsNums" class="layui-form-label">总量</label>
            <div class="layui-input-inline layui-inline-1">
                <input type="number" min="0" max="999999" name="maxGoodsNums" id="maxGoodsNums" lay-verType="tips" lay-verify="required|number" class="layui-input" value="{{d.params.data.model.maxGoodsNums}}" placeholder="请输入每个商品活动数量" lay-reqText="请输入每个商品活动数量并为数字" />
            </div>
            <div class="layui-form-mid layui-word-aux">每个活动商品总量。0为不限制，以商品库存准</div>
        </div>

        <div class="layui-form-item">
            <label for="peopleNumber" class="layui-form-label">人数2-10人</label>
            <div class="layui-input-inline">
                <input type="number" min="2" max="10" name="peopleNumber" id="peopleNumber" lay-verType="tips" lay-verify="required|number" class="layui-input" value="{{d.params.data.model.peopleNumber }}" placeholder="请输入人数2-10人" lay-reqText="请输入人数2-10人并为数字" />
            </div>
            <div class="layui-form-mid layui-word-aux">2-10人</div>
        </div>

        <div class="layui-form-item">
            <label for="significantInterval" class="layui-form-label">有效时长</label>
            <div class="layui-input-inline">
                <input type="number" min="0" max="999999" name="significantInterval" id="significantInterval" lay-verType="tips" lay-verify="required|number" class="layui-input" value="{{d.params.data.model.significantInterval || '' }}" placeholder="请输入单位分钟" lay-reqText="请输入分钟小时并为数字" />
            </div>
            <div class="layui-form-mid layui-word-aux">单位 分钟</div>
        </div>

        <div class="layui-form-item">
            <label for="discountAmount" class="layui-form-label">优惠金额</label>
            <div class="layui-input-inline">
                <input name="discountAmount" id="discountAmount" lay-verType="tips" lay-verify="required" class="layui-input" placeholder="请输入优惠金额" lay-reqText="请输入优惠金额" value="{{d.params.data.model.discountAmount}}" />
            </div>
        </div>

        <div class="layui-form-item">
            <label for="sort" class="layui-form-label">排序</label>
            <div class="layui-input-inline">
                <input type="number" min="0" max="999999" name="sort" id="sort" lay-verType="tips" lay-verify="required|number" class="layui-input" value="{{d.params.data.model.sort}}" placeholder="请输入排序" lay-reqText="请输入排序并为数字" />
            </div>
            <div class="layui-form-mid layui-word-aux">请输入数字</div>
        </div>

        <div class="layui-form-item" pane>
            <label for="isStatusOpen" class="layui-form-label">是否开启</label>
            <div class="layui-input-block">
                <input type="checkbox" lay-filter="switch" name="isStatusOpen" id="isStatusOpen" {{ d.params.data.model.isStatusOpen ? 'checked' : '' }} lay-skin="switch" lay-text="开启|关闭">
            </div>
        </div>
        <div class="layui-form-item">
            <input type="button" class="layui-btn" lay-submit lay-filter="LAY-app-CoreCmsPinTuanRule-editForm-submit" id="LAY-app-CoreCmsPinTuanRule-editForm-submit" value="确认编辑">
        </div>
    </div>
</script>
<script>
    var debug = layui.setter.debug;
    var objData = {};
    layui.data.sendParams = function (d) {
        //开启调试情况下获取接口赋值数据
        if (debug) { console.log(d.params.data); }
        layui.use(['admin', 'form', 'laydate', 'upload', 'coreHelper', 'cropperImg', 'util', 'view'],
            function () {
                var $ = layui.$
                    , form = layui.form
                    , admin = layui.admin
                    , laydate = layui.laydate
                    , upload = layui.upload
                    , cropperImg = layui.cropperImg
                    , util = layui.util
                    , view = layui.view
                    , coreHelper = layui.coreHelper;

                if (d.params.data.goods) {
                    $("#goods_list").empty();
                    var the_val = "";
                    objData = d.params.data.goods[0];

                    for (var i = 0; i < d.params.data.goods.length; i++) {
                        $("#goods_list").append('<li><span id="' + d.params.data.goods[i].id + '"  >×</span>' + d.params.data.goods[i].name + '</li>');
                        the_val += "," + d.params.data.goods[i].id;
                    }
                    $("#goods").val(the_val.slice(1));
                }

                //处理属性 为 lay-active 的所有元素事件
                util.event('lay-active', {
                    goods_show: function () {
                        admin.popup({ shadeClose: false,
                            title: '选择商品',
                            area: ['750px', '600px'],
                            id: 'LAY-app-CoreCmsPinTuanRule-createForm-GetGoodsList',
                            success: function (layero, index) {
                                view(this.id).render('common/getGoodId', { data: objData }).done(function () {
                                    form.render();
                                    //监听商品列表页工具条
                                    var obj_goodsIds = {};
                                    form.on('submit(LAY-app-CoreCmsGoods-getData)',
                                        function (data) {
                                            console.log(ids);
                                            if (!!!ids) {
                                                layer.msg("请先选择商品");
                                                return;
                                            }
                                            $("#goods_list").empty();
                                            $("#goods_list").append('<li><span id="' + ids.id + '"  lay-active="goodsDelete">×</span>' + ids.name + '</li>');
                                            $("#goods").val(ids.id);
                                            layer.close(index);
                                        });
                                });
                            }
                        });
                    }
                });

                $("#goods_list").delegate("span", "click", function () {
                    var ids_array = $("#goods").val().split(",");
                    for (var i = 0; i < ids_array.length; i++) {
                        if (ids_array[i] == $(this).attr("id")) {
                            ids_array.splice(i, 1);
                        }
                    }
                    $("#goods").val(ids_array.join(","));
                    $(this).parent().remove();
                });

                laydate.render({
                    elem: '#editTime-CoreCmsPinTuanRule-startTime',
                    type: 'datetime',
                    range: '到'
                });
                form.verify({
                    verifyname: [/^[\S]{0,255}$/, '活动名称最大只允许输入255位字符，且不能出现空格'],
                });
                //重载form
                form.render(null, 'LAY-app-CoreCmsPinTuanRule-editForm');
            })
    };
</script>