<script setup>
import {reactive, ref, onMounted} 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 {useUserStore} from "../../../pinia/UserStore/index.js";
import Api from "../../../api/index.js";
import {showToast} from "../../../utils/uils.js";

const XFormRef = ref();
const show = defineModel('show');
const rules = {
    nickname: {
        reg: /^[^]*\S[^]*$/,
        msg: '昵称不能为空',
    }
};
const form = reactive({
    nickname: null,
});

const success = async () => {
    XFormRef.value.verify();
    const {msg} = await Api.system.saveInfo({...form, type: 2});
    showToast(msg);
    await UserStore.getUserInfo();
    show.value = false;
}

const UserStore = useUserStore();
onMounted(() => {
    form.nickname = UserStore.userInfo.nickname;
})
</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>
                <x-input height="72rpx" placeholder="微信号" v-model:model-value="form.nickname"></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>
