<template>
	<u-cell-group>
		<u-cell :title="data.info.HIDDENDESCR" />
		<u-cell title="隐患来源" :value="hiddenSource[data.info.SOURCE]" />

		<block v-if="data.info.SOURCE === '2'">
			<u-cell title="风险点（单元）" :value="data.info.RISK_UNIT" />
			<u-cell title="辨识部位" :value="data.info.IDENTIFICATION" />
			<u-cell title="存在风险" :value="data.info.RISK_DESCR" />
			<u-cell title="风险分级" :value="data.info.LEVEL" />
			<u-cell title="检查内容" :value="data.info.CHECK_CONTENT" />
		</block>

		<u-cell title="隐患上报位置（经纬度）">
			<template #label>
				<view v-if="data.info.LONGITUDE && data.info.LATITUDE">
					<view>经度:{{ data.info.LONGITUDE }}</view>
					<view>纬度:{{ data.info.LATITUDE }}</view>
				</view>
			</template>
		</u-cell>

		<u-cell
			title="隐患部位"
			:value="data.info.hregionName || data.info.HIDDENPART"
		/>

		<u-cell title="隐患位置描述" :value="data.info.POSITIONDESC" />
		<u-cell title="隐患类型" :value="data.info.HIDDENTYPENAME" />
		<u-cell title="隐患级别" :value="data.info.HIDDENLEVELNAME" />

		<u-cell
			title="隐患发现人"
			:value="data.hiddenFindPeople.map((item) => item.NAME).join('、')"
		/>
		<u-cell
			title="隐患发现时间"
			:value="fnFormatTime(data.info.DISCOVERYTIME)"
		/>

		<u-cell title="整改类型">
			<template #value>
				<text v-if="data.info.RECTIFICATIONTYPE === '1'">立即整改</text>
				<text v-else-if="data.info.RECTIFICATIONTYPE === '2'">限期整改</text>
			</template>
		</u-cell>

		<u-cell title="整改负责部门" :value="data.info.editDeptName" />
		<u-cell title="整改负责人" :value="data.info.editUserName" />

		<block v-if="data.info.RECTIFICATIONTYPE === '2'">
			<u-cell title="整改期限" :value="data.info.editRectificationDeadline" />
		</block>

		<u-cell title="是否相关方">
			<template #value>
				<text v-if="data.info.ISRELEVANT === '1'">是</text>
				<text v-else-if="data.info.ISRELEVANT === '2'">否</text>
			</template>
		</u-cell>

		<u-cell title="隐患照片">
			<template #label>
				<view class="mt-10 flex-start">
					<view v-for="(item, index) in data.hImgs" :key="index" class="ml-10">
						<u-image
							show-loading
							width="100rpx"
							height="100rpx"
							:src="item.FILEPATH"
							@click="fnPreviewImage(item.FILEPATH, data.hImgs)"
						/>
					</view>
				</view>
			</template>
		</u-cell>

		<block v-if="data.hiddenVideo.length > 0">
			<u-cell title="隐患视频">
				<template #value>
					<u-icon
						name="play-circle-fill"
						size="24"
						@click="fnPreviewVideo(data.hiddenVideo[0].FILEPATH)"
					/>
				</template>
			</u-cell>
		</block>

		<view v-for="(item, index) in data.hiddenExamineList" :key="index">
			<block v-if="item.TYPE === 4">
				<u-divider text-position="left" text="隐患确认"></u-divider>
				<u-cell title="隐患级别" :value="item.editLevelName" />
				<u-cell title="整改负责人部门" :value="item.editDeptName" />
				<u-cell title="整改负责人" :value="item.editUserName" />
				<u-cell title="整改完成期限" :value="item.spare3" />
				<u-cell title="隐患确认人" :value="data.info.conUserName" />
				<u-cell title="隐患确认时间" :value="data.info.CONFIRM_TIME" />
			</block>
			<block v-if="item.TYPE === 2">
				<u-divider text-position="left" text="延期信息"></u-divider>
				<u-cell title="申请延期日期" :value="item.CREATTIME" />
				<u-cell title="延期日期" :value="fnFormatTime(item.DELAY_TIME)" />
				<u-cell title="审核人" :value="data.info.conUserName" />
				<u-cell title="处置方案" :value="item.DISPOSAL_PLAN" />
				<block v-if="item.DISPOSAL_FILE">
					<u-cell title="处置方案附件">
						<template #value>
							<u-button
								type="primary"
								size="mini"
								shape="circle"
								:custom-style="{ width: 'auto' }"
								@click="fnPreviewFile(item.DISPOSAL_FILE)"
							>
								下载
							</u-button>
						</template>
					</u-cell>
				</block>
				<u-cell title="延期审核状态">
					<template #value>
						<text v-if="item.STATE === -1">待审核</text>
						<text v-if="item.STATE === 1">通过</text>
						<text v-if="item.STATE === 2">未通过</text>
					</template>
				</u-cell>
				<block v-if="item.STATE !== -1">
					<u-cell title="审核时间" :value="item.OPERATTIME" />
				</block>
			</block>
			<block v-if="item.TYPE === 1">
				<u-divider text-position="left" text="特殊处理审核信息"></u-divider>
				<u-cell title="无法整改原因" :label="item.EXAMINE" />
				<u-cell title="特殊处置审核状态">
					<template #value>
						<text v-if="item.STATE === -1">待审核</text>
						<text v-if="item.STATE === 1">通过</text>
						<text v-if="item.STATE === 2">不通过</text>
					</template>
				</u-cell>
				<block v-if="item.STATE === 1">
					<u-cell title="处置方案" :value="item.DISPOSAL_PLAN" />
					<block v-if="item.DISPOSAL_FILE">
						<u-cell title="处置方案附件">
							<template #value>
								<up-button
									type="primary"
									size="mini"
									shape="circle"
									:custom-style="{ width: 'auto' }"
									@click="fnPreviewFile(item.DISPOSAL_FILE)"
								>
									下载
								</up-button>
							</template>
						</u-cell>
					</block>
				</block>
				<block v-if="item.STATE !== -1">
					<u-cell title="审核时间" :value="item.OPERATTIME" />
					<u-cell title="审核人" :value="data.info.conUserName" />
				</block>
				<block v-if="item.STATE === 2">
					<u-cell
						title="是否更换整改负责人"
						:value="item.spare1 === '1' ? '是' : '否'"
					/>
					<block v-if="item.spare1 === '1'">
						<u-cell title="整改负责人" :value="item.editUserName" />
					</block>
				</block>
			</block>
		</view>

		<block
			v-if="
				data.info.STATE === '2' ||
				data.info.STATE === '4' ||
				data.info.STATE === '10'
			"
		>
			<u-divider text-position="left" text="整改信息"></u-divider>
			<u-cell title="整改描述" :label="data.info.RECTIFYDESCR" />
			<u-cell title="整改部门" :value="data.info.RECTIFICATIONDEPTNAME" />
			<u-cell title="整改人" :value="data.info.RECTIFICATIONORNAME" />
			<u-cell title="整改时间" :value="data.info.RECTIFICATIONTIME" />
			<u-cell title="投入资金" :value="data.info.INVESTMENT_FUNDS + '元'" />
			<u-cell title="整改后图片">
				<template #label>
					<view class="mt-10 flex-start">
						<view
							v-for="(item, index) in data.rImgs"
							:key="index"
							class="ml-10"
						>
							<u-image
								show-loading
								width="100rpx"
								height="100rpx"
								:src="item.FILEPATH"
								@click="fnPreviewImage(item.FILEPATH, data.rImgs)"
							/>
						</view>
					</view>
				</template>
			</u-cell>
			<u-cell title="整改方案">
				<template #value>
					<text v-if="data.info.HAVESCHEME === '0'">无</text>
					<text v-else-if="data.info.HAVESCHEME === '1'">有</text>
				</template>
			</u-cell>
			<block v-if="data.info.HAVESCHEME === '1'">
				<u-cell
					title="排查日期"
					:value="data.rectificationPlanInfo.SCREENINGDATE"
				/>
				<block v-if="data.rectificationPlanInfo.LISTNAME">
					<u-cell
						title="隐患清单"
						:value="data.rectificationPlanInfo.LISTNAME"
					/>
				</block>
				<u-cell
					title="治理标准要求"
					:value="data.rectificationPlanInfo.GOVERNSTANDARDS"
				/>
				<u-cell
					title="治理方法"
					:value="data.rectificationPlanInfo.GOVERNMETHOD"
				/>
				<u-cell
					title="经费和物资的落实"
					:value="data.rectificationPlanInfo.EXPENDITURE"
				/>
				<u-cell
					title="负责治理人员"
					:value="data.rectificationPlanInfo.PRINCIPAL"
				/>
				<u-cell
					title="工时安排"
					:value="data.rectificationPlanInfo.PROGRAMMING"
				/>
				<u-cell
					title="时限要求"
					:value="data.rectificationPlanInfo.TIMELIMITFOR"
				/>
				<u-cell
					title="工作要求"
					:value="data.rectificationPlanInfo.JOBREQUIREMENT"
				/>
				<u-cell
					title="其他事项"
					:value="data.rectificationPlanInfo.OTHERBUSINESS"
				/>
				<u-cell title="方案图片">
					<template #label>
						<view class="mt-10 flex-start">
							<view
								v-for="(item, index) in data.sImgs"
								:key="index"
								class="ml-10"
							>
								<u-image
									show-loading
									width="100rpx"
									height="100rpx"
									:src="item.FILEPATH"
									@click="fnPreviewImage(item.FILEPATH, data.sImgs)"
								/>
							</view>
						</view>
					</template>
				</u-cell>
			</block>
		</block>

		<block v-if="data.info.STATE === '4'">
			<u-divider text-position="left" text="验收信息"></u-divider>
			<block v-if="data.info.RECTIFICATIONTYPE === '1'">
				<u-cell title="验收人" :value="data.info.CHECKORNAME" />
			</block>
			<block v-else>
				<view v-for="(item, index) in data.checkList" :key="index">
					<u-cell title="验收描述" :label="item.CHECKDESCR" />
					<u-cell title="是否合格" :value="item.STATUS === 1 ? '是' : '否'" />
					<u-cell title="验收部门" :value="item.CHECKDEPTNAME" />
					<u-cell title="验收人" :value="item.CHECKORNAME" />
					<u-cell title="验收时间" :value="item.CHECK_TIME" />
					<u-cell title="验收图片">
						<template #label>
							<view class="mt-10 flex-start">
								<view
									v-for="(item1, index1) in item.cImgs"
									:key="index1"
									class="ml-10"
								>
									<u-image
										show-loading
										width="100rpx"
										height="100rpx"
										:src="item1.FILEPATH"
										@click="fnPreviewImage(item1.FILEPATH, item.cImgs)"
									/>
								</view>
							</view>
						</template>
					</u-cell>
				</view>
			</block>
		</block>

		<u-modal
			:show="data.videoDialog.visible"
			title="视频预览"
			:show-confirm-button="false"
			show-cancel-button
			cancel-text="关闭"
			@cancel="fnCloseVideoDialog"
		>
			<video
				v-if="data.videoDialog.src"
				:src="data.videoDialog.src"
				style="width: 100%; height: 200px; margin: 10px"
				autoplay
			/>
		</u-modal>
	</u-cell-group>
</template>

<script>
import { getHiddenInfo } from "@/api";
import { HIDDEN_LEVEL_COlOR, HIDDEN_SOURCE } from "@/utils/constant";
import dayjs from "dayjs";
import { goEditData as resData } from "@/Mock/responseData.js";

export default {
	props: {
		hiddenId: {
			type: String,
			reequired: true,
		},
	},
	data() {
		return {
			data: {
				info: {},
				hiddenFindPeople: [],
				hImgs: [],
				hiddenVideo: [],
				rImgs: [],
				sImgs: [],
				hiddenExamineList: [],
				checkList: [],
				videoDialog: {
					visible: false,
					src: "",
				},
				specialDisposalReviewInfo: {},
				rectificationPlanInfo: {},
			},
		};
	},
	mounted() {
		this.fnGetData();
	},
	computed: {
		hiddenLevelColor() {
			return HIDDEN_LEVEL_COlOR;
		},
		hiddenSource() {
			return HIDDEN_SOURCE;
		},
		selfStore() {
			return this.$store;
		},
	},
	methods: {
		/** 预览图片处理 */
		fnPreviewImage(src, srcArr) {
			let urls = srcArr.map((sos) => sos.FILEPATH);
			uni.previewImage({
				urls,
				current: src,
			});
		},
		/** 预览视频处理 */
		fnPreviewVideo(src) {
			this.data.videoDialog.visible = true;
			this.data.videoDialog.src = src;
		},
		/** 预览文件处理 */
		fnPreviewFile(src) {
			let { filePath } = this.selfStore.state;
			uni.downloadFile({
				url: filePath + src,
				success: (res) => {
					const filePath = res.tempFilePath;
					uni.openDocument({
						filePath,
					});
				},
			});
		},
		/** 关闭视频弹窗 */
		fnCloseVideoDialog() {
			this.data.videoDialog.visible = false;
			this.data.videoDialog.src = "";
		},
		/** 时间格式化 */
		fnFormatTime(val) {
			return dayjs(val).format("YYYY-MM-DD");
		},
		// 异步获取隐患信息
		async fnGetData() {
			let { filePath } = this.selfStore.state;

			// const responseData = await getHiddenInfo({
			//   HIDDEN_ID: this.hiddenId
			// })
			// console.log('responseData :>> ', responseData);

			for (let i = 0; i < resData.hImgs.length; i++) {
				resData.hImgs[i].FILEPATH = filePath + resData.hImgs[i].FILEPATH;
			}
			for (let i = 0; i < resData.rImgs.length; i++) {
				resData.rImgs[i].FILEPATH = filePath + resData.rImgs[i].FILEPATH;
			}
			for (let i = 0; i < resData.sImgs.length; i++) {
				resData.sImgs[i].FILEPATH = filePath + resData.sImgs[i].FILEPATH;
			}
			for (let i = 0; i < resData.hiddenVideo.length; i++) {
				resData.hiddenVideo[i].FILEPATH =
					filePath + resData.hiddenVideo[i].FILEPATH;
			}
			for (let i = 0; i < resData.checkList.length; i++) {
				for (let j = 0; j < resData.checkList[i].cImgs.length; j++) {
					resData.checkList[i].cImgs[j].FILEPATH =
						filePath + resData.checkList[i].cImgs[j].FILEPATH;
				}
			}
			this.data.info = resData.pd;
			this.data.rectificationPlanInfo = resData.hs;
			this.data.hiddenFindPeople = resData.hiddenFindPeople;
			this.data.hImgs = resData.hImgs;
			this.data.rImgs = resData.rImgs;
			this.data.sImgs = resData.sImgs;
			this.data.checkList = resData.checkList;
			this.data.hiddenVideo = resData.hiddenVideo;
			this.data.hiddenExamineList = resData.hiddenExa;
			this.$emit("throw-basic-info", resData);
		},
	},
};
</script>

<style lang="scss" scoped>
/deep/ .u-cell__body {
	padding: 26rpx 30rpx;
}
</style>
