<template>
	<view>
		<cu-custom bgColor="bg-gradual-blueness" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">检查记录详情</block>
		</cu-custom>
		<view class="bu-title">
			检查内容
		</view>
		<view class="table-box" style="padding: 0 30upx;">
			<uni-table name='varlist' border stripe emptyText="暂无更多数据">
				<!-- 表头行 -->
				<uni-tr>
					<uni-th align="center" style="font-weight: bold;">检查内容</uni-th>
					<uni-th align="center" style="font-weight: bold;width:150upx">状态</uni-th>
				</uni-tr>
				<uni-tr v-for="item in varList" :key="item.RISKPOINT_ID">
					<uni-td>{{item.CHECK_CONTENT}}</uni-td>
					<uni-td v-if='item.ISNORMAL=="0"' align="center">
						<template v-if="item.IMGCOUNT>0">
							<view @click="goToImgs(item.RECORDITEM_ID)" style="color: blue;">合格</view>
						</template>
						<template v-else>合格</template>
					</uni-td>
					<uni-td v-else-if='item.ISNORMAL=="1"' align="center">
						<view @click="goToDetail(item.HIDDEN_ID)" style="color: blue;">不合格</view>
					</uni-td>
					  <uni-td v-else-if='item.ISNORMAL=="2"' align="center">
						<view style="color: blue;">不涉及</view>
					  </uni-td>
					<uni-td v-else align="center">
						<view class="text-center">存在未整改隐患</view>
					</uni-td>
				</uni-tr>

			</uni-table>
		</view>
		<view class="bu-title">
			其他隐患信息
		</view>
		<view class="table-box" style="padding: 0 30upx 30upx;">
			<uni-table name='otherHiddenList' border stripe emptyText="暂无更多数据">
				<!-- 表头行 -->
				<uni-tr>
					<uni-th align="center" style="font-weight: bold;">隐患描述</uni-th>
					<uni-th align="center" style="font-weight: bold;">操作</uni-th>
				</uni-tr>
				<uni-tr v-for="item in otherHiddenList" :key="item.HIDDEN_ID">
					<uni-td>{{item.HIDDENDESCR}}</uni-td>
					<uni-td align="center">
						<view @click="goToDetail(item.HIDDEN_ID)">查看</view>
					</uni-td>
				</uni-tr>
			</uni-table>
		</view>
		<map style="width: 100%; height: 300px;" :scale="scale" :latitude="latitude" :longitude="longitude"
			:markers="covers">
		</map>


		<view class="wui-form-list" style="margin: 0;">
			<view class="bu-title">
				清单信息
			</view>

				<view class="cu-form-group">
					<view class="title">
						<text>清单名称</text>
					</view>
					<view>
						<text class="text-grey">{{pd.LIST_NAME}}</text>
					</view>
				</view>
				<view class="cu-form-group">
					<view class="title">
						<text>排查清单类型</text>
					</view>
					<view>
						<text class="text-grey">{{pd.SCREENTYPENAME}}</text>
					</view>
				</view>
				<view class="cu-form-group">
					<view class="title">
						<text>检查人</text>
					</view>
					<view>
						<text class="text-grey">{{pd.USERS}}</text>
					</view>
				</view>
				<view class="cu-form-group">
					<view class="title">
						<text>检查时间</text>
					</view>
					<view>
						<text class="text-grey">{{pd.CHECK_TIME}}</text>
					</view>
				</view>
				<view class="cu-form-group">
					<view class="title">
						<text>所属部门 </text>
					</view>
					<view>
						<text class="text-grey">{{pd.DEPARTMENT_NAME}}</text>
					</view>
				</view>
				<view class="cu-form-group">
					<view class="title">
						<text>所属岗位 </text>
					</view>
					<view>
						<text class="text-grey">{{pd.POST_NAME}}</text>
					</view>
				</view>
				<view class="cu-form-group">
					<view class="title">
						<text>排查周期</text>
					</view>
					<view>
						<text class="text-grey">{{pd.PERIODNAME}}</text>
					</view>
				</view>
				<view class="cu-form-group bb-default">
					<view class="title">
						<text>清单类型</text>
					</view>
					<view>
						<text class="text-grey">{{pd.TYPENAME}}</text>
					</view>
				</view>
			<view v-if="pd.TYPENAME == '临时'" class="cu-form-group bb-default">
				<view class="title">
					<text>排查日期</text>
				</view>
				<view>
					<text class="text-grey">{{pd.START_DATE}} - {{pd.END_DATE}}</text>
				</view>
			</view>

			<view class="cu-form-textarea">
					<view class="title">
						<text>签字照片</text>
					</view>
					<view class="cu-form-p">
						<scroll-view scroll-x class="bg-white nav" scroll-with-animation>
							<view class="cu-item" v-for="(item,index) in files" v-bind:key="index">
								<view class="imgs">
									<image :src="baseImgPath+item.FILEPATH" :data-index="index" @click="ViewShowImage"
										mode=""></image>
								</view>
							</view>
						</scroll-view>
					</view>
				</view>

			<view class="cu-tabbar-height"></view>
		</view>
	</view>
</template>

<script>
	import {
		basePath,
		deptId,
		corpinfoId,
		loginSession,
		baseImgPath,
      loginUser
	} from '@/common/tool.js';
	import gcoord from '@/common/gcoord.js'
	export default {
		data() {
			return {
				recordItemList: [],
				baseImgPath: baseImgPath,
				CHECKRECORD_ID: '',
				hiddenList: [],
				varList: [],
				pd: [],
				otherHiddenList: [],
				title: 'map',
				scale: 13,
				latitude: 39.8883,
				longitude: 119.519,
				covers: [],
				mapVarList: [],
				mapHdList: [],
				mapPd: [],
				mapCinfo: [],
				mapCheckrecord: [],

				files: [],
			}
		},
		onLoad(e) {
			loginSession();
			this.CHECKRECORD_ID = e.CHECKRECORD_ID;
			this.getData();
			this.getOtherHidden();
			this.getMap();
		},
		methods: {
			//跳转事件
			goToDetail(e) {
				// uni.navigateTo({
				// 	url: '/pages/basics/hidden-perils/fill-in-case/fill-in-case-detail-view?id='+e
				// });
				uni.navigateTo({
					url: '/pages/application/hidden-danger-management/hidden-danger-record/hidden-danger-record-detail?id=' +
						e,
				});
			},
			goToImgs(e) {
				uni.navigateTo({
					url: '/pages/application/check-record/imgs_details?id=' + e,
				});
			},

			getData() {
				var _this = this;
				uni.showLoading({
					title: '请稍候'
				})
				uni.request({
					url: basePath + '/app/customCheckRecord/goEdit',
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						CHECKRECORD_ID: _this.CHECKRECORD_ID,
            CORPINFO_ID:loginUser.CORPINFO_ID,
            USER_ID:loginUser.USER_ID,
					},
					success: (res) => {

						if (res.data != null) {
							uni.hideLoading();
							_this.varList = res.data.varList;
							_this.pd = res.data.pd;
							_this.files = res.data.qianming;
						} else {
							uni.showToast({
								title: res.data.message,
								duration: 2000
							});
						}
					}
				});
			},
			getOtherHidden() {
				var _this = this;
				uni.showLoading({
					title: '请稍候'
				})
				uni.request({
					url: basePath + '/app/customHidden/getCheckHidden',  // /app/hidden/getChcenkHidden
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						CHECKRECORD_ID: _this.CHECKRECORD_ID,
            CORPINFO_ID:loginUser.CORPINFO_ID,
            USER_ID:loginUser.USER_ID,
					},
					success: (res) => {

						if (res.data != null) {
							uni.hideLoading();
							_this.otherHiddenList = res.data.hiddenList;
						} else {
							uni.showToast({
								title: res.data.message,
								duration: 2000
							});
						}
					}
				});
			},
			getMap() {
				var _this = this;
				uni.showLoading({
					title: '请稍候'
				})
				uni.request({
					url: basePath + '/app/customCheckRecord/goMap', // /app/checkrecord/goMap
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						CHECKRECORD_ID: _this.CHECKRECORD_ID,
            CORPINFO_ID:loginUser.CORPINFO_ID,
            USER_ID:loginUser.USER_ID,
					},
					success: (res) => {

						if (res.data != null) {
							uni.hideLoading();
							_this.mapVarList = res.data.varList;
							_this.mapHdList = res.data.hdList;
							_this.mapPd = res.data.pd;
							_this.mapCinfo = res.data.cinfo;
							_this.mapCheckrecord = res.data.checkrecord;
							if (res.data.cinfo.LONGITUDE != undefined && res.data.cinfo.LATITUDE !=
								undefined &&
								res.data.cinfo.LONGITUDE != '' && res.data.cinfo.LATITUDE != '') {
								var result = gcoord.transform(
									[res.data.cinfo.LONGITUDE, res.data.cinfo.LATITUDE], // 经纬度坐标
									gcoord.BD09, // 当前坐标系
									gcoord.GCJ02 // 目标坐标系
								);
								_this.longitude = result[0];
								_this.latitude = result[1];
							}

							if (res.data.checkrecord.LONGITUDE != undefined && res.data.checkrecord.LATITUDE !=
								undefined &&
								res.data.checkrecord.LONGITUDE != '' && res.data.checkrecord.LATITUDE != '') {
								var result1 = gcoord.transform(
									[res.data.checkrecord.LONGITUDE, res.data.checkrecord
									.LATITUDE], // 经纬度坐标
									gcoord.BD09, // 当前坐标系
									gcoord.GCJ02 // 目标坐标系
								);
								var checkMarker = {
									latitude: result1[1],
									longitude: result1[0],
									iconPath: '../../../static/map/50.png'
								}
								_this.covers.push(checkMarker);
							}

							for (var i = 0; i < res.data.varList.length; i++) {
								var result2 = gcoord.transform(
									[res.data.varList[i].LONGITUDE, res.data.varList[i].LATITUDE], // 经纬度坐标
									gcoord.BD09, // 当前坐标系
									gcoord.GCJ02 // 目标坐标系
								);
								var checkMarker = {
									latitude: result2[1],
									longitude: result2[0],
									iconPath: '../../../static/map/50.png'
								}
								_this.covers.push(checkMarker);
							}

							/* 							console.info(res.data.hdList);
														for(var i=0;i<res.data.hdList.length;i++){
															var result3 = gcoord.transform(
																[res.data.hdList[i].LONGITUDE, res.data.hdList[i].LATITUDE], // 经纬度坐标
																gcoord.BD09, // 当前坐标系
																gcoord.GCJ02 // 目标坐标系
															);
															var checkMarker={latitude: result3[1],longitude: result3[0],iconPath: '../../../static/map/h.png'}
															_this.covers.push(checkMarker);
															console.info(_this.covers);
														} */


						} else {
							uni.showToast({
								title: res.data.message,
								duration: 2000
							});
						}
					}
				});
			},

			ViewShowImage(e) {
				let files = [];
				for (var i = 0; i < this.files.length; i++) {
					files.push(baseImgPath + this.files[i].FILEPATH)
				}
				uni.previewImage({
					urls: files,
					current: e.currentTarget.dataset.index
				});
			},
			/* getRecordItem() {
				var _this = this;
				uni.showLoading({
					title: '请稍候'
				})
				uni.request({
					url: basePath + '/app/hidden/getCheckrecord',
					method: 'POST',
					dataType: 'json',
					header:{
							'Content-type':'application/x-www-form-urlencoded'
					},
					data: {
					CHECKRECORD_ID: _this.CHECKRECORD_ID,
					},
					success: (res) => {

						if (res.data != null) {
							uni.hideLoading();
							_this.recordItemList = res.data.varList;
						} else {
							uni.showToast({
								title: res.data.message,
								duration: 2000
							});
						}
					}
				});
			},
			 */
		}

	}
</script>

<style>
	page {
		background-color: #fff;
	}

	.bu-title {
		font-weight: bold;
		margin: 30upx 20upx;
		padding-left: 10upx;
		border-left: 4px solid #0081FF;
	}

	navigator {
		color: #0066CC;
		text-decoration: underline;
	}

	.text-grey {
		color: #808080;
	}
</style>
