@model FineAdmin.Model.UserModel
@{
    ViewBag.Title = "UserInfo";
    Layout = "~/Views/Shared/_LayoutSysSetPage.cshtml";
}
<style type="text/css">
    .fr {
        float: right;
    }

    .img-headshot {
        width: 90px;
        height: 90px;
        position: absolute;
        top: -30px;
        border: medium none;
        border-radius: 50%;
        cursor: pointer;
    }
</style>
<link href="~/Content/css/angelsub.css" rel="stylesheet" />
<div class="childrenBody seting-pass">
    <form class="layui-form changePwd" lay-filter="formTest">
        @Html.HiddenFor(x => x.Id)
        @Html.HiddenFor(x => x.UserPassword)
        @Html.HiddenFor(x => x.CreateTime)
        @Html.HiddenFor(x => x.CreateUserId)
        @Html.HiddenFor(x => x.DepartmentId)
        @Html.HiddenFor(x => x.RoleId)
        @Html.HiddenFor(x => x.EnabledMark)
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="Account" placeholder="用户名" autocomplete="off" disabled class="layui-input  layui-disabled" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input type="text" name="RealName" placeholder="姓名" autocomplete="off" class="layui-input" lay-verify="required">
            </div>
        </div>
        @Html.GenderRadioHtml()
        <div class="layui-form-item">
            <label class="layui-form-label">头像</label>
            <div class="layui-input-inline">
                <input name="HeadIcon" readonly id="HeadShot" placeholder="图片地址" value="" class="layui-input">
            </div>
            <div class="layui-input-inline layui-btn-container" style="width: auto;">
                <button type="button" class="layui-btn layui-btn-primary" id="btnUpload">
                    <i class="layui-icon">&#xe67c;</i>上传图片
                </button>
                <div id="layer-photos-demo" class="fr">
                    <img class="img-headshot" id="imgHeadShot" layer-pid="HeadShot" layer-src="~/Content/images/timg.jpg" src="~/Content/images/timg.jpg" alt="头像预览">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号码</label>
            <div class="layui-input-block">
                <input type="text" name="MobilePhone" placeholder="手机号码" autocomplete="off" class="layui-input" maxlength="11">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">微信</label>
            <div class="layui-input-block">
                <input type="password" name="WeChat" placeholder="微信" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="Email" placeholder="邮箱" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">出生日期</label>
            <div class="layui-input-block">
                <input type="text" name="Birthday" id="birthday" placeholder="出生日期" autocomplete="off" class="layui-input" lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item" style="text-align:center;">
            <button class="layui-btn" lay-submit="" lay-filter="changeUser">立即修改</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </form>
</div>
<script>
    layui.use(["form", "laydate", "angelLayer", "angelUtils", "upload", "layer"], function () {
        let form = layui.form;
        let laydate = layui.laydate;
        let angelLayer = layui.angelLayer;
        let angelUtils = layui.angelUtils;
        let upload = layui.upload;
        let layer = layui.layer;
        let $ = layui.$;
        laydate.render({ elem: "#birthday" });
        upload.render({
            elem: '#btnUpload',
            url: '/Home/ExportFile',
            size: '@ViewBag.UploadFileSize',
            exts: '@ViewBag.UploadFileType',
            done: function (res) {
                if (res.code == 0) {
                    $("#HeadShot").val(res.src);
                    $("#imgHeadShot").attr("src", res.src);
                    $("#imgHeadShot").attr("layer-src", res.src)
                }
            }
        });
        if ("@Model.HeadIcon"!="") {
            $("#imgHeadShot").attr("src", "@Model.HeadIcon");
            $("#imgHeadShot").attr("layer-src", "@Model.HeadIcon");
        }
        layer.photos({
            photos: '#layer-photos-demo',
            anim: 1
        });
        //给表单赋值
        form.val("formTest", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
            "Account": "@Model.Account",
            "RealName": "@Model.RealName",
            "Gender": "@Model.Gender",
            "HeadIcon": "@Model.HeadIcon",
            "MobilePhone": "@Model.MobilePhone",
            "WeChat": "@Model.WeChat",
            "Email": "@Model.Email",
            "Birthday": "@Model.Birthday.ToString("yyyy-MM-dd")"
        });
        form.render(); //更新全部
        form.on("submit(changeUser)", function (data) {
            angelUtils.ajax("/Permissions/User/Edit", "post", data.field, true).done(function (response) {
                angelLayer.greenTickMsg(response.message, function () {
                    location.reload(); // 父页面刷新
                });
            }).fail(function (error) {
                console.log(error)
            });
            return false;
        });
    });
</script>