<template>
	<view>
		<cu-custom bgColor="bg-gradual-blueness" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">风险分布-详情</block>
		</cu-custom>
		<scroll-view scroll-y>
			<view class="dy-card">
				<view class="dy-card-title">
					<text>{{pd.RISKUNITNAME}}</text>
					<text>{{pd.PARTSNAME}}</text>
				</view>
				<view class="dy-card-content">
					<view class="dy-card-content-item">
						<view class="title">
							<text class="l"></text>
							<text>存在风险</text>
						</view>
						<view class="content" v-for="(item,index) in varList" >{{index+1}}. {{item.RISK_DESCR}}</view>
					</view>
					<view class="dy-card-content-item">
						<view class="title">
							<text class="l"></text>
							<text>主要管控措施</text>
						</view>
						<view class="content" v-for="(item,index) in varList">{{index+1}}. {{item.MEASURES}}
						</view>
					</view>
					<view class="dy-card-content-item">
						<view class="title">
							<text class="l"></text>
							<text>管控部门</text>
						</view>
						<view class="name">
							<text>{{DEPT_NAME}}</text>
						</view>
					</view>
					<view class="dy-card-content-item">
						<view class="title">
							<text class="l"></text>
							<text>事故类型</text>
						</view>
						<view class="name">
							<text>{{ACCIDENTS_NAME}}</text>
						</view>
					</view>
				</view>
				<view class="dy-card-foot">
					<!-- <text class="cu-tag radius bg-yellow light">{{pd.DNAME5}}</text> -->
					<text v-if="LEVELID=='levelA'"class="bg-red light cu-tag radius">重大风险</text>
					<text v-else-if="LEVELID=='levelB'"class="bg-orange light cu-tag radius">较大风险</text>
					<text v-else-if="LEVELID=='levelC'"class="bg-yellow light cu-tag radius">一般风险</text>
					<text v-else-if="LEVELID=='levelD'"class="bg-blue light cu-tag radius">低风险</text>
				</view>
				
			</view>
			<view class="cu-tabbar-height"></view>
		</scroll-view>
		<view class="bottom-fixed" @click="$noMultipleClicks(editLocation)">
			<button class="cu-btn bg-green" >提交位置</button>
		</view>
	</view>	
</template>

<script>
	import {
		basePath,corpinfoId
	} from '@/common/tool.js';
	import gcoord from '@/common/gcoord.js'
	export default {
		data() {
			return {
				IDENTIFICATION_ID : '',
				varList:[],
				pd:[],
				longitude : '',
				noClick:true,
				latitude :'',
				LEVELID:'',
				DEPT_NAME:'',
				ACCIDENTS_NAME:"",
			}
		},
		onLoad(e){
			var _this = this;
			_this.IDENTIFICATION_ID=e.id;
			_this.LEVELID=e.LEVELID;
			_this.DEPT_NAME=e.DEPT_NAME;
			_this.getData();
			uni.getLocation({
			    type: 'wgs84 ',
			    success: function (res) {
					_this.longitude = res.longitude;
					_this.latitude = res.latitude;
			    },
				cancel: function (res) {
					uni.showToast({
						icon: 'none',
						title: '用户拒绝授权获取地理位置',
						duration: 1500
					});
				}
			});
		},
		methods: {
			//跳转事件
			goToEdit(e) {
				uni.navigateTo({
					url: '/pages/application/basic-info-manage/basic-information/basic-information-edit'
				});
			},
			getData() {
				var _this = this;
				uni.showLoading({
					title: '请稍候'
				})
				uni.request({
					url: basePath + '/app/riskpoint/getForIdentification',
					method: 'POST',
					dataType: 'json',
					header:{
							'Content-type':'application/x-www-form-urlencoded'
					},
					data: {
						CHECK_IDENTIFICATION_ID: _this.IDENTIFICATION_ID,
					},
					success: (res) => {
						if (res.data != null) {
							uni.hideLoading();
							_this.varList = res.data.varList;
							_this.pd = res.data.varList[0];
							let nameArray=[];
							for (let i = 0; i < _this.varList.length; i++) {
								let ACCIDENTS_NAME=_this.varList[i].ACCIDENTS_NAME
								let names=ACCIDENTS_NAME.split(",")
								for(let j = 0; j < names.length; j++) {
									nameArray.distinctPush(names[j])
								}
							}
							_this.ACCIDENTS_NAME=nameArray.join(",")
						} else {
							uni.showToast({
								title: res.data.message,
								duration: 2000
							});
						}
					}
				});
			},
			
			editLocation (){
				var _this = this;
				uni.showLoading({
					title: '请稍候'
				})
				let longitude;
				let latitude;
				uni.getLocation({
					type: 'GCJ02',
					success: function (res1) {
						longitude = res1.longitude;
						latitude = res1.latitude;
						var result = gcoord.transform(
								[longitude, latitude],    // 经纬度坐标
								gcoord.GCJ02,               // 当前坐标系
								gcoord.BD09                // 目标坐标系
						);
						_this.longitude = result[0];
						_this.latitude  =  result[1];
						//发送 post 请求提交保存
						uni.request({
							url: basePath + '/app/riskpoint/editLonAndLat',
							xhrFields: {
								withCredentials: true
							},
							method: 'POST',
							dataType: 'json',
							header: {
								'Content-type':'application/x-www-form-urlencoded'
							},
							data: {
								IDENTIFICATIONPARTS_ID : _this.IDENTIFICATION_ID,
								LONGITUDE : _this.longitude,
								LATITUDE : _this.latitude,
							},
							dataType:"json",
							success: function(res){
								if("success" == res.data.result){
									uni.showToast({
									    icon: 'none',
									    title: '提交成功', 
									    duration: 1500
									});
									setTimeout(function () {
										var pages = getCurrentPages(); // 获取当前页面栈
										var prePage = pages[pages.length - 2]; // 上一个页面
										prePage.$vm.initflag = true;    // A 页面 init方法 为true
										uni.navigateBack({});
										uni.hideLoading();
									},1500);
									
								}else {
									uni.showToast({
										title: "系统错误",
										duration: 2000
									});
								}
							}
						})
					},
					fail: function(res){
						uni.hideLoading();
						uni.showToast({
							title: "获取位置失败",
							duration: 2000
						});
					}
				});
			},
			
		}
	}
</script>

<style>
	.dy-card{
		background-color: #fff;
		border-radius: 10upx;
		margin:30upx
	}
	.dy-card-title{
		display: flex;
		justify-content: space-between;
		border-bottom: 1px solid #eee;
		min-height: 80upx;
		line-height: 80upx;
		padding: 0 30upx;
	}
	.dy-card-content{
		padding: 0upx 30upx 30upx;
		
	}
	.dy-card-content-item{
		margin-top: 20upx;
	}
	.dy-card-content-item .title{
		display: flex;
		align-items: center;
	}
	.dy-card-content-item .title .l{
		width: 10upx;
		height: 30upx;
		border-radius: 20upx;
		background-color: #666;
		margin-right: 10upx;
	}
	.dy-card-content-item .content{
		background-color: #F1F1F1;
		padding: 10upx 14upx;
		margin-top: 14upx;
		line-height: 1.6;
	}
	.dy-card-content-item .name text{
		background-color: #F1F1F1;
		padding: 10upx 14upx;
		margin-top: 14upx;
		line-height: 1.6;
		display: inline-block;
	}
	.dy-card-foot{
		border-top: 1px solid #eee;
		padding: 30upx;
	}
</style>
