<template>
    <div class="content">
        <Abar :href='"/user/message/read?id=" + userData.userNo'>私聊</Abar>. <Abar
            :href='"/user/gift/give?no=" + userData.userNo'>送礼物</Abar>. <Abar href="/user/interact/dou">逗一下</Abar><br />
        <Abar href="/user/master/add">拜师</Abar>. <Abar :href='"/trade/user?no=" + userData.userNo'>交易</Abar>. <Abar
            href="/bag/give">送道具</Abar><br>
        <Abutton @click="FriendHandle">{{ isFriend ? "删除好友" : "加好友" }}</Abutton>
        <span v-if="isEnemy == false">
            .<Abutton @click="AddEnemy">加仇人</Abutton>
        </span>
    </div>
    <div class="content"></div>
    <div class="content">
        ID:{{ userData.userNo }}({{ online == 1 ? '在线' : '离线' }})<br>
        昵称:{{ userData.nick }}<br>
        特权:<br>
        徽章:<br>
        社交: 暂无<br>
        婚姻:<br>
        结拜:暂无<br>
        宠物:暂无<br>
        坐骑:无<br>
        成就:<br>
        个性签名:{{ userData.sign }}<br>
        罪恶值:{{ accData.enemy }}<br>
        师德:{{ accData.teach }}<br>
    </div>
    <div class="content">
        {{ attrData.lev }}级{{ userData.sex }}性({{ onMap }})
    </div>
    <div>
        <div class="content">
            手持:
            <span class="item" v-for="item in Hold">
                <GameEqu :equ-data="item" :show-url="true" :show-lev="1"></GameEqu>
            </span>
        </div>
        <div class="content">
            副手:
            <span class="item" v-for="item in Vice">
                <GameEqu :equ-data="item" :show-url="true" :show-lev="1"></GameEqu>
            </span>
        </div>
        <div class="content">
            头戴:
            <span class="item" v-for="item in Head">
                <GameEqu :equ-data="item" :show-url="true" :show-lev="1"></GameEqu>
            </span>
        </div>
        <div class="content">
            身穿:
            <span class="item" v-for="item in Wear">
                <GameEqu :equ-data="item" :show-url="true" :show-lev="1"></GameEqu>
            </span>
        </div>
        <div class="content">
            腰带:
            <span class="item" v-for="item in Waist">
                <GameEqu :equ-data="item" :show-url="true" :show-lev="1"></GameEqu>
            </span>
        </div>
        <div class="content">
            脚穿:
            <span class="item" v-for="item in Foot">
                <GameEqu :equ-data="item" :show-url="true" :show-lev="1"></GameEqu>
            </span>
        </div>
        <div class="content">
            佩戴:
            <span class="item" v-for="item in Ornaments">
                <GameEqu :equ-data="item" :show-url="true" :show-lev="1"></GameEqu>
            </span>
        </div>
        <div class="content">
            时装:
            <span class="item" v-for="item in Fashion">
                <GameEqu :equ-data="item" :show-url="true" :show-lev="1"></GameEqu>
            </span>
        </div>
        <div class="content">
            羽翼:
            <span class="item" v-for="item in Wing">
                <GameEqu :equ-data="item" :show-url="true" :show-lev="1"></GameEqu>
            </span>
        </div>
        <div class="content">
            装饰:
            <span class="item" v-for="item in Decorate">
                <GameEqu :equ-data="item" :show-url="true" :show-lev="1"></GameEqu>
            </span>
        </div>
        <div class="content" v-if="suit.length > 0">
            <div class="item" v-for="item in suit">
                套装:<Abar :href='"/prop/suit?no=" + item.suitCode'>{{ item.suitName }}</Abar>
            </div>
        </div>
    </div>
    <div class="content" v-if="team.state == 1">
        队伍:<Abar :href='"/user/team/info?id=" + team.team.teamId'>{{ team.team.name }}</Abar>
    </div>
    <div class="content" v-if="isPk">
        <Abutton @click="FightAtk">攻击</Abutton>
    </div>
</template>
<script setup lang="ts">

definePageMeta({
    layout: layout.default,
    middleware: 'page-loading'
})
const userData = ref<any>({});
const attrData = ref<any>({});
const accData = ref<any>({});
const online = ref(0);
const onMap = ref('');
const isFriend = ref(false);
const isEnemy = ref(false);
const isPk = ref(false);
const team = ref<any>({});
/**装备定义 */
const equ = ref<Array<any>>([]);
const suit = ref<Array<any>>([]);
const Hold = ref<Array<any>>([]);
const Vice = ref<Array<any>>([]);
const Head = ref<Array<any>>([]);
const Wear = ref<Array<any>>([]);
const Waist = ref<Array<any>>([]);
const Foot = ref<Array<any>>([]);
const Ornaments = ref<Array<any>>([]);
const Fashion = ref<Array<any>>([]);
const Wing = ref<Array<any>>([]);
const Decorate = ref<Array<any>>([]);

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



const BindData = async (): Promise<void> => {
    let no = PageExtend.QueryString("no");
    let result = await UserService.GetHomeInfo(no);
    if (result.code == 0) {
        userData.value = result.data.user;
        attrData.value = result.data.attr;
        accData.value = result.data.acc;
        online.value = result.data.isOnline;
        onMap.value = result.data.onMapName;
        isFriend.value = result.data.isFriend;
        isEnemy.value = result.data.isEnemy;
        team.value = result.data.team;
        isPk.value = result.data.isPk;
        equ.value = result.data.equ;
        suit.value = result.data.suit;
        Hold.value = equ.value.filter(it => it.code == 'Hold');
        Vice.value = equ.value.filter(it => it.code == 'Vice');
        Head.value = equ.value.filter(it => it.code == 'Head');
        Wear.value = equ.value.filter(it => it.code == 'Wear');
        Waist.value = equ.value.filter(it => it.code == 'Waist');
        Foot.value = equ.value.filter(it => it.code == 'Foot');
        Ornaments.value = equ.value.filter(it => it.code == 'Ornaments');
        Fashion.value = equ.value.filter(it => it.code == 'Fashion');
        Wing.value = equ.value.filter(it => it.code == 'Wing');
        Decorate.value = equ.value.filter(it => it.code == 'Decorate');
        console.log(result);

    }
    else if (result.code == 101) {
        return PageExtend.RedirectTo("/user");
    }
    else if (result.code == 102) {
        MessageExtend.ShowDialogEvent("提示", "玩家不存在!", () => {
            return PageExtend.RedirectTo("/user");
        }, "确认");
    }
    else {
        MessageExtend.ShowDialog("提示", result.msg);
    }
};

const FriendHandle = async (): Promise<void> => {
    MessageExtend.ShowConfirmDialogAsyc("好友操作", `您确定要${isFriend.value ? "删除" : "添加"}好友吗?`, async () => {
        let no = PageExtend.QueryString("no");
        let result = await RelationService.FriendHandle(no);
        if (result.code == 0) {
            await BindData();
            MessageExtend.Notify(result.msg, "success");
        }
        else {
            MessageExtend.Notify(result.msg, "danger");
        }

        return true;
    });
}

const AddEnemy = async (): Promise<void> => {
    MessageExtend.ShowConfirmDialogAsyc("关系操作", `您确定要添加Ta为仇人吗?(添加消耗300金元)`, async () => {
        let no = PageExtend.QueryString("no");
        let result = await RelationService.AddEnemy(no);
        if (result.code == 0) {
            await BindData();
            MessageExtend.Notify(result.msg, "success");
        }
        else {
            MessageExtend.Notify(result.msg, "danger");
        }

        return true;
    });
}

const FightAtk = async () => {
    let no = PageExtend.QueryString("no");
    MessageExtend.LoadingToast("战斗初始化...");
    let result = await FightService.FightPerson(no);
    MessageExtend.LoadingClose();
    if (result.code == 0) {
        return PageExtend.Redirect("/fight?f=" + result.data);
    }
    else {
        MessageExtend.ShowDialog("提示", result.msg);
    }
}

</script>