<script setup>
import {reactive, useTemplateRef} from 'vue';
import VerificationCode from "../../components/VerificationCode/index.vue";
import Api from "../../api/index.js";
import {Message} from "@arco-design/web-vue";
import {toPath} from "../../utils/index.js";

const formRef = useTemplateRef('formRef');
const form = reactive({
    mobile: null,
    captcha: null,
    password: null,
});

const rules = {
    mobile: [{
        required: true,
        message: '手机号不能为空',
    }],
    captcha: [{
        required: true,
        message: '验证码不能为空',
    }],
    password: [{
        required: true,
        message: '请输入新密码',
    }],
}

const success = () => {
    formRef.value.validate().then(async (res) => {
        if (res) {
            const firstKey = Object.keys(res)[0];
            Message.warning(res[firstKey].message);
        } else {
            const {msg} = await Api.merchant.editPassword(form);
            Message.success(msg);
        }
    });
}
</script>

<template>
    <div class="p-[50px] rounded-[12px] bg-white w-[460px] min-h-[540px] box-border card">
        <div class="text-[24px] text-center text2">忘记密码</div>
        <div class="mt-[48px] flex flex-col gap-[20px]">
            <a-form
                ref="formRef"
                :model="form"
                :rules="rules"
                layout="vertical">
                <a-form-item field="mobile">
                    <a-input v-model:model-value="form.mobile" placeholder="手机号"></a-input>
                </a-form-item>
                <a-form-item field="captcha">
                    <VerificationCode
                        :type="3"
                        :api="Api.merchant.sendSms"
                        :mobile="form.mobile"
                        v-model:verification-code="form.captcha">
                    </VerificationCode>
                </a-form-item>
                <a-form-item field="password">
                    <a-input v-model:model-value="form.password" placeholder="新密码"></a-input>
                </a-form-item>
            </a-form>
        </div>
        <div class="flex flex-col mt-[30px] gap-[32px]">
            <a-button type="primary" @click="success">确认修改</a-button>
            <a-button
                @click="toPath('/loginSYS/login')"
                type="text">
                返回
                <icon-arrow-right class="ml-[5px]"/>
            </a-button>
        </div>
    </div>
</template>

<style>
.arco-form-item-label-col {
    display: none;
}
</style>

<style scoped>
.card {
    box-shadow: 0 8px 20px 0 rgba(0, 0, 0, 0.1);

    :deep(.arco-form-item-label-col) {
        line-height: 20px;
    }
}

.text2 {
    color: rgb(29, 33, 41);
    font-size: 24px;
    font-weight: 400;
    line-height: 32px;
    letter-spacing: 0;
    text-align: left;
}

.text1 {
    /* 14/CN-Regular */
    color: rgb(78, 89, 105);
    font-size: 14px;
    font-weight: 400;
    line-height: 22px;
    letter-spacing: 0;
    text-align: left;
    cursor: pointer;
    transition: 500ms;

    &::after {
        content: '';
        display: block;
        width: 100%;
        height: 2px;
        background-color: rgb(22, 93, 255);
        margin-top: 12px;
        opacity: 0;
        transition: 500ms;
    }
}

.text1-cur {
    color: rgb(22, 93, 255);
    font-size: 14px;
    font-weight: 400;
    line-height: 22px;
    letter-spacing: 0;
    text-align: left;

    &::after {
        opacity: 1;
    }
}
</style>
