<template>
	<view>
		<view>

			<!-- 数据类型为消防设备 --比如一个灭火器 -->
			<u-list height="87vh" @scrolltolower="scrolltolower" v-if="!getqrcode">
				<u-list-item @click="goDetail" v-for="(item, index) in tableData" :key="index">
					<view>
						<view class="titles">{{item.inspName}}:{{item.inspContent}}</view>
						<!-- 消防设备 -->
						<view v-if="item.inspType=='fpd'">
							<view style="display: flex;flex-direction: column;margin-left: 40rpx;">
								<image :src="scan" class="tupian" @click="erWeiMa(item.id,index)"
									style="margin-left: 25rpx;"></image>
								<view style="margin-top: 20rpx;">扫二维码</view>
								<!-- <view>扫码结果 ：{{qrcodeResault}}</view> -->
							</view>
							<!-- #ifdef H5 -->
							<view class="qrcode" v-if="item.qrcodeShow">
								<qrcode-stream @decode="onDecode" />
							</view>
							<!-- #endif -->
						</view>
						<!-- 数据类型不为消防设备 -->
						<uni-grid :column="3" :showBorder="false" v-else>
							<!-- <view v-if="item.inspType!='fpd'"> -->
							<uni-grid-item v-for="(items,indexs) in item.inspectResultList" :key="indexs">
								<!-- 不是消防设施 -->
								<view class="grid-item-box">
									<image :src="items.subValue==1?zhengchang:moren" class="tupian"
										@click="normal(items,indexs,index,item)">
									</image>
									<text class="text">{{items.subLable}}</text>
								</view>
								<!-- 是消防设施，点击事件只是弹框 -->
								<!-- <view class="grid-item-box" v-else>
										<image :src="items.subValue==1?zhengchang:hidden" class="tupian" @click="noNormal">
										</image>
										<text class="text">{{items.subLable}}</text>
									</view> -->
							</uni-grid-item>
							<!-- </view> -->
							<uni-grid-item>
								<view class="grid-item-box" @click="photoUpload(item)">
									<image :src="photograph" class="tupian"></image>
									<text class="text">拍照上传</text>

								</view>

							</uni-grid-item>
						</uni-grid>
						<!-- 线 -->
						<!-- <view style="width: 80%;height: 2rpx;background-color: #f8f8f8;margin-left: 10%;"></view> -->
						<!-- v-if="item.attUrl!=[] -->
						<view class="uni-grid-wrap" v-if="item.attUrl.length!=0">
							<view style="color: #8C8C8C;">设备图片</view>
							<view style="position: relative;width: 180rpx;float: left;margin: 40rpx;"
								v-for="(items,indexs) in item.attUrl" :key="indexs">
								<image :src="items"
									style="width: 160rpx;height: 160rpx;border-radius: 30rpx;float: left;">
								</image>
								<u-icon name="close" color="#4CB2B6" size="19" @click="closeImage(item,indexs,index)">
								</u-icon>
							</view>
						</view>
					</view>
					<view class="slot-contents" v-if="item.showDescription&&item.inspType!='fpd'"
						@click="descript(index)">
						<textarea v-model="item.description" placeholder="请选择或隐患描述内容"
							@click="clickChoiceDanger(index)"></textarea>
						<!-- ----隐患 -->
						<u-popup :show="item.showDanger" :round="10" @close="item.showDanger=false">
							<view style="width: 90vw;overflow-y: auto;margin-bottom: 80rpx;padding:10px">
								<text class="text-xl">选择隐患类型:</text>
								<view class="" class="person-forward">
									<u-checkbox-group v-for="(items, indexs) in item.choiceDanger" :key="indexs"
										placement="column" v-model="items.checkedListDanger"
										@change="checkboxChange2(items.name,$event)" activeColor="#4CB2B6"
										iconSize="red">
										<u-checkbox :customStyle="{marginBottom: '60rpx'}" :label="items.name"
											:name="items.name">
										</u-checkbox>
									</u-checkbox-group>
								</view>
								<view class="flex flex-direction-row "
									style="position: fixed;bottom: 10px;left: 50%;transform: translate(-50%);height: 100rpx;width: 80%">
									<u-button shape="circle" type="primary" color="#4CB2B6" text="确定"
										@click="checkboxConfirm2(index)" customStyle="margin-right:20px;padding:0 30px">
									</u-button>
									<u-button type="primary" plain color="#4CB2B6" text="取消" shape="circle"
										@click="checkboxCancel2(index)" customStyle="padding:0 30px">
									</u-button>
								</view>
							</view>
						</u-popup>
						<!-- ----隐患 -->
					</view>
					<!-- <u-modal :show="show2" title="隐患描述" @confirm="descript(index)" @cancel="show2 = false">
						<view class="slot-content">
							<textarea v-model="description" placeholder="请输入描述内容" />
						</view>
					</u-modal> -->
					<!-- 扫码点击确定后每个设备的信息push到了新的数组里，显示在扫一扫下方的数据-->
					<view v-for="(items, indexs) in item.hisFpdCreateReqVOList" :key="indexs" class="child"
						style="background-color: aliceblue;">
						<view>
							<view class="child-new">
								<view class="child-new-item">
									<u-avatar shape="square" size="80" :src="items.attUrl[0]"
										customStyle="margin: -3px 5px -3px 20rpx"></u-avatar>
								</view>
								<view style="flex:1">
									<view>
										<view style="margin:40rpx 0 0 40rpx;">设备序列号：{{items.fpdCode}}
										</view>
									</view>
									<view class="child-result">
										<uni-grid :column="3" :showBorder="false">
											<uni-grid-item v-for="(items2,indexs2) in items.inspectResultList"
												:key="indexs2">
												<!-- 是消防设施，点击事件只是弹框 -->
												<view class="grid-item-box">
													<image :src="items2.subValue==1?zhengchang:hidden" class="tupian2"
														@click="noNormal">
													</image>
													<text class="text2">{{items2.subLable}}</text>
												</view>
											</uni-grid-item>
										</uni-grid>
									</view>
								</view>
							</view>
							<!-- popup拍照的数据 -->
							<!-- <view class="uni-grid-wraps" style="padding-bottom: 20rpx;">
								<view style="position: relative;width: 180rpx;float: left;"
									v-for="(items3,indexs3) in items.attUrl" :key="indexs3">
									<image :src="items3"
										style="width: 120rpx;height: 120rpx;border-radius: 30rpx;float: left;margin:0 20rpx 20rpx 0;">
										<u-icon name="close" color="#4CB2B6" size="19" @click="closeImage(indexs,index)">
								    			</u-icon>
								</view>
							</view> -->
							<!---->
						</view>
					</view>
				</u-list-item>
			</u-list>

		</view>
		<view
			style="width: 60%;position: fixed;bottom:10rpx;z-index: 9999;left: 50%;transform: translate(-50%);height: 6vh;"
			v-if="!getqrcode">
			<div class="btnList" v-if="tableData.length!=0">
				<u-button shape="circle" type="primary" color="#4CB2B6" text="暂存" customStyle="margin-right:20%"
					@click="checkImplementConfirm">
					<!-- 立即处理改为暂存了 -->
				</u-button>
				<u-button shape="circle" type="primary" color="#4CB2B6" text="完成任务"
					@click="checkImplementRelease">
				</u-button>
			</div>
		</view>
		<!-- <view style="text-align: center;" v-if="tableData.length==0&&!getqrcode">
			<view class="text-gray" style="padding-top: 20px;font-size: 40rpx;"> 暂无任务 </view>
		</view> -->
		<!-- //"show巡查未完成判断--可能需要打开 -->
		<u-modal :show="show" :title="title" :content='content' @confirm="show = false"></u-modal>
		<u-modal :show="show3" :title="title" content='未完成有问题检查项拍照' @confirm="show3= false"></u-modal>
		<u-modal :show="show4" :title="title" content='未对消防设备进行扫码检查' @confirm="show4= false"></u-modal>
		<!-- 弹出层 -->
		<u-popup :show="maShow" :round="10" @close="maShow=false">
			<view v-if="insTypeData!=''">
				<view class="springFarm" v-for="(item,index) in insTypeData" :key="index">
					<view class="show-title">设备名称:{{item.fpdName}}</view>
					<view class="show-title">设备序列号:{{item.fpdCode}}</view>
					<view>
						<view class="show-title">设备检查项:</view>
					</view>
					<view class="" v-if="item.inspectResultList!=''">
						<uni-grid :column="3" :showBorder="false">
							<uni-grid-item v-for="(items,indexs) in item.inspectResultList" :key="indexs">
								<view class="grid-item-box">
									<image :src="items.subValue==1?zhengchang:moren" class="tupian"
										@click="normalPopup(items,indexs,index)">
									</image>
									<text class="text">{{items.subLable}}</text>
								</view>
							</uni-grid-item>
						</uni-grid>
					</view>
					<!-- ----扫码选择隐患 -->
					<view class="slot-contents" v-if="show5">
						<textarea v-model="description2" placeholder="请输入描述内容" @click="popupChoiceDangerFpd"></textarea>
						<u-popup :show="showPopupDanger" :round="10" @close="showPopupDanger=false">
							<view style="width: 90vw;overflow-y: auto;margin-bottom: 80rpx;padding:10px">
								<text class="text-xl">选择隐患类型:</text>
								<view class="" class="person-forward">
									<u-checkbox-group v-for="(items, indexs) in choiceDanger" :key="indexs"
										placement="column" v-model="items.checkedListDanger"
										@change="checkboxChange3(items.name,$event)" activeColor="#4CB2B6"
										iconSize="red">
										<u-checkbox :customStyle="{marginBottom: '60rpx'}" :label="items.name"
											:name="items.name">
										</u-checkbox>
									</u-checkbox-group>
								</view>
								<view class="flex flex-direction-row "
									style="position: fixed;bottom: 10px;left: 50%;transform: translate(-50%);height: 100rpx;width: 80%">
									<u-button shape="circle" type="primary" color="#4CB2B6" text="确定"
										@click="checkboxConfirm3()" customStyle="margin-right:20px;padding:0 30px">
									</u-button>
									<u-button type="primary" plain color="#4CB2B6" text="取消" shape="circle"
										@click="checkboxCancel3()" customStyle="padding:0 30px">
									</u-button>
								</view>
							</view>
						</u-popup>
					</view>
					<!-- ----扫码选择隐患 -->
					<view class="show-title">
						<view class="">巡检拍照:<text style="color:#822e2e;"></text></view>
						<view class="">
							<image :src="photograph" @click="photoUpload(item)" class="tiantupian"></image> <!-- 加载中 -->
							<!-- <isLodingModel></isLodingModel> -->
						</view>
					</view>
					<view class="uni-grid-wraps">
						<view style="position: relative;width: 180rpx;float: left;margin: 10rpx 15rpx 0 0rpx;"
							v-for="(items,indexs) in item.attUrl" :key="indexs">
							<image :src="items" style="width: 160rpx;height: 160rpx;border-radius: 30rpx;float: left;">
								<u-icon name="close" color="#4CB2B6" size="19" @click="closeImage(item,indexs,index)">
								</u-icon>
						</view>
					</view>
					<view style="width: 60%;position: absolute;left:150rpx;;bottom:60rpx;z-index: 9999;">
						<div class="btnList" v-if="tableData.length!=0">
							<u-button shape="circle" type="primary" color="#4CB2B6" text="保存"
								customStyle="margin-right:20%" @click="checkPopupConfirm(item.id)">
							</u-button>
							<u-button shape="circle" type="primary" color="#4CB2B6" text="取消" @click="checkPopupCancel">
							</u-button>
						</div>
					</view>
				</view>
			</view>
			<view v-else>
				暂无数据
			</view>
		</u-popup>
		<!-- 	<u-modal :show="show5" title="隐患描述" @confirm="descriptFpd" @cancel="show5 = false">
			<view class="slot-content shebeidesrip">
				<textarea v-model="description2" placeholder="请输入描述内容" />
			</view>
		</u-modal> -->
		<!-- 多选closeable closeOnClickOverlay--点击遮罩层不可关闭所属部门的弹出内容选中 ，选择部门-->
	</view>
</template>
<script>
	let that = null
	// #ifdef H5
	import {
		QrcodeStream
	} from 'vue-qrcode-reader'
	// #endif
	import {
		CheckActiveImplement, //每日巡查扫码界面
		saveCheckImplement, //保存检查项
		checkSubmitRelease, //提交发布检查下
		inspTypeList //二维码的弹框数据
	} from "@/api/check_active";
	import {
		getAccessToken
	} from '@/utils/auth'
	import config from '@/config'
	import store from "@/store"
	import loadImage from 'blueimp-load-image';
	const baseUrl = config.baseUrl
	const baseUrlImg = config.baseUrlImg
	//隐患弹框--
	import {
		DICT_TYPE,
		getDictDatas
	} from '@/utils/dict';
	//隐患弹框--
	export default {
		components: {
			// #ifdef H5
			QrcodeStream
			// #endif
		},
		data() {
			return {
				// ----隐患
				choiceDanger: getDictDatas(DICT_TYPE.DANGER_TYPE),
				checkedDanger: [],
				checkedListDanger: [], //选择的隐患数据
				DangerIndex: "", //隐患描述的位置下标
				// ----隐患
				// ----扫码选择隐患
				showPopupDanger: false,
				checkedPopupDanger: [], //
				// ----扫码选择隐患
				insType: 1, //1代表检查类型为消防设施，显示扫一扫按钮，其他则显示拍照
				// danger: danger, //有隐患图片
				moren: `${baseUrlImg}/checkActive/moren.png`, //默认图片
				zhengchang: `${baseUrlImg}/checkActive/zhengchang.png`,
				hidden: `${baseUrlImg}/checkActive/hidden.png`,
				photograph: `${baseUrlImg}/checkActive/photograph.png`,
				scan: `${baseUrlImg}/checkActive/scan.png`,
				tableData: [],
				maShow: false, //扫码后弹框是否展示
				// 每页数据量
				// 当前页
				// 数据总量
				total: 0,
				getqrcode: false,
				loading: false,
				formData: {
					id: 0,
					pageNo: 1,
					pageSize: 10,
					status: 0,
					taskStatus: 1,
					broadId: 0,
				},
				saveImplement: {
					inspectList: [],
					inspectTime: "", //传的当前事件
					orgId: 0,
					taskId: 0, //待完成列表所点击的id
					broadId: 0,
					description: ''
				},
				isZhengChang: false, //是否正常
				isYinHuan: false, //是否隐患
				show: false, //未巡查提示框
				show2: false, //隐患描述提示框
				show3: false, //未拍照提示框
				show4: false, //未巡查扫码提示框
				show5: false, //检查设备隐患描述提示框
				title: '注意',
				content: '巡查未完成',
				contents: '',
				description: '', //隐患描述内容
				description2: '', //检查设备的描述内容
				newtableDatas: [], //缓存的数据,防止覆盖
				id: '',
				FinalTime: '',
				Insdengers: '', //每个列的检查项是否勾选
				nnorNormalValue: '',
				erWeiMaShu: '', //二维码内容对象
				insTypeData: '', //扫二维码后出现的消防列表数据内容
				newInsTypeData: [], //点击扫码后的设备内容
				confirminsTypeData: [], //点击确定新建一个新的数组
				checkTableDataId: 0, //扫码所点击的当前检查设施的id
				descriptIndex: '', //描述所在id
				yilou: false, //如果显示了有遗漏的检查项就不提示还未拍照
				type: '',
				selectedIndex: '',
				qrcodeShow: false,
				qrcodeResault: '等待扫码...',
				onDecodeIndex: '',
				submitButton: '完成任务',
			}
		},
		watch: {
			loading: {
				handler(newLength, oldLength) {
					this.$modal.isLoadingModel(this.loading)
				},
				immediate: true
			}
		},
		// 在 vue页面，向起始页通过事件传递数据
		onLoad: function(option) {
			this.choiceDanger.map(i => {
				i.name = i.label;
				i.id = i.value;
			});
			console.log(this.choiceDanger, 'this.choiceDanger');
			this.type = option.type ? option.type : ''
			that = this;
			const eventChannel = this.getOpenerEventChannel();
			eventChannel.on('acceptDataFromOpenerPage', function(val) {

				// that.formData = val
				that.options = val.taskInfo ? val.taskInfo : val
				that.formData.id = parseInt(that.options.id)
				that.contents = that.options.taskContent
				that.formData.broadId = parseInt(option.broadId)
				that.saveImplement.broadId = parseInt(option.broadId)
				that.saveImplement.orgId = parseInt(that.options.orgId)
				that.newtableDatas.push(uni.getStorageSync('tableData'))

				if (that.newtableDatas && that.newtableDatas[0][option.broadId]) { //获取本地缓存的数据
					that.tableData = that.newtableDatas[0][option.broadId]
					that.tableData.map(i => i.choiceDanger = that.choiceDanger)
					console.log(that.tableData, 'that.tableData');
					that.insTypeData = uni.getStorageSync('insTypeData')

				} else {
					that.tableData = []
					that.getData(that.formData.pageNo)
				}
			})
		},
		onShow() {},
		methods: {
			// ----隐患
			checkboxConfirm2(index) {
				this.tableData[index].description = this.checkedListDanger.toString()
				this.tableData[index].showDanger = false
				this.$forceUpdate()
			},
			checkboxCancel2(index) {
				this.tableData[index].showDanger = false
				this.checkedListDanger = []
				this.$forceUpdate()
			},
			clickChoiceDanger(index) { //描述框点击事件
				this.checkedListDanger = this.tableData[index].description.split(',')
				if (this.checkedListDanger.includes('其他')) {
					this.tableData[index].showDanger = false
				} else {
					this.tableData[index].showDanger = true
					this.DangerIndex = index
					this.$forceUpdate()
				}
				this.tableData[index].choiceDanger.map((i, indexs) => { //选中的回显
					i.checkedListDanger = []
					this.checkedListDanger.map(v => {
						if (i.name == v) {
							this.tableData[index].choiceDanger[indexs].checkedListDanger.push(v)
						}
					})
				})
			},
			checkboxChange2(i, n) { //勾选的事件
				if (i && n.length != 0) {
					this.checkedListDanger.push(i)
				} else if (i && n.length == 0) {
					this.checkedListDanger = this.checkedListDanger.filter(item => item != i)
				}
			},
			// ----隐患
			// ----扫码选择隐患
			popupChoiceDangerFpd() {
				this.checkedPopupDanger = this.description2.split(',')
				if (this.checkedPopupDanger.includes('其他')) {
					this.showPopupDanger = false
				} else {
					this.showPopupDanger = true
					this.$forceUpdate()
				}
				this.choiceDanger.map((i, indexs) => { //选中的回显
					i.checkedListDanger = []
					this.checkedPopupDanger.map(v => {
						if (i.name == v) {
							this.choiceDanger[indexs].checkedListDanger.push(v)
						}
					})
				})

			},
			checkboxConfirm3(index) {
				this.description2 = this.checkedPopupDanger.toString()
				this.showPopupDanger = false
				this.$forceUpdate()
			},
			checkboxCancel3(index) {
				this.showPopupDanger = false
				this.checkedPopupDanger = []
				this.$forceUpdate()
			},
			checkboxChange3(i, n) { //勾选的事件
				if (i && n.length != 0) {
					this.checkedPopupDanger.push(i)
				} else if (i && n.length == 0) {
					this.checkedPopupDanger = this.checkedPopupDanger.filter(item => item != i)
				}
			},
			// ----扫码选择隐患
			//扫码
			erWeiMa(checkTableDataIds, index) {
				// #ifdef H5
				console.log(this.tableData[index], '	this.tableData[index].');
				this.tableData[index].qrcodeShow = true
				this.$forceUpdate()
				this.onDecodeIndex = index
				this.checkTableDataId = checkTableDataIds
				// #endif
				// #ifdef MP-WEIXIN
				var that = this
				this.description = ''
				// 只允许从相机扫码
				uni.scanCode({
					onlyFromCamera: true, //只允许从相机扫码
					success: function(res) {
						if (res.errMsg == "scanCode:ok") {
							let result = JSON.parse(res.result)
							if (that.tableData[index].hisFpdCreateReqVOList.length > 0) {
								var temp = that.tableData[index].hisFpdCreateReqVOList
								// console.log(temp);
								console.log("result.id: ", result.id);
								temp = temp.filter(i => i.id == result.id)
								console.log("temp: ", temp);
								if (temp.length > 0) {
									this.tableData[this.onDecodeIndex].qrcodeShow = false
									return that.$modal.alert('该设备已检查')
								}
							}

							//调接口，会传过来id标识，失败显示错误信息，比如该设备不存在，成功的花弹出扫码成功
							inspTypeList(JSON.parse(res.result)).then(reponse => {
								console.log(reponse, 'reponsesssssssssssssss');
								if (reponse.code == 0) {
									that.maShow = true
									that.insTypeData = reponse.data.records
									that.insTypeData.map(i => {})
								}
							})
							setTimeout(() => {
								that.$modal.msgSuccess('扫码成功')
							}, 200)
							that.checkTableDataId = checkTableDataIds

						}

					},
					fail: (err) => {
						that.$modal.msgError('未识别到二维码，请重新尝试！')
					}
				})
				// #endif
			},
			// #ifdef H5
			// H5相机相关函数
			onDecode(qrcodeVal) {
				try {
					let result = JSON.parse(qrcodeVal);
				} catch (error) {
					return this.$modal.alert('无法解析二维码内容');
				}
				this.qrcodeResault = qrcodeVal
				let result = JSON.parse(qrcodeVal)
				this.tableData[this.onDecodeIndex].qrcodeShow = false
				var that = this
				if (that.tableData[this.onDecodeIndex].hisFpdCreateReqVOList.length > 0) {
					var temp = that.tableData[this.onDecodeIndex].hisFpdCreateReqVOList
					temp = temp.filter(i => i.id == result.id)
					if (temp.length > 0) return that.$modal.alert('该设备已检查')
				}

				//调接口，会传过来id标识，失败显示错误信息，比如该设备不存在，成功的花弹出扫码成功
				inspTypeList(JSON.parse(qrcodeVal)).then(reponse => {
					if (reponse.code == 0) {
						that.maShow = true
						that.insTypeData = reponse.data.records
						that.insTypeData.map(i => i.attUrl = [])
					}
				})
			},
			onInit(promise) { //未使用
				promise
					.then(console.log)
					.catch(console.error)
			},
			// #endif
			descript(index) { //隐患描述点击确认
				// this.show2 = false
				// this.tableData[index].description = this.description
			},
			descriptFpd() { //隐患描述点击确认
				this.show5 = false

			},
			closeImage(item, val, k) { //删除图片
				console.log(item, 'iii', k, this.insTypeData, this.tableData);
				if (item.fpdType == 'fpd') {
					this.insTypeData[k].attUrl.splice(val, 1)
				} else {
					this.tableData[k].attUrl.splice(val, 1)
				}

				that.$forceUpdate();
			},
			goDetail() { //去详情
				uni.navigateTo({
					url: '/pagesA/fire/check_active/check_implement_detail/check_implement_detail',
				})
			},
			checkImplementConfirm() { //确认保存检查项  
				this.shuJu()
				var total = uni.getStorageSync('tableData') ? uni.getStorageSync('tableData') : {} //避免掉覆盖
				total[this.saveImplement.broadId] = this.tableData
				uni.setStorageSync('tableData', total)
				this.$modal.msg('暂存成功')
				// this.tableData.map(i => {
				// 	if (i.isdenger == undefined) {
				// 		this.show = true
				// 	}
				// }) //判断是否完成巡查
				//批量保存
				// console.log(this.show,'Confirmthis.show');
				// if (!this.show) {
				// saveCheckImplement(JSON.stringify(this.saveImplement)).then(response => { 调接口了
				// 	if (response.data) {
				// 		uni.showToast({
				// 			title: '保存成功',
				// 			icon: 'none',
				// 			duration: 2000
				// 		})
				// 		uni.navigateBack()
				// 	} else {
				// 		this.$modal.msgError('保存失败')
				// 	}
				// });
				// }
			},
			checkImplementRelease() { //提交发布
				this.shuJu()
				this.saveImplement.inspectList.map((i) => { //提交数据组装
					if (i.inspType == 'fpd') {
						i.hisFpdCreateReqVOList.map(k => {
							k.status = 0
							k.fpdId = k.id
							if (k.dangerDescribe != undefined) {
								let strs = ""
								strs += `${k.dangerDescribe},`
								i.description = strs.slice(0, strs.length - 1)
							}
							k.imgUrl1 = k.attUrl[0]
							k.imgUrl2 = k.attUrl[1]
							k.imgUrl3 = k.attUrl[2]
							k.fpdResultCreateReqVOList = []
							k.fpdResultCreateReqVOList = k.inspectResultList
							k.fpdResultCreateReqVOList.map(z => {
								z.broadId = this.formData.broadId
								z.fpdId = z.id
								z.resLable = z.subLable
								z.resValue = z.subValue
								z.status = 0
								if (z.subValue == 0 && z.isNormal ==
									1) { //必传参数，只有该检查项正常为0,那么isdenger==1
									k.isdanger = 1
									i.isdanger = 1
								}
							})
						})
					} else {
						i.hisResultCreateReqVOList = i.inspectResultList
						i.hisResultCreateReqVOList.map(k => {
							k.status = 0
							k.broadId = this.formData.broadId
							k.fpdId = k.id
							k.resLable = k.subLable
							k.resValue = k.subValue
							k.status = 0
							if (k.subValue == 0 && k.isNormal == 1) {
								i.isdanger = 1
							}
						})
					}
				});
				//检查拍照是否有遗漏没有勾选拍照的----------
				let arrs = new Array()
				this.saveImplement.inspectList.map((i, index) => {
					if (i.inspType != 'fpd') {
						console.log('12222');
						arrs[index] = new Array()
						i.inspectResultList.map((k, indexs) => {
							arrs[index][indexs] = new Array(i.inspectResultList.length)
							arrs[index][indexs] = k.subValue
						})
					}
				})
				arrs.map(i => {
					if (!i.includes(1)) {
						// this.yilou = true
						this.show = true
						return;
					}
				})
				// console.log(this.saveImplement, '消防设备和消防设施');  屏蔽未检查校验2
				this.saveImplement.inspectList.map((i, index) => {
					if (i.inspType != 'fpd') { //有不正常的必须拍照 
						i.inspectResultList.map((k, indexs) => {
							if (i.attUrl.length == 0) {
								if (k.isNormal == 1 && k.subValue == 0 && !this.yilou) return this.show3 =
									true
							}
						})
					} else if (i.inspType == 'fpd' && i.hisFpdCreateReqVOList.length == 0) {
						return this.show4 = true
					}
				})
				// console.log(this.saveImplement, '消防设备和消防设施');  屏蔽未检查校验2
				//检查拍照是否有遗漏没有勾选的-----------
				if (!this.show && !this.show3 && !this.show4) { //屏蔽未检查校验2
					if (!this.show) {
						// 巡查未完成判断
						console.log(this.saveImplement, '1111111111111111');
						checkSubmitRelease(JSON.stringify(this.saveImplement)).then(response => {
							if (response.data) {
								uni.showToast({
									title: '提交成功',
									icon: 'none',
									duration: 2000
								})
								const table = uni.getStorageSync('tableData')
								delete table[this.saveImplement.broadId] //保存时删除掉保存的那一项再保存
								uni.setStorageSync('tableData', table)
								setTimeout(() => {
									uni.redirectTo({
										url: `/pagesA/fire/check_active/index?current=1&type=${this.type}`
									});
								}, 1000)
							} else {
								this.$modal.msgError('提交失败')
							}
						})
					}
				}
			},
			shuJu() {
				this.saveImplement.inspectList = this.tableData
				this.saveImplement.taskId = this.formData.id
				console.log(this.saveImplement, 'this.saveImplementthis.saveImplement');
			},
			// 获取数据
			getData(pageNo, value = '') {
				this.loading = true
				this.formData.pageNo = pageNo
				CheckActiveImplement(JSON.stringify(this.formData)).then(response => {
					if (response.data) {
						this.total = response.data.total
						this.loading = false;
						this.tableData = response.data.records
						this.tableData.map(i => {
							i.inspId = i.id
							// i.inspName = i.insp_name
							// i.inspCode = i.insp_code
							i.isreport = 0
							i.status = 0
							i.attUrl = []
							i.description = ''
							i.isdanger = i.isdanger
							i.hisFpdCreateReqVOList = []
							i.hisResultCreateReqVOList = []
							i.qrcodeShow = false
							// ----隐患
							i.choiceDanger = this.choiceDanger //隐患描述下拉的数据
							// ----隐患
						})
					}
					console.log(this.tableData, 'this.tableData');
				});
				// this.newInsTypeData.map(i => {
				// 	i.attUrl = []
				// })
			},
			// 触底的事件
			scrolltolower() {
				// 判断是否还有下一页数据
				if (this.formData.pageNo * this.formData.pageSize >= this.total) return uni.showToast({
					title: `数据加载完毕`
				})
				// 判断是否正在请求其它数据，如果是，则不发起额外的请求
				if (this.loading) return
				this.formData.pageNo += 1
			},
			noNormal() {
				this.$modal.alert('此检查项为消防设备，请对设备进行扫码')
			},

			normal(items, indexs, index, item) {
				this.tableData[index].description = this.description
				// 根据norNormal == 1判断哪一个是单独与其他互斥的
				this.id = items.id
				this.descriptIndex = index //给提交发布的描述用的
				this.tableData[index].inspectResultList.map(k => {
					if (k.isNormal == 1) this.nnorNormalValue = k.id
					//给提交发布的描述用的
					if (this.tableData[index].inspectResultList[indexs].isNormal != 1 && this.tableData[index]
						.inspectResultList[indexs].subValue != 1) {
						this.show2 = true

					}
				})

				// tableItem当前点击的复选框值
				let tableItem = this.tableData[index].inspectResultList[indexs]
				let ALLinspectResultList = this.tableData[index].inspectResultList
				let YesinspectResultList = [] //独一个
				let NorinspectResultList = [] //其他的互斥的
				var Y = ALLinspectResultList.filter(i => i.id == this.nnorNormalValue)
				var N = ALLinspectResultList.filter(i => i.id != this.nnorNormalValue)
				N.map(n => {
					NorinspectResultList.push(n.subValue)
				})
				Y.map(y => {
					YesinspectResultList.push(y.subValue)
				})
				// items.isdenger = 0 ? 1 : 0
				if (NorinspectResultList.includes(1)) { //如果互斥的数组存在true  normal!=1的数组
					if (tableItem.id == this.nnorNormalValue) { //当点击的是value == this.nnorNormalValue是
						this.tableData[index].inspectResultList.map((i, kindex) => {
							console.log(i.id, this.nnorNormalValue, 'llllllllo');
							if (i.id != this.nnorNormalValue) {
								i.subValue = 0
								this.show2 = false
							} else {
								i.subValue = 1

							}
						})
					} else {
						// tableItem.subValue = !tableItem.subValue //不为独一份时，执行改语句
						items.subValue = items.subValue == 0 ? 1 : 0
						this.show2 = false
					}
				} else { //如果互斥的数组不存在true，全是false  normal!=1的数组
					if (tableItem.id == this.nnorNormalValue) { //如果点击的是独一份
						// tableItem.subValue = !tableItem.subValue //允许执行
						items.subValue = items.subValue == 0 ? 1 : 0
					} else { //如果点击的是互斥的
						// if (YesinspectResultList.includes(true)) { //是否存在第一份
						this.tableData[index].inspectResultList.map((i, kindex) => {
							if (i.id == this.nnorNormalValue) {
								i.subValue = 0
							}
						})
						// }
						// tableItem.subValue = !tableItem.subValue
						items.subValue = items.subValue == 0 ? 1 : 0
					}
				}
				if (items.isNormal == 0 && items.subValue == 1) {
					item.showDescription = true; // 显示描述框
					// ----隐患
					this.tableData[this.descriptIndex].choiceDanger.map(i => i.checkedListDanger = [])
					// ----隐患
				} else {
					item.showDescription = false; // 显示描述框
				}

			},
			// 消防设备扫码
			normalPopup(items, indexs, index) {
				// this.insTypeData.map(k => {
				// 	k.attUrl = []
				// })
				this.insTypeData[index].inspectResultList.map(k => {
					if (k.isNormal == 1) this.nnorNormalValue = k.id
					if (this.insTypeData[index].inspectResultList[indexs].isNormal != 1 && this.insTypeData[index]
						.inspectResultList[indexs].subValue != 1) {
						this.show5 = true
					}
				})
				let tableItem = this.insTypeData[index].inspectResultList[indexs]
				let ALLinspectResultList = this.insTypeData[index].inspectResultList
				let YesinspectResultList = []
				let NorinspectResultList = []
				var Y = ALLinspectResultList.filter(i => i.id == this.nnorNormalValue)
				var N = ALLinspectResultList.filter(i => i.id != this.nnorNormalValue)
				N.map(n => {
					NorinspectResultList.push(n.subValue)
				})
				Y.map(y => {
					YesinspectResultList.push(y.subValue)
				})
				// items.isdenger = 0 ? 1 : 0
				if (NorinspectResultList.includes(1)) { //如果互斥的数组存在true  normal!=1的数组
					if (tableItem.id == this.nnorNormalValue) {
						this.insTypeData[index].inspectResultList.map((i, kindex) => {
							if (i.id != this.nnorNormalValue) {
								i.subValue = 0
							} else {
								i.subValue = 1
							}
						})
					} else {
						items.subValue = items.subValue == 0 ? 1 : 0
					}
				} else {
					if (tableItem.id == this.nnorNormalValue) {
						items.subValue = items.subValue == 0 ? 1 : 0
					} else {
						// if (YesinspectResultList.includes(true)) { //是否存在第一份
						this.insTypeData[index].inspectResultList.map((i, kindex) => {
							if (i.id == this.nnorNormalValue) {
								i.subValue = 0
							}
						})
						// }
						items.subValue = items.subValue == 0 ? 1 : 0
					}
				}
				// ----扫码选择隐患
				if (items.isNormal == 0 && items.subValue == 1) {
					this.show5 = true; // 显示描述框
					// this.insTypeData.choiceDanger.map(i => i.checkedListDanger = [])
				} else {
					this.show5 = false; // 显示描述框
				}
				// ----扫码选择隐患

			},
			checkPopupConfirm(fpdId) { //弹出得到的那一条数据insTypeData的id    弹出保存
				//this.insTypeData[0]扫二维码后点击出现的一条消防列表数据内容    this.newInsTypeData的多条数据列表
				let arr = []
				let normalArr = 0
				this.insTypeData[0].inspectResultList.map((i, index) => {
					arr.push(i.subValue)
					if (i.isNormal == 1) {
						normalArr = index //找到正常的所在的index
					}

				})
				if (arr.includes(1)) { //包含了证明勾选了
					arr.map((i, index) => {
						if (i == 1) { //如果i是1表示点击了隐患，判断点击的隐患是否是isnormal=1的，如不是并且图片长度为0,就提示拍照
							// if (index != normalArr && this.insTypeData[0].attUrl.length == 0) {
							// 	that.$modal.alert('请对有问题设备进行拍照')
							// } else {
							// this.newInsTypeData = [...this.newInsTypeData, ...this.insTypeData]
							// uni.setStorageSync('newInsTypeDatas', this.newInsTypeData)
							// this.newInsTypeData = uni.getStorageSync('newInsTypeDatas')
							this.tableData.map(i => {
								if (i.id == this.checkTableDataId) {
									i.hisFpdCreateReqVOList = [...i.hisFpdCreateReqVOList, ...
										this.insTypeData
									]
									i.hisFpdCreateReqVOList.map(k => {
										k['broadId'] = that.formData.broadId
										if (k.id == fpdId) {
											k['dangerDescribe'] = this.description2
										}

									})
								}
							})
							this.insTypeData = []
							this.insTypeData.map(k => {
								k.attUrl = []
							})
							console.log(this.tableData, '111111');
							this.maShow = false

							// }
						}

					})
				} else {
					that.$modal.msg('请勾选检查结果')
				}
				// ----扫码选择隐患
				this.description2 = ''
				this.show5 = false
				// this.tableData.map((i) => { //这一段不用放开，以前是用于消防设备扫多个码统计数据展示的
				// 	if (i.id = fpdId) {
				// 		let isNormalZero=new Array(i.inspectResultList.length)  //新建数组用来放isNormal为1和不为1处理后的分别的数组
				// 		this.newInsTypeData.map(k => {
				// 			k.inspectResultList.map((j,index) => {
				// 						isNormalZero[index]=[]
				// 						isNormalZero[index].push(j.subValue)
				// 			})	
				// 		})
				// 		i.inspectResultList.map((g,index)=>{
				// 			if(isNormalZero[index].includes(1)){
				// 				g.subValue=1
				// 				if(g.isNormal==1){
				// 					g.subValue=0
				// 				}
				// 			}
				// 		})
				// 	}
				// })	
				// this.$forceUpdate()
			},
			checkPopupCancel() {
				this.tableData[this.onDecodeIndex].qrcodeShow = false
				this.maShow = false
			},

			//拍照上传
			photoUpload(val) {
				let pictures = [];
				var that = this;
				uni.chooseImage({
					sourceType: ['camera'], //实现拍照
					count: 3,
					sizeType: ['original', 'compressed'],
					// sourceType: ['album','camera'], //打开系统相册
					success(res) {
						that.loading = true
						if (Array.isArray(res.tempFilePaths)) { //从相册选择有三张的情况
							// if (res.tempFilePaths.length === 3) {
							// 	pictures.length = 0
							// } else if (res.tempFilePaths.length == 2 && pictures.length == 2) {
							// 	pictures.splice(0, 1)
							// }
							res.tempFilePaths.forEach(item => {
								// let picture = {
								// 	url: item,
								// 	show: false
								// }
								// pictures.push(picture)
								loadImage(
									item,
									function(canvas) {
										canvas.toBlob(function(blob) {
											// 压缩后的 Blob 对象
											const compressedFile = blob;
											// 将压缩后的文件 `compressedFile` 转换为临时URL
											const fileUrl = URL.createObjectURL(
												compressedFile);

											uni.uploadFile({
												url: baseUrl +
													'/admin-api/infra/file/upload', //后端用于处理图片并返回图片地址的接口    
												filePath: item,
												name: 'file',
												header: {
													"Authorization": 'Bearer ' +
														getAccessToken(),
												}, //请求token
												success: (res) => {
													that.loading = false
													let imgUrl = JSON.parse(res
														.data)
													// that.imageList.push(imgUrl.data)
													if (!val.fpdType || val
														.inspType != 'fpd') {
														that.tableData.map((i,
															index) => {
															if (val.id == i
																.id) {
																i.attUrl
																	.push(
																		imgUrl
																		.data
																	)
															}
														})
													} else { //消防设备外（扫一扫下方）展示的图片
														//弹出层的消防设备展示的图片
														that.insTypeData.map((i,
															index) => {
															if (val.id == i
																.id) {
																i.attUrl
																	.push(
																		imgUrl
																		.data
																	)
															}
														})
													}
													that.$forceUpdate();
													// // 返回的url
												},
												fail: (err) => {
													that.loading = false
													this.$modal.msg(err.msg)
												}
											})
											// // 保存到本地
											// uni.saveImageToPhotosAlbum({
											// 	filePath: item,
											// })
											// 上传完毕后，释放临时URL
											URL.revokeObjectURL(fileUrl);
										}, 'image/jpeg', 0.6); // 设置压缩后的图片格式为 JPEG，压缩质量为 0.6
									}, {
										canvas: true,
										maxWidth: 800
									} // 设置最大宽度为 800px
								);
							})
						}
					}
				})
			},
			// // 将拍的照片的base64转成文件格式然后再转成FormData，就可以使用上传图片的接口了
			// base64ToFile(base64){
			// 	const dataArr = base64.split(',');
			// 	const byteString = atob(dataArr[1]);
			// 	const options = {
			// 		type:'image/jpeg',
			// 		endings:'native'
			// 	};
			// 	const u8Arr = new Uint8Array(byteString.length)
			// 	for(let i=0;i<byteString.length;i++){
			// 		u8Arr[i]=byteString.charCodeAt(i);
			// 	}
			// 	return new File([u8Arr],'phone.png',options)
			// },
			//methode结束
		}
	}
</script>
<style lang="scss" scoped>
	page {
		background-color: rgb(245, 247, 249) !important;
	}

	.container {
		// height: 100vh;
		position: relative;
		background-color: rgb(245, 247, 249);
	}

	/deep/.uni-card {
		box-shadow: 0px 0px 3px 0px rgba(86, 165, 168, 0.63) !important;
		border-radius: 20rpx;
	}

	.tupian {
		width: 48rpx;
		height: 48rpx;
	}

	.tupian2 {
		width: 30rpx;
		height: 30rpx;
	}

	.text {
		text-align: center;
		color: #000;
		font-size: 26rpx;
		margin-top: 20rpx;
	}

	.text2 {
		text-align: center;
		color: #000;
		font-size: 22rpx;
		margin-top: 10rpx;
	}

	.child {
		margin: 20rpx 0 0 20rpx;
		border-radius: 10rpx;

		.child-new {
			display: flex;

			.child-new-item {
				width: 30%;
				margin-top: 25%;
				transform: translateY(-50px);
			}

			.child-result {
				/deep/.data-v-525ecd67 {
					// width: 130rpx;
					height: 100rpx;
				}
			}
		}
	}

	.titles {
		padding: 20rpx 0;
		color: #383838;

	}

	.grid-item-box {
		flex: 1;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}

	/deep/ .uni-grid-item {
		height: 140rpx !important;
	}

	/deep/.uni-textarea-textarea {
		// border: 1px solid #4CB2B6;
		border-radius: 16rpx;
	}

	.shebeidesrip {
		/deep/.uni-textarea-textarea {
			border: none;
			border-radius: 16rpx;
		}
	}

	.btnList {
		display: flex
	}

	// /deep/.u-icon--right[data-v-172979f2],
	// /deep/.u-icon--right.data-v-172979f2,
	// /deep/.u-icon--right {
	// 	background-color: #f8f8f8;
	// 	border-radius: 5rpx;
	// 	position: absolute;
	// 	top: -14rpx;
	// 	right: 20rpx;
	// }

	.uni-grid-wraps {
		margin-left: 60rpx;
		margin-bottom: 40rpx;
	}

	/deep/.u-slide-up-enter-active[data-v-39e33bf2],
	/deep/.u-slide-up-enter-active.data-v-39e33bf2,
	/deep/.u-slide-up-enter-active {
		height: 90% !important;
	}

	.springFarm {
		margin-left: 40rpx;
	}

	.show-title {
		font-size: 32rpx;
		color: #383838;
		margin: 40rpx 0;
	}

	.tiantupian {
		margin: 40rpx;
		width: 100rpx;
		height: 100rpx
	}

	/deep/.u-modal {
		border: 1px solid #4CB2B6 !important;
	}

	.slot-contents {
		margin-left: 40rpx;
	}

	/deep/ .slot-contents .uni-textarea-textarea {
		border: 1px solid #4CB2B6;
		// background-color: #F0F2F3;
	}

	/deep/ .uni-textarea-placeholder {
		color: #274647;
		margin-top: 20rpx;
		margin-left: 30rpx;
	}

	/deep/.canvasBox {
		.box {
			width: 600rpx;
			/* 设置扫码容器宽度 */
			height: 600rpx;
			/* 设置扫码容器高度 */
		}
	}

	//隐患弹框
	/deep/.u-popup__content {
		overflow-y: auto;

	}

	.text-xl {
		font-size: 18px;
		font-weight: 600;
	}

	.person-forward {
		padding-top: 40rpx;
		display: flex;
		flex-direction: column;
		flex-wrap: wrap;
		overflow-y: auto;
		margin-bottom: 100rpx;

	}
</style>