<template>
	<div class="table-box">
		<div class="statistics-top">
			<div class="sta-item" v-for="(item, index) in statisticsOption" :key="index">
				<div class="sta-num">
					<span>{{ item.name }}</span>
					<span>{{ item.value ? item.value : 0 }}</span>
				</div>
				<img :src="item.img" alt="" />
			</div>
		</div>
		<div class="table">
			<ProTable
				ref="proTable"
				title="考勤设备列表"
				:columns="columns"
				:requestApi="getTableList"
				:dataCallback="dataCallback"
				:tool-button="false"
				:pagination="true"
				background
				:isShowSearch="false"
				:onReset="false"
			>
				<template #operation="{ row }">
					<el-button type="primary" link @click="handleLookItem(row)">
						<img src="@/assets/images/tableIcon/look.png" alt="" class="configureIcon" />
						<span>查看</span>
					</el-button>
				</template>
				<template #state="{ row }">
					<span>{{
						row.state == 1
							? "执法中"
							: row.state == 2
							? "待整改"
							: row.state == 3
							? "待审核"
							: row.state == 4
							? "已闭合"
							: row.state == 5
							? "已驳回"
							: ""
					}}</span>
				</template>
			</ProTable>
		</div>
		<transformInfo v-model:detailsDialog="detailsDialog" :relativeId="relativeId" @confirm="confirmReform"></transformInfo>
	</div>
</template>

<script setup lang="tsx" name="ProjectSupervisionRecord">
import { ref, reactive, nextTick, onMounted } from "vue";
import { ColumnProps } from "@/components/ProTable/interface";
import ProTable from "@/components/ProTable/index.vue";
import transformInfo from "./components/transformInfo.vue";
import { statisticsInfo, statisticsTable } from "@/api/modules/project";
const statisticsOption = ref([
	{
		name: "累计下达整改单",
		value: 0,
		img: new URL("@/assets/images/govermentImg/整改单.png", import.meta.url).href,
		prop: "inspectNum"
	},
	{
		name: "累计下达停工单",
		value: 0,
		img: new URL("@/assets/images/govermentImg/停工单.png", import.meta.url).href,
		prop: "shutdownNum"
	},
	{
		name: "累计问题数",
		value: 0,
		img: new URL("@/assets/images/govermentImg/问题数.png", import.meta.url).href,
		prop: "questionNum"
	},
	{
		name: "累计闭合问题数",
		value: 0,
		img: new URL("@/assets/images/govermentImg/闭合问题数.png", import.meta.url).href,
		prop: "solveNum"
	},
	{
		name: "总检查次数",
		value: 0,
		img: new URL("@/assets/images/govermentImg/总检查次数.png", import.meta.url).href,
		prop: "recordNum"
	}
]);
// 表格配置项
const columns: ColumnProps[] = [
	{ type: "index", label: "序号", width: 80 },
	{
		prop: "engineeringName",
		label: "工程名称",
		search: { el: "input" }
	},
	{
		prop: "inspectUserName",
		label: "监督员"
	},
	{
		prop: "createTime",
		label: "检查时间"
	},
	{
		prop: "buildEnt",
		label: "建设单位"
	},
	{
		prop: "supervisorEnt",
		label: "监理单位"
	},
	{
		prop: "opEnt",
		label: "施工单位"
	},
	{
		prop: "surveyEnt",
		label: "勘察单位"
	},
	{
		prop: "designEnt",
		label: "设计单位"
	},
	{
		prop: "state",
		label: "状态"
	},
	{ prop: "operation", label: "操作", fixed: "right", width: 260 }
];
const detailsDialog = ref(false);
const relativeId = ref("");
// 获取 ProTable 元素，调用其获取刷新数据方法（还能获取到当前查询参数，方便导出携带参数）
const proTable = ref();
// 整改完成，全部已提交审核
const confirmReform = () => {
	proTable.value.getTableList();
};
const handleLookItem = row => {
	console.log(row);
	relativeId.value = row.id;
	detailsDialog.value = true;
};
const getTableList = (params: any) => {
	let newParams = JSON.parse(JSON.stringify(params));
	if (newParams.createTime) {
		newParams.createTime_begin = newParams.createTime[0];
		newParams.createTime_end = newParams.createTime[1];
		delete newParams.createTime;
	}
	newParams.type = 1;
	return statisticsTable(newParams);
};
// dataCallback 是对于返回的表格数据做处理，如果你后台返回的数据不是 list && total && pageNum && pageSize 这些字段，那么你可以在这里进行处理成这些字段
// 或者直接去 hooks/useTable.ts 文件中把字段改为你后端对应的就行
const dataCallback = (data: any) => {
	// console.log(data);
	return {
		list: data.records,
		total: Number(data.total),
		pageNo: Number(data.current),
		pageSize: Number(data.size)
	};
};
// 获取顶部统计信息
const getInfo = async () => {
	const res = await statisticsInfo({ type: 1 });
	statisticsOption.value.map(item => {
		item.value = res.result[item.prop];
	});
	console.log(res);
};
onMounted(() => {
	getInfo();
});
</script>
<style scoped lang="scss">
.table-box {
	.statistics-top {
		display: flex;
		flex-wrap: wrap;
		.sta-item:not(:last-child) {
			margin-right: 28px;
		}
		.sta-item {
			min-width: 310px;
			height: 113px;
			background: rgba(255, 255, 255, 0.9);
			border-radius: 8px 8px 8px 8px;
			opacity: 1;
			display: flex;
			margin-bottom: 20px;
			.sta-num {
				display: flex;
				flex-direction: column;
				margin-top: 20px;
				margin-left: 42px;
				margin-right: auto;
				span:first-child {
					font-size: 16px;
					font-family: Source Han Sans CN-Regular, Source Han Sans CN;
					color: #6b7275;
				}
				span:last-child {
					font-size: 32px;
					font-family: OPPOSans-Heavy, OPPOSans;
					font-weight: 800;
					color: #2e3038;
				}
			}
			> img {
				width: 44px;
				height: 40px;
				margin-right: 22px;
				margin-top: 20px;
			}
		}
	}
	.table {
		position: relative;
		z-index: 500;
	}
}
</style>
