<template>
	<view id="page">
		<view class="Width100 Box BorderBox">
			<view class="Content BorderBox Width100">
				<top-title :is-show-left="true" :title="'排查'" :rightWidth='120' class="custom_bg">

				</top-title>
			</view>
			<view class="query-form">
				<view class="tab">
					<view class="tab-item" :class="tab === 1 ? 'active' : ''" @click='handleTabClick(1)'>
						<text>基本信息和隐患</text>

					</view>
					<!-- <view class="tab-item" :class="tab === 2 ? 'active' : ''" @click='handleTabClick(2)'>
						<text>正在办理</text>
						<text class="number">{{ totalData.InGovernance }}</text>
					</view> -->
					<view class="tab-item" :class="tab === 3 ? 'active' : ''" @click='handleTabClick(3)'>
						<text>任务流转过程</text>
					</view>
				</view>
			</view>
			<view v-if="tab === 1">
				<view class="formBox">
					<uni-forms :modelValue="formData" border>

						<view class="label-box">
							<view class="border"></view> 基本信息
						</view>
						<uni-forms-item label="隐患名称" class="border-top">
							<view class="Height100 Flex Flex_end Flex_C_S-Center" style="line-height: 37px; ">
								<view class="Height100">{{ name }}</view>
								<view class="Height100"></view>
							</view>
						</uni-forms-item>
						<uni-forms-item label="所属辖区">
							<view class="Height100 Flex Flex_end Flex_C_S-Center" style="line-height: 37px; ">

								<view class="Height100">{{ formData.xqname }}</view>
								<view class="Height100"></view>
							</view>
						</uni-forms-item>
						<uni-forms-item label="所属街道" class="border-bottom">
							<view class="Height100 Flex Flex_end Flex_C_S-Center" style="line-height: 37px; ">

								<view class="Height100">{{ formData.jdname }}</view>
								<view class="Height100"></view>
							</view>
						</uni-forms-item>
						<view class="label-box">
							{{sectionName}}
						</view>
						<uni-forms-item label="道路类型" label-width="80">
							<view class="Height100 Flex Flex_end Flex_C_S-Center" style="line-height: 37px; ">
								<view class="Height100">{{ formData.roadType }}</view>
								<view class="Height100"></view>
							</view>
						</uni-forms-item>
						<uni-forms-item label="道路宽度" label-width="80">
							<view class="Height100 Flex Flex_end Flex_C_S-Center" style="line-height: 37px; ">
								<view class="Height100">{{ formData.roadWidth }}</view>
								<view class="Height100">米</view>
							</view>
						</uni-forms-item>
						<uni-forms-item label="车道数" label-width="80">
							<view class="Height100 Flex Flex_end Flex_C_S-Center" style="line-height: 37px; ">
								<view class="Height100">{{ formData.laneCount }}</view>
								<view class="Height100">道</view>
							</view>
						</uni-forms-item>
						<uni-forms-item label="路面结构">
							<view class="Height100 Flex Flex_end Flex_C_S-Center" style="line-height: 37px; ">
								<view class="Height100">{{ formData.roadStructure }}</view>
								<view class="Height100"></view>
							</view>
						</uni-forms-item>
						<uni-forms-item label="路侧防护">
							<view class="Height100 Flex Flex_end Flex_C_S-Center" style="line-height: 37px; ">
								<view class="Height100">{{ formData.sideProtec }}</view>
								<view class="Height100"></view>
							</view>
						</uni-forms-item>
						<uni-forms-item label="中央隔离">
							<view class="Height100 Flex Flex_end Flex_C_S-Center" style="line-height: 37px; ">
								<view class="Height100">{{ formData.centerSeparate }}</view>
								<view class="Height100"></view>
							</view>
						</uni-forms-item>
						<uni-forms-item label="设计时速" label-width="80">
							<view class="Height100 Flex Flex_end Flex_C_S-Center" style="line-height: 37px; ">
								<view class="Height100">{{ formData.designSpeed }}</view>
								<view class="Height100">Km/h</view>
							</view>
						</uni-forms-item>
						<uni-forms-item label="限速" label-width="80">
							<view class="Height100 Flex Flex_end Flex_C_S-Center" style="line-height: 37px; ">
								<view class="Height100">{{ formData.limitSpeed }}</view>
								<view class="Height100">Km/h</view>
							</view>
						</uni-forms-item>
					</uni-forms>
				</view>
				<view class="formBox">
					<uni-forms  border>
						<view class="label-box">
							<view class="border"></view> 重点排查
						</view>
						<view v-for="(itemData,indexData) in reversedTroubleshootingData" :key="indexData">
							<view style="margin-bottom:20rpx;font-size:28rpx">{{ indexData + 1 }}.
								{{ itemData.length > 0 ? itemData[0].nname : '' }}
							</view>
							<view v-for="(item,index) in itemData" :key="index" :label="item.itemname"
								v-show="item.extraConfigs">
								<view style="padding: 5px 0px;font-size:28rpx">隐患({{index+1}})：{{item.itemname}}</view>
								<view class="investigation-item" v-for="(it, idx) in item.extraConfigs" :key="idx"
									style="width: 96%; padding: 0">

									<view class="detail-item" v-if="it.type === 'number' || it.type === '1'">
										<uni-forms-item :label="it.name" label-width="450rpx"
											style="display: flex; align-items: center">
											<u-input :disabled="true" placeholder="- -" border="none"
												v-model="it.standar" inputAlign="right" type="number">
												<u-text :text="it.unit" slot="suffix" margin="0 3px 0 0"
													type="tips"></u-text>
											</u-input>
										</uni-forms-item>
									</view>
									<view class="detail-item" v-else-if="it.type === 'text' || it.type === '2'">
										<uni-forms-item :label="it.name" label-width="450rpx"
											style="display: flex; align-items: center">
											<u-input :disabled="true" placeholder="- -" border="none"
												v-model="it.standar" inputAlign="right" />
										</uni-forms-item>
									</view>
									<view class="detail-item" v-else-if="it.type === 'check' || it.type === '3'">
										<uni-forms-item :label="it.name" label-width="450rpx"
											style="display: flex; align-items: center">
											<u-checkbox :disabled="true" v-model="it.standar"
												:customStyle="{ justifyContent: 'space-between' }" :name="'sdfs'" />
										</uni-forms-item>
									</view>
									<view class="detail-item" v-else-if="it.type === 'upload' || it.type === '4'">
										<uni-forms-item :label="it.name" label-width="450rpx"
											style="display: flex; align-items: start;flex-direction:column;">
											<u-upload :disabled="true" :fileList="it.standar"
												 name="1"
												:maxCount="10"></u-upload></uni-forms-item>

									</view>
								</view>
								<view v-if="item.checkedSelect" style="margin-bottom: 30rpx;">
									<view class="investigation-item" style="width: 96%; padding: 0">
										<view class="detail-item">
											<uni-forms-item label="隐患描述" label-position="top" label-width="200px" />
											<u-textarea placeholder="- -" :disabled="true" border="none"
												v-model="item.checkedSelect.hdDesc" style="margin-top: -20rpx;" />
										</view>
									</view>
									<view class="investigation-item" style="width: 96%; padding: 0">
										<view class="detail-item">
											<uni-forms-item label="隐患图片" label-position="top" label-width="200px" />
											<u-upload :fileList="item.checkedSelect.hdPic" :disabled="true" style="margin-top: -20rpx;"
												 name="1"
												:maxCount="10"></u-upload>
										</view>
									</view>
									<view class="investigation-item" style="width: 96%; padding: 0">
										<view class="detail-item">
											<uni-forms-item label="补充信息" label-position="top" label-width="200px" />
											<u-textarea :disabled="true" placeholder="- -" border="none"
												v-model="item.checkedSelect.hdInfo" style="margin-top: -20rpx;" />
										</view>
									</view>
								</view>

							</view>
						</view>
					</uni-forms>
				</view>
				<view class="formBox">
					<uni-forms  border>
						<view class="label-box">
							<view class="border"></view> 存在隐患
						</view>
						<view v-for="(itemData,indexData) in hiddenDangerList" :key="indexData" v-show="itemData.pcType==2">
							<view style="margin-bottom:20rpx;font-size:28rpx">{{ indexData + 1 }}.
								{{ itemData.dangerProblem}}
							</view>
						
								<view v-if="itemData" style="margin-bottom: 30rpx;">
									<view class="investigation-item" style="width: 96%; padding: 0">
										<view class="detail-item">
											<uni-forms-item label="隐患描述" label-position="top" label-width="200px" />
											<u-textarea placeholder="- -" :disabled="true" border="none"
												v-model="itemData.hdDesc" style="margin-top: -20rpx;" />
										</view>
									</view>
									<view class="investigation-item" style="width: 96%; padding: 0">
										<view class="detail-item">
											<uni-forms-item label="隐患图片" label-position="top" label-width="200px" />
											<u-upload :fileList="itemData.hdPic" :disabled="true" style="margin-top: -20rpx;"
												 name="1"
												:maxCount="10"></u-upload>
										</view>
									</view>
									<view class="investigation-item" style="width: 96%; padding: 0">
										<view class="detail-item">
											<uni-forms-item label="补充信息" label-position="top" label-width="200px" />
											<u-textarea :disabled="true" placeholder="- -" border="none"
												v-model="itemData.hdInfo" style="margin-top: -20rpx;" />
										</view>
									</view>
								</view>
				
						</view>
					</uni-forms>
				</view>
				<view style="width: 100%;height: 1rpx;"></view>
			</view>
		</view>
	</view>
</template>

<script>
	import Tabbar from "../../components/tabbar.vue";
	import TopTitle from "../../components/top-title";
	import $ from "../../common/globalJs/globalJs";
	export default {
		// 组件
		components: {
			TopTitle,
		},
		data() {
			return {

				tab: 1,
				businessId: "",
				name: "",
				sectionName: '',
				$: this.$,
				boxHeight: 773,
				formData: {},
				investigationSelectList: [],
				troubleshootingData: [],
				checked: [],
				investigationSelectList: [],
				investigationSelectList: [],
				hiddenDangerList: []

			}
		},
		// 页面加载
		onLoad(e) {

			this.boxHeight = uni.getSystemInfoSync().windowHeight;
			if (e.id) {
				this.businessId = e.id;
				this.name = e.taskName
				this.sectionName = e.sectionName

				this.type = e.type;

				this.getBaseData(e.id);
				// this.getStreetCommunity()
			}


		},
		computed: {
			reversedTroubleshootingData() {
				const array = Array.from({
					length: this.investigationSelectList.length
				}, (_, i) => []);
				let nidname = this.investigationSelectList.length > 0 ? this.investigationSelectList[0].name : ''
				let nx = 0
				this.troubleshootingData.map(r => {
					this.investigationSelectList.map(m => {
						if (r.nid == m.nid) {
							r.nname = m.name
							if (r.nname == nidname) {
								array[nx].push(r)
							} else {
								nidname = r.nname
								nx++
								array[nx].push(r)
							}
						}
					})
				})
				console.log(array)
				return array
			}
		},
		onShow() {

		},

		// 方法
		methods: {
			handleTabClick(tab) {
				this.tab = tab;

				// this.getList()
			},
			initTroubleshootingData(id, index) {
				this.troubleshootingData[index].extraConfigs = []
				this.$request
					.globalRequest(
						"/hiddenDanger/highDanger/getImportDangerDisplayDetail", {
							dangerId: id,
							businessId: this.businessId,
						},
						"GET"
					)
					.then((res) => {
						if (res.code == 200) {
							// res.result=[{type:4,standar:'https://img-cdn-tx.dcloud.net.cn/stream/plugin_screens/map-plugin_0.jpg?&v=1630404859'}]
							for(let item of res.result){
								if(item.type==4){
									let arr=item.standar.split(',')
									let hdPic=[]
									for(let it of arr){
										if(it){
											hdPic.push({url:it})
										}
									}
									item.standar=hdPic
								}
							}
							this.troubleshootingData[index].extraConfigs.push(...res.result)
							console.log(this.troubleshootingData[index].extraConfigs,11111)
						}
						

						if (this.checked.length - 1 == index) {
							// alert(1111)
							this.initCheckedSelect(index)

						}

					});
				// this.$request.globalRequest('/hiddenDanger/highDanger/getImportDangers', {}, 'GET').then(res => {
				// 	if (res.code == 200) {
				// 		this.investigationList = res.result
				// 	}
				// })
			},
			initCheckedSelect() {
				this.$request
					.globalRequest(
						"/hiddenDanger/highDanger/getUserHiddenDangerList", {
							nuserid: this.$.getData("token"),
							pcType: 1,
							businessId: this.businessId
						},
						"GET"
					)
					.then((res) => {
						if (res.code === 200) {
							this.hiddenDangerList.push(...res.result)
							for (let i in this.troubleshootingData) {
								for (let j in res.result) {
									if (this.troubleshootingData[i].id == res.result[j].hdTerm) {
										let arr=res.result[j].hdPic.split(',')
										let hdPic=[]
										for(let item of arr){
											if(item){
												hdPic.push({url:item})
											}
										}
										this.$set(this.troubleshootingData[i], "checkedSelect", {
											hdInfo: res.result[j].hdInfo,
											hdPic: hdPic,
											hdDesc: res.result[j].hdDesc,
											hdTerm: res.result[j].hdTerm,
											pcType: 1
										})
									}
								}
							}
							console.log(this.hiddenDangerList,11111)
						}
					});
			},
			getBaseData(businessId) {
				this.$request
					.globalRequest(
						"/hiddenDanger/highDanger/getSectionInfo", {
							nuserid: this.$.getData("token"),
							businessId
						},
						"GET"
					)
					.then((res) => {
						if (res.code === 200) {
							for (let k in res.result) {
								if (res.result[k] == 0) {
									res.result[k] = ""
								}
							}
							this.formData = {
								...this.formData,
								...res.result
							};
						}
					});
				// return false
				this.$request
					.globalRequest(
						"/hiddenDanger/highDanger/getSectionTraffic", {
							nuserid: this.$.getData("token"),
							businessId
						},
						"GET"
					)
					.then((res) => {
						if (res.code === 200) {
							// todo 无数据结构
							this.formData = {
								...this.formData,
								...res.result
							};
						}
					});
				this.$request
					.globalRequest(
						"/hiddenDanger/highDanger/getImportDangerDisplay", {
							sid: "02",
							businessId
						},
						"GET"
					)
					.then((res) => {
						if (res.code === 200) {
							// todo 无数据结构
							for (let items of res.result) {
								for (let item of items.dangerItems) {
									item.nid = items.nid
								}
							}
							// console.log(res.result,11111)
							this.investigationSelectList = res.result;
							this.investigationSelectList.map((r) => {
								this.troubleshootingData = [...this.troubleshootingData, ...r.dangerItems]
							});
							// console.log(this.troubleshootingData, 11111)
							this.checked = this.troubleshootingData.map(r => {
								if (r.checked == 1) {
									return r.id
								}
							})
							this.checked = this.checked.filter(item => item !== undefined);
							for (let i in this.troubleshootingData) {
								if (this.troubleshootingData[i].checked == 1) {
									// alert(111)

									this.initTroubleshootingData(this.troubleshootingData[i].id, i)
								}

							}
							// console.log(this.troubleshootingData)
							// this.$request
							// 	.globalRequest(
							// 		"/hiddenDanger/highDanger/getImportDangerDisplayDetail", {
							// 		nuserid: this.$.getData("token"),
							// 		businessId,
							// 		dangerId: '26'
							// 	},
							// 		"GET"
							// 	)
							// 	.then((res) => {
							// 		if (res.code === 200) {
							// 			this.investigationSelectList.map((r) => {
							// 				r.extraConfigs = [];
							// 				res.result.map((m) => {
							// 					if (r.nid == m.scenesId) {
							// 						r.extraConfigs.push(m);
							// 					}
							// 				});
							// 			});
							// 		}
							// 	});
						}
					});
				this.$request
					.globalRequest(
						"/hiddenDanger/highDanger/getImportDangers", {
							nuserid: this.$.getData("token"),
							businessId
						},
						"GET"
					)
					.then((res) => {
						if (res.code === 200) {
							this.investigationList = res.result;
						}
					});
				this.$request
					.globalRequest(
						"/hiddenDanger/highDanger/getUserHiddenDangerList", {
							// nuserid: this.$.getData("token"),
							pcType: 2,
							businessId
						},
						"GET"
					)
					.then((res) => {
						if (res.code === 200) {
							this.hiddenDangerList.push(...res.result)
						}
					});

				this.$request
					.globalRequest(
						"/hiddenDanger/highDanger/getDangerItems", {
							nuserid: this.$.getData("token"),
							businessId
						},
						"GET"
					)
					.then((res) => {
						if (res.code === 200) {
							this.problemTreeSelectConfirmList = res.result;
						}
					});
			},


		},
		onReady() {},
		// 页面卸载
		onUnload() {

		},


	}
</script>

<style>
</style>
<style lang="scss" scoped>
	page {
		background: #F6F8FA;
	}


	.query-form {

		font-size: 16px;
		height: 44px;
		background: #ffffff;
		box-shadow: 3px 0px 10px #ccc;
		color: #666666;
		position: sticky;
		// top: var(--status-bar-height + 88rpx);
		top: calc(var(--status-bar-height) + 88rpx);
		z-index: 10;

		.tab {
			display: flex;
			align-items: center;
			justify-content: space-around;

			.tab-item {
				position: relative;
				height: 41px;
				line-height: 41px;
				padding: 0 30rpx 0 30rpx;
				border-bottom: 3px solid #fff;
				display: flex;
				align-items: center;

				&.active {
					color: rgb(60, 109, 195);
					border-color: rgb(60, 109, 195);
				}

				.number {
					font-weight: bold;
					font-size: 18px;
					margin-left: 10rpx;
				}
			}
		}

		.search-box {
			padding: 10px 10px 3px;
		}
	}

	.formBox {
		margin: 30rpx 20rpx;
		border: 1px solid #e6e6e6;
		background: #ffffff;
		padding: 0 20rpx 20rpx;
		box-sizing: border-box;

		/deep/ .uni-forms-item--border .uni-forms-item__content {
			justify-content: flex-end;
			text-align: right;
		}

		.photo {
			width: 100%;

			image {
				width: 100%;
			}
		}
	}

	.Box {
		padding-top: var(--status-bar-height);

		.Content {
			width: calc(100% - 48rpx);
			padding-bottom: 88rpx;
		}

		.Unit {
			padding: 12rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			position: relative;
			box-shadow: 1px 1px 3px #ccc;

			.trapezoidal {
				position: absolute;
				top: -0px;
				right: 0px;
				color: #ffffff;
				font-size: 22rpx;
				font-weight: normal;
				z-index: 1;
			}

			image {
				width: 200rpx;
			}

			.right {
				flex: 1;
				padding-left: 30rpx;

				.title {
					font-size: 16px;
					width: 380rpx;
					min-height: 80rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}

				.type {
					font-size: 14px;
					color: #666;
					font-weight: normal;

					text {
						margin-right: 20rpx;
					}
				}
			}
		}
	}

	.label-box {
		display: flex;
		align-items: center;
		height: 110rpx;
		font-size: 30rpx;
		font-weight: 600;

		.border {
			background-color: #2663BF;
			height: 35rpx;
			width: 6rpx;
			margin-right: 14rpx;
		}
	}

	.label-box2 {
		height: 100rpx;


	}

	.label-box-small {
		font-size: 28rpx;
		margin-top: -25rpx;
		font-weight: 500;
	}

	.border-bottom {
		border-bottom: 1px #eee solid;
	}

	.border-top {
		border-top: 1px #eee solid;
	}

	/deep/ .uni-forms-item__label {
		font-size: 28rpx;
		height: auto;
		margin-bottom: 20rpx;
	}

	/deep/ .u-input {
		background-color: #ffffff !important;
	}
</style>