<template>
	<view style="background: #f6f6f6;">
		<headers :showBack="true">
			<view class="headerName">
				升降机整改
			</view>
		</headers>

		<view class="form_box">
			<view class="flex between form_item" style="height: 60rpx;font-size: 24rpx;">
				<view class="letBox flex">
					<view class="xian">

					</view>
					<view class="" style="margin-left: 20rpx;">
						上报安全隐患
					</view>
				</view>
			</view>
			<view class="flex between form_item">
				<view class="letBox">
					检查类型
				</view>
				<view class="rigBox">
					安全检查
				</view>
			</view>

			<view class="form_item2">
				<view class="letBox">
					报警类型
				</view>
				<view style="margin:12rpx 0;font-size: 24rpx;" class="rigBox">
					人数报警：<text :style="{color:dangerInfo.peopleCntAlarm==0?'#44AB47':'#FF3F33'}">{{dangerInfo.peopleCntAlarm==0?'正常':'报警'}}</text>
				</view>
				<view style="margin:12rpx 0;font-size: 24rpx;" class="rigBox">
					载重报警：<text :style="{color:dangerInfo.weightAlarm==0?'#44AB47':'#FF3F33'}">{{dangerInfo.weightAlarm==0?'正常':'报警'}}</text>
				</view>
				<view style="margin:12rpx 0;font-size: 24rpx;" class="rigBox">
					速度报警：<text :style="{color:dangerInfo.speedAlarm==0?'#44AB47':'#FF3F33'}">{{dangerInfo.speedAlarm==0?'正常':'报警'}}</text>
				</view>
				<view style="margin:12rpx 0;font-size: 24rpx;" class="rigBox">
					高度报警：<text :style="{color:dangerInfo.heightAlarm==0?'#44AB47':'#FF3F33'}">{{dangerInfo.heightAlarm==0?'正常':'报警'}}</text>
				</view>
				<view style="margin:12rpx 0;font-size: 24rpx;" class="rigBox">
					倾角X报警：<text :style="{color:dangerInfo.obliguityXAlarm==0?'#44AB47':'#FF3F33'}">{{dangerInfo.obliguityXAlarm==0?'正常':'报警'}}</text>
				</view>
				<view style="margin:12rpx 0;font-size: 24rpx;" class="rigBox">
					倾角Y报警：<text :style="{color:dangerInfo.obliguityYAlarm==0?'#44AB47':'#FF3F33'}">{{dangerInfo.obliguityYAlarm==0?'正常':'报警'}}</text>
				</view>
				<view style="margin:12rpx 0;font-size: 24rpx;" class="rigBox">
					风速报警：<text :style="{color:dangerInfo.windSpeedAlarm==0?'#44AB47':'#FF3F33'}">{{dangerInfo.windSpeedAlarm==0?'正常':'报警'}}</text>
				</view>
				<view style="margin:12rpx 0;font-size: 24rpx;" class="rigBox">
					1号电机报警：<text :style="{color:dangerInfo.motor1Alarm==0?'#44AB47':'#FF3F33'}">{{dangerInfo.motor1Alarm==0?'正常':'报警'}}</text>
				</view>
				<view style="margin:12rpx 0;font-size: 24rpx;" class="rigBox">
					2号电机报警：<text  :style="{color:dangerInfo.motor2Alarm==0?'#44AB47':'#FF3F33'}">{{dangerInfo.motor2Alarm==0?'正常':'报警'}}</text>
				</view>
				<view style="margin:12rpx 0;font-size: 24rpx;" class="rigBox">
					3号电机报警：<text :style="{color:dangerInfo.motor3Alarm==0?'#44AB47':'#FF3F33'}">{{dangerInfo.motor3Alarm==0?'正常':'报警'}}</text>
				</view>
				<view style="margin:12rpx 0;font-size: 24rpx;" class="rigBox">
					防冲顶报警：<text :style="{color:dangerInfo.topAlarm==0?'#44AB47':'#FF3F33'}">{{dangerInfo.topAlarm==0?'正常':'报警'}}</text>
				</view>
				<view style="margin:12rpx 0;font-size: 24rpx;" class="rigBox">
					防坠器报警：<text :style="{color:dangerInfo.fallAlarm==0?'#44AB47':'#FF3F33'}">{{dangerInfo.fallAlarm==0?'正常':'报警'}}</text>
				</view>
				<view style="margin:12rpx 0;font-size: 24rpx;" class="rigBox">
					下限位报警：<text :style="{color:dangerInfo.bottomAlarm==0?'#44AB47':'#FF3F33'}">{{dangerInfo.bottomAlarm==0?'正常':'报警'}}</text>
				</view>
				
			</view>
			<view class="flex between form_item">
				<view class="letBox">
					报警设备
				</view>
				<view class="rigBox">
					{{dangerInfo.devName}}
				</view>
			</view>
			<!-- <view class="flex between form_item">
				<view class="letBox">
					报警地址
				</view>
				<view class="rigBox">
					{{dangerInfo.location}}
				</view>
			</view> -->

			<view class="flex between form_item">
				<view class="letBox">
					整改负责人
				</view>
				<view class="rigBox">
					<text v-for="(item,index) in changeUser" :key="index">
						{{item.realName}}
					</text>
				</view>
			</view>

			<view class="flex between form_item">
				<view class="letBox">
					整改部门
				</view>
				<view class="rigBox">
					安全部
				</view>
			</view>
			<view class="flex between form_item">
				<view class="letBox">
					要求完成时间
				</view>
				<view class="rigBox">
					{{dangerInfo.addTime}}
				</view>
			</view>
			<!-- <view class="" style="margin: 40rpx 0;">
				报警抓拍
			</view>
			<view class="">
				<image class="imgbox" @click="seeImg" :src="url_config+'image/'+dangerInfo.imageUrl" mode=""></image>
			</view>
			 -->
			<view class="" v-if="userInfo.accountType==6&&dangerInfo.status!=3">
				<view class="form-lable" style="margin-top: 30rpx;">
					上传整改图片
				</view>
				<view class="form-item flex f-column a-start">

					<view class="uni-form-input imgBox_wrap">
						<view class="addImgBox" @click="uploadImg" v-show="imgFileList.length<3">

							<image src="/static/safeMange/upload_image.png" class="icon-add" color="#F56C6C">
							</image>
						</view>
						<view class="imgBox" v-show="imgFileList.length>0" v-for="(item,index) in imgFileList"
							:key="index">
							<image :src="url_config+'image/'+item.url" class="img"
								@click="previewImage(url_config+'image/'+item.url)"></image>
							<view v-if="!isDisabled" @click="deleteImg(item,1)" class="deleteImg">
								<image src="/static/safeMange/close_icon.png" color="#F56C6C"></image>
							</view>
						</view>
					</view>
				</view>
				<view class="form-lable" style="margin-top: 30rpx;">
					整改说明
				</view>
				<textarea class="explain" v-model="explain" placeholder="选填" />
			</view>

			<view class="" style="margin-top: 20rpx;" v-if="dangerInfo.status==3">
				<view class="" style="margin: 40rpx 0;">
					整改图片
				</view>
				<view class="uni-form-input imgBox_wrap">
					<view class="imgBox" v-for="(item,index) in dangerInfo.correctImage" :key="index">
						<image :src="url_config+'image/'+item.url" class="imgBox"
							@click="previewImage(url_config+'image/'+item.url)"></image>

					</view>
				</view>
				<view class="form-lable" style="margin-top: 30rpx;">
					整改说明
				</view>
				<textarea class="explain" :disabled="true" v-model="dangerInfo.correctRemark" />
			</view>
		</view>

		<view class="" style="height:200rpx;" v-if="userInfo.accountType==6">

		</view>
		<view v-if="dangerInfo.status!=3" class="svanbtn" @click="saveBtn">
			{{userInfo.accountType==5?'提交':'提交整改'}}
		</view>
	</view>
</template>

<script>
	import headers from "@/components/headers/headers.vue"
	import {
		dateformat
	} from "@/utils/tool.js"
	export default {

		data() {
			return {
				dangerInfo: {},

				userId: "",
				userInfo: {},
				isDisabled: false,
				imgFileList: [],
				explain: "",
				detailsId: '',
				changeUser: {},
			}
		},
		onLoad(op) {

			// this.dangerInfo = JSON.parse(decodeURIComponent(op.dangerInfo));
			this.detailsId = op.id;
			console.log(this.dangerInfo, "url_config")

			this.queryTypeList();
			this.queryUserData();
			this.userInfo = JSON.parse(uni.getStorageSync('userInfo'));
			this.userId = this.userInfo.userId;
			this.getDeatils();
			console.log(this.userInfo);

		},
		methods: {
			//获取详情
			getDeatils() {
				let _this = this;
				this.sendRequest({
					url: 'xmgl/lifterAlarm/getDetails',
					method: 'post',
					data: {
						id: _this.detailsId
					},
					success: res => {

						_this.dangerInfo = res.result;
						_this.dangerInfo.addTime = dateformat(_this.dangerInfo.addTime, 'yyyy-MM-dd');
						if (_this.dangerInfo.correctImage) {
							_this.dangerInfo.correctImage = JSON.parse(_this.dangerInfo.correctImage)
						} else {
					 	_this.dangerInfo.correctImage = []
						}

					}
				})
			},
			//删除附件
			deleteImg(val, type) {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '确定删除该附件吗?',
					success: function(res) {
						if (res.confirm) {
							let fileArr = JSON.parse(JSON.stringify(that.imgFileList));
							fileArr.forEach((item, index) => {
								if (item.url == val.url) {
									fileArr.splice(index, 1)
								}
							})
							that.imgFileList = fileArr;

						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});

			},
			//预览图片
			previewImage(url) {
				uni.previewImage({
					urls: [url]
				})
			},
			//上传附件
			uploadImg() {

				var that = this
				uni.chooseImage({
					count: 3 - that.imgFileList.length,
					success(res) {
						const tempFilePaths = res.tempFilePaths;
						console.log(tempFilePaths, "tempFilePaths")
						for (let i in tempFilePaths) {
							uni.uploadFile({
								url: that.url_config + 'upload/image', //仅为示例，非真实的接口地址
								filePath: tempFilePaths[i],
								name: 'files',
								success: (uploadFileRes) => {
									let data = {
										name: JSON.parse(uploadFileRes.data).data[0].filename,
										url: JSON.parse(uploadFileRes.data).data[0].imageUrl
									};
									console.log(uploadFileRes)
									that.imgFileList.push(data)
								},
								fail(e) {
									console.log(e)
								}
							});
						}

					}
				})
			},
			seeImg() {
				uni.previewImage({
					urls: `${this.url_config}+'image/'+${this.dangerInfo.imageUrl}`
				})
			},
			//获取检查类型
			queryTypeList() {
				let sn = JSON.parse(uni.getStorageSync('userInfo')).headquartersSn
				let _this = this
				this.sendRequest({
					url: 'xmgl/inspectType/list',
					method: 'post',
					data: {
						sn: sn
					},
					success: res => {
						let typeList = res.result
						_this.inspectTypeId = typeList.find(item => item.inspectTypeName == "安全检查").id;
						console.log(_this.inspectTypeId, '-----检查类型')
					}
				})
			},
			queryUserData() {
				let _this = this
				this.sendRequest({
					url: 'xmgl/systemUser/getProjectChilderSystemUserList',
					method: 'post',
					data: {
						projectSn: JSON.parse(uni.getStorageSync('userInfo')).sn
					},
					success: res => {
						_this.changeUser = res.result
						console.log(res.result, '-----检查人')
					}
				})
			},
			saveBtn() {


				let data = {
					...this.dangerInfo
				};
				if (this.userInfo.accountType == 5) {
					data.reType = 1;
				} else if (this.userInfo.accountType == 6) { //整改人需要的字段
					data.correctImage = JSON.stringify(this.imgFileList);
					data.correctRemark = this.explain;
					data.reType = 2;
				}
				this.sendRequest({
					url: 'xmgl/lifterAlarm/rectification',
					method: 'post',
					data: data,
					success: (res) => {
						if (res.code == 200) {
							uni.showToast({
								title: '提交成功'
							})
							let routes = getCurrentPages();
							if(routes.length>1){
								uni.navigateBack({})
							}else{
								uni.redirectTo({
									url:'/pages/projectEnd/projectIndex/projectIndex'
								})
							}
							


						}
						console.log(res.result)
					}
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.explain {
		padding: 12rpx;
		font-size: 28rpx;
		background-color: #F7F7F7;
		margin-top: 20rpx;
		border-radius: 20rpx;
		height: 120rpx;
	}

	.imgBox_wrap {
		display: flex;
		flex-wrap: wrap;
		margin-top: 20rpx;
		width: 75%;
		min-height: 120rpx;
	}

	.imgBox {
		width: 120rpx;
		height: 120rpx;
		display: inline-flex;
		position: relative;
		margin-right: 30rpx;
		margin-bottom: 16rpx;

		.img {
			width: 120rpx;
			height: 120rpx;
			border-radius: 12rpx;
		}

		.deleteImg {
			position: absolute;
			right: -12rpx;
			top: -18rpx;

			uni-image {
				width: 20rpx;
				height: 20rpx;
			}
		}

	}

	.addImgBox {
		border: 1px solid rgba(42, 43, 91, 0.1);
		background-color: #f6f5f8;
		width: 120rpx;
		height: 120rpx;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		border-radius: 20rpx;
		font-size: 24rpx;
		margin-right: 12rpx;

		uni-image {
			width: 120rpx;
			height: 120rpx;
		}


	}

	page {
		background-color: #f6f6f6;
	}

	.imgbox {
		width: 176rpx;
		height: 176rpx;
		border-radius: 20rpx;
	}

	.svanbtn {
		width: 100%;
		background-color: #007AFF;
		color: #fff;
		text-align: center;
		font-size: 28rxp;
		line-height: 80rpx;
		height: 80rpx;
		position: fixed;
		bottom: 0;
		left: 0;
	}

	.xian {
		height: 30rpx;
		width: 6rpx;
		background-color: #007AFF;
	}

	.form_box {
		padding: 20rpx;
		background-color: #fff;
		margin: 20rpx;
		border-radius: 8rpx;


		.form_item {
			width: 100%;
			font-size: 28rpx;
			height: 80rpx;
			border-bottom: 2rpx solid #F7F7F7;

		}

		.form_item2 {
			padding: 20rpx 0;
			width: 100%;
			font-size: 28rpx;
			border-bottom: 2rpx solid #F7F7F7;
		}
	}

	.flex {
		display: flex;
		align-items: center;
	}

	.center {
		justify-content: center;
	}

	.between {
		justify-content: space-between;
	}

	.warp {
		flex-wrap: wrap;
	}

	.evenly {
		justify-content: space-evenly;
	}
</style>
