<script setup>
import {onMounted, reactive, ref} from "vue";
import XInfoModal from "../../../components/XInfoModal.vue";
import XForm from "../../../components/XForm.vue";
import XFormItem from "../../../components/XFormItem.vue";
import XInput from "../../../components/XInput.vue";
import SendMsg from "../../../components/SendMsg.vue";
import Api from "../../../api/index.js";
import {showToast} from "../../../utils/uils.js";
import {useUserStore} from "../../../pinia/UserStore/index.js";

const XFormRef = ref();
const UserStore = useUserStore();
const show = defineModel('show');
const rules = {
    mobile: {
        reg: /^1[3-9]\d{9}$/,
        msg: '请输入正确的手机号',
    },
    captcha: {
        reg: /.+/,
        msg: '请输入正确的验证码',
    },
    password: {
        reg: /.+/,
        msg: '请输入正确的密码',
    },
};
const form = reactive({
    mobile: UserStore.userInfo.full_mobile,
    captcha: null,
    password: null,
});

const success = async () => {
    XFormRef.value.verify();
    const {msg} = await Api.system.savePassword(form);
    showToast(msg);
    await UserStore.getUserInfo();
    show.value = false;
}
</script>

<template>
    <x-info-modal v-model:show="show" @success="success">
        <view class="title">修改密码</view>

        <x-form ref="XFormRef" :model="form" :rules="rules">
            <x-form-item label="手机号">
                <x-input height="72rpx" placeholder="微信号" disabled v-model:model-value="form.mobile"></x-input>
            </x-form-item>
            <x-form-item label="验证码">
                <send-msg height="72rpx" :mobile="form.mobile" v-model:model-value="form.captcha" :type="3"></send-msg>
            </x-form-item>
            <x-form-item label="新登录密码">
                <x-input height="72rpx" placeholder="新登录密码" v-model:model-value="form.password"></x-input>
            </x-form-item>
        </x-form>
    </x-info-modal>
</template>

<style scoped lang="scss">
.title {
    color: rgb(29, 33, 41);
    font-size: 32rpx;
    font-weight: 500;
    line-height: 24px;
    letter-spacing: 0;
    text-align: center;
    margin-bottom: 20rpx;
}
</style>
