<template>
  <view>
  	<cu-custom bgColor="bg-gradual-blueness" :isBack="true">
  		<block slot="backText">返回</block>
  		<block slot="content">重点工程信息</block>
  	</cu-custom>
    <view class="form">
    	<view class="wui-form-list">
			<view class="cu-form-group">
				<view class="title">重点工程名称:</view>
				<view>{{info.OUTSOURCED_NAME}}</view>
			</view>
			<view class="cu-form-group">
				<view class="title">计划工期:</view>
				<view>{{info.STARTTIME}}至{{info.ENDTIME}}</view>
			</view>
			<view class="cu-form-group">
				<view class="title">合同号:</view>
				<view>{{info.CONTRACT_NUM}}</view>
			</view>
			<view class="cu-form-group">
				<view class="title">施工相关方:</view>
				<view>{{info.UNITS_NAME}}</view>
			</view>
			<view class="cu-form-group">
				<view class="title">相关方单位工程负责人:</view>
				<view>{{info.UNITS_PIC_NAME}}</view>
			</view>
			<view class="cu-form-group" >
				<view class="title">相关方单位负责人手机:</view>
				<view>{{info.UNITS_PHONE}}</view>
			</view>
			<view v-if="info.WORK_LONGITUDE" class="cu-form-group" >
				<view class="title">经度:</view>
				<view>{{info.WORK_LONGITUDE}}</view>
			</view>
			<view v-if="info.WORK_LATITUDE" class="cu-form-group" >
				<view class="title">纬度:</view>
				<view>{{info.WORK_LATITUDE}}</view>
			</view>
			<view class="cu-form-group" >
				<view class="title">具体位置:</view>
				<view>{{info.LOCATION}}</view>
			</view>
		</view>
	</view>
	<view class="cu-bar btn-group" style="margin-top: 30upx;">
		<button v-if="info.STATE==='-1'&& anniuShow" class="cu-btn bg-blue margin-tb-sm lg"
			@click="fnUpdateStateKeyProject('1')">工程开始</button>
			<button v-if="info.STATE==='-2'&& anniuShow" class="cu-btn bg-blue margin-tb-sm lg"
				@click="fnUpdateStateKeyProject('2')">工程结束</button>
		<button class="cu-btn bg-green margin-tb-sm lg"
			@click="goback">返回</button>
	</view>
  </view>
</template>

<script>
import {
  basePath,corpinfoId,loginSession,formatDate,loginUser,loginUserId
} from '@/common/tool.js';
export default {

  data() {
    return {
      OUTSOURCED_ID: '',
      KEYPROJECTCHECK_ID: '',
      type: '',
      info: {},
	  WORK_LONGITUDE: '', //经度
	  WORK_LATITUDE: '', //纬度
      hiddenData: {},
      popupShow: false,
      videoShow: false,
      videoSrc: '',
	  anniuShow: false
    }
  },
  computed: {
    userInfo() {
      return this.$store.getters.getUserInfo
    }
  },
  onLoad(options) {
    this.OUTSOURCED_ID = options.OUTSOURCED_ID
    this.fnGetData()
  },
  methods: {
    fnGetData() {
		 var _this = this;
		 uni.showLoading({
		   title:"加载中..."
		 });//加载中动画
		//获取重点工程详细信息
		uni.request({
		  url: basePath +'/app/keyProjects/getOutsourced',
		  method: 'POST',
		  dataType: 'json',
		  header: {
		    'Content-type':'application/x-www-form-urlencoded'
		  },
		  data: {
		    OUTSOURCED_ID: _this.OUTSOURCED_ID,
		  },
		  success: (res) => {
		    uni.hideLoading();//结束加载中动画
		    if (res.data != null) {
		      _this.info = res.data.pd;
		      _this.WORK_LONGITUDE = _this.info.WORK_LONGITUDE; //经度
		      _this.WORK_LATITUDE = _this.info.WORK_LATITUDE; //纬度
	
				  _this.anniuShow = true;
			  
		    }
		  }
		})
    },
	//返回方法
	goback() {
		var pages = getCurrentPages(); // 获取当前页面栈
		var prePage = pages[pages.length - 2]; // 上二级页面
		prePage.$vm.initflag = true; // A 页面 init方法 为true
		uni.navigateBack({
			delta: 1
		});
		uni.hideLoading();
	},
	//工程开始
	fnUpdateStateKeyProject(state){
		var _this = this;
		var content = '';
		if(state === '1'){
			content = '确定同意开工吗?'
		}else if(state === '2'){
			content = '确定同意结束吗?'
		}
		uni.showModal({
			title: '提示',
			cancelText: '确认',
			confirmText: '取消',
			content: content,
			success: function (res) {
				if (res.cancel) {
					//获取重点工程详细信息
					uni.request({
					  url: basePath +'/app/keyProjects/updateState',
					  method: 'POST',
					  dataType: 'json',
					  header: {
					    'Content-type':'application/x-www-form-urlencoded'
					  },
					  data: {
					    OUTSOURCED_ID: _this.OUTSOURCED_ID,
					    STATE:state,
					    OPERATOR: loginUserId //修改人
					  },
					  success: (res) => {
					    uni.hideLoading();//结束加载中动画
						_this.goback()
					  }
					})
				}
			}
		});
		
	},
  },
}
</script>

<style lang="scss" scoped>
.content {
  padding: 0 20upx;
  background-color: #fff;
}

.button {
  text-align: center;
  margin-top: 40upx;
  margin-bottom: 40upx;
  display: flex;
  justify-content: space-between;

  button {
    width: 45%;
  }
}

.ml-10:first-child {
  margin-left: 0 !important;
}
</style>