<template>
    <div class="content">
        【恢复活力】
    </div>
    <div class="content">
        当前活力：{{ data.vitality }}/{{ maxVigour }}
    </div>
    <div class="content" v-if="data.vitality < maxVigour">
        [<Abutton @click="Recover">立即恢复</Abutton>]
    </div>
    <div class="content" v-else>
        活力满满,无需恢复!
    </div>
</template>
<script setup lang="ts">

definePageMeta({
    layout: layout.default,
    middleware: 'page-loading'
})
const data = ref<any>({});
const maxVigour = ref(0);
onMounted(async () => {
    try {
        await BindData();
    }
    finally {
        PageLoading.Close();
    }
})



const BindData = async (): Promise<void> => {
    let result = await RecoverService.GetUserVigour()
    if (result.code == 0) {
        data.value = result.data.data;
        maxVigour.value = result.data.maxVigour;
    }
    else {
        MessageExtend.ShowDialog("提示", result.msg);
    }
};

const Recover = async (): Promise<void> => {
    let npcId = LocalStorageHelper.GetOnNpc();
    MessageExtend.LoadingToast("恢复中...");
    let result = await RecoverService.RecoverVigour(Number(npcId));
    MessageExtend.LoadingClose();
    if (result.code == 0) {
        MessageExtend.Notify("恢复成功!", "success");
        await BindData();
    }
    else {
        MessageExtend.ShowDialog("提示", result.msg);
    }
};


</script>