function update(call) {

    let validate = $("#passwordForm").form('validate');
    if (!validate) {
        topWin.layer.msg("必填项不得为空!");
        return false;
    }
    var data = $('#passwordForm').serializeJson();
    var pwdReg = $("#pwdReg").val()
    // 创建 RegExp 对象
    const regex = new RegExp(pwdReg);
    if (!regex.test(data.pwd) || !regex.test(data.rePwd)) {
        return false;
    }

    $.ajax({
        url: g.ctx + 'pc/sys/user/updatePassword',
        method: "POST",
        data: data,
        success: function (data) {
            topWin.layer.alert("修改成功", {icon: 1}, function (idx) {
                topWin.layer.close(idx);
                call();
            });
        },
        error: function (data) {
            topWin.layer.alert(data.responseJSON.message, {icon: 2});
        }
    });
}

// 密码实时验证
function pwdChange(newValue) {
    validatePassword(newValue);
    checkPasswordsMatch()
}

function validatePassword(password) {
    // 各个条件的正则表达式
    const onlayChar = /^[a-zA-Z0-9]+$/;
    const lengthReq = /.{8,}/;
    const upperReq = /[A-Z]/;
    const lowerReq = /[a-z]/;
    const digitReq = /\d/;
    // 更新条件样式
    updateRequirement('#specialCharReq', onlayChar.test(password));
    updateRequirement('#lengthReq', lengthReq.test(password));
    updateRequirement('#upperReq', upperReq.test(password));
    updateRequirement('#lowerReq', lowerReq.test(password));
    updateRequirement('#digitReq', digitReq.test(password));
}


function updateRequirement(selector, isValid) {
    if (isValid) {
        $(selector).addClass('valid');
    } else {
        $(selector).removeClass('valid');
    }
}

function checkPasswordsMatch() {
    const password = $('input[textboxname="pwd"]').textbox("getValue");
    const confirmPassword = $('input[textboxname="rePwd"]').textbox("getValue");
    if (password === confirmPassword && password.length > 0) {
        $('#passwordMatch').addClass('valid').text('密码一致');
    } else {
        $('#passwordMatch').removeClass('valid').text('密码不一致');
    }
}