<template>
    <div class="content">
        【恢复体力】
    </div>
    <div class="content">
        当前体力：{{ data.blood }}/{{ data.upBlood }}
    </div>
    <div class="content" v-if="data.blood < data.upBlood">
        [<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>({});
onMounted(async () => {
    try {
        await BindData();
    }
    finally {
        PageLoading.Close();
    }
})



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

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


</script>