<template>
	<div class="overview">
		<el-dialog :show-close="false" v-model="visible1" width="1350px" @close="closeMain">
			<template #title>
				<div class="title-detail">
					<img src="@/assets/images/tableIcon/look.png" alt="" />
					<span>查看危大工程信息</span>
					<el-icon>
						<close @click="closeMain" />
					</el-icon>
				</div>
			</template>
			<el-form ref="formRef" :model="formData" label-width="180px" :rules="rules" class="basic-form" size="default">
				<div class="basic-info">
					<div class="content-title">基本信息</div>
					<el-row :gutter="120">
						<el-col :span="12">
							<el-form-item label="危大工程名称:" prop="engineeringName">
								<el-input v-model="formData.engineeringName" placeholder="请输入" disabled />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="危大工程类别:" prop="type">
								<el-select v-model="formData.type" placeholder="请选择" style="width: 100%" disabled>
									<el-option v-for="item in typeList" :key="item.value" :label="item.label" :value="item.value"> </el-option>
								</el-select>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="120">
						<el-col :span="12">
							<el-form-item label="危大工程概况:" prop="engineeringSurvey">
								<el-input v-model="formData.engineeringSurvey" placeholder="请输入" disabled />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="类别描述:" prop="typeDescribe">
								<el-input v-model="formData.typeDescribe" placeholder="请输入" disabled />
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="120">
						<el-col :span="12">
							<el-form-item label="施工部位:" prop="constructionLocation">
								<el-input v-model="formData.constructionLocation" placeholder="请输入" disabled />
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="计划时间:" prop="planRange">
								<el-date-picker
									disabled
									style="width: 100%"
									v-model="formData.planRange"
									range-separator="至"
									start-placeholder="开始日期"
									end-placeholder="结束日期"
									format="YYYY-MM-DD"
									value-format="YYYY-MM-DD"
									type="daterange"
									placeholder="请选择时间"
								/>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="120">
						<el-col :span="12">
							<el-form-item label="施工时间:" prop="constructionRange">
								<el-date-picker
									disabled
									style="width: 100%"
									v-model="formData.constructionRange"
									range-separator="至"
									start-placeholder="开始日期"
									end-placeholder="结束日期"
									format="YYYY-MM-DD"
									value-format="YYYY-MM-DD"
									type="daterange"
									placeholder="请选择时间"
								/>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="责任人:" prop="personLiable">
								<el-input v-model="formData.personLiable" placeholder="请输入" disabled />
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="120">
						<el-col :span="12">
							<el-form-item label="责任分包单位:" prop="responsibilityCompany">
								<el-input v-model="formData.responsibilityCompany" placeholder="请输入" disabled />
							</el-form-item>
						</el-col>
					</el-row>
				</div>
				<div class="basic-info">
					<div class="content-title">危大工程资料</div>
					<el-row :gutter="120">
						<el-col :span="12">
							<el-form-item label="安全技术交底:" prop="devName">
								<div class="switch-box">
									<el-switch v-model="formData.technicalDisclosureType" :active-value="2" :inactive-value="1" disabled />
									<span>未完成</span>
									<el-button type="primary" @click="onDownLoad('technicalDisclosureFile')">点击下载</el-button>
								</div>
							</el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="安全专项施工方案及附件:" prop="devNumber">
								<div class="switch-box">
									<el-switch v-model="formData.securityConstructionSchemeType" :active-value="2" :inactive-value="1" disabled />
									<span>未完成</span>
									<el-button type="primary" @click="onDownLoad('securityConstructionSchemeFile')">点击下载</el-button>
								</div>
							</el-form-item>
						</el-col>
					</el-row>
					<el-row :gutter="120">
						<el-col :span="12">
							<el-form-item label="专项施工方案交底:" prop="devName">
								<div class="switch-box">
									<el-switch v-model="formData.specialConstructionSchemeType" :active-value="2" :inactive-value="1" disabled />
									<span>未完成</span>
									<el-button type="primary" @click="onDownLoad('specialConstructionSchemeFile')">点击下载</el-button>
								</div>
							</el-form-item>
						</el-col>
					</el-row>
				</div>
				<div class="basic-info">
					<div class="content-title">过程管控</div>
					<div class="tabs-option">
						<el-tabs v-model="tabPosition" type="card" class="demo-tabs" @tab-click="handleClick">
							<el-tab-pane :label="item.name" :name="index" v-for="(item, index) in tabsList" :key="index"> </el-tab-pane>
						</el-tabs>
						<div class="content-button">
							<el-button class="addButtonStyle" @click="addData">新增</el-button>
						</div>
						<div class="table" v-if="tabPosition != 5 && tabPosition != 6 && tabPosition != 7">
							<el-table
								:data="arrOne"
								border
								height="260"
								class="el-table"
								:row-style="{ height: '40px', textAlign: 'center' }"
								:header-cell-style="{ height: '40px', backgroundColor: '#e1eeff', textAlign: 'center' }"
								:cell-style="{ height: '40px', textAlign: 'center' }"
							>
								<el-table-column type="index" label="序号" width="200" />
								<el-table-column prop="annexName" label="附件名称">
									<template #default="{ row, $index }">
										<span v-if="row.id">{{ row.annexName }}</span>
										<el-input v-else class="test" v-model="row.annexName" />
									</template>
								</el-table-column>
								<el-table-column prop="fileList" label="操作">
									<template #default="{ row, $index }">
										<el-button v-if="row.id" type="primary" @click="onTableDownLoad(row)" link>下载附件</el-button>
										<el-button v-else type="primary" @click="onUpload(row, $index)" link>上传附件</el-button>
										<el-button v-if="!row.id" type="primary" link @click="confirmAdd(row, $index)">保存</el-button>
										<el-button type="danger" link @click="removeEngineeringSingle(row, $index)">删除</el-button>
									</template>
								</el-table-column>
								<template #empty>
									<div class="table-empty">
										<slot name="empty">
											<img src="@/assets/images/notData.png" alt="notData" />
											<div>暂无数据</div>
										</slot>
									</div>
								</template>
							</el-table>
						</div>
						<div class="table" v-if="tabPosition == 5">
							<el-table
								:data="arrFive"
								class="el-table"
								height="260"
								:row-style="{ height: '40px' }"
								:header-cell-style="{ backgroundColor: '#F5F7FA', textAlign: 'center', height: '40px' }"
								:cell-style="{ textAlign: 'center', height: '40px' }"
							>
								<el-table-column type="index" label="序号" width="100" />
								<el-table-column prop="currentProgress" label="当前进度">
									<template #default="{ row }">
										<el-input v-model="row.currentProgress" v-if="row.isEdit" />
										<span v-else>{{ row.currentProgress }}</span>
									</template>
								</el-table-column>
								<el-table-column prop="imageUrl" label="图片">
									<template #default="{ row }">
										<div class="face-img" v-if="row.isEdit">
											<el-upload
												class="face-uploader"
												:action="`${baseUrl}` + '/xmgl/file/upload'"
												:show-file-list="false"
												:on-success="(response, uploadFile) => handleAvatarSuccess(row, response, uploadFile)"
												accept="image/jpg, image/jpeg, image/png"
											>
												<img v-if="row.imageUrl" :src="row.imageUrl" class="face-avatar" />
												<el-icon v-else><plus /></el-icon>
											</el-upload>
										</div>
										<img class="showImg" v-else :src="row.imageUrl" />
									</template>
								</el-table-column>
								<el-table-column prop="createByName" label="记录人">
									<template #default="{ row }">
										<!-- <el-input v-model="row.createByName" v-if="row.isEdit" />
												<span v-else>{{ row.createByName }}</span> -->
										<span>{{ row.createByName }}</span>
									</template>
								</el-table-column>
								<el-table-column prop="createTime" label="记录时间">
									<template #default="{ row }">
										<!-- <el-date-picker
													v-if="row.isEdit"
													v-model="row.createTime"
													style="width: 100%"
													format="YYYY-MM-DD"
													value-format="YYYY-MM-DD"
													type="date"
													placeholder="请选择"
												/>
												<span v-else>{{ row.createTime }}</span> -->
										<span>{{ row.createTime }}</span>
									</template>
								</el-table-column>
								<el-table-column align="center" fixed="right" width="180" label="操作">
									<template #default="scope">
										<el-button type="primary" v-if="scope.row.isEdit" link @click="confirmAdd(scope.row, scope.$index)">
											<img src="@/assets/images/tableIcon/save.png" alt="" class="configureIcon" />
											<span>保存</span>
										</el-button>
										<el-button type="primary" v-if="!scope.row.isEdit" link @click="scope.row.isEdit = true">
											<img src="@/assets/images/tableIcon/updateIcon.png" alt="" class="configureIcon" />
											<span>编辑</span>
										</el-button>
										<el-button type="danger" link :icon="Delete" @click="removeEngineeringSingle(scope.row, scope.$index)"
											>删除</el-button
										>
									</template>
								</el-table-column>
								<template #empty>
									<div class="table-empty">
										<slot name="empty">
											<img src="@/assets/images/notData.png" alt="notData" />
											<div>暂无数据</div>
										</slot>
									</div>
								</template>
							</el-table>
						</div>

						<div class="table" v-if="tabPosition == 6">
							<el-table
								:data="arrSeven"
								class="el-table"
								height="260"
								:row-style="{ height: '40px' }"
								:header-cell-style="{ backgroundColor: '#F5F7FA', textAlign: 'center', height: '40px' }"
								:cell-style="{ textAlign: 'center', height: '40px' }"
							>
								<el-table-column type="index" label="序号" width="100" />
								<el-table-column prop="inspectResult" label="检查结果">
									<template #default="{ row }">
										<el-input v-model="row.inspectResult" v-if="row.isEdit" />
										<span v-else>{{ row.inspectResult }}</span>
									</template>
								</el-table-column>
								<el-table-column prop="inspectUser" label="检查人">
									<template #default="{ row }">
										<el-input v-model="row.inspectUser" v-if="row.isEdit" />
										<span v-else>{{ row.inspectUser }}</span>
									</template>
								</el-table-column>
								<el-table-column prop="inspectTime" label="检查时间">
									<template #default="{ row }">
										<el-date-picker
											v-if="row.isEdit"
											v-model="row.inspectTime"
											style="width: 100%"
											format="YYYY-MM-DD"
											value-format="YYYY-MM-DD"
											type="date"
											placeholder="请选择"
										/>
										<span v-else>{{ row.inspectTime }}</span>
									</template>
								</el-table-column>
								<el-table-column prop="question" label="隐患信息">
									<template #default="{ row }">
										<el-select v-if="row.isEdit" style="width: 100%" v-model="row.question" clearable placeholder="请选择">
											<el-option label="无隐患" :value="0" />
											<el-option label="一般隐患" :value="1" />
											<el-option label="重大隐患" :value="2" />
										</el-select>
										<span v-else>{{ row.question == 1 ? "一般隐患" : row.question == 2 ? "重大隐患" : "无隐患" }}</span>
									</template>
								</el-table-column>
								<el-table-column prop="solveUser" label="整改人">
									<template #default="{ row }">
										<el-input v-model="row.solveUser" v-if="row.isEdit" />
										<span v-else>{{ row.solveUser }}</span>
									</template>
								</el-table-column>
								<el-table-column prop="questionDesc" label="隐患详情">
									<template #default="{ row }">
										<el-input v-model="row.questionDesc" v-if="row.isEdit" />
										<span v-else>{{ row.questionDesc }}</span>
									</template>
								</el-table-column>
								<el-table-column align="center" fixed="right" width="180" label="操作">
									<template #default="scope">
										<el-button type="primary" v-if="scope.row.isEdit" link @click="confirmAdd(scope.row, scope.$index)">
											<img src="@/assets/images/tableIcon/save.png" alt="" class="configureIcon" />
											<span>保存</span>
										</el-button>
										<el-button type="primary" v-if="!scope.row.isEdit" link @click="scope.row.isEdit = true">
											<img src="@/assets/images/tableIcon/updateIcon.png" alt="" class="configureIcon" />
											<span>编辑</span>
										</el-button>
										<el-button type="danger" link :icon="Delete" @click="removeEngineeringSingle(scope.row, scope.$index)"
											>删除</el-button
										>
									</template>
								</el-table-column>
								<template #empty>
									<div class="table-empty">
										<slot name="empty">
											<img src="@/assets/images/notData.png" alt="notData" />
											<div>暂无数据</div>
										</slot>
									</div>
								</template>
							</el-table>
						</div>
						<div class="table" v-if="tabPosition == 7">
							<el-table
								:data="arrEight"
								class="el-table"
								height="260"
								:row-style="{ height: '40px' }"
								:header-cell-style="{ backgroundColor: '#F5F7FA', textAlign: 'center', height: '40px' }"
								:cell-style="{ textAlign: 'center', height: '40px' }"
							>
								<el-table-column type="index" label="序号" width="100" />
								<el-table-column prop="type" label="验收类型">
									<template #default="{ row }">
										<el-select v-if="row.isEdit" style="width: 100%" v-model="row.type" clearable placeholder="请选择">
											<el-option v-for="item in acceptTypeList" :key="item.value" :label="item.label" :value="item.value" />
										</el-select>
										<!-- <span v-else>{{ singleEngText() }}</span> -->
										<span v-else>{{ textTransform(row.type) }}</span>
									</template>
								</el-table-column>
								<el-table-column prop="result" label="验收结果">
									<template #default="{ row }">
										<el-select v-if="row.isEdit" style="width: 100%" v-model="row.result" clearable placeholder="请选择">
											<el-option label="合格" :value="1" />
											<el-option label="不合格" :value="2" />
										</el-select>
										<span v-else>{{ row.result == 1 ? "合格" : "不合格" }}</span>
									</template>
								</el-table-column>
								<el-table-column prop="state" label="验收状态">
									<template #default="{ row }">
										<el-select v-if="row.isEdit" style="width: 100%" v-model="row.state" clearable placeholder="请选择">
											<el-option label="待验收" :value="1" />
											<el-option label="已验收" :value="2" />
										</el-select>
										<span v-else>{{ row.state == 2 ? "已验收" : "待验收" }}</span>
									</template>
								</el-table-column>
								<el-table-column prop="imageUrl" label="图片">
									<template #default="{ row }">
										<div class="face-img" v-if="row.isEdit">
											<el-upload
												class="face-uploader"
												:action="`${baseUrl}` + '/xmgl/file/upload'"
												:show-file-list="false"
												:on-success="(response, uploadFile) => handleAvatarSuccess(row, response, uploadFile)"
												accept="image/jpg, image/jpeg, image/png"
											>
												<img v-if="row.imageUrl" :src="row.imageUrl" class="face-avatar" />
												<el-icon v-else><plus /></el-icon>
											</el-upload>
										</div>
										<img class="showImg" v-else :src="row.imageUrl" />
									</template>
								</el-table-column>
								<el-table-column prop="acceptTime" label="验收时间" width="160">
									<template #default="{ row }">
										<el-date-picker
											v-if="row.isEdit"
											v-model="row.acceptTime"
											style="width: 100%"
											format="YYYY-MM-DD"
											value-format="YYYY-MM-DD"
											type="date"
											placeholder="请选择"
										/>
										<span v-else>{{ row.acceptTime }}</span>
									</template>
								</el-table-column>
								<el-table-column prop="createByName" label="记录人">
									<template #default="{ row }">
										<span>{{ row.createByName }}</span>
									</template>
								</el-table-column>
								<el-table-column prop="createTime" label="记录时间" width="180">
									<template #default="{ row }">
										<span>{{ row.createTime }}</span>
									</template>
								</el-table-column>
								<el-table-column align="center" fixed="right" width="180" label="操作">
									<template #default="scope">
										<el-button type="primary" v-if="scope.row.isEdit" link @click="confirmAdd(scope.row, scope.$index)">
											<img src="@/assets/images/tableIcon/save.png" alt="" class="configureIcon" />
											<span>保存</span>
										</el-button>
										<el-button type="primary" v-if="!scope.row.isEdit" link @click="scope.row.isEdit = true">
											<img src="@/assets/images/tableIcon/updateIcon.png" alt="" class="configureIcon" />
											<span>编辑</span>
										</el-button>
										<el-button type="danger" link :icon="Delete" @click="removeEngineeringSingle(scope.row, scope.$index)"
											>删除</el-button
										>
									</template>
								</el-table-column>
								<template #empty>
									<div class="table-empty">
										<slot name="empty">
											<img src="@/assets/images/notData.png" alt="notData" />
											<div>暂无数据</div>
										</slot>
									</div>
								</template>
							</el-table>
						</div>
					</div>
				</div>
			</el-form>
			<template #footer>
				<el-button type="primary" @click="visible1 = false">关闭</el-button>
			</template>
		</el-dialog>
		<!-- 附件上传 -->
		<FilesUploadPlus v-model="showFilesUpload" @update:files="handlechange" :files="current.files" :reset="true" />
	</div>
</template>

<script lang="ts" setup>
import { onMounted, ref, watch } from "vue";
import type { FormInstance, UploadProps } from "element-plus";
import { ElMessage } from "element-plus";
import { getDicList } from "@/api/modules/jxjview";
import FilesUploadPlus from "@/components/FilesUploadPlus/FilesUpload.vue";
import {
	dangerousEngineerDetails,
	constructionSchemeList,
	constructionSchemeAdd,
	constructionSchemeDelete,
	constructionSchemeFile,
	constructionProgressList,
	constructionProgressAdd,
	constructionProgressEdit,
	constructionProgressDelete,
	localInspectList,
	localInspectAdd,
	localInspectEdit,
	localInspectDelete,
	engineerAcceptList,
	engineerAcceptAdd,
	engineerAcceptEdit,
	engineerAcceptDelete
} from "@/api/modules/project";
import DownLoad from "@/utils/annexDowload.ts";
import { Delete } from "@element-plus/icons-vue";
import { useHandleData } from "@/hooks/useHandleData";
const tabsList = ref([
	{ name: "专项施工方案" },
	{ name: "专家论证" },
	{ name: "方案交底" },
	{ name: "安全技术交底" },
	{ name: "施工条件验收" },
	{ name: "施工进度" },
	{ name: "现场巡视" },
	{ name: "危大工程验收" },
	{ name: "全部管控资料" }
]);
const baseUrl = import.meta.env.VITE_API_URL;
const props = defineProps({
	detailsVisible: Boolean,
	searchSn: String,
	activeValue: String,
	relativeId: String
});
const emits = defineEmits(["update:detailsVisible"]);
const arrOne = ref<any>([]);
const arrFive = ref<any>([]);
const arrSeven = ref<any>([]);
const arrEight = ref<any>([]);
const tabPosition = ref(0);
const documentDataIndex = ref(0);
const current = ref({
	files: []
});
const showFilesUpload = ref(false);
const typeList = ref([]);
const acceptTypeList = ref([]);
const rules = ref({
	engineeringName: [
		{
			required: true,
			message: "请输入",
			trigger: "blur"
		}
	],
	type: [
		{
			required: true,
			message: "请输入",
			trigger: "change"
		}
	],
	typeDescribe: [
		{
			required: true,
			message: "请输入",
			trigger: "blur"
		}
	]
});
const formRef = ref<FormInstance>();
const formData = ref<any>({
	technicalDisclosureFile: [],
	securityConstructionSchemeFile: [],
	specialConstructionSchemeFile: []
});
const visible1 = ref(false);
// 验收类型文本转换;
const textTransform = (id: any) => {
	let findItem: any = acceptTypeList.value.find(item => item.value == id);
	return findItem?.label;
};
// 图片上传成功后的钩子
const handleAvatarSuccess: UploadProps["onSuccess"] = (row, response, uploadFile) => {
	console.log(response.result.url);
	console.log(response, uploadFile);
	row.imageUrl = response.result.url;
	console.log(arrFive.value);
};
// 保存表格数据
const confirmAdd = async (row: any, index: any) => {
	let requestData = { ...row, dangerousEngineeringId: props.relativeId };
	const addOperation = [constructionSchemeAdd, constructionProgressAdd, localInspectAdd, engineerAcceptAdd];
	const updateOperation = [constructionSchemeAdd, constructionProgressEdit, localInspectEdit, engineerAcceptEdit]; // 编辑的第一项是用来充数的，为了方便与新增的下标统一
	const listOperation = [getConstructionSchemeList, getConstructionProgressList, getLocalInspectList, getengineerAcceptList];
	switch (true) {
		case tabPosition.value < 5 || tabPosition.value == 8:
			let updateArr = [] as any;
			if (!requestData.annexName || requestData.fileList.length == 0) {
				ElMessage.error("请输入名称以及上传附件");
				break;
			}
			requestData.fileList.map(item => {
				updateArr.push({
					createTime: item.response.createTime,
					extendName: item.response.ext,
					fileId: item.response.id,
					fileName: item.response.originalFilename,
					fileSize: item.response.size,
					fileUrl: item.response.url,
					contentType: item.response.contentType
				});
			});
			requestData.annexFiles = updateArr;
			requestData.type = tabPosition.value;
			delete requestData.fileList;
			const res = await addOperation[0](requestData);
			if (res.success) {
				ElMessage.success("操作成功");
				listOperation[0]();
			}
			break;
		default:
			row.isEdit = false;
			if (row.id) {
				const res2 = await updateOperation[tabPosition.value - 4](requestData);
				if (res2.success) {
					ElMessage.success("操作成功");
				}
			} else {
				const res2 = await addOperation[tabPosition.value - 4](requestData);
				if (res2.success) {
					ElMessage.success("操作成功");
				}
			}
			listOperation[tabPosition.value - 4]();
			break;
	}
};
// 删除数据
const removeEngineeringSingle = async (row: any, index: any) => {
	const deleteOperation = [constructionSchemeDelete, constructionProgressDelete, localInspectDelete, engineerAcceptDelete]; // 编辑的第一项是用来充数的，为了方便与新增的下标统一
	const listOperation = [getConstructionSchemeList, getConstructionProgressList, getLocalInspectList, getengineerAcceptList];
	if (row.id) {
		switch (true) {
			case tabPosition.value < 5 || tabPosition.value == 8:
				await useHandleData(deleteOperation[0], { id: row.id }, `删除【${row.annexName}】`);
				listOperation[0]();
				break;
			default:
				await useHandleData(deleteOperation[tabPosition.value - 4], { id: row.id }, "删除");
				listOperation[tabPosition.value - 4]();
				break;
		}
	} else {
		switch (true) {
			case tabPosition.value < 5 || tabPosition.value == 8:
				arrOne.value.splice(index, 1);
				break;
			case tabPosition.value == 5:
				arrFive.value.splice(index, 1);
				break;
			case tabPosition.value == 6:
				arrSeven.value.splice(index, 1);
				break;
			case tabPosition.value == 7:
				arrEight.value.splice(index, 1);
				break;
			default:
				break;
		}
	}
};
// 获取附件列表
const getConstructionSchemeList = async () => {
	const res = await constructionSchemeList({ dangerousEngineeringId: props.relativeId, type: tabPosition.value });
	console.log(res);
	if (res.result && res.result.length > 0) {
		arrOne.value = res.result;
	} else {
		arrOne.value = [];
	}
};
// 获取施工进度列表
const getConstructionProgressList = async () => {
	const res = await constructionProgressList({ dangerousEngineeringId: props.relativeId });
	console.log(res);
	if (res.result && res.result.length > 0) {
		arrFive.value = res.result;
	} else {
		arrFive.value = [];
	}
};
// 获取现场巡视列表
const getLocalInspectList = async () => {
	const res = await localInspectList({ dangerousEngineeringId: props.relativeId });
	console.log(res);
	if (res.result && res.result.length > 0) {
		arrSeven.value = res.result;
	} else {
		arrSeven.value = [];
	}
};
// 获取危大工程验收列表
const getengineerAcceptList = async () => {
	const res = await engineerAcceptList({ dangerousEngineeringId: props.relativeId });
	console.log(res);
	if (res.result && res.result.length > 0) {
		arrEight.value = res.result;
	} else {
		arrEight.value = [];
	}
};
// 获取危大工程详情
const getDetailsData = async () => {
	const res = await dangerousEngineerDetails({ id: props.relativeId });
	console.log(res);
	if (res && res.result) {
		formData.value = { ...res.result };
	}
	if (formData.value.constructionPlanStartTime && formData.value.constructionPlanEndTime) {
		formData.value.planRange = [formData.value.constructionPlanStartTime, formData.value.constructionPlanEndTime];
	}
	if (formData.value.constructionStartTime && formData.value.constructionEndTime) {
		formData.value.constructionRange = [formData.value.constructionStartTime, formData.value.constructionEndTime];
	}
};
// 新增
const addData = () => {
	console.log(tabPosition.value);
	switch (true) {
		case tabPosition.value < 5 || tabPosition.value == 8:
			let findOneItem = arrOne.value.find(item => {
				return item.insertNew;
			});
			if (!findOneItem) {
				arrOne.value.push({
					annexName: "",
					fileList: [],
					insertNew: true
				});
			}
			break;
		case tabPosition.value == 5:
			let findTwoItem = arrFive.value.find(item => {
				return item.insertNew;
			});
			if (!findTwoItem) {
				arrFive.value.push({
					currentProgress: "",
					imageUrl: "",
					// createByName: "",
					// createTime: "",
					isEdit: true,
					insertNew: true
				});
			}
			break;
		case tabPosition.value == 6:
			let findThreeItem = arrSeven.value.find(item => {
				return item.insertNew;
			});
			if (!findThreeItem) {
				arrSeven.value.push({
					inspectResult: "",
					inspectUser: "",
					inspectTime: "",
					question: "",
					solveUser: "",
					questionDesc: "",
					isEdit: true,
					insertNew: true
				});
			}
			break;
		case tabPosition.value == 7:
			let findFourItem = arrEight.value.find(item => {
				return item.insertNew;
			});
			if (!findFourItem) {
				arrEight.value.push({
					type: null,
					result: null,
					state: null,
					imageUrl: "",
					acceptTime: "",
					isEdit: true,
					insertNew: true
				});
			}
			break;
		default:
			break;
	}
};
// tabs项点击时
const handleClick = (pane: any) => {
	tabPosition.value = pane.props.name;
	const listOperation = [getConstructionSchemeList, getConstructionProgressList, getLocalInspectList, getengineerAcceptList];
	if (tabPosition.value < 5 || tabPosition.value == 8) {
		listOperation[0]();
	} else {
		listOperation[tabPosition.value - 4]();
	}
};
// 附件上传改变
const handlechange = e => {
	console.log(e);
	current.value.files = e.map(item => {
		item.label = current.value.dictLabel;
		return item;
	});
	console.log(current.value.files);
	arrOne.value[documentDataIndex.value].fileList = current.value.files;
};
// 危大工程资料
const onDownLoad = (key: any) => {
	console.log(key);
	console.log(formData.value[key]);
	let val = JSON.parse(formData.value[key]);
	if (val && val.length > 0) {
		DownLoad(val);
	} else {
		ElMessage.error("暂无可下载文件");
	}
};

// 上传附件按钮
const onUpload = async (row: any, index: any) => {
	console.log(row);
	showFilesUpload.value = true;
	documentDataIndex.value = index;
	if (row.fileList.length > 0) {
		let arr: any = [];
		row.fileList.map(item => {
			if (item.response) {
				arr.push({
					response: { ...item.response, url: item.response.url },
					name: item.response.originalFilename,
					url: item.response.url,
					size: +item.response.size,
					type: item.response.contentType
				});
			} else {
				arr.push({
					response: { ...item, url: item.fileUrl },
					name: item.fileName,
					url: item.fileUrl,
					size: +item.fileSize,
					type: item.contentType
				});
			}
			delete item.response;
		});
		current.value.files = arr;
		console.log(current.value.files);
	} else {
		current.value.files = [];
	}
};
// 表格附件下载
const onTableDownLoad = async (row: any) => {
	console.log(row);
	let requestData = {
		id: row.id
	};
	const { result } = await constructionSchemeFile(requestData);
	console.log(result);
	if (result && result.length > 0) {
		DownLoad(result);
	} else {
		ElMessage.error("暂无可下载文件");
	}
};
// 获取验收类型字典
const getAcceptTypeList = async () => {
	const { result } = await getDicList({ dictType: "check_accept_type" });
	if (result.length > 0) {
		let arr: any = [];
		result.map(item => {
			arr.push({
				label: item.dictValue,
				value: item.dictLabel
			});
		});
		acceptTypeList.value.length = 0;
		acceptTypeList.value.push(...arr);
	}
};
const getTypeDicMainList = async () => {
	// 获取起重机械设备类型字典
	const { result } = await getDicList({ dictType: "dangerous_engineer_type" });
	if (result.length > 0) {
		let arr: any = [];
		result.map(item => {
			arr.push({
				label: item.dictValue,
				value: item.dictLabel
			});
		});
		typeList.value.length = 0;
		typeList.value.push(...arr);
	}
};
// 关闭两个对话框
const closeMain = () => {
	visible1.value = false;
	emits("update:detailsVisible", false);
};
watch(
	() => props.detailsVisible,
	n => {
		if (n) {
			if (n) {
				getAcceptTypeList();
				getTypeDicMainList();
				getDetailsData();
				getConstructionSchemeList();
				setTimeout(function () {
					formRef.value?.clearValidate();
				}, 200);
			}
			visible1.value = n;
		}
	}
);
watch(
	() => visible1,
	n => {
		emits("update:detailsVisible", n);
	}
);
onMounted(() => {});
</script>

<style lang="scss" scoped>
@mixin flex {
	display: flex;
	align-items: center;
}
@mixin title {
	font-size: 14px;
	font-family: Source Han Sans CN-Regular, Source Han Sans CN;
	font-weight: 400;
	color: #333333;
	border-left: 2px solid #008bff;
	padding-left: 5px;
}
.overview {
	:deep() {
		.el-dialog__body {
			padding-top: 0;
			padding-bottom: 0;
		}
	}
	.title-detail {
		@include flex;
		> img {
			width: 16px;
			height: 18px;
		}
		> span {
			font-size: 18px;
			font-family: Source Han Sans CN-Regular, Source Han Sans CN;
			font-weight: 400;
			color: #333333;
			margin-left: 5px;
			margin-right: auto;
		}
		:deep(.el-icon) {
			cursor: pointer;
			color: #a8abb2;
		}
	}
	.basic-form {
		margin-bottom: 42px;
		.basic-info {
			.content-title {
				@include title;
				margin-bottom: 35px;
			}
			.switch-box {
				width: 100%;
				display: flex;
				align-items: center;
				> span {
					margin-right: auto;
					margin-left: 9px;
				}
			}
			.tabs-option {
				width: 100%;
				.content-button {
					@include flex;
					justify-content: flex-end;
					> span {
						font-size: 14px;
						font-family: Source Han Sans CN-Regular, Source Han Sans CN;
						font-weight: 400;
						color: #008bff;
					}
				}
				.table {
					width: 100%;
					// height: 310px;
					margin-top: 15px;
					:deep(.el-table) {
						height: 100%;
					}
					.face-img {
						width: 100%;
						align-self: flex-start;
						:deep(.face-uploader .el-upload) {
							border: 1px dashed #d9d9d9 !important;
							border-radius: 6px !important;
							cursor: pointer !important;
							position: relative !important;
							overflow: hidden !important;
						}
						.face-uploader .el-upload:hover {
							border-color: #409eff !important;
						}
						:deep(.el-icon) {
							font-size: 24px;
							color: #8c939d;
							width: 35px;
							height: 35px;
							line-height: 35px;
							text-align: center;
						}
						.face-avatar {
							width: 35px;
							height: 35px;
							display: block;
						}
					}
					.showImg {
						width: 35px;
						height: 35px;
						border-radius: 6px;
					}
					.table-empty {
						display: flex;
						justify-content: center;
						align-items: center;
						height: 150px;
						flex: 1;
						flex-direction: column;
						color: #999;
					}
				}
			}
		}
	}
}
:deep(.el-tabs--card > .el-tabs__header) {
	border-bottom: none;
}
:deep(.el-tabs--card > .el-tabs__header .el-tabs__nav) {
	width: 100%;
	background: #f8f8f8;
	border: 0;
}
:deep(.el-tabs__nav-scroll) {
	display: flex;
	.el-tabs__item {
		width: 50%;
		text-align: center;
		// background: #f8f8f8;
		color: #333;
		// border: 1px solid #e5e5e5;
		// border-radius: 8px;
	}
	.el-tabs__item.is-active {
		background-color: #008bff;
		color: #fff;
	}
}
:deep(.el-tabs--card > .el-tabs__header .el-tabs__item.is-active) {
	border-bottom-color: #008bff !important;
}
:deep(#tab-0) {
	border-radius: 4px 0 0 4px;
	border: 1px solid #e5e5e5;
	border-right: 0;
}
:deep() {
	#tab-1,
	#tab-2,
	#tab-3,
	#tab-4,
	#tab-5,
	#tab-6,
	#tab-7 {
		border: 1px solid #e5e5e5;
		border-right: 0;
	}
}
:deep(#tab-8) {
	border: 1px solid #e5e5e5;
	border-radius: 0 4px 4px 0;
}
</style>
