@using MySystem.Models;
@{CouponAssignRecords editData = ViewBag.data as CouponAssignRecords;}
@{
string RightInfo = ViewBag.RightInfo as string;
string right = ViewBag.right as string;

}
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>继续发放优惠券</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <script src="/admin/js/jquery-1.10.1.min.js"></script>
    <script src="/admin/js/LAreaData2.js"></script>
</head>

<body>

    <div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin">
        <input type="hidden" name="Id" value="@editData.Id" />

        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-tab" lay-filter="mytabbar">
                    <ul class="layui-tab-title">
                        <li class="layui-this" lay-id="1">基本信息</li>
                        <li lay-id="12">SEO设置</li>
                    </ul>
                    <div class="layui-tab-content mt20">
                        <div class="layui-tab-item layui-show">
                            <div class="layui-form-item">
                                <label class="layui-form-label">创客等级</label>
                                <div class="layui-input-inline">
                                    <select id="UserMinLevel" name="UserMinLevel" lay-search="">
                                        <option value="">请选择</option>
                                        @{Dictionary<string, string> UserLevelSetDic = new
                                            MySystem.UserDictionary().getUserLevelSet();}
                                            @foreach (string key in UserLevelSetDic.Keys)
                                            {
                                            <option value="@key">@UserLevelSetDic[key]</option>
                                            }
                                    </select>
                                    <script>
                                        $("#UserMinLevel").val("@editData.UserMinLevel");
                                    </script>
                                </div>
                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline">
                                    <select id="UserMaxLevel" name="UserMaxLevel" lay-search="">
                                        <option value="">请选择</option>
                                        @foreach (string key in UserLevelSetDic.Keys)
                                        {
                                        <option value="@key">@UserLevelSetDic[key]</option>
                                        }
                                    </select>
                                    <script>
                                        $("#UserMaxLevel").val("@editData.UserMaxLevel");
                                    </script>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">消费总额</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input" type="text" id="TotalOrderMoneyMin"
                                        name="TotalOrderMoneyMin" value="@editData.TotalOrderMoneyMin" maxlength="20"
                                        lay-verify="required|number|" autocomplete="off" placeholder="请输入最小消费总额">
                                </div>
                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline">
                                    <input class="layui-input" type="text" id="TotalOrderMoneyMax"
                                        name="TotalOrderMoneyMax" value="@editData.TotalOrderMoneyMax" maxlength="20"
                                        lay-verify="required|number|" autocomplete="off" placeholder="请输入最大消费总额">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">消耗积分总额</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input" type="text" id="TotalUseIntegralMin"
                                        name="TotalUseIntegralMin" value="@editData.TotalUseIntegralMin" maxlength="20"
                                        lay-verify="required|number|" autocomplete="off" placeholder="请输入最小消耗积分总额">
                                </div>
                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline">
                                    <input class="layui-input" type="text" id="TotalUseIntegralMax"
                                        name="TotalUseIntegralMax" value="@editData.TotalUseIntegralMax" maxlength="20"
                                        lay-verify="required|number|" autocomplete="off" placeholder="请输入最大消耗积分总额">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">最低余额</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input" type="text" id="CurMoneyMin" name="CurMoneyMin"
                                        value="@editData.CurMoneyMin" maxlength="20" lay-verify="required|number|"
                                        autocomplete="off" placeholder="请输入当前最低余额">
                                </div>
                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline">
                                    <input class="layui-input" type="text" id="CurMoneyMax" name="CurMoneyMax"
                                        value="@editData.CurMoneyMax" maxlength="20" lay-verify="required|number|"
                                        autocomplete="off" placeholder="请输入当前最高余额">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">创客分组</label>
                                <div class="layui-input-block">
                                    <input type="hidden" id="UserGroupId" name="UserGroupId"
                                        value="@editData.UserGroupId" />
                                    <div id="UserGroupIdTransfer" class="demo-transfer"></div>
                                    @{string UserGroupJson = "[";}
                                    @{Dictionary<string, string> UserGroupDic = new
                                        MySystem.UserDictionary().getUserGroupDic();}
                                        @foreach (string key in UserGroupDic.Keys)
                                        {
                                        UserGroupJson += "{\"value\": \"" + key + "\", \"title\": \"" +
                                        UserGroupDic[key] + "\" },";
                                        }
                                        @{UserGroupJson = UserGroupJson.TrimEnd(','); UserGroupJson += "]";}
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">创客所在地区</label>
                                <input type="hidden" id="Areas" name="Areas" value="@editData.Areas" />
                                <div class="layui-input-inline">
                                    <select id="AreasProvince" lay-search="" lay-filter="AreasProvince">
                                        <option value="">省</option>
                                    </select>
                                </div>
                                <div class="layui-input-inline">
                                    <select id="AreasCity" lay-search="" lay-filter="AreasCity">
                                        <option value="">市</option>
                                    </select>
                                </div>
                                <div class="layui-input-inline">
                                    <select id="AreasArea" lay-search="" lay-filter="AreasArea">
                                        <option value="">县/区</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">手机号</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input" type="text" id="Mobile" name="Mobile"
                                        value="@editData.Mobile" maxlength="11" lay-verify="" autocomplete="off"
                                        placeholder="请输入手机号">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">优惠券</label>
                                <div class="layui-input-block">
                                    <input type="hidden" id="CouponIds" name="CouponIds" value="@editData.CouponIds" />
                                    <div id="CouponIdsTransfer" class="demo-transfer"></div>
                                    @{string CouponsJson = "[";}
                                    @{Dictionary<string, string> CouponsDic = new
                                        MySystem.CouponDictionary().getCouponsDic();}
                                        @foreach (string key in CouponsDic.Keys)
                                        {
                                        CouponsJson += "{\"value\": \"" + key + "\", \"title\": \"" + CouponsDic[key] +
                                        "\" },";
                                        }
                                        @{CouponsJson = CouponsJson.TrimEnd(','); CouponsJson += "]";}
                                </div>
                            </div>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-form-item">
                                <label class="layui-form-label">网页标题</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" type="text" id="SeoTitle" name="SeoTitle"
                                        value="@editData.SeoTitle" maxlength="50" autocomplete="off"
                                        placeholder="请输入网页标题">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">网页关键字</label>
                                <div class="layui-input-block">
                                    <input class="layui-input" type="text" id="SeoKeyword" name="SeoKeyword"
                                        value="@editData.SeoKeyword" maxlength="50" autocomplete="off"
                                        placeholder="请输入网页关键字">
                                </div>
                            </div>
                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">网页描述</label>
                                <div class="layui-input-block">
                                    <textarea class="layui-textarea" name="SeoDescription" id="SeoDescription"
                                        placeholder="请输入网页描述">@editData.SeoDescription</textarea>
                                </div>
                            </div>

                        </div>

                    </div>
                </div>
                <div class="layui-form-item layui-hide">
                    <input type="button" lay-submit lay-filter="LAY-list-front-submit" id="LAY-list-front-submit"
                        value="确认">
                </div>
            </div>
        </div>
    </div>

    <script src="/layuiadmin/layui/layui.js"></script>
    <script src="/other/oss/upload-min@(MySystem.OssHelper.Instance.OssStatus ? "-oss" : "").js"></script>
    <script src="/other/mybjq/kindeditor-min.js"></script>
    <script src="/other/mybjq/lang/zh_CN.js"></script>
    <script>
        //编辑器
        KindEditor.ready(function (K) {

        });

        var ids = "";

        function getChildren(obj) {
            $.each(obj, function (index, value) {
                var id = obj[index].id;
                ids += id + ",";
                var children = obj[index].children;
                if (children) {
                    getChildren(children);
                }
            });
        }

        function AreasProvinceInit(tagId, areasVal, form) {
            for (var i = 0; i < provs_data.length; i++) {
                var sel = "";
                if (areasVal.indexOf(provs_data[i].text) > -1) {
                    sel = " selected=selected";
                }
                $("#" + tagId + "Province").append('<option value="' + provs_data[i].value + '"' + sel + '>' +
                    provs_data[i].text + '</option>');
            }
            form.render();
        }

        function AreasProvinceSelected(tagId, areasVal, form, value) {
            $("#" + tagId + "City").html('<option value="">市</option>');
            var list = citys_data[value];
            for (var i = 0; i < list.length; i++) {
                var sel = "";
                if (areasVal.indexOf(list[i].text) > -1) {
                    sel = " selected=selected";
                }
                $("#" + tagId + "City").append('<option value="' + list[i].value + '"' + sel + '>' + list[i].text +
                    '</option>');
            }
            $("#" + tagId + "Area").html('<option value="">县/区</option>');
            form.render();
            $("#" + tagId + "").val($("#" + tagId + "Province option:selected").text() + "," + $("#" + tagId +
                "City option:selected").text() + "," + $("#" + tagId + "Area option:selected").text());
        }

        function AreasCitySelected(tagId, areasVal, form, value) {
            $("#" + tagId + "Area").html('<option value="">县/区</option>');
            var list = dists_data[value];
            for (var i = 0; i < list.length; i++) {
                var sel = "";
                if (areasVal.indexOf(list[i].text) > -1) {
                    sel = " selected=selected";
                }
                $("#" + tagId + "Area").append('<option value="' + list[i].value + '"' + sel + '>' + list[i].text +
                    '</option>');
            }
            form.render();
            $("#" + tagId + "").val($("#" + tagId + "Province option:selected").text() + "," + $("#" + tagId +
                "City option:selected").text() + "," + $("#" + tagId + "Area option:selected").text());
        }

        function AreasAreaSelected(tagId, form) {
            form.render();
            $("#" + tagId + "").val($("#" + tagId + "Province option:selected").text() + "," + $("#" + tagId +
                "City option:selected").text() + "," + $("#" + tagId + "Area option:selected").text());
        }

        function movePrev(obj, tagId) {
            $(obj).parent().prev().insertAfter($(obj).parent());
            checkPics(tagId);
        }

        function moveNext(obj, tagId) {
            $(obj).parent().next().insertBefore($(obj).parent());
            checkPics(tagId);
        }

        function deletePic(obj, tagId) {
            $(obj).parent().remove();
            checkPics(tagId);
        }

        function checkPics(tagId) {
            var pics = "";
            var texts = "";
            $("#" + tagId + "Image div img").each(function (i) {
                pics += $(this).attr("src").replace(osshost, '') + "|";
            });
            $("#" + tagId + "Image div input").each(function (i) {
                texts += $(this).val() + "|";
            });
            if (pics == "") {
                $("#" + tagId).val("");
            } else {
                pics = pics.substring(0, pics.length - 1);
                texts = texts.substring(0, pics.length - 1);
                $("#" + tagId).val(pics + "#cut#" + texts);
            }
        }

        function checkBox(tagId) {
            var text = "";
            $("input[type=checkbox][name=" + tagId + "List]:checked").each(function (i) {
                text += $(this).val() + ",";
            });
            $("#" + tagId).val(text);
        }

        function showBigPic(picpath) {
            parent.layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                shadeClose: true,
                area: ['auto', 'auto'],
                content: '<img src="' + picpath + '" style="max-width:800px; max-height:800px;" />'
            });
        }

        var tree;
        var element;
        layui.config({
            base: '/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'upload', 'layedit', 'laydate', 'element', 'croppers', 'transfer', 'tree', 'util'],
            function () {
                var $ = layui.$,
                    form = layui.form,
                    layer = layui.layer,
                    layedit = layui.layedit,
                    laydate = layui.laydate,
                    croppers = layui.croppers,
                    upload = layui.upload,
                    transfer = layui.transfer,
                    util = layui.util;
                tree = layui.tree;
                element = layui.element;

                //Hash地址的定位
                var layid = location.hash.replace(/^#test=/, '');
                element.tabChange('test', layid);
                element.on('tab(test)', function (elem) {
                    location.hash = 'test=' + $(this).attr('lay-id');
                });

                //日期


                //上传文件


                //穿梭框
                transfer.render({
                    elem: '#UserGroupIdTransfer',
                    data: @Html.Raw(UserGroupJson),
                    title: ['待选项', '选中项'],
                    value: ["@Html.Raw(Library.function.CheckNull(editData.UserGroupId).Replace(",", "\",\""))"], 
                    showSearch: true,
                    onchange: function (obj, index) {
                        if (index == 0) {
                            var source = $("#UserGroupId").val();
                            $.each(obj, function (index, value) {
                                var val = obj[index].value;
                                if (source != "") {
                                    source += "," + val;
                                } else {
                                    source += val;
                                }
                            });
                            $("#UserGroupId").val(source);
                        } else if (index == 1) {
                            var source = "," + $("#UserGroupId").val() + ",";
                            $.each(obj, function (index, value) {
                                var val = obj[index].value;
                                source = source.replace("," + val + ",", ",");
                            });
                            if (source != "") {
                                if (source == ",") {
                                    source = "";
                                } else {
                                    source = source.substring(1, source.length - 1);
                                }
                            }
                            $("#UserGroupId").val(source);
                        }
                    }
                });

                transfer.render({
                    elem: '#CouponIdsTransfer',
                    data: @Html.Raw(CouponsJson),
                    title: ['待选项', '选中项'],
                    value: ["@Html.Raw(Library.function.CheckNull(editData.CouponIds).Replace(",", "\",\""))"], 
                    showSearch: true, 
                    onchange: function (obj, index) {
                        if (index == 0) {
                            var source = $("#CouponIds").val();
                            $.each(obj, function (index, value) {
                                var val = obj[index].value;
                                if (source != "") {
                                    source += "," + val;
                                } else {
                                    source += val;
                                }
                            });
                            $("#CouponIds").val(source);
                        } else if (index == 1) {
                            var source = "," + $("#CouponIds").val() + ",";
                            $.each(obj, function (index, value) {
                                var val = obj[index].value;
                                source = source.replace("," + val + ",", ",");
                            });
                            if (source != "") {
                                if (source == ",") {
                                    source = "";
                                } else {
                                    source = source.substring(1, source.length - 1);
                                }
                            }
                            $("#CouponIds").val(source);
                        }
                    }
                });


                //TreeView，比如权限管理


                //省市区
                form.on('select(AreasProvince)', function (data) {
                    AreasProvinceSelected("Areas", "@editData.Areas", form, data.value);
                });
                form.on('select(AreasCity)', function (data) {
                    AreasCitySelected("Areas", "@editData.Areas", form, data.value)
                });
                form.on('select(AreasArea)', function (data) {
                    AreasAreaSelected("Areas", form)
                });
                setTimeout(function () {
                    AreasProvinceInit("Areas", "@(Html.Raw(editData.Areas))", form);
                    AreasProvinceSelected("Areas", "@(Html.Raw(editData.Areas))", form, $("#AreasProvince").val());
                    AreasCitySelected("Areas", "@(Html.Raw(editData.Areas))", form, $("#AreasCity").val());
                    AreasAreaSelected("Areas", form);
                }, 1000);

        });
    </script>
</body>

</html>