import { getIfBind, getBindInfo, getBindGoogle, getBindCode, getCloseStepTwo, getCloseCode, getUpdatePwd, getUpdatePwdCode } from "../../../api/personalCenter"
import { encryption } from "../../../utils/fun";
import { getResetPwd, getResetPwdCode, sendCloseAccount, closeAccount } from "../../../api/login"
import { validatePassword, formatPasswordErrors } from "../../../utils/passwordValidator";
export default {
    data() {
        return {
            dialogVisible: false,
            verificationDialogVisible: false,
            checked: "",
            confirmationVerification: false,
            maintainDialogVisible: false,
            deleteAccountDialog: false,
            params: {
                gCode: "",
                eCode: "",
                pwd: "",
                secret: "",
            },
            btnDisabled: false,
            btnDisabledClose: false,
            btnDisabledPassword: false,
            bthText: "user.obtainVerificationCode",
            bthTextClose: "user.obtainVerificationCode",
            bthTextPassword: "user.obtainVerificationCode",
            time: "",
            clauseList: [
                {
                    title: "进行帐户删除操作将发生什么？",
                    children: [
                        {
                            value: "1",
                            label: "此帐户及其所属子帐户将无法继续使用。",
                        },
                        {
                            value: "2",
                            label: "此帐户及其子帐户的数据将按照我们的数据保留政策被删除。一些情况将不受此限。",
                        },
                        {
                            value: "3",
                            label: "帐户被永久删除后，您将无法找回帐户。",
                        },

                    ]
                },
                {
                    title: "在申请删除此帐户之前，请您：",
                    children: [
                        {
                            value: "1",
                            label: "在电脑端访问收益页面，导出您需要的收益记录进行备份。",
                        },
                        {
                            value: "2",
                            label: "仔细检查每个帐户、子帐户的余额。",
                        },
                        {
                            value: "3",
                            label: "在矿机及软件的挖矿配置中，确定已删除此帐户名及其子帐户名。",
                        },
                        {
                            value: "4",
                            label: "确定已经在所有设备登出此帐户。",
                        },

                    ]
                },
            ],
            reasonList: [],
            value: "",
            isItBound: false,
            bindInfo: {
                // secret:"455645645646ABC",
                // img:"iVBORw0KGgoAAAANSUhEUgAAAIwAAACMCAYAAACuwEE+AAAC+UlEQVR42u3dW27lQAgFQO9/05MljJJu4GAXUr5y4/i6yxKCfjz/hPhFPB6BAEYAI0LBPM/T+vPfG/zl359+/vR53L5+2vgAAwwwwAADzBYw15Om4QG/DeIU/OkL1D4+wAADDDDAALMUTHcSWD1A3Un1dBJ9fH1ggAEGGGCAASYiSb1dSKy+H2CAAQYYYIAB5htgqpuf0yCAAQYYYIABBphvNh9vf5/upFu3GhhggAEGGGBqksrppPjtv//8qgG/BwYYYIAB5iWR1rxMS2qPny8wwAADDDDALAUzPeGoe+FZNdjuF+D4BQEGGGCAAQaYUDDTA7htgtPtz3c3K8srvcAAAwwwwAATAiZ9sXva9aZBAgMMMMAAA8xXwaQVntL+32lS3n398ZWPwAADDDDAAFMEproZ172JYHczr7sZ2w0YGGCAAQYYYFLBpDf/pu9nerOA8cIjMMAAAwwwwISC6f7C00C3FdrGX0hggAEGGGCACQWTXlj6elI7njQDAwwwwAADzBIw1c286qS4uxm4bePq8kngwAADDDDAANMEpnsAbaS8/HAKYIABBhhggFl6XlJ3YSwtiU4/yPz6/QMDDDDAAANMKJhqAN2FveoH2F04HG9eAgMMMMAAA0womOlCWHchaluS3D2BDRhggAEGGGC2gOlOMqubfdVguw/1nE7agQEGGGCAASYVzPSAdQ/odOHvdasGgAEGGGCAASZkXdJ0ErftfqYLa9WFQGCAAQYYYIBJBZO26eD0gVnpGya1T7gCBhhggAEGmFAwb0s605LG6iR5/JBQYIABBhhggBkCM52UdU8KX7ehz/RCP2CAAQYYYIBZAibtgUwDn55Qdb0QBwwwwAADDDAfAfO2pHb7oaDtGzoBAwwwwAADDDCfOMBrunl7/QUABhhggAEGGGAiD9mcBt2dBK9PeoEBBhhggAEmpPnYnXSmbZAUv4ERMMAAAwwwwCwBs26xePNCsLSFd59bNQAMMMAAAwwwQvyl+SgEMAIYMRM/WzKCeTSdtfoAAAAASUVORK5CYII",
            },
            BindInfoLoading: false,
            changePasswordDialogVisible: false,
            securityLoading: false,
            changePasswordParams: {
                // email:"",
                password: "",
                updatePwdCode: "",
                // gCode:"",
            },
            newPassword: "",
            ResetPwdLoading: false,
            closeDialogVisible: false,
            closeLoading: false,
            closeParams: {
                gCode: "",
                eCode: "",

            },
            countDownTime: 60,
            timer: null,
            countDownTimeClose: 60,
            timerclose: null,
            countDownTimePassword: 60,
            timerPassword: null,
            lang:"zh",
            // 删除账户相关
            deleteAccountParams: {
                eCode: "",
                gCode: "",
            },
            btnDisabledDeleteAccount: false,
            bthTextDeleteAccount: "user.obtainVerificationCode",
            countDownTimeDeleteAccount: 60,
            timerDeleteAccount: null,
            deleteAccountLoading: false,
            deleteAccountCodeLoading: false, // 获取验证码按钮loading状态
            userEmail: "",
        }
    },
    computed: {
        countDown() {
            const minutes = Math.floor(this.countDownTime / 60);
            const seconds = this.countDownTime % 60;
            const m = minutes < 10 ? "0" + minutes : minutes;
            const s = seconds < 10 ? "0" + seconds : seconds;
            return `${s}`;
            // return`${s}`
        },
        countDownClose() {
            const minutes = Math.floor(this.countDownTimeClose / 60);
            const seconds = this.countDownTimeClose % 60;
            const m = minutes < 10 ? "0" + minutes : minutes;
            const s = seconds < 10 ? "0" + seconds : seconds;
            return `${s}`;
            // return`${s}`
        },

        countDownPassword() {
            const minutes = Math.floor(this.countDownTimePassword / 60);
            const seconds = this.countDownTimePassword % 60;
            const m = minutes < 10 ? "0" + minutes : minutes;
            const s = seconds < 10 ? "0" + seconds : seconds;
            return `${s}`;
            // return`${s}`
        },

    },
    created() {
        

        if (window.sessionStorage.getItem("security_time")) {
            this.countDownTime = Number(window.sessionStorage.getItem("security_time"));
            this.startCountDown()
            this.btnDisabled = true;
            this.bthText = `user.again`
        }

        if (window.sessionStorage.getItem("close_time")) {
            this.countDownTimeClose = Number(window.sessionStorage.getItem("close_time"));
            this.startCountDownClose()
            this.btnDisabledClose = true;
            this.bthTextClose = `user.again`
        }
        if (window.sessionStorage.getItem("Password_time")) {
            this.countDownTimePassword = Number(window.sessionStorage.getItem("Password_time"));
            this.startCountDownPassword()
            this.btnDisabledPassword = true;
            this.bthTextPassword = `user.again`
        }

        if (window.sessionStorage.getItem("deleteAccount_time")) {
            this.countDownTimeDeleteAccount = Number(window.sessionStorage.getItem("deleteAccount_time"));
            this.startCountDownDeleteAccount()
            this.btnDisabledDeleteAccount = true;
            this.bthTextDeleteAccount = `user.again`
        }

    },
    mounted() {

        this.lang = this.$i18n.locale; // 初始化语言值
        this.fetchIfBind()
        this.registerRecoveryMethod('fetchIfBind', "");
        if (this.$route.params.active) {
            this.handelVerification()
        }
        // 获取用户邮箱
        this.getUserEmail();
    },
    methods: {
        async fetchIfBind(params) {
            this.setLoading('securityLoading', true);
            const data = await getIfBind(params)
            if (data && data.code === 200) {
                if (data.data) {
                    this.isItBound = true
                } else if (!data.data) {
                    this.isItBound = false
                }
            }
            this.setLoading('securityLoading', false);
        },
        async fetchBindInfo(params) {
            this.setLoading('BindInfoLoading', true);
            const data = await getBindInfo(params)
            console.log(data, "绑定信息");
            if (data && data.code === 200) {
                this.bindInfo = data.data
                this.verificationDialogVisible = true
                this.dialogVisible = false
            }

            this.setLoading('BindInfoLoading', false);
        },
        async fetchBindGoogle(params) {
            this.setLoading('BindInfoLoading', true);
            const data = await getBindGoogle(params)
            console.log(data, "绑定");
            if (data && data.code === 200) {
                this.isItBound = true
                this.$message({
                    message: this.$t(`user.verificationEnabled`),
                    type: "success",
                    showClose: true
                });
                this.verificationDialogVisible = false
                this.confirmationVerification = false
                for (const key in this.params) {
                    this.params[key] = ""
                }


            }
            this.setLoading('BindInfoLoading', false);
        },
        async fetchBindCode(params) {
            const data = await getBindCode(params)
            if (data && data.code === 200) {
                this.$message({
                    message: this.$t(`user.verificationCodeSuccessful`),
                    type: "success",
                    showClose: true
                });
            }
        },
        async fetchResetPwd(params) {
            this.setLoading('ResetPwdLoading', true);
            const data = await getUpdatePwd(params)
            if (data && data.code === 200) {
                this.$message({
                    message: this.$t(`user.modifiedSuccessfully`),
                    type: "success",
                    showClose: true
                });
                this.changePasswordDialogVisible = false
                this.dialogVisible = false
                this.verificationDialogVisible = false
                localStorage.removeItem("token")
                // 修改密码成功后跳转到登录页面
                const lang = this.$i18n.locale || this.lang || 'zh';
                this.$router.push(`/${lang}/login`); 
            }
            this.setLoading('ResetPwdLoading', false);
        },
        async fetchResetPwdCode(params) {
            const data = await getUpdatePwdCode(params)
            if (data && data.code === 200) {
                this.$message({
                    message: this.$t(`user.codeSuccess`),
                    type: "success",
                    showClose: true
                });
            }

        },
        async fetchCloseStepTwo(params) {
            this.setLoading('closeLoading', true);
            const data = await getCloseStepTwo(params)
            if (data && data.code === 200) {
                this.$message({
                    message: this.$t(`personal.Closed`),
                    type: "success",
                    showClose: true
                });
                this.verificationDialogVisible = false
                this.confirmationVerification = false
                this.closeDialogVisible = false
                this.fetchIfBind()
                for (const key in this.closeParams) {
                    this.closeParams[key] = ""
                }
            }
            this.setLoading('closeLoading', false);
        },
        async fetchCloseCode(params) {
            const data = await getCloseCode(params)
            if (data && data.code === 200) {
                this.$message({
                    message: this.$t(`user.codeSuccess`),
                    type: "success",
                    showClose: true
                });

            }
        },
        changePassword() {

            this.changePasswordDialogVisible = true
            // if ( this.isItBound) {
            //     this.changePasswordDialogVisible =true
            // }else{
            //     this.dialogVisible=true
            // }

        },
        jumpVerification() {
            // this.dialogVisible=false
            // this.verificationDialogVisible = true
            this.fetchBindInfo()

        },
        nextStep() {
            if (!this.checked) {
                this.$message({
                    showClose: true,
                    message: this.$t(`personal.confirmSelection`),
                    type: 'error'
                });
                return
            }
            this.verificationDialogVisible = false
            this.maintainDialogVisible = false
            this.confirmationVerification = true
        },
        previousStep() {
            this.confirmationVerification = false
            this.verificationDialogVisible = true
        },
        maintainPassword() {
            this.maintainDialogVisible = true
        },

        /**
         * 获取用户邮箱
         */
        getUserEmail() {
            try {
                const emailData = localStorage.getItem("userEmail");
                if (emailData) {
                    const emailObj = JSON.parse(emailData);
                    // 如果是对象，尝试取常见的邮箱字段
                    this.userEmail = emailObj.email || emailObj.value || emailObj.userEmail || emailObj;
                    // 如果最终结果不是字符串，可能数据有问题
                    if (typeof this.userEmail !== "string") {
                        this.userEmail = "";
                    }
                }
            } catch (e) {
                console.error("获取用户邮箱失败:", e);
                this.userEmail = "";
            }
        },
        /**
         * 打开删除账户弹窗
         */
        deleteAccount() {
            this.getUserEmail(); // 确保获取最新邮箱
            this.deleteAccountDialog = true
        },
        /**
         * 获取删除账户验证码
         */
        async handelDeleteAccountCode() {
            if (!this.userEmail) {
                this.$message({
                    showClose: true,
                    message: this.$t(`personal.mailbox`) + this.$t(`personal.pleaseEnter`),
                    type: 'error'
                });
                return;
            }
            
            this.deleteAccountCodeLoading = true;
            try {
                const data = await sendCloseAccount({ account: this.userEmail });
                if (data && data.code === 200) {
                    this.$message({
                        message: this.$t(`user.codeSuccess`),
                        type: "success",
                        showClose: true
                    });
                    // 成功后开始倒计时
                    if (window.sessionStorage.getItem("deleteAccount_time") == null) {
                        this.startCountDownDeleteAccount()
                    } else {
                        this.countDownTimeDeleteAccount = Number(window.sessionStorage.getItem("deleteAccount_time"));
                        this.startCountDownDeleteAccount()
                    }
                }
            } catch (error) {
                console.error("获取删除账户验证码失败:", error);
                this.$message({
                    message: this.$t(`user.codeFailed`) || '获取验证码失败',
                    type: "error",
                    showClose: true
                });
            } finally {
                this.deleteAccountCodeLoading = false;
            }
        },
        /**
         * 删除账户验证码倒计时
         */
        startCountDownDeleteAccount() {
            this.timerDeleteAccount = setInterval(() => {
                if (this.countDownTimeDeleteAccount <= 1) {
                    clearInterval(this.timerDeleteAccount);
                    sessionStorage.removeItem("deleteAccount_time");
                    this.countDownTimeDeleteAccount = 60
                    this.btnDisabledDeleteAccount = false;
                    this.bthTextDeleteAccount = `user.obtainVerificationCode`
                } else if (this.countDownTimeDeleteAccount > 0) {
                    this.countDownTimeDeleteAccount--;
                    this.btnDisabledDeleteAccount = true;
                    this.bthTextDeleteAccount = `user.again`
                    window.sessionStorage.setItem("deleteAccount_time", this.countDownTimeDeleteAccount);
                }
            }, 1000);
        },
        /**
         * 确认删除账户
         */
        confirmDeleteAccount() {
            if (!this.deleteAccountParams.eCode) {
                this.$message({
                    showClose: true,
                    message: this.$t(`personal.eCode`),
                    type: 'error'
                });
                return
            }
            if (!this.deleteAccountParams.gCode) {
                this.$message({
                    showClose: true,
                    message: this.$t(`personal.gCode`),
                    type: 'error'
                });
                return
            }

            // 二次确认
            this.$confirm(
                this.$t(`personal.deleteAccountWarning`) || '删除后关于此账户的相关信息将不能恢复，请慎重操作！',
                this.$t(`personal.Tips`) || '提示',
                {
                    confirmButtonText: this.$t(`personal.determine`) || '确定',
                    cancelButtonText: this.$t(`personal.Cancel`) || '取消',
                    type: 'warning'
                }
            ).then(() => {
                this.submitDeleteAccount();
            }).catch(() => {
                // 用户取消
            });
        },
        /**
         * 提交删除账户请求
         */
        async submitDeleteAccount() {
            this.setLoading('deleteAccountLoading', true);
            try {
                const data = await closeAccount({
                    userEmail: this.userEmail,
                    eCode: this.deleteAccountParams.eCode,
                    gCode: this.deleteAccountParams.gCode
                });
                if (data && data.code === 200) {
                    this.$message({
                        message: this.$t(`personal.deleteAccountSuccess`) || '账户删除成功',
                        type: "success",
                        showClose: true
                    });
                    this.deleteAccountDialog = false;
                    // 清除本地存储并跳转到登录页
                    localStorage.removeItem("token");
                    localStorage.removeItem("userEmail");
                    const lang = this.$i18n.locale;
                    this.$router.push(`/${lang}/login`);
                }
            } catch (error) {
                console.error("删除账户失败:", error);
            }
            this.setLoading('deleteAccountLoading', false);
        },
        /**
         * 关闭删除账户弹窗
         */
        closeDeleteAccountDialog() {
            // 重置表单
            this.deleteAccountParams.eCode = "";
            this.deleteAccountParams.gCode = "";
        },
        handelVerification() {
            // this.verificationDialogVisible = true
            this.fetchBindInfo()

        },
        modifyVerification() {
            this.fetchBindInfo()
            // this.verificationDialogVisible = true
        },
        closeVerification() {
            this.closeDialogVisible = true
        },
        copySecret() {

            navigator.clipboard.writeText(this.bindInfo.secret).then(() => {
                this.$message({
                    showClose: true,
                    message: this.$t(`personal.copySuccessful`),
                    type: 'success'
                });
            }).catch(err => {
                console.log('复制失败', err);
                this.$message({
                    showClose: true,
                    message: this.$t(`personal.copyFailed`),
                    type: 'error'
                });
            });

        },

        handelCode() {
            // if (!this.changePasswordParams.email) {
            //     this.$message({
            //         showClose: true,
            //         message: this.$t(`user.inputEmail`),
            //         type: 'error'
            //     });
            //     return
            // }
            this.fetchResetPwdCode()

            if (window.sessionStorage.getItem("Password_time") == null) {
                this.startCountDownPassword()
            } else {
                this.countDownTimePassword = Number(window.sessionStorage.getItem("Password_time"));
                this.startCountDownPassword()
            }
            // this.time = 60;
            // let timer = setInterval(() => {
            //     if (this.time) {
            //         this.time--
            //         this.btnDisabled = true;
            //         // this.bthText= this.time+`s后重新获取`
            //         this.bthText = `user.again`
            //     } else {
            //         this.btnDisabled = false;
            //         this.bthText = "user.obtainVerificationCode"
            //         this.time = "";
            //         clearTimeout(timer)
            //     }
            // }, 1000)
        },
        confirmchangePassword() {
            // if (!this.changePasswordParams.email) {
            //     this.$message({
            //         showClose: true,
            //         message: this.$t(`user.inputEmail`),
            //         type: 'error'
            //     });
            //     return
            // }

            if (!this.changePasswordParams.password) {
                this.$message({
                    showClose: true,
                    message: this.$t(`personal.pwd`),
                    type: 'error'
                });
                return
            }

            if (!this.changePasswordParams.updatePwdCode) {
                this.$message({
                    showClose: true,
                    message: this.$t(`personal.eCode`),
                    type: 'error'
                });
                return
            }
            // if (this.isItBound && !this.changePasswordParams.gCode) {
            //     this.$message({
            //         showClose: true,
            //         message: this.$t(`personal.gCode`),
            //         type: 'error'
            //     });
            //     return
            // }
            if (this.changePasswordParams.password !== this.newPassword) {

                this.$message({
                    showClose: true,
                    message: this.$t(`user.confirmPassword2`),
                    type: 'error'
                });
                return

            }

            // 密码验证 - 使用优化后的详细校验逻辑
            const validation = validatePassword(this.changePasswordParams.password);
            if (!validation.valid) {
                // 生成友好的逐项错误提示
                const errorMessage = formatPasswordErrors(validation.errors, this.$t.bind(this));
                this.$message({
                    message: errorMessage,
                    type: "error",
                    showClose: true,
                    duration: 5000, // 延长显示时间,因为错误信息可能有多条
                });

                return;
            }

            //加密
            const form = { ...this.changePasswordParams };
            form.password = encryption(this.changePasswordParams.password);


            this.fetchResetPwd(form)

        },


        confirmActivation() {


            if (!this.params.pwd) {
                this.$message({
                    showClose: true,
                    message: this.$t(`personal.pwd`),
                    type: 'error'
                });
                return
            }

            if (!this.params.eCode) {
                this.$message({
                    showClose: true,
                    message: this.$t(`personal.eCode`),
                    type: 'error'
                });
                return
            }
            if (!this.params.gCode) {
                this.$message({
                    showClose: true,
                    message: this.$t(`personal.gCode`),
                    type: 'error'
                });
                return
            }

            this.params.secret = this.bindInfo.secret

            //加密
            const form = { ... this.params };
            form.pwd = encryption(this.params.pwd);


            this.fetchBindGoogle(form)

        },
        handelECode() {

            this.fetchBindCode()

            if (window.sessionStorage.getItem("security_time") == null) {
                this.startCountDown()
            } else {
                this.countDownTime = Number(window.sessionStorage.getItem("security_time"));
                this.startCountDown()
            }

            // this.time = 60;   
            // let timer = setInterval(()=>{
            //   if ( this.time) {
            //     this.time--
            //     this.btnDisabled = true;
            //     // this.bthText= this.time+`s后重新获取`
            //     this.bthText= `user.again`
            //   }else {
            //     this.btnDisabled = false;
            //     this.bthText="user.obtainVerificationCode"
            //     this.time = "";
            //     clearTimeout(timer)
            //   }
            // },1000)
        },
        startCountDown() {
            this.timer = setInterval(() => {

                if (this.countDownTime <= 1) {
                    //当监测到countDownTime为0时,清除计数器并且移除sessionStorage,然后执行提交试卷逻辑
                    clearInterval(this.timer);
                    sessionStorage.removeItem("security_time");

                    this.countDownTime = 60
                    this.btnDisabled = false;
                    this.bthText = `user.obtainVerificationCode`
                } else if (this.countDownTime > 0) {
                    //每秒让countDownTime -1秒,并设置到sessionStorage中
                    this.countDownTime--;
                    this.btnDisabled = true;
                    this.bthText = `user.again`
                    window.sessionStorage.setItem("security_time", this.countDownTime);
                }
            }, 1000);
        },
        startCountDownClose() {
            this.timerclose = setInterval(() => {

                if (this.countDownTimeClose <= 1) {
                    //当监测到countDownTime为0时,清除计数器并且移除sessionStorage,然后执行提交试卷逻辑
                    clearInterval(this.timerclose);
                    sessionStorage.removeItem("close_time");

                    this.countDownTimeClose = 60
                    this.btnDisabledClose = false;
                    this.bthTextClose = `user.obtainVerificationCode`
                } else if (this.countDownTimeClose > 0) {
                    //每秒让countDownTimeClose -1秒,并设置到sessionStorage中
                    this.countDownTimeClose--;
                    this.btnDisabledClose = true;
                    this.bthTextClose = `user.again`
                    window.sessionStorage.setItem("close_time", this.countDownTimeClose);
                }
            }, 1000);
        },
        startCountDownPassword() {
            this.timerPassword = setInterval(() => {

                if (this.countDownTimePassword <= 1) {
                    //当监测到countDownTime为0时,清除计数器并且移除sessionStorage,然后执行提交试卷逻辑
                    clearInterval(this.timerPassword);
                    sessionStorage.removeItem("Password_time");

                    this.countDownTimePassword = 60
                    this.btnDisabledPassword = false;
                    this.bthTextPassword = `user.obtainVerificationCode`
                } else if (this.countDownTimePassword > 0) {
                    //每秒让countDownTimePassword -1秒,并设置到sessionStorage中
                    this.countDownTimePassword--;
                    this.btnDisabledPassword = true;
                    this.bthTextPassword = `user.again`
                    window.sessionStorage.setItem("Password_time", this.countDownTimePassword);
                }
            }, 1000);
        },

        handelCloseCode() {
            this.fetchCloseCode()

            if (window.sessionStorage.getItem("close_time") == null) {
                this.startCountDownClose()
            } else {
                this.countDownTimeClose = Number(window.sessionStorage.getItem("close_time"));
                this.startCountDownClose()
            }
            // this.time = 60;   
            // let timer = setInterval(()=>{
            //   if ( this.time) {
            //     this.time--
            //     this.btnDisabled = true;
            //     // this.bthText= this.time+`s后重新获取`
            //     this.bthText= `user.again`
            //   }else {
            //     this.btnDisabled = false;
            //     this.bthText="user.obtainVerificationCode"
            //     this.time = "";
            //     clearTimeout(timer)
            //   }
            // },1000)
        },
        confirmClose() {
            if (!this.closeParams.eCode) {
                this.$message({
                    showClose: true,
                    message: this.$t(`personal.eCode`),
                    type: 'error'
                });
                return
            }
            if (!this.closeParams.gCode) {
                this.$message({
                    showClose: true,
                    message: this.$t(`personal.gCode`),
                    type: 'error'
                });
                return
            }

            this.fetchCloseStepTwo(this.closeParams)

        },
        closeDialog() {
            // this.btnDisabled = false;
            // this.bthText="user.obtainVerificationCode"
            // this.time = "";
        },
        /**
         * 去除输入值中的空格
         * @param {string} value - 输入值
         * @returns {string} 去除空格后的值
         */
        removeSpaces(value) {
            if (typeof value === 'string') {
                return value.replace(/\s/g, '');
            }
            return value;
        },
        /**
         * 处理密码输入，自动去除空格
         * @param {string} value - 输入值
         * @param {string} field - 字段名
         */
        handlePasswordInput(value, field) {
            const trimmedValue = this.removeSpaces(value);
            if (field === 'password') {
                this.changePasswordParams.password = trimmedValue;
            } else if (field === 'newPassword') {
                this.newPassword = trimmedValue;
            } else if (field === 'pwd') {
                this.params.pwd = trimmedValue;
            }
        },
        /**
         * 处理验证码输入，自动去除空格
         * @param {string} value - 输入值
         * @param {string} field - 字段名
         */
        handleCodeInput(value, field) {
            const trimmedValue = this.removeSpaces(value);
            if (field === 'updatePwdCode') {
                this.changePasswordParams.updatePwdCode = trimmedValue;
            } else if (field === 'eCode') {
                this.closeParams.eCode = trimmedValue;
            } else if (field === 'paramsECode') {
                this.params.eCode = trimmedValue;
            } else if (field === 'deleteAccountECode') {
                this.deleteAccountParams.eCode = trimmedValue;
            }
        },



    }
}