<!--
 * @Author: PoJun
 * @Date: 2023-09-28 10:38:11
 * @LastEditors: PoJun
 * @LastEditTime: 2023-12-25 16:39:42
 * @Message: 修改密码
-->
<template>
    <view class="update-psd">
        <uv-alert type="error" description="密码修改成功后将清除登录相关信息，需重新登录" center></uv-alert>
        <view class="update-psd-cont">
            <kirin-form ref="form" :list="list"></kirin-form>
            <view class="uv-m-t-30">
                <uv-button type="primary" text="确定" @click="save"></uv-button>
            </view>
        </view>
    </view>
</template>

<script>
import { logoutApp } from "@/utils/utils.js";
import { updatePsdFormList } from "./constant";
import { updatePassword } from "@/config/http.js";
export default {
    data() {
        return {
            list: updatePsdFormList,
        };
    },
    onLoad() {},
    methods: {
        async save() {
            const formData = this.$refs.form.getFormData();
            if (!formData) {
                return;
            }
            if (formData.rePassword.length < 6) {
                uni.$uv.toast("密码长度不能低于6位数");
                return;
            }

            uni.showLoading({ mask: true });
            await updatePassword(formData);
            try {
                await uni.$uv.sleep(500);
                logoutApp(this);
            } finally {
                uni.hideLoading();
            }
        },
    },
};
</script>

<style lang="scss">
.update-psd {
    &-cont {
        padding: 10rpx 25rpx;
    }
}
</style>
