<template>
	<view class="uni-container uni-container-bg">
		<view class="example container" :style="'height: ' + (screenHeight - 75) + 'px'">
			<!-- 下拉框 -->
			<view class="u-page__tag-item" style="margin-bottom: 26upx;width: 700upx;border-bottom: 2px solid #55cbbf;">
				<u-form>
					<u-form-item prop="orgName" @click="
						showOrg = true;
						hideKeyboard();
					" label="单位选择:" labelWidth="120px">
						<u--input border="none" disabled v-model="formData.orgName" placeholder="请选择所属单位"></u--input>
						<u-icon slot="right" name="arrow-down" class="danwei"></u-icon>
					</u-form-item>
				</u-form>
			</view>
			<view class="tops" v-if="!getqrcode">
				<view style="display: flex;flex-direction: column;">
					<image :src="scan" class="tupian" @click="erWeiMa"></image>
					<view style="margin-top: 20rpx;">设施扫码</view>
				</view>
				<!-- #ifdef H5 -->
				<u-popup :show="qrScanShow" mode="center" @close="qrScanClose" @open="qrScanOpen" closeable
					:safeAreaInsetTop="true" zoom>
					<view class="qr-scan-containner">

						<view class="qr-scan-middle">
							<view class="qr-scan-title">
								扫码
							</view>
							<qrcode-stream class="qr-scan-view" @decode="onDecode" />
						</view>
					</view>
				</u-popup>
				<!-- <view class="qrcode" v-if="qrcodeShow">
				<qrcode-stream @decode="onDecode" />
			</view> -->
				<!-- #endif -->
				<view>
					<image :src="Group" @click="
						showMCheck = true;
						hideKeyboard();
					" class="tiantupian"></image>
					<view style="margin-top: 20rpx;">手动添加</view>
				</view>
			</view>
			<view class="cont" v-if="!getqrcode">
				主动检查记录
			</view>
			<view v-if="!getqrcode" class="main-content">
				<uni-card v-for="(item, index) in tableData" :key="index">
					<view class="titles"><text class="name-align-task">检查项:</text>{{item.inspName}}
						<u-icon v-if="item.isdenger==1" name="warning-fill" color="#ff5647" size="28"
							:customStyle="{marginTop:'20px',backgroundColor:'#fff'}"></u-icon>
					</view>
					<view><text class="name-align-task">检查结果:</text>{{item.handleResult}}</view>
					<view class="an-niu">
						<text><text class="name-align-task">检查时间:</text>{{item.inspectTime}}</text>
						<text @click="addClickDetail(item.id)" class="detail">查看详情</text>
					</view>
				</uni-card>
			</view>
		</view>
		<!-- 扫码弹出层 -->
		<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 style="display: flex;flex-direction: column;">
						<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="tupians"
											@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="show2">
							<textarea v-model="dangerDescribe" placeholder="请输入隐患描述内容"></textarea>
						</view> -->
					</view>
					<!-- ----扫码选择隐患 -->
					<view class="slot-contents" v-if="show2">
						<textarea v-model="dangerDescribe" placeholder="请输入隐患描述内容"
							@click="popupChoiceDangerFpd('show2')"></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>
						</view>
						<uni-load-more v-show="loading" status="loading" :content-text="contentText" />
					</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)"
									class="icon-style">
								</u-icon>
						</view>
					</view>
					<view style="width: 60%;position: absolute;left:150rpx;;bottom:60rpx;z-index: 9999;">
						<div class="btnList" v-if="show2">
							<u-button shape="circle" type="primary" color="#4CB2B6" text="立即处理"
								customStyle="margin-right:20%" @click="checkPopupConfirmNow">
							</u-button>
							<u-button v-if="show2" shape="circle" type="primary" color="#4CB2B6" text="生成隐患"
								@click="checkPopupYinHuan">
							</u-button>
						</div>
						<div class="btnList" v-if="!show2">
							<u-button shape="circle" type="primary" color="#4CB2B6" text="保存"
								customStyle="margin-right:20%" @click="checkPopupConfirm()">
							</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-popup :show="manualPopup" :round="10" @close="manualPopup=false">
			<view v-if="checkManualData!=[]">
				<view class="springFarm" v-for="(item,index) in checkManualData" :key="index">
					<view class="show-title">检查项名称:{{item.inspName}}</view>
					<view>
						<view class="show-title">设备检查项:</view>
					</view>
					<view style="display: flex;flex-direction: column;">
						<view class="" v-if="item.inspectSubDOList!=''">
							<uni-grid :column="3" :showBorder="false">
								<uni-grid-item v-for="(items,indexs) in item.inspectSubDOList" :key="indexs">
									<view class="grid-item-box">
										<image :src="items.isdenger==1?zhengchang:moren" class="tupians"
											@click="checkPopupManual(items,indexs,index)">
										</image>
										<text class="text">{{items.subLable}}</text>
									</view>
								</uni-grid-item>
							</uni-grid>

						</view>
						<!-- 		<view class="slot-contents" v-if="showManual">
							<textarea v-model="dangerDescribe" placeholder="请输入隐患描述内容"></textarea>
						</view> -->
						<!-- <view class="slot-contents" @click="descript(index)">
							<textarea class="slot-contents" v-model="remark" placeholder="请输入描述内容"></textarea>
						</view> -->
					</view>
					<!-- ----扫码选择隐患 -->
					<view class="slot-contents" v-if="showManual">
						<textarea v-model="dangerDescribe" placeholder="请输入隐患描述内容"
							@click="popupChoiceDangerFpd('Manual')"></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> <!-- 加载中 -->
						</view>
						<uni-load-more v-show="loading" status="loading" :content-text="contentText" />
					</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)"
									class="icon-style">
								</u-icon>
						</view>
					</view>
					<view style="width: 60%;position: fixed;left:150rpx;;bottom:60rpx;z-index: 9999;">
						<div class="btnList" v-if="showManual">
							<u-button shape="circle" type="primary" color="#4CB2B6" text="立即处理"
								customStyle="margin-right:20%" @click="checkPopupConfirmNow">
							</u-button>
							<u-button v-if="showManual" shape="circle" type="primary" color="#4CB2B6" text="生成隐患"
								@click="checkPopupYinHuan">
							</u-button>
						</div>
						<div class="btnList" v-if="!showManual">
							<u-button shape="circle" type="primary" color="#4CB2B6" text="保存"
								customStyle="margin-right:20%" @click="checkPopupConfirm()">
							</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 jieguo">
				<textarea v-model="handleResult" placeholder="请输入" />
			</view>
		</u-modal>
		<u-action-sheet :show="showOrg" :actions="actions" title="请选择单位" @close="showOrg = false" @select="sexSelect">
		</u-action-sheet>
		<u-action-sheet :show="showMCheck" :actions="actionsManual" title="请选择检查项" @close="showMCheck = false">
			<view style="margin-bottom: 20rpx;">
				<view class="manual-hand">
					手动输入设施编码:
				</view>
				<view class="manual-hand-item">
					<u--input placeholder="请输入设施编号" v-model="manualValue" class="manual-hand-input"></u--input>
					<u-button shape="circle" type="primary" color="#4CB2B6" text="确认"
						customStyle="width:120rpx;margin-left:2%" @click="manualHandConfirm()">
					</u-button>
				</view>

			</view>
			<hr>
			<view class="manual-hand">
				选择检查项大类:
			</view>
			<view v-for="(item,index) in actionsManual" :key="index" @click="SelectMCheck(item)" class="manual">
				{{item.name}}
			</view>
		</u-action-sheet>

	</view>
</template>

<script>
	// #ifdef H5
	import {
		QrcodeStream
	} from 'vue-qrcode-reader'
	// #endif
	import {
		getInspect, //获取主动检查列表
		inspTypeList,
		createInspect, //创建主动检查
		getInspectInfo, //手动添加的检查项列表
		getFpd //根据编码获取设施信息
	} from "@/api/check_active";
	import loadImage from 'blueimp-load-image';
	import {
		getAccessToken
	} from '@/utils/auth'
	import config from '@/config'
	import store from "@/store"
	const baseUrl = config.baseUrl
	const baseUrlImg = config.baseUrlImg
	import {
		getOrgId //获取orgId
	} from '@/api/fire_device';
	import {
		shijianc,
		viewImgBig
	} from '@/utils/common.js'
	//隐患弹框--
	import {
		DICT_TYPE,
		getDictDatas
	} from '@/utils/dict';
	//隐患弹框--
	let that = '';
	export default {
		components: {
			// #ifdef H5
			QrcodeStream
			// #endif
		},
		data() {
			return {
				contentText: {
					contentrefresh: '上传照片中',
				},
				screenHeight: this.$screenHeight,
				// ----扫码选择隐患
				showPopupDanger: false,
				dangerDict: getDictDatas(DICT_TYPE.DANGER_RESULT),
				choiceDanger: getDictDatas(DICT_TYPE.DANGER_TYPE),
				checkedPopupDanger: [], //
				// ----扫码选择隐患
				manualValue: '', //手动输入的设施编号
				manualPopup: false,
				scan: `${baseUrlImg}/checkActive/scan.png`,
				// 是否开启扫描
				qrScanShow: false,
				Group: `${baseUrlImg}/checkActive/Group2.png`,
				erWeiMaShu: '', //二维码内容对象
				tableData: [],
				loading: false,
				dengerType: 0,
				saveImplement: {
					dengerType: 0,
					attUrl: [],
					dangerDescribe: "", //隐患描述
					fpdId: "",
					fpdResultCreateReqVOList: [], //传的当前事件
					hisResultCreateReqVOList: [], //手动检查
					handleMethod: "", //处理方式
					handleResult: "", //处理结果描述
					handleTime: '',
					inspectTime: '',
					imgUrl1: "",
					imgUrl2: "",
					imgUrl3: "",
					orgId: 0,
					taskId: 0,
					broadId: 0,
					remark: "", //附加描述
					isdenger: 0,
				},
				maShow: false, //扫码后弹框是否展示
				manualCheck: false, //手动检查弹框是否显示
				actionsManual: [], //手动检查弹框数据
				ManualData: [], //手动检查弹框完整数据
				checkManualData: [], //手动检查选中的一条检查项数据
				showManual: false, //手动检查是否显示描述
				showMCheck: false,
				insTypeData: '', //扫二维码后出现的消防列表数据内容
				moren: `${baseUrlImg}/checkActive/moren.png`, //默认图片
				zhengchang: `${baseUrlImg}/checkActive/zhengchang.png`,
				show5: false,
				remark: '',
				photograph: `${baseUrlImg}/checkActive/photograph.png`,
				show2: false,
				handleResult: '',
				dangerDescribe: '',
				showOrg: false,
				actions: [],
				// 每页数据量
				pageSize: 10,
				// 当前页
				pageNo: 1,
				// 数据总量
				total: 0,
				formData: {
					orgName: '',
					orgId: ''
				},
				getqrcode: false,
				qrcodeShow: false, //h5端扫码是否显示

			}
		},
		watch: {
			loading: {
				handler(newLength, oldLength) {
					this.$modal.isLoadingModel(this.loading)
				},
				immediate: true
			}
		},
		onShow() {
			this.choiceDanger.map(i => {
				i.name = i.label;
				i.id = i.value;
			});
			this.tableData = []
			this.actions = []
			that = this;
			getOrgId({
				pageNo: this.pageNo,
				pageSize: this.pageSize,
				userId: this.$store.state.user.id
			}).then(response => {
				// 取到用户对应的单位名称与id
				response.data.map(v => {
					this.actions.push({
						id: v.dwid,
						name: v.orgName
					});
				});
				this.formData.orgName = response.data.length > 0 ? response.data[0].orgName : '' //默认
				this.formData.orgId = response.data.length > 0 ? response.data[0].dwid : ''

			});
			this.getData(1)
			this.getInspect()
		},
		methods: {
			// ----扫码选择隐患
			popupChoiceDangerFpd(type) {
				this.checkedPopupDanger = this.dangerDescribe.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.choiceDanger.map(i => {
					if (i.name == this.checkedPopupDanger[this.checkedPopupDanger.length - 1]) {
						this.dengerType = i.value
					}
				});
				this.dangerDescribe = this.checkedPopupDanger.toString()
				if (this.dangerDescribe.startsWith(',')) {
					this.dangerDescribe = this.dangerDescribe.slice(1);
				}
				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)
				}
			},
			// ----扫码选择隐患
			qrScanOpen() {},
			async getInspect() {
				const res = await getInspectInfo({
					pageNo: 1,
					pageSize: 100
				})
				this.ManualData = res.data.list
				this.actionsManual = res.data.list.filter(obj => obj.inspType !== 'fpd').map(obj => {
					return {
						id: obj.id,
						name: obj.inspName
					};
				})
			},
			closeImage(item, val, k) { //删除图片---5.25新加--未验证
		this.$nextTick(()=>{
			if (this.manualPopup) { //手动检查
				console.log(val, 'vvvvvvvvvvvvvvv');
				this.checkManualData[0].attUrl.splice(val, 1)
			
			} else { //扫码添加
				if (item.fpdType) {
					this.insTypeData[k].attUrl.splice(val, 1)
				}
				// this.tableData[k].attUrl.splice(val, 1)
			}
			this.$forceUpdate();
		})
			},
			sexSelect(e) { //单位
				this.formData.orgId = e.id;
				this.formData.orgName = e.name;
				this.tableData = []
				this.getData(1)
			},
			manualHandConfirm() { //手动输入编号确认
				var that = this
				getFpd({
					fpdCode: this.manualValue
				}).then(res => {
					if (res.data.list.length > 0) {
						inspTypeList({
							id: res.data.list[0].id,
							fpdCode: this.manualValue
						}).then(reponse => {
							that.showMCheck = false
							that.maShow = true
							that.show2 = false
							this.manualValue = ''
							that.insTypeData = reponse.data.records
							that.insTypeData.map(i => i.attUrl = [])
						})
					} else {
						this.$modal.msg('不存在该设备编码，请确认是否输入正确')
					}

				})

			},
			SelectMCheck(e) { //手动选择
				this.reselt()
				this.loading = false
				this.checkManualData = this.ManualData.filter(ManualDataItem => {
					return ManualDataItem.id == e.id
				})
				this.showMCheck = false
				this.manualPopup = true
				this.checkManualData.map(i => {
					i.inspectSubDOList.map(v => {
						v.isdenger = 0
					})
					i.isdenger = i.isdenger
					i.remark = ''
					i.attUrl = []
					i.handleMethod = ''
					i.handleResult = ''
					i.handleTime = ''
					i.inspectTime = ''
				})
				this.remark = ''
			},
			checkPopupManual(items, indexs, index) { //手动选择
				this.checkManualData[0].inspectSubDOList.map(i => {
					if (i.id == items.id) {
						i.isdenger = i.isdenger === 1 ? 0 : 1;
						this.showManual = i.isdenger === 1 ? true : false;
					} else {
						i.isdenger = 0
						this.showManual = false
					}
				})
				this.$forceUpdate()
			},
			descript(index) { //隐患描述点击确认
				// this.show2 = false

			},
			getData(pageNo) {
				this.loading = true
				const id = this.$store.state.user.id
				getInspect({
					pageNo: pageNo,
					pageSize: this.pageSize,
					userId: id,
					orgId: this.formData.orgId
				}).then(response => {
					this.loading = false
					this.tableData = [...this.tableData, ...response.data.list]
					this.dangerDict.map(i => {
						this.tableData.map(k => {
							if (k?.handleResult == i.value) {
								k.handleResult = i.label
							}
						})

					})
					// this.tableData = response.data.list
					this.total = response.data.total
				})
			},
			//小程序端扫码
			erWeiMa() {
				// #ifdef H5
				this.qrScanShow = true
				// #endif
				// #ifdef MP-WEIXIN
				var that = this
				this.remark = ''
				// 只允许从相机扫码
				uni.scanCode({
					onlyFromCamera: true, //只允许从相机扫码
					success: function(res) {
						if (res.errMsg == "scanCode:ok") {
							let result = JSON.parse(res.result)
							inspTypeList(JSON.parse(res.result)).then(reponse => {
								if (reponse.code == 0) {
									that.maShow = true
									that.show2 = false
									that.insTypeData = reponse.data.records
									that.insTypeData.map(i => {
										i.remark = ''
										i.attUrl = []
										i.handleMethod = ''
										i.handleResult = ''
										i.handleTime = ''
										i.inspectTime = ''
									})
								}
							})
							setTimeout(() => {
								that.$modal.msgSuccess('扫码成功')
							}, 200)
						}
					},
					fail: () => {
						that.$modal.msgError('未识别到二维码，请重新尝试！')
					}
				})
				// #endif
			},
			// #ifdef H5
			// 扫码成功后执行函数
			onDecode(qrcodeVal) {
				this.$modal.msgSuccess('扫码成功', qrcodeVal)
				this.qrcodeResault = qrcodeVal
				this.qrScanShow = false
				let result = JSON.parse(qrcodeVal)

				var that = this
				inspTypeList(JSON.parse(qrcodeVal)).then(reponse => {
					if (reponse.code == 0) {
						that.maShow = true
						that.show2 = false
						that.insTypeData = reponse.data.records
						that.insTypeData.map(i => i.attUrl = [])
					}
				})
				setTimeout(() => {
					that.$modal.msgSuccess('扫码成功')
				}, 200)
			},
			// 点击关闭按钮
			qrScanClose() {
				this.qrScanShow = false
			},
			onInit(promise) { //未使用
				promise
					.then(console.log)
					.catch(console.error)
			},
			// #endif
			descriptFpd() { //隐患描述点击确认
				this.show5 = false
				// this.handleResult = this.handleResult
				this.handleMethod = this.handleResult
				if (this.manualPopup) {
					// this.checkManualData[0].handleResult = this.handleResult
					this.checkManualData[0].handleMethod = this.handleResult
					this.checkManualData[0].handleResult = 1

				}
				this.handleResult = 1
				this.checkPopupConfirm()

				// this.maShow=false
			},
			checkPopupConfirmNow() {
				this.show5 = true
				this.handleMethod = "立即处理" //立即整改
				if (this.manualPopup) {
					this.checkManualData[0].handleMethod = "立即处理"
				}
			},
			checkPopupYinHuan() {
				console.log(this.dengerType, 'this.dengerType');
				this.handleMethod = "生成隐患" //生成隐患
				// this.handleResult = "不正常"
				this.handleResult = 2
				if (this.manualPopup) { //手动检查
					this.checkManualData[0].handleMethod = "生成隐患"
					// this.checkManualData[0].handleResult = "不正常"
					this.checkManualData[0].handleResult = 2
				}
				this.checkPopupConfirm()
			},
			photoUpload(val) {
				let pictures = [];
				let that = this;
				uni.chooseImage({
					sourceType: ['camera'], //实现拍照
					count: 3,
					sizeType: ['original', 'compressed'],
					// sourceType: ['album','camera'], //打开系统相册
					success(res) {
						that.loading = true
						if (Array.isArray(res.tempFilePaths)) { //从相册选择有三张的情况
							res.tempFilePaths.forEach(item => {
								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) => {
													let imgUrl = JSON.parse(res
														.data)
													that.loading = false
													//消防设备外（扫一扫下方）展示的图片
													//弹出层的消防设备展示的图片
													if (that.manualPopup) { //手动检查

														that.checkManualData.map(
															i => {
																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: () => {
													that.loading = false
												}
											})
											// 上传完毕后，释放临时URL
											URL.revokeObjectURL(fileUrl);
										}, 'image/jpeg', 0.6); // 设置压缩后的图片格式为 JPEG，压缩质量为 0.6
									}, {
										canvas: true,
										maxWidth: 800
									} // 设置最大宽度为 800px
								);
							})

						}
					}
				})
			},


			// 消防设备扫码
			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
						this.show2 = 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
								this.show2 = false
							} else {
								i.subValue = 1
							}
						})
					} else {
						items.subValue = items.subValue == 0 ? 1 : 0
						this.show2 = false
					}
				} 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
					}
				}
			},
			checkPopupConfirm() { //弹出得到的那一条数据insTypeData的id    弹出保存
				if (this.manualPopup) { //手动检查
					this.saveImplement = this.checkManualData[0]

					this.saveImplement.dengerType = this.dengerType
					this.saveImplement.hisResultCreateReqVOList = this.checkManualData[0].inspectSubDOList
					this.saveImplement.dangerDescribe = this.dangerDescribe
					this.saveImplement.handleTime = shijianc(new Date().getTime())
					this.saveImplement.inspectTime = shijianc(new Date().getTime())
					this.saveImplement.remark = this.remark
					this.saveImplement.imgUrl1 = this.checkManualData[0].attUrl[0] ? this.checkManualData[0].attUrl[0] :
						"";
					this.saveImplement.imgUrl2 = this.checkManualData[0].attUrl[1] ? this.checkManualData[0].attUrl[1] :
						"";
					this.saveImplement.imgUrl3 = this.checkManualData[0].attUrl[2] ? this.checkManualData[0].attUrl[2] :
						"";
					this.saveImplement.hisResultCreateReqVOList.map(z => {
						z.resLable = z.subLable
						z.resValue = z.isdenger
					})
					this.saveImplement.inspId = this.saveImplement.id
					this.saveImplement.inspectSubDOList.map(i => {
						if (i.isdenger == 1 && i.isNormal == 0) { //必传参数，只有该检查项正常为0,那么isdenger==1
							this.saveImplement.isdenger = 1
						} else {
							this.saveImplement.isdenger = 0
						}
					})

					this.saveImplement.orgId = this.formData.orgId
					if (!this.saveImplement.dangerDescribe && this.saveImplement.isdenger == 1) return that.$modal
						.msgError('请填写隐患描述');
					this.baocun(this.saveImplement)
				} else { //设施扫码
					//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)) { //包含了证明勾选了
						this.insTypeData.map(i => {

						})
						this.saveImplement = this.insTypeData
						this.saveImplement.map(i => {
							i.dengerType = this.dengerType
							i.handleTime = shijianc(new Date().getTime())
							i.inspectTime = shijianc(new Date().getTime())
							i.orgId = this.formData.orgId
							i.dangerDescribe = this.dangerDescribe
							i.handleMethod = this.handleMethod
							i.remark = this.remark
							i.handleResult = this.handleResult
							i.fpdId = i.id
							i.inspType = "fpd"
							i.imgUrl1 = i.attUrl[0] ? i.attUrl[0] : ""
							i.imgUrl2 = i.attUrl[1] ? i.attUrl[1] : ""
							i.imgUrl3 = i.attUrl[2] ? i.attUrl[2] : ""
							i.inspName = i.fpdName
							i.inspCode = i.fpdCode
							i.inspId = i.id
							i.fpdResultCreateReqVOList = i.inspectResultList
							i.fpdResultCreateReqVOList.map(z => {
								z.broadId = 0
								z.fpdId = z.id
								z.resLable = z.subLable
								z.resValue = z.subValue
								z.status = 0
								if (z.subValue == 1 && z.isNormal ==
									0) { //必传参数，只有该检查项正常为0,那么isdenger==1
									i.isdenger = 1
								} else {
									i.isdenger = 0
								}
							})
						})
						if (!this.saveImplement[0].dangerDescribe && this.saveImplement[0].isdenger == 1) return that
							.$modal.msgError('请填写隐患描述');
						this.baocun(this.saveImplement[0])
						// ----扫码选择隐患
						this.description2 = ''
						this.show2 = false
					} else {
						that.$modal.alert('请勾选检查结果')
					}
				}
			},
			baocun(val) {
				createInspect(JSON.stringify(val)).then(response => {
					if (response.data) {
						uni.showToast({
							title: '提交成功',
							icon: 'none',
							duration: 2000
						})
						this.tableData = []

						this.getData(1)
						this.reselt()
						this.$forceUpdate()
					} else {
						this.$modal.msgError('提交失败')
					}
				})
				this.maShow = false
				this.manualPopup = false
			},
			reselt() {
				this.dangerDescribe = ''
				this.handleResult = ''
				this.saveImplement = { //重置
					attUrl: [],
					dangerDescribe: "", //隐患描述
					fpdId: "",
					fpdResultCreateReqVOList: [], //传的当前事件
					hisResultCreateReqVOList: [],
					handleMethod: "", //处理方式
					handleResult: "", //处理结果描述
					handleTime: "",
					inspectTime: "",
					imgUrl1: "",
					imgUrl2: "",
					imgUrl3: "",
					orgId: 0,
					taskId: 0,
					broadId: 0,
					remark: "", //附加描述
					isdenger: 0,
				}
				this.checkManualData = [{ //重置
					attUrl: [],
					dangerDescribe: "", //隐患描述
					fpdId: "",
					fpdResultCreateReqVOList: [], //传的当前事件
					hisResultCreateReqVOList: [],
					handleMethod: "", //处理方式
					handleResult: "", //处理结果描述
					handleTime: "",
					inspectTime: "",
					imgUrl1: "",
					imgUrl2: "",
					imgUrl3: "",
					orgId: 0,
					taskId: 0,
					broadId: 0,
					remark: "", //附加描述
					isdenger: 0,
				}]

			},
			checkPopupCancel() {
				this.maShow = false
				this.showManual = false
				this.manualPopup = false
			},
			// 隐藏键盘
			hideKeyboard() {
				uni.hideKeyboard();
			},
			addClick() {
				this.manualCheck = true
			},
			addClickDetail(val) {
				uni.navigateTo({
					url: `/pagesA/fire/check_inspection/inspect_detail/inspect_detail?id=${val}`,
					success: function(res) {
						res.eventChannel.emit('acceptDataFromOpenerPage', val);
					}
				})

			},
		},
		// 触底的事件
		onReachBottom() {
			// 判断是否还有下一页数据
			if (this.pageNo * this.pageSize >= this.total) return uni.showToast({
				title: `数据加载完毕`
			})
			// 判断是否正在请求其它数据，如果是，则不发起额外的请求
			if (this.loading) return
			this.pageNo += 1
			this.getData(this.pageNo)
		},
	}
</script>
<style>
	page {
		background-color: #F5F7F9;
	}
</style>
<style lang="scss" scoped>
	page {
		background-color: #F5F7F9 !important;
	}

	.tops {
		display: flex;
		justify-content: space-between;
		width: 80%;
		margin: 50rpx 10%;

		// 二维码扫描相关样式
		.qr-scan-containner {
			max-width: 600rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			align-content: center;
			background-color: transparent;

			.qr-scan-middle {
				.qr-scan-title {
					font-size: 30rpx;
					text-align: center;
					padding: 20rpx 0;
				}

				max-width: 100%;
			}
		}


	}

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

	.tupians {
		width: 45rpx;
		height: 45rpx;
	}

	.tiantupian {
		width: 95rpx;
		height: 95rpx;
	}

	.cont {
		font-size: 16px;
		color: #4CB2B6;
		margin-bottom: 30rpx;
	}

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

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

	::v-deep .u-icon__icon {
		margin-right: 0px !important;
	}

	.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 {
		display: flex;
		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;
	}

	.btnList {
		display: flex
	}

	.main-content {

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


	/deep/.danwei.u-icon--right[data-v-172979f2],
	/deep/.danwei.u-icon--right.data-v-172979f2,
	.danwei.u-icon--right {
		top: 58rpx !important;
		right: 58rpx !important;
	}

	.uni-grid-wraps {
		margin-left: 60rpx;
		margin-bottom: 480rpx !important;
		// margin-bottom: 200rpx;
	}

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

	.springFarm {
		margin-left: 40rpx;
	}

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


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

	.slot-contents {
		// margin-left: 40rpx;
		margin-bottom: 20rpx;
		border-radius: 1px solid #E5E5E5 !important;
		// background-color: #F0F2F3 !important;
	}

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

	.jieguo {
		/deep/.uni-textarea-textarea {
			border: none !important
		}
	}

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

	.detail {
		// width: 72px;
		// height: 60rpx;
		float: right;
		border-radius: 30px;
		background-color: #F7C41E;
		margin-right: 20rpx;
		text-align: center;
		// line-height: 60rpx;
		padding: 3rpx 15rpx;
	}

	.an-niu {
		display: flex;
		justify-content: space-between;
	}

	/deep/.u-input {
		padding: 4px !important;
	}

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

	.manual {
		font-size: 16px;
		padding: 25rpx 0;
	}

	.manual:last-child {
		font-size: 25px;
		padding: 60rpx 0;
		background-color: red;
	}

	.manual-hand {
		margin-left: 30rpx;
		display: flex;
		font-size: 18px;
		color: #30746b;
		margin: 20rpx;
	}

	.manual-hand-item {
		display: flex;
		width: 90%;
		justify-content: space-between;
		margin-left: 3%;

		/deep/.u-input {
			border: 1px solid #726f74 !important;
		}
	}

	//隐患弹框
	/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;

	}

	.example {
		overflow-y: auto;
	}

	/deep/.u-action-sheet {
		height: 80vh;
		background-color: #fff;
		overflow-y: auto;
	}

	.icon-style {
		position: absolute;
		top: -8px;
		right: 8px;
	}
</style>vh