<template>
  <view class="content">
    <u-cell-group>
      <u-cell title="重点工程名称" :value="info.OUTSOURCED_NAME"/>
      <u-cell title="计划工期" :value="info.STARTTIME+ '至'+ info.ENDTIME"/>
      <u-cell title="合同号" :value="info.CONTRACT_NUM"/>
      <u-cell title="施工相关方" :value="info.UNITS_NAME"/>
      <u-cell title="相关方单位工程负责人" :value="info.UNITS_PIC_NAME"/>
      <u-cell title="相关方单位负责人手机" :value="info.UNITS_PHONE"/>
	 <u-cell title="经度" v-show="WORK_LONGITUDE" :value="WORK_LONGITUDE"/>
	 <u-cell title="纬度" v-show="WORK_LATITUDE" :value="WORK_LATITUDE"/>
	 <u-cell title="具体位置" :value="info.LOCATION"/>
    </u-cell-group>
	<view class="button">
	  <u-button
	      v-if="info.STATE==='-1'&& anniuShow"
	      type="success"
	      @click="fnUpdateStateKeyProject('1')"
	      size="small"
	      text="工程开始"
	  />
	  <u-button
		  v-if="info.STATE==='-2'&& anniuShow"
	      type="error"
	      @click="fnUpdateStateKeyProject('2')"
	      size="small"
	      text="工程结束"
	  />
	  <u-button
	      @click="fnBack"
	      size="small"
	      text="返回"
	  />
	</view>
  </view>
</template>

<script>
import {getKeyProjectsView,setKeyProjectsState} from "@/api"
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: {
    async fnGetData() {
		//获取重点工程详细信息
      const resData = await getKeyProjectsView({
        OUTSOURCED_ID: this.OUTSOURCED_ID,
      });
      this.info = resData.pd;
	  this.WORK_LONGITUDE = this.info.WORK_LONGITUDE; //经度
	  this.WORK_LATITUDE = this.info.WORK_LATITUDE; //纬度
	  if(this.userInfo.USER_ID == this.info.CREATOR){
		  this.anniuShow = true;
	  }
    },
	//返回方法
	fnBack() {
	  uni.$u.route({
	    type: 'navigateBack'
	  })
	},
	//工程开始
	async fnUpdateStateKeyProject(state){
		console.log(state)
		var content = '';
		if(state === '1'){
			content = '确定同意开工吗?'
		}else if(state === '2'){
			content = '确定同意结束吗?'
		}
		uni.showModal({
		  title: '提示',
		  cancelText: '确认',
		  confirmText: '取消',
		  content: content,
		  success: (res) => {
			  console.log(res)
		    if (res.cancel) {
		      setKeyProjectsState({
		      		OUTSOURCED_ID: this.OUTSOURCED_ID,
		      		OPERATOR: this.userInfo.USER_ID, //修改人
		      		STATE:state
		      });
		      uni.$u.toast('提交成功')
		      setTimeout(() => {
		        this.fnBack()
		      }, 1000)
		    }
		  }
		})
	},
	endUpdate(state){
		
		
		
	},
	
  },
}
</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>
