<template>
    <div class="content">
        【修复装备】
    </div>
    <div class="content">
        请选择:
        <div v-if="equData.length > 0">
            <span v-if="allCopper > 0">
                ➛<Abutton @click="retEqu('')">全部修复({{ allCopper }}铜)</Abutton>
            </span>
            <div class="item" v-for="(item, index) in equData" :key="index">
                {{ index + 1 }}.<GameEqu :equ-data="item" :show-lev="1" :show-url="true"></GameEqu>
                <span>({{ item.durability }}/{{ item.maxdurability }})</span>
                <span v-if="item.durability < item.maxdurability">
                    [<Abutton @click="retEqu(item.ueId)">修复({{ GameTool.FormatCopper((item.maxdurability -
                        item.durability) * 500) }})</Abutton>
                    ]
                </span>
            </div>
        </div>
        <div v-else>
            暂无穿戴中的装备.
        </div>
    </div>
    <div class="clear"></div>
    <div class="content" style="font-size: 16px;">
        说明:<br>
        1.装备仅可修复当前穿戴中的装备。<br>
        2.每修复1点耐久消耗500铜。
    </div>
</template>
<script setup lang="ts">

definePageMeta({
    layout: layout.default,
    middleware: 'page-loading'
})
const equData = ref<Array<any>>([]);
const allCopper = ref(0);
onMounted(async () => {
    try {
        await BindData();
    }
    finally {
        PageLoading.Close();
    }
})
const BindData = async (): Promise<void> => {
    let npcId = LocalStorageHelper.GetOnNpc();
    let result = await RecoverService.GetUserRecoverEqu(Number(npcId));
    if (result.code == 0) {
        equData.value = result.data.data;
        allCopper.value = result.data.need;
    }
    else {
        MessageExtend.ShowDialog("修理装备", result.msg);
    }
};

const retEqu = async (ueId: string) => {
    let npcId = LocalStorageHelper.GetOnNpc();
    MessageExtend.LoadingToast("修复中...");
    let result = await RecoverService.RecoverEqu(Number(npcId), ueId);
    MessageExtend.LoadingClose();
    if (result.code == 0) {
        MessageExtend.Notify(result.msg, "success");
        await BindData();
    }
    else {
        MessageExtend.ShowDialog("提示", result.msg);
    }
}
</script>