<!-- 随手拍列表 -->
<template>
	<view class="snapshotList">
		<scroll-view scroll-y @scrolltolower="scrollGet" class="info-max-box">
			<view class="tabTitle" v-if="userType==0">
				<view :class="tabIndex==index?'tab-A':'tab-B'" v-for="(item,index) in tabList" :key='index' @click="tabClick(index)">
					{{item}}
				</view>
			</view>
			<view class="tabTitleTow" v-if="userType==1">
				<view :class="tabIndexTow==index?'tab-C':'tab-D'" v-for="(item,index) in tabListTow" :key='index'
					@click="tabClickTow(index)">{{item}}</view>
			</view>
			<view v-if="pageType==0">
				<view class="list">
					<view class="list-li srearch">
						<view>{{form.subName?form.subName:'实验室名称'}}（{{form.subRoom?form.subRoom:'房间号'}}）</view>
						<view>
							<view class="srearch-l" @click="popupClick(1)">
								<img src="@/pages_safetyCheck/images/icon_aqjc_ss.png">
							</view>
							<view class="srearch-r" @click="saoCode()">
								<img src="@/pages_safetyCheck/images/icon_aqjc_sm.png">
							</view>
						</view>
					</view>
					<view class="list-li">
						<view>学院单位名称</view>
						<view>{{form.deptName}}</view>
					</view>
					<view class="list-li">
						<view>检查项目</view>
						<view @click="inspectionItemsClick()">
							{{form.hazardCheckCode?form.hazardCheckCode:''}}{{form.hazardCheckName?form.hazardCheckName:'模糊搜索检查项'}}
							<img src="@/pages_safetyCheck/images/icon_wd_gd@1x.png">
						</view>
					</view>
					<view class="list-li">
						<view>隐患描述</view>
						<view></view>
					</view>
					<textarea class="describe" type="text" v-model="form.hazardDescribe" maxlength="200"
						placeholder="请填写隐患描述" placeholder-style="font-size:24rpx;color:#999;"></textarea>
					<view class="check-for-img-max-box">
						<view class="left-title-p"></view>
						<view class="right-img-box">
							<view class="img-box" v-for="(imgUrl,imgIndex) in form.imgDtoList" :key="imgIndex">
								<img class="img-data" :src="baseUrl+imgUrl.fileUrl">
								<img class="position-img" src="@/pages_safetyCheck/images/icon_ssp_closure.png"
									@click="delImg(imgIndex)">
							</view>
							<img class="add-button" src="@/pages_safetyCheck/images/img_ssp_pz@1x.png"
								@click="selectImage()" v-if="form.imgDtoList.length<5">
						</view>
					</view>
				</view>
				<view class="subBtn" @click="submitForm">提交</view>
			</view>
			<!-- 上报记录 -->
			<view class="escalation" v-if="pageType==1">
				<view class="escalation-li" @click="recordClick(item)" v-for="(item,index) in dataList">
					<view class="escalation-li-t">
						<view>{{item.subName}} ({{item.subRoom}})</view>
						<view :id="item.rectifyStatus==0?'color-A':(item.rectifyStatus==1?'color-B':(item.rectifyStatus==2?'color-C':''))">
							{{item.rectifyStatus==0?'待整改':(item.rectifyStatus==1?'已整改':(item.rectifyStatus==2?'暂无法整改':''))}}
							<img src="@/pages_safetyCheck/images/icon_wd_gd@1x.png">
						</view>
					</view>
					<view class="escalation-li-b">
						<view>上报时间</view>
						<view>{{item.createTime}}</view>
					</view>
				</view>
			</view>
			<!-- 隐患整改 -->
			<view class="hidden" v-if="pageType==2">
				<view class="hidden-li" @click="hiddenClick(item)" v-for="(item,index) in dataList">
					<img class="hidden-li-l" src="@/pages_safetyCheck/images/icon_sys_xz@1x.png">
					<view class="hidden-li-c">{{item.subName}}</view>
					<view class="hidden-li-r">
						<view v-if="item.stayhRectifyCheckNum!=0">待整改{{item.stayhRectifyCheckNum}}项</view>
						<img src="@/pages_safetyCheck/images/icon_wd_gd@1x.png">
					</view>
				</view>
			</view>
			<view class="get-data-null-p" v-if="getDataType">- 没有更多数据 -</view>
		</scroll-view>
		<view class="popup-max-box" v-if="popupType">
			<view class="popup-null" @click="popupClick(2)"></view>
			<view class="popup-big-box">
				<view class="popup-input-box">
					<input type="text" maxlength="10" v-model="form.searchValue" placeholder="请输入关键字">
					<view @click="buildBySub">搜索</view>
				</view>
				<view class="popup-for-max-box">
					<view class="popup-for-null" v-if="!roomList[0]">暂无数据</view>
					<view class="popup-for-box" v-for="(item,index) in roomList" :key="index">
						<view class="name-p">{{item.subName}} ({{item.roomNum?item.roomNum:'-'}})</view>
						<view class="button-p" @click="popupClickItem(item)">确定</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		config
	} from '@/api/request/config.js'
	import {} from '@/pages/api/index.js'
	import {
		laboratorySubRelInfoGetRelList,
		securityAppCheckPhotoMyAdd,
		securityAppCheckPhotoMyList,
		securityAppCheckPhotoRectifyList,
	} from '@/pages_safetyCheck/api/index.js'
	export default {
		name: "snapshotList",
		components: {

		},
		data() {
			return {
				baseUrl: config.base_url,
				pageType: 0,
				userType: 1,
				tabList: ['随手拍上报', '上报记录'],
				tabIndex: 0,
				tabListTow: ['随手拍上报', '上报记录', '隐患整改'],
				tabIndexTow: 0,
				newData: {

				},
				form: {
					rectifyDescribe: '',
					imgDtoList: [],
					hazardCheckName: '',
				},
				popupType: false,
				roomList: [],
				checkOptionList: [],
				getDataType: false,
				// 查询参数
				queryParams: {
					page: 1,
					pageSize: 10,
				},
				total: 0,
				dataList:[],
			}
		},
		onLoad(option) {

			if (option.form) {
				this.form = JSON.parse(decodeURIComponent(option.form));
			}
		},
		onShow() {

		},
		mounted() {

		},
		methods: {
			//滚动事件
			scrollGet() {
				let self = this;
				if (self.total / self.queryParams.pageSize <= self.queryParams.page) {
					this.$set(this, 'getDataType', true);
				} else {
					this.queryParams.page += 1;
					this.$nextTick(() => {
						if(this.pageType==1){
							this.getList();
						}else if(this.pageType==2){
							this.getListTow();
						}
					})
				}
			},
			//上报记录
			async getList() {
				let self = this;
				const {
					data
				} = await securityAppCheckPhotoMyList(this.queryParams);
				if (data.code == 200) {
					if (self.queryParams.page == 1) {
						this.dataList = data.data.records;
						this.total = data.data.total;
						if (data.data.total / self.queryParams.pageSize <= self.queryParams.page) {
							this.$set(this, 'getDataType', true);
						}
					} else {
						this.dataList = [...this.dataList, ...data.data.records]
						this.total = data.data.total;
						if (data.data.total / self.queryParams.pageSize <= self.queryParams.page) {
							this.$set(this, 'getDataType', true);
						}
					}
				}
			},
			//隐患整改
			async getListTow() {
				let self = this;
				const {
					data
				} = await securityAppCheckPhotoRectifyList();
				if (data.code == 200) {
					if (data.data[0]) {
						this.dataList = data.data;
					} else {
						this.$set(this, 'getDataType', true);
					}
				}
			},
			//上报记录跳转详情
			recordClick(row){
				let infoData=row;
				uni.navigateTo({
					url: '/pages_safetyCheck/views/snapshotManage/snapshotDetail?infoData=' + encodeURIComponent(JSON.stringify(infoData))
				});
			},
			//隐患整改跳转详情
			hiddenClick(row){
				let infoData=row;
				infoData.pageType=2;
				uni.navigateTo({
					url: '/pages_safetyCheck/views/snapshotManage/snapshotItems?infoData=' + encodeURIComponent(JSON.stringify(infoData))
				});
			},
			tabClick(index) {
				this.tabIndex = index;
				this.pageType = index;
				this.dataList=[];
				if(index==1){
					this.getList();
				}else if(index==2){
					this.getListTow();
				}
			},
			tabClickTow(index) {
				this.tabIndexTow = index;
				this.pageType = index;
				this.dataList=[];
				if(index==1){
					this.getList();
				}else if(index==2){
					this.getListTow();
				}
			},
			/******图片上传******/
			selectImage() {
				let self = this;
				if (this.form.imgDtoList.length > 4) {
					uni.showToast({
						title: '最多上传5张图片',
						icon: "none",
						mask: true,
						duration: 2000
					});
					return
				}
				wx.chooseImage({
					count: 1,
					sizeType: ["original", "compressed"],
					sourceType: ["album", "camera"],
					success: function(res) {
						let tempFilePaths = res.tempFilePaths[0];
						self.uploadImg(tempFilePaths);
					}
				});
			},
			async uploadImg(tempFilePaths) {
				var self = this;
				uni.showLoading({
					title: '上传中',
					mask: true
				});
				uni.uploadFile({
					url: config.base_url + '/system/file/upload', //仅为示例，非真实的接口地址
					header: {
						'Authorization': uni.getStorageSync('token')
					},
					filePath: tempFilePaths,
					name: 'file',
					formData: {
						'user': 'test'
					},
					success: (uploadFileRes) => {
						let res = JSON.parse(uploadFileRes.data);
						if (res.code == 200) {
							this.form.imgDtoList.push({
								'fileUrl': res.data.url,
								'fileName': res.data.name
							});
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none",
								mask: true,
								duration: 2000
							});
						}
					},
					fail: err => {},
					complete: () => {
						uni.hideLoading()
					}
				});
			},
			//删除图片
			delImg(minIndex) {
				this.form.imgDtoList.splice(minIndex, 1);
				this.$forceUpdate();
			},
			/******搜索房间弹层开关******/
			popupClick(type) {
				if (type == 1) {
					this.room = "";
					this.roomList = [];
					this.popupType = true;
					this.buildBySub();
				} else if (type == 2) {
					this.popupType = false;
				}
			},
			//搜索房间接口
			async buildBySub() {
				let self = this;
				const {
					data
				} = await laboratorySubRelInfoGetRelList({
					'searchValue': this.form.searchValue,
				});
				if (data.code == 200) {
					if (data.data[0]) {
						this.roomList = data.data;
					} else {
						uni.showToast({
							title: '未找到相关实验室',
							icon: "none",
							mask: true,
							duration: 2000
						});
					}
				}
			},
			//确认搜索房间
			popupClickItem(item) {
				this.$set(this.form, "subId", item.subId)
				this.$set(this.form, "subName", item.subName)
				this.$set(this.form, "subRoom", item.roomNum)
				this.$set(this.form, "deptId", item.deptId)
				this.$set(this.form, "deptName", item.deptName)
				this.$set(this.form, "buildId", item.buildId)
				this.$set(this.form, "buildName", item.buildName)
				this.$set(this.form, "floorId", item.floorId)
				this.$set(this.form, "floorName", item.floorName)
				this.$set(this.form, "typeId", item.typeId)
				this.$set(this.form, "classTypeNames", item.classTypeNames)
				this.$set(this.form, "levelId", item.levelId)
				this.$set(this.form, "classLevelName", item.classLevelName)

				this.popupType = false;
			},
			/******调用摄像头******/
			saoCode() {
				let self = this;
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						let list = res.result.split("?")[1].split("&");
						let codeData = {};
						list.forEach((item) => {
							codeData[item.split("=")[0]] = item.split("=")[1];
						})
						console.log('二维码', codeData)
						if (codeData.code) {
							self.laboratoryAppletGetSubDetailInfo(codeData.code);
						} else {
							uni.showToast({
								title: '请扫描正确的二维码',
								icon: "none",
								mask: true,
								duration: 2000
							});
						}
					}
				});
			},
			//搜索项跳转
			inspectionItemsClick() {
				this.form.pageType=1;//1随手拍检查项
				uni.navigateTo({
					url: '/pages_safetyCheck/views/itemsManage/hiddenDangerItemsSearch?form=' + encodeURIComponent(
						JSON.stringify(this.form))
				});
			},
			//上报
			async submitForm() {
				let self = this;
				if (!this.form.subId) {
					uni.showToast({
						title: '请选择实验室!',
						icon: "none",
						mask: true,
						duration: 2000
					});
					return
				}
				if (!this.form.hazardDescribe) {
					uni.showToast({
						title: '请输入隐患描述!',
						icon: "none",
						mask: true,
						duration: 2000
					});
					return
				}
				if (this.form.imgDtoList.length<=0) {
					uni.showToast({
						title: '请选择现场照片!',
						icon: "none",
						mask: true,
						duration: 2000
					});
					return
				}
				const {
					data
				} = await securityAppCheckPhotoMyAdd(self.form);
				if (data.code == 200) {
					uni.showToast({
						title: '提交成功',
						icon: "none",
						mask: true,
						duration: 2000
					});
					let infoData={
						photoId:data.data
					};
					uni.navigateTo({
						url: '/pages_safetyCheck/views/snapshotManage/snapshotDetail?infoData=' + encodeURIComponent(JSON.stringify(infoData))
					});
					
				}
			},


		}
	}
</script>

<style lang="stylus" scoped>
	.snapshotList {
		height: 100%;
		display flex;

		.tabTitle {
			width: 600rpx;
			height: 80rpx;
			display: flex;
			justify-content: center;
			margin: 20rpx 0 0 74rpx;

			>view:nth-of-type(1) {
				width: 300rpx;
				height: 80rpx;
				border-radius: 50rpx 0rpx 0rpx 50rpx;
			}

			>view:nth-of-type(2) {
				width: 300rpx;
				height: 80rpx;
				border-radius: 0rpx 50rpx 50rpx 0rpx;
			}

			.tab-A {
				font-size: 30rpx;
				color: #FFFFFF;
				line-height: 80rpx;
				text-align: center;
				background: #0183FA;
			}

			.tab-B {
				font-size: 30rpx;
				color: #333333;
				line-height: 80rpx;
				text-align: center;
				background: #FFFFFF;
			}
		}

		.tabTitleTow {
			width: 690rpx;
			height: 80rpx;
			display: flex;
			justify-content: center;
			margin: 20rpx 0 0 30rpx;

			>view:nth-of-type(1) {
				width: 230rpx;
				height: 80rpx;
				border-radius: 50rpx 0rpx 0rpx 50rpx;
			}

			>view:nth-of-type(2) {
				width: 230rpx;
				height: 80rpx;
				border-radius: 0rpx 0rpx 0rpx 0rpx;
			}

			>view:nth-of-type(3) {
				width: 230rpx;
				height: 80rpx;
				border-radius: 0rpx 50rpx 50rpx 0rpx;
			}

			.tab-C {
				font-size: 30rpx;
				color: #FFFFFF;
				line-height: 80rpx;
				text-align: center;
				background: #0183FA;
			}

			.tab-D {
				font-size: 30rpx;
				color: #333333;
				line-height: 80rpx;
				text-align: center;
				background: #FFFFFF;
			}
		}


		.list {
			width: 690rpx;
			min-height: 765rpx;
			background: #FFFFFF;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			margin: 20rpx 0 0 30rpx;

			.list-li {
				display: flex;
				justify-content: space-between;
				border-bottom: 1rpx solid #E0E0E0;
				padding: 0 22rpx 0 28rpx;
				box-sizing: border-box;

				>view:nth-of-type(1) {
					font-size: 30rpx;
					color: #333333;
					line-height: 80rpx;
					text-align: left;
				}

				>view:nth-of-type(2) {
					font-size: 28rpx;
					color: #666666;
					line-height: 80rpx;
					text-align: left;
					display: flex;
					justify-content: flex-start;
					align-items: center;

					>img {
						width: 24rpx;
						height: 24rpx;
						margin-left: 8rpx;
					}
				}

				.project_r {
					width: 510rpx;
					min-height: 80rpx;
					display: flex;
					justify-content: flex-end;
					align-items: center;
					padding-left: 20rpx;
					box-sizing: border-box;
					color: #666;
				}

			}

			.srearch {
				.srearch-l {
					width: 60rpx;
					height: 60rpx;
					margin-right: 40rpx;

					>img {
						width: 30rpx;
						height: 30rpx;
						margin: 15rpx 0 0 15rpx;
					}
				}

				.srearch-r {
					width: 60rpx;
					height: 60rpx;

					>img {
						width: 30rpx;
						height: 30rpx;
						margin: 15rpx 0 0 15rpx;
					}
				}
			}

			.describe {
				width: 636rpx;
				height: 120rpx;
				border-radius: 10rpx 10rpx 10rpx 10rpx;
				border: 1rpx solid #E0E0E0;
				margin: 20rpx 0 0 28rpx;
				padding: 12rpx 16rpx;
				box-sizing: border-box;
			}

			.check-for-img-max-box {
				margin: 20px 28rpx;

				.left-title-p {
					width: 100%;
					text-align: left;
					font-size: 30rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 400;
					color: #333333;
					line-height: 80rpx;
				}

				.right-img-box {
					.img-box {
						display inline-block;
						height: 150rpx;
						width: 150rpx;
						position relative;
						margin: 0 14rpx 20rpx 0;
						border-radius 10rpx;
						overflow hidden;

						.img-data {
							height: 150rpx;
							width: 150rpx;
						}

						.position-img {
							position absolute;
							right: 0;
							top: 0;
							width: 36rpx;
							height: 36rpx;
						}
					}

					.img-box:nth-of-type(3n+3) {
						margin-right: 0rpx;
					}

					.add-button {
						margin: 0 0rpx 20rpx 0;
						border-radius 10rpx;
						overflow hidden;
						display inline-block;
						height: 150rpx;
						width: 150rpx;
					}
				}
			}
		}




		/* 实验室弹框 */
		.popup-max-box {
			z-index: 10;
			height: 100%;
			width: 100%;
			position fixed;
			background rgba(0, 0, 0, 0.2);
			display flex;

			flex-direction column;

			.popup-null {
				flex: 1;
			}

			.popup-big-box {
				border-top-left-radius: 20rpx;
				border-top-right-radius: 20rpx;

				background #fff;

				.popup-input-box {
					padding: 30rpx 20rpx;
					display: flex;

					input {
						flex: 1;
						height: 70rpx;
						border: 1rpx solid #e0e0e0;
						border-radius: 10rpx;
						margin-right: 20rpx;
						padding: 0 20rpx;
					}

					view {
						background #0183FA;
						color: #fff;
						border-radius: 10rpx;
						width: 140rpx;
						line-height: 70rpx;
						text-align center;
						font-size: 28rpx;
					}
				}

				.popup-for-max-box {
					margin: 0 20rpx 30rpx;
					height: 600rpx;
					overflow-y scroll;

					.popup-for-null {
						line-height: 100rpx;
						text-align center;
						color: #999;
					}

					.popup-for-box {
						display: flex;
						padding: 10px 0;

						.name-p {
							flex: 1;
							line-height: 60rpx;
						}

						.button-p {
							background #0183FA;
							color: #fff;
							text-align center;
							width: 100rpx;
							line-height: 60rpx;
							height: 60rpx;
							border-radius: 10rpx;
						}
					}
				}
			}
		}

		.subBtn {
			width: 690rpx;
			height: 100rpx;
			background: #0183FA;
			border-radius: 50rpx 50rpx 50rpx 50rpx;
			font-weight: 400;
			font-size: 30rpx;
			color: #FFFFFF;
			line-height: 100rpx;
			text-align: center;
			position: fixed;
			left: 30rpx;
			bottom: 10rpx;
		}

		/* 上报记录 */
		.escalation {

			.escalation-li {
				width: 690rpx;
				height: 162rpx;
				background: #FFFFFF;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				margin: 20rpx 30rpx;
				padding: 0 30rpx;
				box-sizing: border-box;

				.escalation-li-t {
					display: flex;
					justify-content: space-between;
					align-items: center;
					border-bottom: 1rpx solid #E0E0E0;

					>view:nth-of-type(1) {
						font-weight: 400;
						font-size: 30rpx;
						color: #333333;
						line-height: 80rpx;
						text-align: left;
					}

					>view:nth-of-type(2) {
						font-weight: 400;
						font-size: 28rpx;
						color: #0183FA;
						line-height: 80rpx;
						text-align: left;
						display: flex;
						justify-content: flex-start;
						align-items: center;

						>img {
							width: 24rpx;
							height: 24rpx;
						}
					}
				}

				.escalation-li-b {
					display: flex;
					justify-content: space-between;
					align-items: center;

					>view:nth-of-type(1) {
						font-weight: 400;
						font-size: 30rpx;
						color: #333333;
						line-height: 80rpx;
						text-align: left;
					}

					>view:nth-of-type(2) {
						font-weight: 400;
						font-size: 30rpx;
						color: #666666;
						line-height: 80rpx;
						text-align: left;
					}
				}

			}
		}

		/* 隐患整改 */
		.hidden {
			width: 690rpx;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			background: #FFFFFF;
			padding: 0 30rpx;
			box-sizing: border-box;
			margin: 20rpx 30rpx;

			.hidden-li {
				height: 80rpx;
				border-bottom: 1rpx solid #E0E0E0;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				.hidden-li-l {
					width: 34rpx;
					height: 34rpx;
				}

				.hidden-li-c {
					font-size: 28rpx;
					color: #333333;
					line-height: 30rpx;
					text-align: left;
					flex: 1;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					margin: 0 84rpx 0 12rpx;
				}

				.hidden-li-r {
					font-size: 28rpx;
					color: #0183FA;
					line-height: 80rpx;
					text-align: left;
					display: flex;
					justify-content: flex-start;
					align-items: center;

					>img {
						width: 24rpx;
						height: 24rpx;
					}
				}
			}

			.hidden-li:last-of-type {
				border: none;
			}
		}

		#color-A {
			color: #0183FA;
		}

		#color-B {
			color: #16B531;
		}

		#color-C {
			
			color: #FF8C00;
		}
		.get-data-null-p {
			text-align: center;
			height: 100rpx;
			line-height: 100rpx;
			color: #999;
			padding-bottom:200rpx;
		}
	}
</style>
