<template>
    <div class="module-title">
        【更改昵称】
    </div>
    <div class="module-content">
        <div class="inArea">
            <input name="nick" type="text" class="ipt" maxlength="12" v-model="nick" />
        </div>
        <div class="inArea">
            <input type="button" class="btn btn-danger" value="更改昵称" @click="ChangeNick" />
        </div>
    </div>
    <div class="module-content" style="font-size:15px;font-weight:bold">
        *更改昵称需要改名卡 1 张。<br>
        *昵称修改需要符合《<Abar href="/customer/rule">游戏用户守则规范</Abar>》。
    </div>
</template>
<script setup lang="ts">
definePageMeta({
    layout: layout.default,
    middleware: middleware.loading
})

const nick = ref('');


onMounted(async () => {
    try {
        await BindData();
    }
    finally {
        PageLoading.Close();
    }
})

const BindData = async () => {
    let result = await UserService.GetUserBaseInfo("");
    if (result.code == 0) {
        nick.value = result.data.nick;
    }
    else {
        MessageExtend.ShowDialog("更改昵称", result.msg);
    }
}

const ChangeNick = async (): Promise<void> => {
    if (nick.value == null || nick.value == '') {
        MessageExtend.ShowToast("昵称不能为空!", "default");
        return;
    }
    MessageExtend.LoadingToast("更改中...");
    let result = await UserService.UpdateUserNick(nick.value);
    MessageExtend.LoadingClose();
    if (result.code == 0) {
        MessageExtend.Notify("修改成功!","success");        
    }
    else {
        MessageExtend.ShowDialog("更改昵称", result.msg);
    }
}


</script>