@using MySystem.Models;
@{Merchants editData = ViewBag.data as Merchants;}
<!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 style="background-color:#fff;">

    <div class="layui-form" style="padding: 20px 0 0 0;">
        <form class="layui-form" id="confirmFrm">
            <div class="layui-card">
          <div class="layui-card-body">
        <div class="layui-tab" lay-filter="mytabbar">
                <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-block">
                                <input class="layui-input" type="text" id="Name" name="Name" value="@editData.Name" maxlength="50" lay-verify="required|" autocomplete="off" placeholder="请输入名称">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">Logo图片</label>
                            <div class="layui-input-block">
                                <div class="layui-upload">
                                    <input type="hidden" id="Logo" name="Logo" value="@editData.Logo">
                                    <button class="layui-btn" type="button" id="LogoBtn">选择图片</button>
                                    <div class="layui-inline layui-word-aux"></div>
                                </div>
                                <div class="mt10" id="LogoImage">
                                    @if (!string.IsNullOrEmpty(editData.Logo))
                                    {
                                        <img src="@(MySystem.OssHelper.Instance.SourceHost)@editData.Logo" class="layui-upload-img" style="max-width:85px; max-height:85px;" onclick="showBigPic('@(MySystem.OssHelper.Instance.SourceHost)@editData.Logo')">
                                    }
                                </div>
                            </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-block">
                                <input class="layui-input" type="text" id="Address" name="Address" value="@editData.Address" maxlength="50" lay-verify="" 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="Principal" name="Principal" value="@editData.Principal" maxlength="30" lay-verify="required|" 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="Phone" name="Phone" value="@editData.Phone" maxlength="30" lay-verify="required|" autocomplete="off" placeholder="请输入联系电话">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">营业执照</label>
                            <div class="layui-input-block">
                                <div class="layui-upload">
                                    <input type="hidden" id="BusinessLicense" name="BusinessLicense" value="@editData.BusinessLicense">
                                    <button class="layui-btn" type="button" id="BusinessLicenseBtn">选择图片</button>
                                    <div class="layui-inline layui-word-aux"></div>
                                </div>
                                <div class="mt10" id="BusinessLicenseImage">
                                    @if (!string.IsNullOrEmpty(editData.BusinessLicense))
                                    {
                                        <img src="@(MySystem.OssHelper.Instance.SourceHost)@editData.BusinessLicense" class="layui-upload-img" style="max-width:85px; max-height:85px;" onclick="showBigPic('@(MySystem.OssHelper.Instance.SourceHost)@editData.BusinessLicense')">
                                    }
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item ml10">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" onclick="save()">立即提交</button>
                </div>
            </div>
        </form>
    </div>

    <script src="/layuiadmin/layui/layui.js"></script>
    <script src="/other/oss/upload-min@(MySystem.OssHelper.Instance.OssStatus ? "-oss" : "").js"></script>
    <script>
        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 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;" />'
            });
        }

        function save() {
            var index = layer.load(1, {
                shade: [0.5, '#000']
            });
            var userdata = $("#confirmFrm").serialize();
            $.ajax({
                type: "POST",
                url: "/Admin/Merchants/AdminInfoPost?r=" + Math.random(1),
                data: userdata,
                dataType: "text",
                success: function (data) {
                    layer.close(index);
                    if (data == "success") {
                        layer.msg("修改成功");
                    } else {
                        layer.msg(data);
                    }
                }
            });
        }
        
        
        layui.config({
            base: '/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'upload', 'layedit'], function () {
            var $ = layui.$;
            var form = layui.form;
            var 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');
            });

            //上传文件
            WebUploadJs('LogoBtn', '@(Library.ConfigurationManager.AppSettings["Database"].ToString())/upload', @(Html.Raw(new MySystem.PublicFunction().GetUploadParam("MerchantsLogo"))),  function (filename) {
                $('#LogoImage').html('<img src="' + osshost + filename + '" class="layui-upload-img" style="max-width:85px; max-height:85px;" onclick="showBigPic(\'' + osshost + filename + '\')">')
                $('#Logo').val(filename);
            });
            WebUploadJs('BusinessLicenseBtn', '@(Library.ConfigurationManager.AppSettings["Database"].ToString())/upload', @(Html.Raw(new MySystem.PublicFunction().GetUploadParam("MerchantsBusinessLicense"))),  function (filename) {
                $('#BusinessLicenseImage').html('<img src="' + osshost + filename + '" class="layui-upload-img" style="max-width:85px; max-height:85px;" onclick="showBigPic(\'' + osshost + filename + '\')">')
                $('#BusinessLicense').val(filename);
            });

            //省市区
            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>