<template>
	<div class="warning-page" v-if="!showScreen">
		<div class="table-box">
			<div class="table">
				<ProTable
					ref="proTable"
					title="项目审批"
					:columns="columns"
					:requestApi="getTableList"
					:dataCallback="dataCallback"
					:tool-button="false"
					:pagination="true"
					background
					:isShowSearch="true"
					:onReset="true"
				>
					<template #formButton="scope">
						<el-button v-auth="'pre_project_add'" class="btnStyle" @click="handleAddItem">新增</el-button>
					</template>
					<template #operation="{ row }">
						<el-button type="primary" v-auth="'pre_file_list'" link @click="onFileList(row)"
							><img src="@/assets/images/tableIcon/look.png" alt="" class="configureIcon" /><span>文件列表</span></el-button
						>
						<el-button type="primary" link @click="onSee(row)"
							><img src="@/assets/images/tableIcon/look.png" alt="" class="configureIcon" /><span>查看</span></el-button
						>
						<el-button v-auth="'pre_project_update'" type="primary" link @click="onEdit(row)"
							><img src="@/assets/images/tableIcon/updateIcon.png" alt="" class="configureIcon" /><span>编辑</span></el-button
						>
						<!-- <el-button v-auth="'pre_project_update'" type="primary" link @click="toScreen(row)"
							><img src="@/assets/images/tableIcon/look.png" alt="" class="configureIcon" /><span>项目大屏</span></el-button
						> -->
						<!-- <el-button type="primary" link @click="openMap(row)"
								><img src="@/assets/images/tableIcon/修正定位.png" alt="" class="configureIcon" /><span>修正定位</span></el-button
							>
							<el-button v-if="row.examineState === 3" type="primary" link @click="onState(row)"
								><img src="@/assets/images/tableIcon/修改状态.png" alt="" class="configureIcon" /><span>修改状态</span></el-button
							> -->
					</template>
				</ProTable>
				<!-- 盒子嵌入版 -->
				<divDialogComponent v-model:visible="detailsDialog" class="add-edit-box">
					<template #topContent>
						<div class="title-detail">
							<span>{{ approvalTitle }}</span>
							<el-icon>
								<close @click="detailsDialog = false" />
							</el-icon>
						</div>
					</template>
					<template #centerContent>
						<ProjectSupervisionDiv @confirm="confirmReform"></ProjectSupervisionDiv>
					</template>
				</divDialogComponent>
				<!-- 查看 -->
				<divDialogComponent v-model:visible="ennMEssageVisible" class="add-edit-box">
					<template #topContent>
						<div class="title-detail">
							<span>查看项目信息</span>
							<el-icon>
								<close @click="ennMEssageVisible = false" />
							</el-icon>
						</div>
					</template>
					<template #centerContent>
						<readonlyDialogDiv :relativeId="relativeId"></readonlyDialogDiv>
					</template>
				</divDialogComponent>
				<!-- 项目列表 -->
				<divDialogComponent v-model:visible="fileListVisible" class="add-edit-box">
					<template #topContent>
						<div class="title-detail">
							<span>查看文件列表</span>
							<el-icon>
								<close @click="fileListVisible = false" />
							</el-icon>
						</div>
					</template>
					<template #centerContent>
						<fileListDialogDiv
							:relativeId="relativeId"
							:engineeringSn="engineeringSn"
							@confirm="childrenDataUpdate"
						></fileListDialogDiv>
					</template>
				</divDialogComponent>
				<!-- 弹窗版 -->
				<!-- <ProjectSupervision
					v-model:detailsDialog="detailsDialog"
					:title="approvalTitle"
					@confirm="confirmReform"
				></ProjectSupervision> -->
				<!-- 查看 -->
				<!-- <readonlyDialog v-model:ennMEssageVisible="ennMEssageVisible" :relativeId="relativeId"></readonlyDialog> -->
				<!-- 编辑 -->
				<!-- <editDialog
					v-model:editennMEssageVisible="editennMEssageVisible"
					:relativeId="relativeId"
					@confirm="childrenDataUpdate"
				></editDialog> -->
				<!-- 项目列表 -->
				<!-- <fileListDialog
					v-model:fileListVisible="fileListVisible"
					:relativeId="relativeId"
					:engineeringSn="engineeringSn"
					@confirm="childrenDataUpdate"
				></fileListDialog> -->
			</div>
		</div>
	</div>
	<largeScreen v-if="showScreen" :engineeringSn="engineeringSn" @change="toScreen"></largeScreen>
</template>

<script setup lang="tsx" name="ProjectSupervisionRecord">
import { ref, onMounted, onBeforeMount, reactive } from "vue";
import { useRoute, useRouter } from "vue-router";
import { ColumnProps } from "@/components/ProTable/interface";
import ProTable from "@/components/ProTable/index.vue";
import ProjectSupervision from "./components/ProjectSupervision/index.vue";
import ProjectSupervisionDiv from "./components/ProjectSupervisionDiv/index.vue";
import readonlyDialog from "./components/readonlyDialog/index.vue";
import readonlyDialogDiv from "./components/readonlyDialogDiv/index.vue";
import editDialog from "./components/editDialog/index.vue";
import fileListDialog from "./components/fileListDialog/index.vue";
import fileListDialogDiv from "./components/fileListDialogDiv/index.vue";
import { getPreEngineeringApproveList, getEngineeringApproveArea, getIdEngApproveList } from "@/api/modules/goverment";
import { getDicList } from "@/api/modules/jxjview";
import { GlobalStore } from "@/stores";
import largeScreen from "../../../hz-enterprise/largeScreen/largeScreenOne/index.vue";
import { sendIframeMessage } from "@/utils/util";
import divDialogComponent from "@/components/divDialogComponent/index.vue";
const showScreen = ref(false);
const route = useRoute();
const router = useRouter();
const fileListVisible = ref(false);
const editennMEssageVisible = ref(false);
const ennMEssageVisible = ref(false);
const DicStatusList = ref([]);
const DicPurposeList = ref([]);
const DicTypeList = ref([]);
const engineeringArea = ref([]);
const store = GlobalStore();
const engineeringSn = ref("");
// 表格配置项
const columns: ColumnProps[] = [
	{ type: "index", label: "序号", width: 80 },
	{
		prop: "engineeringName",
		label: "项目名称",
		search: { el: "input" }
	},
	{
		prop: "engineeringCode",
		label: "项目编号",
		search: { el: "input" }
	},
	{
		prop: "engineeringType",
		label: "项目类型",
		enum: DicTypeList.value,
		search: { el: "select", props: { filterable: true } },
		fieldNames: { label: "dictValue", value: "dictLabel" }
	},
	{
		prop: "engineeringUse",
		label: "项目用途",
		enum: DicPurposeList,
		search: { el: "select", props: { filterable: true, clearable: true } },
		fieldNames: { label: "dictValue", value: "dictLabel" }
	},
	{
		prop: "createTime",
		label: "提交时间",
		search: {
			el: "date-picker",
			props: {
				type: "daterange",
				format: "YYYY-MM-DD",
				valueFormat: "YYYY-MM-DD"
				// defaultTime: defaultTime2
			}
		}
	},
	{ prop: "operation", label: "操作", fixed: "right", width: 320 }
];
const relativeId = ref("");
const detailsDialog = ref(false);
const approvalTitle = ref("");
// 获取 ProTable 元素，调用其获取刷新数据方法（还能获取到当前查询参数，方便导出携带参数）
const proTable = ref();
const childrenDataUpdate = () => {
	console.log(666);
	proTable.value.getTableList();
};
// 查看文件列表
const onFileList = (row: any) => {
	engineeringSn.value = row.engineeringSn;
	relativeId.value = row.id;
	fileListVisible.value = true;
};
const onSee = row => {
	relativeId.value = row.id;
	ennMEssageVisible.value = true;
};
const toScreen = row => {
	if (row) {
		engineeringSn.value = row.engineeringSn;
	}
	showScreen.value = !showScreen.value;
};
const getDicPurposeList = async () => {
	const { result } = await getDicList({ dictType: "engineering_purpose" });
	DicPurposeList.value.length = 0;

	DicPurposeList.value.push(...result);
};
const getDicStatusList = async () => {
	const { result } = await getDicList({ dictType: "engineering_state" });
	DicStatusList.value.length = 0;

	DicStatusList.value.push(...result);
};
const getDicTypeList = async () => {
	const { result } = await getDicList({ dictType: "engineering_type" });
	DicTypeList.value.length = 0;
	DicTypeList.value.push(...result);
};
const getAreaList = async () => {
	const { result } = await getEngineeringApproveArea();
	engineeringArea.value.length = 0;
	engineeringArea.value.push(...result);
};
// 整改完成，全部已提交审核
const confirmReform = () => {
	proTable.value.getTableList();
	console.log("我爱你");
	detailsDialog.value = false;
};
// 新增项目
const handleAddItem = () => {
	store.Message = null;
	approvalTitle.value = "新增";
	detailsDialog.value = true;
};
// 编辑项目
const onEdit = async row => {
	const res: any = await getIdEngApproveList({ id: row.id });
	store.Message = res.result;
	approvalTitle.value = "编辑";
	detailsDialog.value = true;
	// relativeId.value = row.id;
	// editennMEssageVisible.value = true;
};
const getTableList = (params: any) => {
	let newParams = JSON.parse(JSON.stringify(params));
	console.log(newParams);
	if (newParams.createTime) {
		newParams.createTime_begin = newParams.createTime[0];
		newParams.createTime_end = newParams.createTime[1];
		delete newParams.createTime;
	}
	return getPreEngineeringApproveList(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)
	};
};
onBeforeMount(() => {
	if (route.query.projectStatus) {
		columns[5].search.defaultValue = +route.query.projectStatus;
	}
	if (route.query.projectNature) {
		columns[6].search.defaultValue = +route.query.projectNature;
	}
});
onMounted(async () => {
	getAreaList();
	getDicTypeList();
	getDicStatusList();
	getDicPurposeList();
	await sendIframeMessage({ obj: { path: route.path } }, 2, undefined);
	if (route.query.engineeringSn) {
		engineeringSn.value = route.query.engineeringSn;
		showScreen.value = true;
	}
});
</script>
<style scoped lang="scss">
@import "./index.scss";
</style>
