<template>
	<div class="game-order-container">
		<el-card shadow="hover">
			<div class="game-order-search mb15">
				<el-form :inline="true">
					<el-form-item label="服务器">
						<el-select v-model="serverSwitch" class="m-2" placeholder="选择服务器" size="large" style="width: 80px">
							<el-option v-for="item in serverCategorize" :key="item.value" :label="item.label" :value="item.value" />
						</el-select>
						<el-select v-model="queryParams.serverId" placeholder="选择服务器" filterable>
							<el-option v-for="item in switchServer()" :key="item.id" :label="item.name" :value="item.id" />
						</el-select>
					</el-form-item>
					<el-form-item label="id">
						<el-input v-model="queryParams.id" placeholder="请输入id" clearable />
					</el-form-item>
					<el-form-item label="uid">
						<el-input v-model="queryParams.uid" placeholder="请输入uid" clearable />
					</el-form-item>
					<el-form-item label="账号">
						<el-select v-model="queryParams.channel" placeholder="选择渠道" style="width: 115px">
							<el-option v-for="item in channels" :key="item.value" :label="item.label" :value="item.value" />
						</el-select>
						<el-input v-model="queryParams.account" placeholder="请输入账号" clearable style="width: 250px" />
					</el-form-item>
					<el-form-item label="身份证:">
						<el-input v-model="queryParams.ident" placeholder="身份证" clearable />
					</el-form-item>
					<el-form-item label="名字:">
						<el-input v-model="queryParams.name" placeholder="名字" clearable />
					</el-form-item>
					<el-form-item>
						<el-button type="primary" class="ml10" @click="roleList">
							<el-icon>
								<ele-Search />
							</el-icon>
							查询
						</el-button>
					</el-form-item>
					<el-form-item>
						<el-button v-if="tableData.account.uid" type="primary" class="ml10" @click="noticePop"> 退出并选择删除排行榜 </el-button>
					</el-form-item>
				</el-form>
			</div>
		</el-card>
		<el-card shadow="hover" header="基本信息">
			<template #header>
				基本信息
				<el-button v-show="item.listShow == false" @click="item.listShow = true" class="button-caret" type="text">
					<el-icon size="20">
						<ele-CaretBottom />
					</el-icon>
				</el-button>
				<el-button v-show="item.listShow == true" @click="item.listShow = false" class="button-caret" type="text">
					<el-icon>
						<ele-CaretTop />
					</el-icon>
				</el-button>
			</template>
			<div v-show="item.listShow && tableData.data[0]">
				<el-form :inline="true"> id：{{ tableData.account.StringId }}</el-form>
				<el-form :inline="true"> uid：{{ tableData.account.uid }}</el-form>
				<el-form :inline="true"> 账号：{{ tableData.account.AccountName }}</el-form>
				<el-form :inline="true"> 账号类型：{{ tableData.account.AccountType }}</el-form>
				<el-form :inline="true"> 创建时间：{{ tableData.account.CreateTime }}</el-form>
				<el-form :inline="true"> 是否未成年：{{ checkAdult() }}</el-form>
				<el-form :inline="true">
					实名信息：
					<el-button type="text" @click="showIdentity">查看</el-button>
				</el-form>
			</div>
		</el-card>
		<el-card shadow="hover" header="存档信息">
			<template #header>
				存档信息
				<el-button v-show="item.listShow == false" @click="item.listShow = true" class="button-caret" type="text">
					<el-icon size="20">
						<ele-CaretBottom />
					</el-icon>
				</el-button>
				<el-button v-show="item.listShow == true" @click="item.listShow = false" class="button-caret" type="text">
					<el-icon>
						<ele-CaretTop />
					</el-icon>
				</el-button>
			</template>
			<div v-show="item.listShow && tableData.data[0]">
				<el-form :inline="true">
					山谷名称： {{ tableData.data[0] && tableData.data[0].ValleyComponent && tableData.data[0].ValleyComponent.Name }}
				</el-form>
				<el-form :inline="true">
					山谷创建时间：
					{{ tableData.data[0] && new Date(tableData.data[0].UnitCreateTime).toLocaleString() }}
				</el-form>
				<el-form :inline="true">
					游戏时间： {{ tableData.data[0] && tableData.data[0].ValleyComponent && tableData.data[0].ValleyComponent.Day }}天
					{{ tableData.data[0] && tableData.data[0].ValleyComponent && Math.floor(tableData.data[0].ValleyComponent.GameTime / 100) }}时
					{{ tableData.data[0] && tableData.data[0].ValleyComponent && tableData.data[0].ValleyComponent.GameTime % 100 }}分
					{{
						tableData.data[0] &&
						tableData.data[0].ValleyComponent &&
						seasonConfig.find((r) => r.Id == tableData.data[0].ValleyComponent.SeasonId).Name
					}}季
				</el-form>
				<el-form :inline="true">
					游戏规模：
					{{
						tableData.data[0] &&
						tableData.data[0].ValleyComponent &&
						tableData.data[0].ValleyComponent.Scale + '--' + scaleConfig.find((r) => r.Id == tableData.data[0].ValleyComponent.Scale).ScaleName
					}}
				</el-form>
				<el-form :inline="true">
					成功防守： {{ tableData.data[0] && tableData.data[0].ValleyComponent && tableData.data[0].ValleyComponent.Scale }}
				</el-form>
				<el-divider border-style="dotted" />
				<el-form>
					<el-descriptions direction="vertical" :column="6" border>
						<el-descriptions-item label="桃谷"> 解锁</el-descriptions-item>
						<div v-for="(item, k) in villageShow" :key="k">
							<el-descriptions-item :label="item.name + item.id">
								{{
									tableData.data[0] && tableData.data[0].RegionComponent && tableData.data[0].RegionComponent.UnLockRegionList.indexOf(item.id) == -1
										? '未解锁'
										: '解锁'
								}}
							</el-descriptions-item>
						</div>
					</el-descriptions>
				</el-form>
				<el-divider border-style="dotted" />
				<el-form>
					<el-descriptions direction="vertical" :column="4" border>
						<div v-for="(item, k) in valleyShow" :key="k">
							<el-descriptions-item :label="valleyShowCN[item]">
								{{ tableData.data[0] && tableData.data[0].ValleyComponent && tableData.data[0].ValleyComponent[item] }}
							</el-descriptions-item>
						</div>
					</el-descriptions>
				</el-form>
				<el-divider border-style="dotted" />
				<el-form :inline="true">
					<el-form-item label="物品名称:">
						<el-select size="default" v-model="queryParams.itemName" filterable placeholder="请填写物品名称">
							<el-option v-for="item in allItemConfig" :key="item.Id" :label="item.DetailsPageName" :value="item.Id" />
						</el-select>
					</el-form-item>
					<el-form-item>
						<el-button size="default" type="primary" class="ml10" @click="findItem">
							<el-icon>
								<ele-Search />
							</el-icon>
							查询
						</el-button>
					</el-form-item>
				</el-form>
				<el-form :inline="true">
					<el-form-item label="建筑名称:">
						<el-select size="default" v-model="queryParams.buildingName" filterable placeholder="请填写建筑名称">
							<el-option v-for="item in structureConfig" :key="item.Id" :label="item.Name" :value="item.Name" />
						</el-select>
					</el-form-item>
					<el-form-item>
						<el-button size="default" type="primary" class="ml10" @click="findBuilding">
							<el-icon>
								<ele-Search />
							</el-icon>
							查询
						</el-button>
					</el-form-item>
				</el-form>
				<el-form :inline="true">
					<el-form-item label="勇士名称:">
						<el-select size="default" v-model="queryParams.warriorName" filterable placeholder="请填写勇士名称">
							<el-option v-for="item in warriorConfig" :key="item.Id" :label="item.FirstName + item.Name" :value="item.FirstName + item.Name" />
						</el-select>
					</el-form-item>
					<el-form-item>
						<el-button size="default" type="primary" class="ml10" @click="findWarrior">
							<el-icon>
								<ele-Search />
							</el-icon>
							查询
						</el-button>
					</el-form-item>
				</el-form>
				<el-form :inline="true">
					<el-form-item label="村民名称:">
						<el-input size="default" v-model="queryParams.villagerName" placeholder="村民名称" class="w-50 m-2" clearable />
					</el-form-item>
					<el-form-item>
						<el-button size="default" type="primary" class="ml10" @click="findVillager">
							<el-icon>
								<ele-Search />
							</el-icon>
							查询
						</el-button>
					</el-form-item>
				</el-form>
			</div>
		</el-card>
		<el-card shadow="hover" header="付费信息">
			<template #header>
				付费信息
				<el-button v-show="item.listShow == false" @click="item.listShow = true" class="button-caret" type="text">
					<el-icon size="20">
						<ele-CaretBottom />
					</el-icon>
				</el-button>
				<el-button v-show="item.listShow == true" @click="item.listShow = false" class="button-caret" type="text">
					<el-icon>
						<ele-CaretTop />
					</el-icon>
				</el-button>
			</template>
			<div v-show="item.listShow && tableData.data[0]">
				付费总额：{{ tableData.data[0] && tableData.data[0].RechargeComponent && tableData.data[0].RechargeComponent.RechargeTotal }}
				<el-table :data="tableData.orderData" style="width: 100%">
					<el-table-column prop="tradeNo" label="订单id" show-overflow-tooltip></el-table-column>
					<el-table-column prop="tradeNo" label="订单状态" show-overflow-tooltip>
						<template #default="scope">
							<div v-if="scope.row.tradeNo.indexOf('Sandbox') > -1" style="color: #e60000">沙盒充值</div>
							<div v-else style="color: #22bc76">正常充值</div>
						</template>
					</el-table-column>
					<el-table-column prop="externalTradeNo" label="渠道订单id" show-overflow-tooltip></el-table-column>
					<el-table-column prop="stringId" label="账号" show-overflow-tooltip></el-table-column>
					<el-table-column prop="uid" label="uid" show-overflow-tooltip></el-table-column>
					<el-table-column prop="Rmb" label="金额（元）" show-overflow-tooltip width="120">
						<template #default="scope">
							{{ (Number(scope.row.Rmb) / 100).toFixed(2) }}
						</template>
					</el-table-column>
					<el-table-column prop="timeStr" label="充值时间" show-overflow-tooltip width="180"></el-table-column>

					<el-table-column prop="status" label="状态" show-overflow-tooltip width="120">
						<template #default="scope">
							<div v-if="scope.row.status == 1">
								<span style="color: #a8a17b">未付款</span>
							</div>
							<div v-else-if="scope.row.status == 2">
								<span>充值成功</span>
							</div>
							<div v-else>
								<span style="color: #e60000">充值失败</span>
							</div>
						</template>
					</el-table-column>
					<el-table-column prop="channel" label="渠道" show-overflow-tooltip width="120">
						<template #default="scope">
							<span>{{
								channels.find((r) => r.value == scope.row.channel) ? channels.find((r) => r.value == scope.row.channel).label : scope.row.channel
							}}</span>
						</template>
					</el-table-column>
					<el-table-column prop="server" label="区服" show-overflow-tooltip width="60"></el-table-column>
				</el-table>
				<el-row justify="space-evenly">
					<el-pagination
						:hide-on-single-page="true"
						v-model:page-size="queryParams.orderPageSize"
						v-model:current-page="queryParams.orderPageNum"
						:pager-count="5"
						@current-change="orderList"
						layout="total, prev, pager, next"
						:total="queryParams.orderTotal"
					/>
				</el-row>
			</div>
		</el-card>
		<el-card shadow="hover" header="登录信息">
			<template #header>
				登录信息
				<el-button v-show="item.listShow == false" @click="item.listShow = true" class="button-caret" type="text">
					<el-icon size="20">
						<ele-CaretBottom />
					</el-icon>
				</el-button>
				<el-button v-show="item.listShow == true" @click="item.listShow = false" class="button-caret" type="text">
					<el-icon>
						<ele-CaretTop />
					</el-icon>
				</el-button>
			</template>
			<div v-show="item.listShow && tableData.loginOutData.length > 0">
				<el-table :data="tableData.loginOutData" border>
					<el-table-column label="时间" width="180">
						<template #default="scope">
							<span>{{ scope.row.cDate }}</span>
						</template>
					</el-table-column>
					<el-table-column label="状态" width="80">
						<template #default="scope">
							<span>{{ scope.row.state == 1 ? '登录' : '登出' }}</span>
						</template>
					</el-table-column>
					<el-table-column label="山谷信息" width="100">
						<template #default="scope">
							<el-tag @click="getShowData(1, scope.row)">点击查看</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="部分信息" width="100">
						<template #default="scope">
							<el-tag @click="getShowData(2, scope.row)">点击查看</el-tag>
						</template>
					</el-table-column>
					<el-table-column label="其他信息" width="100">
						<template #default="scope">
							<el-tag @click="getShowData(3, JSON.stringify(scope.row))">点击查看</el-tag>
						</template>
					</el-table-column>
				</el-table>
				<el-row justify="space-evenly">
					<el-pagination
						:hide-on-single-page="true"
						v-model:page-size="queryParams.loginOutPageSize"
						v-model:current-page="queryParams.loginOutPageNum"
						:pager-count="5"
						@current-change="loginOut"
						layout="total, prev, pager, next"
						:total="queryParams.loginOutTotal"
					/>
				</el-row>
			</div>
		</el-card>
		<el-card shadow="hover" header="重要信息">
			<template #header>
				重要信息
				<el-button v-show="item.listShow == false" @click="item.listShow = true" class="button-caret" type="text">
					<el-icon size="20">
						<ele-CaretBottom />
					</el-icon>
				</el-button>
				<el-button v-show="item.listShow == true" @click="item.listShow = false" class="button-caret" type="text">
					<el-icon>
						<ele-CaretTop />
					</el-icon>
				</el-button>
			</template>
			<div v-show="item.listShow && tableData.itemRecordData.length > 0">
				<el-table :data="tableData.itemRecordData" border>
					<el-table-column label="物品Id" width="180">
						<template #default="scope">
							<span>{{ scope.row.itemId }}</span>
						</template>
					</el-table-column>
					<el-table-column label="物品名称" width="180">
						<template #default="scope">
							<span>{{ allItemConfig.find((r) => r.Id == scope.row.itemId)?.Name }}</span>
						</template>
					</el-table-column>
					<el-table-column label="物品数量" width="180">
						<template #default="scope">
							<span>{{ scope.row.num }}</span>
						</template>
					</el-table-column>
					<el-table-column label="添加前数量" width="180">
						<template #default="scope">
							<span>{{ scope.row.oldTotal }}</span>
						</template>
					</el-table-column>
					<el-table-column label="状态" width="180">
						<template #default="scope">
							<div v-if="scope.row.state == 1"><span style="color: #f81f1fd5">消耗</span></div>
							<div v-else><span style="color: #087512d6">增加</span></div>
						</template>
					</el-table-column>
					<el-table-column label="时间" width="180">
						<template #default="scope">
							<span>{{ scope.row.cTime }}</span>
						</template>
					</el-table-column>
				</el-table>
				<el-row justify="space-evenly">
					<el-pagination
						:hide-on-single-page="true"
						v-model:page-size="queryParams.itemPageSize"
						v-model:current-page="queryParams.itemPageNum"
						:pager-count="5"
						@current-change="itemRecord"
						layout="total, prev, pager, next"
						:total="queryParams.itemTotal"
					/>
				</el-row>
			</div>
		</el-card>

		<el-dialog v-model="buildingDialogVisible" width="90%" :show-close="false" center>
			<el-form :inline="true"> 建筑名称： {{ JSON.stringify(tableData.building.buidlingId) }}{{ tableData.building.name }} </el-form>
			<el-form :inline="true"> 建筑数量： {{ tableData.building.num }}</el-form>
			<el-table :data="tableData.building.buildingList" border>
				<el-table-column type="index" width="50" />
				<el-table-column prop="Position" label="位置" width="180">
					<template #default="scope">
						<span>x:{{ scope.row.Position.x }}-y:{{ scope.row.Position.y }}</span>
					</template>
				</el-table-column>
				<el-table-column label="耐久" width="180">
					<template #default="scope">
						<span>{{ scope.row.durableLeft[1] }}/{{ scope.row.Durable }}</span>
					</template>
				</el-table-column>
				<el-table-column label="损耗" width="180">
					<template #default="scope">
						<span>{{ scope.row.DurableLoss }}/日</span>
					</template>
				</el-table-column>
				<el-table-column label="宝物" width="180">
					<template #default="scope">
						<span>{{ scope.row.gemName.length === 0 ? '无' : scope.row.gemName }}</span>
					</template>
				</el-table-column>
				<el-table-column prop="name" label="强化" width="180">
					<template #default="scope">
						<span>{{ scope.row.StrengthenLv }}/{{ scope.row.StrengthenNumMax }}</span>
					</template>
				</el-table-column>
			</el-table>
		</el-dialog>

		<el-dialog v-model="warriorDialogVisible" width="90%" :show-close="false" center>
			<el-form :inline="true"> 勇士名称： {{ JSON.stringify(tableData.warrior.id) }}{{ tableData.warrior.name }} </el-form>
			<el-form :inline="true"> 加入时间-现实： {{ tableData.warrior.num }}</el-form>
			<el-form :inline="true"> 加入时间-游戏： {{ tableData.warrior.num }}</el-form>
			<el-table :data="tableData.warrior.list" border>
				<el-table-column label="是否出战" width="100">
					<template #default="scope">
						<span>{{ scope.row.troop }}</span>
					</template>
				</el-table-column>
				<el-table-column label="是否队长" width="100">
					<template #default="scope">
						<span>{{ scope.row.captain }}</span>
					</template>
				</el-table-column>
				<el-table-column label="战力" width="100">
					<template #default="scope">
						<span>{{ scope.row.fightingCapacity }}</span>
					</template>
				</el-table-column>
				<el-table-column label="位置" width="190">
					<template #default="scope">
						<span
							>x:{{ Math.floor(scope.row.BehaveComponent.DayPos.x * 100) / 100 }}-y:{{
								Math.floor(scope.row.BehaveComponent.DayPos.y * 100) / 100
							}}</span
						>
					</template>
				</el-table-column>
				<el-table-column label="睡前位置" width="190">
					<template #default="scope">
						<span
							>x:{{ Math.floor(scope.row.BehaveComponent.BeforeSleepPos.x * 100) / 100 }}-y:{{
								Math.floor(scope.row.BehaveComponent.BeforeSleepPos.y * 100) / 100
							}}</span
						>
					</template>
				</el-table-column>
			</el-table>
			<div v-for="warrior in tableData.warrior.list" :key="warrior.index">
				<el-form>
					<el-descriptions direction="vertical" :column="12" border>
						<div v-for="(item, k) in warrior.GameNumericComponent.NumericDic" :key="k">
							<el-descriptions-item
								:label="
									item[0] > 9999
										? NumericType['' + Math.floor(parseInt(item[0]) / 10)] + '基础'
										: NumericType[item[0]]
										? NumericType[item[0]]
										: item[0]
								"
							>
								{{ item[1] }}
							</el-descriptions-item>
						</div>
					</el-descriptions>
				</el-form>
			</div>
			<div v-for="(warrior, k) in tableData.warrior.list" :key="k">
				<el-table :data="warrior.SlotComponent.SlotDic" border>
					<el-table-column label="装备" width="180">
						<template #default="scope">
							<span>{{ scope.row[3] && scope.row[3].config && scope.row[3].config.Name }}</span>
						</template>
					</el-table-column>
					<el-table-column label="类型" width="180">
						<template #default="scope">
							<span>{{ Clothes_Type[scope.row[0]] }}</span>
						</template>
					</el-table-column>
					<el-table-column label="数值" width="180">
						<template #default="scope">
							<div v-for="(data, k) in scope.row[4]" :key="k">
								<div>{{ NumericType[data.id] }}：{{ data.operator }}{{ data.value }}</div>
							</div>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<div v-for="warrior in tableData.warrior.list" :key="warrior.index">
				<el-table :data="warrior.SkillComponent.Children" border>
					<el-table-column label="技能" width="180">
						<template #default="scope">
							<span>{{ scope.row.config.Name }}</span>
						</template>
					</el-table-column>
					<el-table-column label="类型" width="180">
						<template #default="scope">
							<span>{{ scope.row.config.CastType == 1 ? '主动' : '被动' }}</span>
						</template>
					</el-table-column>
					<el-table-column label="是否解锁" width="180">
						<template #default="">
							<span>是</span>
						</template>
					</el-table-column>
					<el-table-column label="等级" width="180">
						<template #default="scope">
							<span>{{ scope.row.Level }}</span>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</el-dialog>

		<el-dialog v-model="villagerDialogVisible" width="90%" :show-close="false" center>
			<el-form :inline="true"> 村民名称：{{ JSON.stringify(tableData.villager.Id) }}{{ tableData.villager.name }} </el-form>
			<el-form :inline="true"> 加入时间-现实： {{ tableData.villager.num }}</el-form>
			<el-form :inline="true"> 加入时间-游戏： {{ tableData.villager.num }}</el-form>
			<div v-for="(warrior, k) in tableData.villager.list" :key="k">
				<el-form>
					<el-descriptions direction="vertical" :column="12" border>
						<el-descriptions-item label="Id">
							{{ warrior.PeopleComponent.StringId }}
						</el-descriptions-item>
						<el-descriptions-item label="性别">
							{{ Gender[warrior.PeopleComponent.Gender] }}
						</el-descriptions-item>
						<el-descriptions-item label="状态">
							{{ ConstBehaveType[warrior.BehaveComponent.BehaveType] }}
						</el-descriptions-item>
						<div v-for="(item, k) in warrior.GameNumericComponent.NumericDic" :key="k">
							<el-descriptions-item
								:label="
									item[0] > 9999
										? (NumericType['' + Math.floor(parseInt(item[0]) / 10)]
												? NumericType['' + Math.floor(parseInt(item[0]) / 10)]
												: Math.floor(parseInt(item[0]) / 10)) + '基础'
										: NumericType[item[0]]
										? NumericType[item[0]]
										: item[0]
								"
							>
								{{ item[1] }}
							</el-descriptions-item>
						</div>

						<el-descriptions-item label="父">
							{{ warrior.MarriageComponent.ParentsShow.pa }}
						</el-descriptions-item>
						<el-descriptions-item label="母">
							{{ warrior.MarriageComponent.ParentsShow.ma }}
						</el-descriptions-item>
						<el-descriptions-item label="夫妻">
							<div v-for="(data, k) in warrior.MarriageComponent.MatesShow" :key="k">
								{{ data }}
							</div>
						</el-descriptions-item>
						<el-descriptions-item label="兄弟姐妹">
							<div v-for="(data, k) in warrior.MarriageComponent.BSShow" :key="k">
								{{ data }}
							</div>
						</el-descriptions-item>
						<el-descriptions-item label="子女">
							<div v-for="(data, k) in warrior.MarriageComponent.MyChildrenShow" :key="k">
								{{ data }}
							</div>
						</el-descriptions-item>
					</el-descriptions>
				</el-form>
				<el-table :data="warrior.SlotComponent.SlotDic" border>
					<el-table-column label="装备" width="180">
						<template #default="scope">
							<span>{{ scope.row[3].config.Name }}</span>
						</template>
					</el-table-column>
					<el-table-column label="类型" width="180">
						<template #default="scope">
							<span>{{ Clothes_Type[scope.row[0]] }}</span>
						</template>
					</el-table-column>
					<el-table-column label="数值" width="180">
						<template #default="scope">
							<div v-for="(data, k) in scope.row[4]" :key="k">
								<div>{{ NumericType[data.id] }}：{{ data.operator }}{{ data.value }}</div>
							</div>
						</template>
					</el-table-column>
				</el-table>

				<el-table :data="warrior.SkillComponent.Children" border>
					<el-table-column label="技能" width="180">
						<template #default="scope">
							<span>{{ scope.row.config.Name }}{{ scope.row.config.Action }}</span>
						</template>
					</el-table-column>
					<el-table-column label="类型" width="180">
						<template #default="scope">
							<span>{{ scope.row.config.CastType == 1 ? '主动' : '被动' }}</span>
						</template>
					</el-table-column>
					<el-table-column label="是否解锁" width="180">
						<template #default="">
							<span>是</span>
						</template>
					</el-table-column>
					<el-table-column label="等级" width="180">
						<template #default="scope">
							<span>{{ scope.row.Level }}</span>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</el-dialog>

		<el-dialog v-model="listVisible" :show-close="false" :before-close="handleClose" center>
			<p v-html="showData"></p>
		</el-dialog>
	</div>
</template>

<script lang="ts">
import { h, toRefs, reactive, onMounted, defineComponent } from 'vue';
import { deleteGameRank } from '/@/api/game/gameConfig';
import { gameLoginOut, gameLoginOutLog, gameItemRecord } from '/@/api/game';
import { gameRoleList, gameAccountList} from '/@/api/game/basicinfo';
import { gameOrderList } from '/@/api/game/order';
import { gameNoticePop } from '/@/api/game/notice';
import SeasonConfigCategory from '/@/api/config/SeasonConfigCategory.json';
import ScaleConfigCategory from '/@/api/config/ScaleConfigCategory.json';
import RegionConfigCategory from '/@/api/config/RegionConfigCategory.json';
import AllItemConfigCategory from '/@/api/config/AllItemConfigCategory.json';
import StructureConfigCategory from '/@/api/config/StructureConfigCategory.json';
import WorldParametersConfigCategory from '/@/api/config/WorldParametersConfigCategory.json';
import TreasureConfigCategory from '/@/api/config/TreasureConfigCategory.json';
import WarriorConfigCategory from '/@/api/config/WarriorConfigCategory.json';
import SkillConfigCategory from '/@/api/config/SkillConfigCategory.json';
import EquipmentConfigCategory from '/@/api/config/EquipmentConfigCategory.json';
import ClothesConfigCategory from '/@/api/config/ClothesConfigCategory.json';
import { ConstRegion, GameUnitType, NumericType, Clothes_Type, AttributeOperator, Gender, ConstBehaveType, AccountType } from '/@/api/common/consts';
import { ElMessage, ElMessageBox } from 'element-plus';
import { channelList, ServerCategorize, serverList } from '/@/utils/game';
import { getAccount, getCompleteChannel, gSwitchServer } from '/@/utils/utils';

// 定义接口来定义对象的类型
interface TableData {
	uid: number;
	name: string;
	region: number;
	totalTime: number;
	rechargeTotal: number;
	CreateTime: string;
	AccountType: string;
	AccountName: string;
}

interface TableDataState {
	item: { listShow: boolean };
	buildingDialogVisible: boolean;
	warriorDialogVisible: boolean;
	villagerDialogVisible: boolean;
	queryParams: {
		id: string;
		uid: number;
		serverId: number;
		channel: string;
		account: string;
		ident: string;
		name: string;
		itemName: string;
		buildingName: string;
		warriorName: string;
		villagerName: string;
		pageSize: number;
		pageNum: number;
		loginOutPageSize: number;
		loginOutPageNum: number;
		loginOutTotal: number;
		loginOutLogPageSize: number;
		loginOutLogPageNum: number;
		loginOutLogTotal: number;
		itemPageSize: number;
		itemPageNum: number;
		itemTotal: number;
		orderPageNum: number;
		orderPageSize: number;
		orderTotal: number;
		orderAccount: string;
	};
	tableData: {
		orderData: object[];
		account: TableData;
		data: Array<TableData>;
		loginOutData: object[];
		loginOutLogData: object[];
		itemRecordData: object[];
		total: 0;
		building: { buildingList: object[] };
		warrior: { list: object[] };
		villager: { list: object[] };
		accountType: Array<{ label: string; value: number }>;
	};
	villageList: object[];
	valleyComponent: object[];
	valleyShow: string[];
	valleyShowCN: object;
	villageShow: string[];
	villageShowCN: object;
	seasonConfig: object;
	scaleConfig: object;
	worldParametersConfig: object;
	treasureConfig: object;
	warriorConfig: object;
	regionConfig: object;
	equipmentConfig: object;
	clothesConfigCategory: object;
	NumericType: object;
	Clothes_Type: object;
	Gender: object;
	ConstBehaveType: object;
	channels: object;
	showData: string;
	listVisible: boolean;
	servers: object[];
	serverCategorize: object[];
	serverSwitch: number;
}

export default defineComponent({
	name: 'apiV1GameRoleRole',
	setup: function () {
		const state = reactive<TableDataState>({
			serverSwitch: 0,
			item: { listShow: true },
			queryParams: {
				id: '',
				serverId: '',
				channel: '',
				account: '',
				uid: '',
				ident: '',
				name: '',
				itemName: '',
				buildingName: '',
				warriorName: '',
				villagerName: '',
				pageSize: 10,
				pageNum: 1,
				loginOutPageSize: 10,
				loginOutPageNum: 1,
				loginOutTotal: 0,
				loginOutLogPageSize: 10,
				loginOutLogPageNum: 1,
				loginOutLogTotal: 0,
				itemPageSize: 10,
				itemPageNum: 1,
				itemTotal: 0,
				orderPageNum: 1,
				orderPageSize: 10,
				orderTotal: 0,
				orderAccount: '',
			},
			tableData: {
				loginOutData: [],
				itemRecordData: [],
				loginOutLogData: [],
				orderData: [],
				account: {},
				data: [],
				total: 0,
				building: { buildingList: [] },
				warrior: { list: [] },
				villager: { list: [] },
				accountType: AccountType,
			},
			seasonConfig: SeasonConfigCategory,
			scaleConfig: ScaleConfigCategory,
			valleyShow: ['Prosperity', 'Food', 'Copper', 'GoldIngot'],
			valleyShowCN: { Prosperity: '繁荣', Food: '食物', Copper: '铜钱', GoldIngot: '桃花石' },
			villageShow: [],
			villageShowCN: {},
			regionConfig: RegionConfigCategory,
			structureConfig: StructureConfigCategory,
			allItemConfig: AllItemConfigCategory,
			worldParametersConfig: WorldParametersConfigCategory,
			treasureConfig: TreasureConfigCategory,
			warriorConfig: WarriorConfigCategory,
			equipmentConfig: EquipmentConfigCategory,
			clothesConfig: ClothesConfigCategory,
			NumericType: NumericType,
			Clothes_Type: Clothes_Type,
			Gender: Gender,
			ConstBehaveType: ConstBehaveType,
			buildingDialogVisible: false,
			warriorDialogVisible: false,
			villagerDialogVisible: false,
			listVisible: false,
			showData: '',
			channels: [],
			servers: [],
			serverCategorize: ServerCategorize,
		});
		const roleList = (value: number) => {
			if (!value) {
				state.queryParams.itemPageNum = 1;
				state.queryParams.orderPageNum = 1;
				state.queryParams.loginOutLogPageNum = 1;
				state.queryParams.loginOutPageNum = 1;
			}
			if (
				state.queryParams.channel.length > 0 &&
				state.queryParams.account.length > 0 &&
				state.queryParams.account.indexOf(state.queryParams.channel) != 0
			) {
				state.queryParams.account = state.queryParams.channel + state.queryParams.account;
			}
			gameAccountList(state.queryParams).then((res) => {
				if (!res.data.list || res.data.list.length == 0) {
					ElMessage.error('未查询到用户信息！');
					return;
				}
				console.log('gameAccountList: ', res);
				const list = res.data.list ?? [];
				list.map((item: TableData) => {
					item.AccountType = state.tableData.accountType.find((r) => r.value == item.AccountType).label;
					item.CreateTime = new Date(item.CreateTime).toLocaleString();
				});
				if (list.length > 0) {
					state.tableData.account = list[0];
					gameRoleList({ id: list[0].StringId, serverId: state.queryParams.serverId }).then((res) => {
						if (!res.data.list || res.data.list.length == 0) {
							// ElMessage.error('未查询到玩家信息！');
							return;
						}
						console.log('gameRoleList: ', res);
						let roleList = res.data.list || [];
						state.tableData.total = res.data.total;
						roleList.map((item: TableData) => {
							for (let i in item.C) {
								item[item.C[i]._t] = item.C[i];
							}
						});
						state.tableData.data = roleList;
					});
					state.queryParams.orderAccount = list[0].AccountName;
					state.queryParams.channel = getCompleteChannel(list[0].Channel, list[0].SubChannel);
					// console.log('gameRoleList: ', list[0],list[0].Channel, list[0].SubChannel, state.queryParams, getCompleteChannel(list[0].Channel+"", list[0].SubChannel+""));
					orderList();
					loginOut();
					loginOutLog();
					itemRecord();
				}
			});
		};
		const orderList = () => {
			state.tableData.orderData = [];
			gameOrderList({
				account: getAccount(state.queryParams.orderAccount, state.queryParams.channel),
				pageNum: state.queryParams.orderPageNum,
				pageSize: state.queryParams.orderPageSize,
			}).then((res) => {
				if (!res.data.list || res.data.list.length == 0) {
					// ElMessage.error('未查询到充值信息！');
					return;
				}
				console.log('orderData: ', res);
				let list = res.data.list || [];
				state.queryParams.orderTotal = res.data.total;
				list.map((item: any) => {
					state.tableData.orderData.push({
						tradeNo: item.tradeNo,
						externalTradeNo: item.externalTradeNo,
						AccountName: item.account,
						timeStr: item.CreateTime,
						CfgId: item.config,
						Rmb: item.amount,
						status: item.status,
						CreateTime: item.CreateTime,
						channel: item.channel,
						server: item.server,
						uid: item.uid,
						stringId: item.stringId,
					});
				});
				// console.log('orderData: ', list);
			});
		};
		const loginOut = () => {
			state.tableData.loginOutData = [];
			gameLoginOut({
				account: getAccount(state.queryParams.orderAccount, state.queryParams.channel),
				serverId: state.queryParams.serverId,
				id: state.queryParams.id,
				pageSize: state.queryParams.loginOutPageSize,
				pageNum: state.queryParams.loginOutPageNum,
			}).then((res) => {
				if (!res.data.logs || res.data.logs.length == 0) {
					// ElMessage.error('未查询到登录登出信息！');
					return;
				}
				console.log('loginOut: ', res.data);
				state.queryParams.loginOutTotal = res.data.total;
				state.tableData.loginOutData = res.data.logs;
			});
		};
		const loginOutLog = () => {
			state.tableData.loginOutLogData = [];
			gameLoginOutLog({
				account: getAccount(state.queryParams.orderAccount, state.queryParams.channel),
				id: state.queryParams.id,
				serverId: state.queryParams.serverId,
				pageSize: state.queryParams.loginOutLogPageSize,
				pageNum: state.queryParams.loginOutLogPageNum,
			}).then((res) => {
				if (!res.data.logs || res.data.logs.length == 0) {
					// ElMessage.error('未查询到登录登出信息！');
					return;
				}
				console.log('loginOutLog: ', res.data);
				state.queryParams.loginOutLogTotal = res.data.total || 0;
				state.tableData.loginOutLogData = res.data.logs || [];
			});
		};
		const itemRecord = () => {
			state.tableData.itemRecordData = [];
			gameItemRecord({
				account: getAccount(state.queryParams.orderAccount, state.queryParams.channel),
				id: state.queryParams.id,
				serverId: state.queryParams.serverId,
				pageSize: state.queryParams.itemPageSize,
				pageNum: state.queryParams.itemPageNum,
			}).then((res) => {
				if (!res.data.logs || res.data.logs.length == 0) {
					// ElMessage.error('未查询到物品交易记录！');
					return;
				}
				console.log('itemRecord: ', res);
				state.queryParams.itemTotal = res.data.total || 0;
				state.tableData.itemRecordData = res.data.logs || [];
			});
		};
		// const onHandleSizeChange = (val: number) => {
		// 	state.queryParams.pageSize = val;
		// };
		const onHandleCurrentChange = (val: number) => {
			state.queryParams.pageNum = val;
			roleList(1);
		};
		onMounted(() => {
			serverList().then((res) => {
				state.servers = res;
				if (res.length > 0) {
					state.queryParams.serverId = res[0].id;
				}
			});
			channelList().then((res) => {
				state.channels = res;
			});
			state.villageShow = [];
			for (let i in RegionConfigCategory) {
				if (RegionConfigCategory[i].Type == 3) {
					state.villageShow.push({ id: RegionConfigCategory[i].Id, name: RegionConfigCategory[i].Region });
				}
			}
			console.log(state.villageShow);
		});
		const checkAdult = () => {
			if (!state.tableData.account) {
				return;
			}
			if (!state.tableData.account.StringId) {
				return;
			}
			if (!state.tableData.account.Identity) {
				return '未实名';
			}
			let year = state.tableData.account.Identity.substring(6, 10);
			let month = state.tableData.account.Identity.substring(11, 12);
			let day = state.tableData.account.Identity.substring(13, 14);

			return new Date(Number(year) + 18, month, day) > new Date() ? '是' : '否';
		};
		const showIdentity = (done: () => void) => {
			if (!state.tableData.account) {
				return;
			}
			if (!state.tableData.account.StringId) {
				return;
			}
			if (!state.tableData.account.Identity) {
				ElMessageBox({
					title: '实名信息',
					message: h('p', null, [h('div', null, '未实名')]),
				});
				return;
			}
			ElMessageBox({
				title: '实名信息',
				message: h('p', null, [
					h('div', null, '姓名: ' + (state.tableData.account.RealName || '')),
					h('div', null, '身份证号: ' + (state.tableData.account.Identity || '')),
				]),
			});
		};
		const findItem = (val: number) => {
			let itemId = 0;
			for (let i in AllItemConfigCategory) {
				let item = AllItemConfigCategory[i];
				if (item.Name == state.queryParams.itemName) {
					itemId = item.Id;
				}
			}

			if (!itemId) {
				return;
			}
			let showData = [h('div', null, '物品名称: ' + (itemId || '') + (state.queryParams.itemName || ''))];
			let warehouse = 0;
			let bag = 0;
			for (let i in state.tableData.data[0].StoreComponent.Children) {
				let c = state.tableData.data[0].StoreComponent.Children[i];
				if (c.ConfigId == itemId && c.Region == ConstRegion.Valley) {
					warehouse += c.Amount;
				}
				if (c.ConfigId == itemId && c.Region == ConstRegion.Bag) {
					bag += c.Amount;
				}
			}

			showData.push(h('div', null, '仓库持有: ' + warehouse));
			showData.push(h('div', null, '背包持有: ' + bag));
			if (showData) {
				ElMessageBox({
					title: '查询结果',
					message: h('p', null, showData),
				});
			}
		};
		const findBuilding = (val: number) => {
			let buidlingId = [];
			for (let i in StructureConfigCategory) {
				let item = StructureConfigCategory[i];
				console.log(item);
				if (item.Name == state.queryParams.buildingName) {
					buidlingId.push(item.Id);
				}
			}
			if (buidlingId.length <= 0) {
				console.log('findBuilding: ', buidlingId, state.queryParams);
				return;
			}
			let lost = 0;
			for (let i in state.tableData.data[0].ResearchComponent.HighUnLockList) {
				let id = state.tableData.data[0].ResearchComponent.HighUnLockList[i];
				if (id == 2001) {
					lost -= 1;
				}
				if (id == 2002) {
					lost -= 2;
				}
			}
			let buildingList = [];
			let num = 0;
			for (let i in state.tableData.data[0].GameUnitComponent.Children) {
				let c = state.tableData.data[0].GameUnitComponent.Children[i];
				if (c.UnitType == GameUnitType.Building) {
					for (let j in c.C) {
						let data = c.C[j];
						c[data._t] = data;

						if (data._t == 'BuildingComponent' && buidlingId.indexOf(data.ConfigId) !== -1) {
							num += 1;
							c.StrengthenLv = data.StrengthenLv;
							c.DurableLoss = WorldParametersConfigCategory[0].DurableLoss - WorldParametersConfigCategory[0].StrengthenDurable * data.StrengthenLv;
							c.Durable = StructureConfigCategory.find((r) => r.Id == data.ConfigId).Durable;
							buildingList.push(c);
						}
					}
				}
			}

			for (let i in buildingList) {
				buildingList[i].durableLeft = buildingList[i].GameNumericComponent.NumericDic.find((r) => r[0] == 2008);
				buildingList[i].DurableLoss += lost;
				buildingList[i].StrengthenNumMax = WorldParametersConfigCategory[0].StrengthenNumMax;
				buildingList[i].gemName = '';
				for (let j in buildingList[i].BuildingSlotComponent.Gems) {
					let item = AllItemConfigCategory.find((r) => r.Id == buildingList[i].BuildingSlotComponent.Gems[j]);
					if (!item) {
						break;
					}
					buildingList[i].gemName += (buildingList[i].gemName.length > 0 ? ';' : '') + item.DetailsPageName;
					let config = TreasureConfigCategory.find((r) => r.Id == item.RelatedId);
					if (!config) {
						break;
					}
					buildingList[i].DurableLoss -= config.DurableRecovery;
				}
			}

			state.tableData.building.name = state.queryParams.buildingName;
			state.tableData.building.num = num;
			state.tableData.building.buidlingId = buidlingId;
			state.tableData.building.buildingList = buildingList;
			state.buildingDialogVisible = true;
		};
		const findWarrior = () => {
			for (let i in WarriorConfigCategory) {
				let warriorConf = WarriorConfigCategory[i];
				if (!warriorConf || warriorConf.FirstName + warriorConf.Name != state.queryParams.warriorName) {
					continue;
				}
				state.tableData.warrior.name = state.queryParams.warriorName;
				state.tableData.warrior.id = warriorConf.Id;
			}

			let warriorList = [];
			let num = 0;

			let troop = state.tableData.data[0].TroopComponent.PeopleList;
			for (let i in state.tableData.data[0].GameUnitComponent.Children) {
				let c = state.tableData.data[0].GameUnitComponent.Children[i];
				if (c.UnitType == GameUnitType.Warrior) {
					for (let j in c.C) {
						let data = c.C[j];
						c[data._t] = data;
						c['captain'] = '否';

						c['troop'] = '否';
						let troopIndex = troop.indexOf(c._id);
						if (troopIndex == 0) {
							c['captain'] = '是';
						}
						if (troopIndex > -1) {
							c['troop'] = '是';
						}
						if (data._t == 'WarriorComponent' && state.tableData.warrior.id == data.ConfigId) {
							num += 1;
							c.SoulLevel = data.SoulLevel;
							warriorList.push(c);
						}
						if (data._t == 'SkillComponent') {
							for (let z in data.Children) {
								data.Children[z].config = SkillConfigCategory.find((r) => r.Id == data.Children[z].ConfigId);
							}
						}
						if (data._t == 'SlotComponent') {
							for (let z in data.SlotDic) {
								if (data.SlotDic[z][0] == Clothes_Type.WEAPON || data.SlotDic[z][0] == Clothes_Type.ARMOR) {
									data.SlotDic[z][3] = data.Children.find((r) => r.StringId == data.SlotDic[z][2]);
									if (data.SlotDic[z][3]) data.SlotDic[z][3].config = AllItemConfigCategory.find((r) => r.Id == data.SlotDic[z][3].ConfigId);
									data.SlotDic[z][4] = [];
									if (data.SlotDic[z][3] && data.SlotDic[z][3].config) {
										let equip = EquipmentConfigCategory.find((r) => r.Id == data.SlotDic[z][3].config.RelatedId);
										if (equip.Attribute1 > 0)
											data.SlotDic[z][4].push({
												id: equip.Attribute1,
												value: equip.AttributeValue1,
												operator: AttributeOperator[equip.AttributeOperator1],
											});
										if (equip.Attribute2 > 0)
											data.SlotDic[z][4].push({
												id: equip.Attribute2,
												value: equip.AttributeValue2,
												operator: AttributeOperator[equip.AttributeOperator2],
											});
										if (equip.Attribute3 > 0)
											data.SlotDic[z][4].push({
												id: equip.Attribute3,
												value: equip.AttributeValue3,
												operator: AttributeOperator[equip.AttributeOperator3],
											});
									}

									console.log(data.SlotDic[z]);
								}
							}
						}
					}
				}
			}

			for (let i in warriorList) {
				let ATK = 0;
				let HP = 0;
				let DEF = 0;
				let Hit = 0;
				let Dodge = 0;
				let Crit = 0;
				for (let j in warriorList[i].GameNumericComponent.NumericDic) {
					if (warriorList[i].GameNumericComponent.NumericDic[j][0] === NumericType.ATK) {
						ATK = warriorList[i].GameNumericComponent.NumericDic[j][1];
					}
					if (warriorList[i].GameNumericComponent.NumericDic[j][0] === NumericType.HP) {
						HP = warriorList[i].GameNumericComponent.NumericDic[j][1];
					}
					if (warriorList[i].GameNumericComponent.NumericDic[j][0] === NumericType.DEF) {
						DEF = warriorList[i].GameNumericComponent.NumericDic[j][1];
					}
					if (warriorList[i].GameNumericComponent.NumericDic[j][0] === NumericType.Hit) {
						Hit = warriorList[i].GameNumericComponent.NumericDic[j][1];
					}
					if (warriorList[i].GameNumericComponent.NumericDic[j][0] === NumericType.Dodge) {
						Dodge = warriorList[i].GameNumericComponent.NumericDic[j][1];
					}
					if (warriorList[i].GameNumericComponent.NumericDic[j][0] === NumericType.Crit) {
						Crit = warriorList[i].GameNumericComponent.NumericDic[j][1];
					}
				}
				warriorList[i]['fightingCapacity'] = ATK * 2 + HP * 2 + DEF * 5 + Hit * 2 + Dodge * 2 + Crit * 30;
			}

			state.tableData.warrior.list = warriorList;

			state.warriorDialogVisible = true;
		};
		const findVillager = () => {
			let warriorList = [];
			for (let i in state.tableData.data[0].GameUnitComponent.Children) {
				let c = state.tableData.data[0].GameUnitComponent.Children[i];
				if (c.UnitType == GameUnitType.Villager) {
					for (let j in c.C) {
						let data = c.C[j];
						c[data._t] = data;
						if (data._t == 'PeopleComponent' && data.FamilyName + data.Name == state.queryParams.villagerName) {
							warriorList.push(c);
						}
						if (data._t == 'SkillComponent') {
							for (let z in data.Children) {
								data.Children[z].config = SkillConfigCategory.find((r) => r.Id == data.Children[z].ConfigId);
							}
						}
						if (data._t == 'MarriageComponent') {
							let parent = {};
							data.BS = [];
							for (let z in data.Parents) {
								let people = getPeopleName(data.Parents[z], true);
								// console.log(data.Parents[z], people);
								if (people.people && people.people.Gender == Gender.MAN) {
									parent.pa = people.people.FamilyName + people.people.Name;
								}
								if (people.people && people.people.Gender == Gender.WOMAN) {
									parent.ma = people.people.FamilyName + people.people.Name;
								}
								if (people.MyChildren && people.MyChildren.length > 0) {
									people.MyChildren = people.MyChildren.filter((item) => item !== data.StringId);
									data.BS.concat(people.MyChildren);
								}
							}
							data.ParentsShow = parent;
							data.MyChildrenShow = [];
							// console.log(data.Parents);
							for (let z in data.MyChildren) {
								let people = getPeopleName(data.MyChildren[z]);
								if (people.people) {
									data.MyChildrenShow[z] = people.people.FamilyName + people.people.Name;
								}
							}
							data.MatesShow = [];
							for (let z in data.Mates) {
								let people = getPeopleName(data.Mates[z]);
								if (people.people) {
									data.MatesShow[z] = people.people.FamilyName + people.people.Name;
								}
							}
							data.BSShow = [];
							for (let z in data.BS) {
								let people = getPeopleName(data.BS[z]);
								if (people.people) {
									data.BSShow[z] = people.people.FamilyName + people.people.Name;
								}
							}
						}
						if (data._t == 'SlotComponent') {
							for (let z in data.SlotDic) {
								if (data.SlotDic[z][0] == Clothes_Type.APPAREL || data.SlotDic[z][0] == Clothes_Type.RAINGEAR) {
									data.SlotDic[z][3] = state.tableData.data[0].StoreComponent.Children.find((r) => r.StringId == data.SlotDic[z][2]);
									data.SlotDic[z][3].config = AllItemConfigCategory.find((r) => r.Id == data.SlotDic[z][3].ConfigId);
									data.SlotDic[z][4] = [];
									let equip = ClothesConfigCategory.find((r) => r.Id == data.SlotDic[z][3].config.RelatedId);
									if (equip.IllnessReduce > 0)
										data.SlotDic[z][4].push({
											id: NumericType.IllnessReduce,
											value: equip.IllnessReduce * 100,
											operator: AttributeOperator[1],
										});
									if (equip.DiseaseDeduction > 0)
										data.SlotDic[z][4].push({
											id: NumericType.DiseaseDeduction,
											value: equip.DiseaseDeduction * 100,
											operator: AttributeOperator[1],
										});
									if (equip.LifeExp > 0)
										data.SlotDic[z][4].push({
											id: NumericType.LifeExp,
											value: equip.LifeExp,
											operator: AttributeOperator[1],
										});
								}
								if (data.SlotDic[z][0] == Clothes_Type.WEAPON || data.SlotDic[z][0] == Clothes_Type.ARMOR) {
									data.SlotDic[z][3] = state.tableData.data[0].StoreComponent.Children.find((r) => r.StringId == data.SlotDic[z][2]);
									data.SlotDic[z][3].config = AllItemConfigCategory.find((r) => r.Id == data.SlotDic[z][3].ConfigId);
									data.SlotDic[z][4] = [];
									let equip = EquipmentConfigCategory.find((r) => r.Id == data.SlotDic[z][3].config.RelatedId);
									if (equip.Attribute1 > 0)
										data.SlotDic[z][4].push({
											id: equip.Attribute1,
											value: equip.AttributeValue1,
											operator: AttributeOperator[equip.AttributeOperator1],
										});
									if (equip.Attribute2 > 0)
										data.SlotDic[z][4].push({
											id: equip.Attribute2,
											value: equip.AttributeValue2,
											operator: AttributeOperator[equip.AttributeOperator2],
										});
									if (equip.Attribute3 > 0)
										data.SlotDic[z][4].push({
											id: equip.Attribute3,
											value: equip.AttributeValue3,
											operator: AttributeOperator[equip.AttributeOperator3],
										});
									// console.log(data.SlotDic[z]);
								}
							}
						}
					}
				}
			}

			state.tableData.villager.name = state.queryParams.villagerName;
			state.tableData.villager.list = warriorList;
			state.villagerDialogVisible = true;
		};
		const getPeopleName = (id: string, children: boolean) => {
			let res = {};
			for (let zz in state.tableData.data[0].GameUnitComponent.Children) {
				let c = state.tableData.data[0].GameUnitComponent.Children[zz];
				if (c.UnitType == GameUnitType.Villager && c.StringId === id) {
					for (let j in c.C) {
						let data = c.C[j];
						if (data._t == 'PeopleComponent') {
							res.people = data;
							if (!children) {
								return res;
							}
						}
						if (children && data._t == 'MarriageComponent') {
							res.MyChildren = data;
						}
					}
					return res;
				}
			}
			return res;
		};
		const getShowData = (type: number, data: any) => {
			if (type == 1) {
				state.showData =
					'游戏时间: ' +
					data.day +
					'天' +
					data.gameTime +
					'时， 规模: ' +
					data.scale +
					'， 村民数量: ' +
					data.villagerNum +
					'， 繁荣值: ' +
					data.prosperity;
			} else if (type == 2) {
				state.showData = '桃花石: ' + data.goldIngot + '， 铜币: ' + data.copper + '， 基础食物: ' + data.baseFood;
			} else if (type == 3) {
				state.showData = data;
			}
			state.listVisible = true;
		};
		const handleClose = () => {
			state.listVisible = false;
		};

		const switchServer = () => {
			return gSwitchServer(state.serverSwitch, state.servers);
		};
		const noticePop = () => {
			ElMessageBox.confirm(
				'是否确认强制踢出编号' +
					state.queryParams.serverId +
					'区的玩家' +
					state.tableData.account.AccountName +
					'[' +
					state.tableData.account.uid +
					']？',
				'提示',
				{
					confirmButtonText: '确认',
					cancelButtonText: '取消',
					type: 'warning',
				}
			).then(() => {
				let data = {
					serverId: state.queryParams.serverId,
					content: '强制踢出',
					uids: state.tableData.account.uid,
					popType: 3,
					popTo: 2,
				};
				console.log('Notice: ', data);
				gameNoticePop(data)
					.then(() => {
						ElMessage.success(data.serverId + '退出弹窗发送成功');
						deleteRank();
					})
					.finally(() => {
						// state.loading = false;
					});
			});
		};
		const deleteRank = () => {
			let data = {
				serverId: state.queryParams.serverId,
				uid: state.tableData.account.uid,
			};
			console.log('Notice: ', data);
			ElMessageBox.confirm(
				'是否确认删除编号' +
					state.queryParams.serverId +
					'区的玩家' +
					state.tableData.account.AccountName +
					'[' +
					state.tableData.account.uid +
					']的排行榜？',
				'提示',
				{
					confirmButtonText: '确认',
					cancelButtonText: '取消',
					type: 'warning',
				}
			).then(() => {
				deleteGameRank(data)
					.then((res) => {
						if (res.data.mess) {
							ElMessage.success(data.serverId + '区[uid:' + data.uid + ']' + '排行榜删除成功!' + res.data.mess);
						}
					})
					.finally(() => {
						// state.loading = false;
					});
			});
		};
		return {
			deleteRank,
			noticePop,
			switchServer,
			handleClose,
			getShowData,
			loginOut,
			orderList,
			loginOutLog,
			itemRecord,
			// onHandleSizeChange,
			onHandleCurrentChange,
			roleList,
			checkAdult,
			showIdentity,
			findItem,
			findBuilding,
			findWarrior,
			findVillager,
			...toRefs(state),
		};
	},
});
</script>
<style scoped lang="scss">
.el-form-item {
	display: -moz-flex;
	vertical-align: middle;
	margin-right: 32px;
}

::v-deep .el-table--striped .el-table__body tr.el-table__row--striped td {
	background: #ffffd5;
}

::v-deep .el-table .el-table--enable-row-hover .el-table__body tr:hover > td {
	background: inherit;
}

.el-row {
	margin-bottom: 20px;
}

.el-row:last-child {
	margin-bottom: 0;
}

.el-col {
	border-radius: 4px;
}

.grid-content {
	border-radius: 4px;
	min-height: 36px;
}
</style>
