function updatePasswordLayer() {

    var updatePasswordDialog = openDialog('updatePassword', g.ctx + 'pc/sys/user/updatePasswordPage', {
        title: '修改密码',
        width: '350px',
        height: '450px',
        cache: false,
        modal: true,
        border: 'thin',
        onClose: function () {
            updatePasswordDialog.dialog('destroy');
        },
        buttons: [{
            text: '确定', iconCls: 'icon-save', handler: function () {
                topWin.frames['updatePassword'].update(function (data) {
                    updatePasswordDialog.dialog('close');
                });
            }
        }, {
            text: '关闭', iconCls: 'icon-cancel', handler: function () {
                updatePasswordDialog.dialog('close');
            }
        }]
    });
}


function updateFirstPasswordLayer() {
    var index = topWin.layer.load(0, {shade: false});
    topWin.layer.open({
        type: 2,
        title: '密码初始化',
        closeBtn: 0,
        area: ['420px', '450px'],
        btn: ['提交'],
        yes: function (index, layero, that) {
            console.log(layero.find('iframe')[0]['name'])
            console.log(topWin.window[layero.find('iframe')[0]['name']])
            var iframeWin = topWin.window[layero.find('iframe')[0]['name']];
            let formData = iframeWin.getFormData();
            var newpassword = formData.password;
            var confirmpassword = formData.confirmPassword;
            if (newpassword === '') {
                return
            }
            if (confirmpassword === '') {
                return
            }
            var pwdReg = $("#pwdReg").val()
            // 创建 RegExp 对象
            const regex = new RegExp(pwdReg);
            if (!regex.test(newpassword)) {
                return
            }
            if (newpassword !== confirmpassword) {
                return
            }
            $.ajax({
                type: "POST", //请求方式
                url: g.ctx + "pc/sys/user/updatePasswordFirstLogin",
                data: {pwd: newpassword, rePwd: confirmpassword},
                success: function (data) {
                    topWin.layer.alert("修改成功", {icon: 1}, function (idx) {
                        topWin.layer.close(index)
                        topWin.layer.close(idx);
                        window.location.href=g.ctx+'logout'
                    })

                }, error: function (data) {
                    topWin.layer.alert(data.responseJSON.message, {icon: 2});
                }
            });
        },
        content: [g.ctx + 'pc/sys/user/firstLoginUpdatePasswordPage', 'no']
    });
    topWin.layer.close(index);
}

//个人档案编辑
function editAccount(id) {
    if (id == 0) {
        return;
    }
    var userInfoDialog = openDialog('userInfoDialog', g.ctx + 'pc/sys/user/currentUserDetail', {
        title: '用户信息',
        width: '800px',
        height: '450px',
        cache: false,
        modal: true,
        border: false,
        draggable: false,
        shadow: false,
        onClose: function () {
            userInfoDialog.dialog('destroy');
        },
        buttons: [{
            text: itablei8n.save, iconCls: 'icon-save', handler: function () {
                topWin.frames['userInfoDialog'].saveUser(function () {
                    topWin.layer.msg('数据保存成功', {icon: 1});
                    userInfoDialog.dialog('close');
                });
            }
        }, {
            text: itablei8n.close, iconCls: 'icon-cancel', handler: function () {
                userInfoDialog.dialog('close');
            }
        }]
    });
}

//后台轮询请求任务
// setInterval("getNotice();", 60*1000); //1分钟一次
// setInterval("getEmail();", 300*1000);//5分钟一次Email获取
// setInterval("getTask();", 600*1000);//10分钟一次任务获取
//获得新消息数量
function getNewMessageNum() {
    $.ajax({
        type: "POST", //请求方式
        url: "pc/message/received/rest/getNewMessageNum", //请求路径
        success: function (data) {
            console.log(data)
            if (data===0) {
                $("#newMessageNum").hide();
            } else {
                $("#newMessageNum").html(data);
            }
        }
    });
}

function refreshNewMessageNum() {
    var num = $("#newMessageNum").html();
    if (Number(num) - 1 <= 0) {
        $("#newMessageNum").hide();
    } else {
        $("#newMessageNum").html(Number(num) - 1);
    }
}

//获得任务
function getNotice() {
    $.ajax({
        type: "POST", //请求方式
        url: "/task/getMessage.do", //请求路径
        success: function (data) {
            var liinfo = "";
            $("#message_badge").text(data.length);
            $("#message_span").text(data.length);
            for (var i = 0; i < data.length; i++) {
                var m = data[i];
                var aa = "";
                if (m.notictitle == null || m.notictitle == undefined) {
                    return;
                }
                if (m.notictitle.length > 19) aa = m.notictitle.substring(0, 19) + "..."; else aa = m.notictitle;

                liinfo = liinfo + "<li style='text-align: left'><a href = '#' onclick='showNotice(" + m.id + ")' >" + " <span class='details'> <span class='label label-sm label-icon label-success' >" + " </span > " + aa + "</span >  &nbsp;  &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  <span class='time' >" + DateFormatMs(m.createdate) + "</span > " + " </a >  <hr></li >";
            }
            $("#worknotice_page").html("<ul >" + liinfo + "</ul >");
            return false;
        }
    });
}

//获得Email
function getEmail() {
//                layer.msg("您有一封Email，已经发送到您的邮箱，请您注意查收");
    $.ajax({
        type: "POST", //请求方式
        url: "/task/getEmail.do", //请求路径
        success: function (data) {
            var liinfo = "";
            $("#email_badge").text(data.length);
            $("#email_span").text(data.length);

            for (var i = 0; i < data.length; i++) {
                var m = data[i];
                var aa = "";
                if (m.email_title.length > 19) aa = m.email_title.substring(0, 19) + "..."; else aa = m.email_title;
                liinfo = liinfo + "<li ><a href = '#' onclick='showEmail(" + m.id + ")' >" + " <span class='details'> <span class='label label-sm label-icon label-success' >" + " </span > " + aa + "</span ><span class='time' >" + DateFormatMs(m.create_date) + "</span > " + " </a ><hr></li >";
            }
            $("#worknotice_email_page").html("<ul >" + liinfo + "</ul >");
            return false;
        }
    });
}

//获得任务
function getTask() {
    $.ajax({
        type: "POST", //请求方式
        url: "/task/getTask.do", //请求路径
        success: function (data) {
            var liinfo = "";
            $("#task_badge").text(data.length);
            $("#task_span").text(data.length);
            for (var i = 0; i < data.length; i++) {
                var m = data[i];
                var aa = "";
                if (m.task_title != undefined && m.task_title != null) {
                    if (m.task_title.length > 9) aa = m.task_title.substring(0, 9) + "..."; else aa = m.task_title;
                    liinfo = liinfo + "<li ><a href = '#' onclick='showTask(" + m.id + ")' ><span class='time' >" + DateFormatMs(m.create_date) + "</span > " + " <span class='details'> <span class='label label-sm label-icon label-success' >" + " <i class='fa fa-plus' ></i >" + " </span > " + aa + "</span >" + " </a ></li >";
                }
            }
            $("#task").html("<ul class='dropdown-menu-list scroller' style = 'height: 250px;' data-handle-color = '#637283'>" + liinfo + "</ul >");
            return false;
        }
    });
}

function showCollect(m) {
    tabAdd(m.name, m.resurl);
}

//取消收藏
function cancelCollect(m) {

    $.ajax({
        url: "/task/cancelCollect", method: "post", data: {id: m.id}, success: function (data) {
            getCollect();
        }, error: function (data) {
            console.log(data);
            alert(data);
        }
    });
}


var pageii;

function showNotice(id) {
    pageii = layer.open({
        title: "查阅消息", type: 2, // closeBtn: 0,
        area: ["540px", "450px;"], content: "/task/showNoticeUI?id=" + id, end: function () {
            var url = "/task/updateNoticeStatus.do";
            $.ajax({
                url: url, method: "post", data: {status: 2, id: id}, success: function (data) {
                    if (data == 0) {
                        getNotice();
                        return false;
                    } else {
                        layer.msg("更新已读状态失败");
                    }
                }, error: function (data) {
                    console.log(data);
                    alert(data);
                }
            });
        }
    });
}

function showEmail(id) {
    pageii = layer.open({
        title: "查看邮件信息", type: 2, // closeBtn: 0,
        area: ["540px", "450px;"], content: "/task/showEmailUI?id=" + id, end: function () {
            var url = "/task/updateEmailStatus.do";
            $.ajax({
                url: url, method: "post", data: {status: 2, id: id}, success: function (data) {
                    if (data == 0) {
                        getEmail();
                        return false;
                    } else {
                        layer.msg("更新已读状态失败");
                    }
                }, error: function (data) {
                    console.log(data);
                    alert(data);
                }
            });
        }
    });
}

function showTask(id) {
    pageii = layer.open({
        title: "查看任务信息", type: 2, // closeBtn: 0,
        area: ["540px", "450px;"], content: "/task/showTaskUI?id=" + id, end: function () {
            var url = "/task/updateTaskStatus.do";
            $.ajax({
                url: url, method: "post", data: {status: 2, id: id}, success: function (data) {
                    if (data == 0) {
                        getTask();
                        return false;
                    } else {
                        layer.msg("更新已读状态失败");
                    }
                }, error: function (data) {
                    console.log(data);
                    alert(data);
                }
            });
        }
    });
}



