<template>
    <div class="content">
        <img src="/images/logo.png" class="logo" />
    </div>
    <div class="content">
        <div class="common">
            <div class="input">
                昵称:<input name="nick" placeholder="输入昵称(1-12个长度字符)" maxlength="12" class="ipt" type="text"
                    v-model="nick" />
            </div>
            <div class="input">
                性别:<select name="sex" class="ipt" v-model="sex">
                    <option value="0">女</option>
                    <option value="1">男</option>
                </select>
            </div>
            <div class="input" v-if="isNeedCode">
                激活码:<input name="nick" placeholder="联系客服获取激活码" maxlength="50" class="ipt" type="text" v-model="code" />
            </div>
            <div class="input">
                <input type="button" class=" btn btn-danger" value="注册角色" @click="SubRegInfo" />.
                <Abar href="/">返回首页</Abar>
            </div>
        </div>
    </div>
</template>
<script setup lang="ts">
definePageMeta({
    layout: layout.empty,
    middleware: middleware.loading
})

const nick = ref('');
const sex = ref(0);
const code = ref('');
const isNeedCode = ref(false);
const data = ref<any>({});

const SubRegInfo = async (): Promise<void> => {
    if (nick.value == null || nick.value == '') {
        MessageExtend.ShowToast("昵称不能为空!", "default");
        return;
    }
    MessageExtend.LoadingToast("注册中...");
    let result = await LoginService.RegisterInfo(nick.value, sex.value, code.value);
    MessageExtend.LoadingClose();
    if (result.code == 0) {
        PageExtend.Redirect("/map");
    }
    else {
        MessageExtend.ShowDialog("注册角色", result.msg);
    }
}


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

const BindData = async () => {
    let result = await PubService.GetOnAreaInfo();
    if (result.code == 0) {
        data.value = result.data;
        isNeedCode.value = result.data.isNeedCode == 1;
    }
    else {
        MessageExtend.ShowDialogEvent("提示", result.msg, () => {
            PageExtend.RedirectTo('/');
        });
    }

}
</script>