<script setup>
import {reactive} from "vue";
import XNav from "../../components/XNav.vue";
import XLink from "../../components/XLink.vue";
import XInput from "../../components/XInput.vue";
import Api from "../../api/index.js";
import {backPage, showToast, verifyForm} from "../../utils/uils.js";
import SendMsg from "../../components/SendMsg.vue";

const form = reactive({
    mobile: null,
    captcha: null,
    password: null,
});
const rules = {
    mobile: {
        reg: /^1[3-9]\d{9}$/,
        title: '手机号',
        msg: '手机号错误',
        required: true,
    },
    captcha: {
        reg: /^\d{6}$/,
        title: '验证码',
        msg: '验证码错误',
        required: true,
    },
    password: {
        title: '密码',
        msg: '密码错误',
        required: true,
    }
}

const success = async () => {
    verifyForm(form, rules);
    const {msg} = await Api.system.editPassword(form);
    showToast(msg);
    backPage();
}
</script>

<template>
    <!--忘记密码-->
    <XNav></XNav>

    <view class="relative !px-[36rpx]">
        <view class="!mt-[56rpx]">
            <view class="title">修改密码</view>
            <view class="title-desc">请完成验证后，设置新密码</view>
        </view>

        <view class="!flex flex-col gap-[56rpx] !mt-[60rpx]">
            <x-input v-model:model-value="form.mobile" placeholder="请输入手机号"></x-input>
            <send-msg v-model:model-value="form.captcha" :mobile="form.mobile" :type="3"></send-msg>
            <x-input v-model:model-value="form.password" placeholder="请输入密码"></x-input>

            <tui-button @click="success">确定修改</tui-button>
        </view>
    </view>
</template>

<style lang="scss">
page {
    background-color: #fff;
}
</style>

<style lang="scss" scoped>
.title {
    color: rgb(29, 33, 41);
    font-size: 26px;
    font-weight: 700;
    line-height: 28px;
    letter-spacing: 0;
    text-align: left;
}

.title-desc {
    margin-top: 16rpx;
    color: rgb(78, 89, 105);
    font-size: 28rpx;
    font-weight: 400;
    line-height: 56rpx;
    letter-spacing: 0;
    text-align: left;
}
</style>
