<template>
  <view>
    <cu-custom bgColor="bg-gradual-blueness" :isBack="true" >
      <block slot="backText">返回</block>
      <block slot="content">气体名称</block>
    </cu-custom>
    <scroll-view scroll-y="false" >
      <view class="form">
        <view class="wui-form-list">
          <view class="cu-form-group">
            <view class="title">有毒有害气体名称1：</view>
            <input name="input" ref="ANALYZE_PLACE" :disabled="isShow" v-model="pd.GAS_NAME1" placeholder="请输入有毒有害气体名称1"></input>
          </view>
          <view class="cu-form-group">
            <view class="title">合格标准：</view>
            <input name="input" ref="HARMFUL_MATERIALS" :disabled="isShow"  v-model="pd.GAS_STANDARD1" placeholder="请输入合格标准"></input>
          </view>
        </view>
        <view class="wui-form-list">
          <view class="cu-form-group">
            <view class="title">有毒有害气体名称2：</view>
            <input name="input" ref="ANALYZE_PLACE" :disabled="isShow"   v-model="pd.GAS_NAME2" placeholder="请输入有毒有害气体名称2"></input>
          </view>
          <view class="cu-form-group">
            <view class="title">合格标准：</view>
            <input name="input" ref="HARMFUL_MATERIALS" :disabled="isShow"  v-model="pd.GAS_STANDARD2" placeholder="请输入合格标准"></input>
          </view>
        </view>
        <view class="wui-form-list">
          <view class="cu-form-group">
            <view class="title">可燃气体名称1：</view>
            <input name="input" ref="ANALYZE_PLACE" :disabled="isShow"  v-model="pd.GAS_NAME3" placeholder="请输入可燃气体名称1"></input>
          </view>
          <view class="cu-form-group">
            <view class="title">合格标准：</view>
            <input name="input" ref="HARMFUL_MATERIALS" :disabled="isShow"  v-model="pd.GAS_STANDARD3" placeholder="请输入合格标准"></input>
          </view>
        </view>
        <view class="wui-form-list">
          <view class="cu-form-group">
            <view class="title">可燃气体名称2：</view>
            <input name="input" ref="ANALYZE_PLACE" :disabled="isShow"  v-model="pd.GAS_NAME4" placeholder="请输入可燃气体名称2"></input>
          </view>
          <view class="cu-form-group">
            <view class="title">合格标准：</view>
            <input name="input" ref="HARMFUL_MATERIALS" :disabled="isShow"  v-model="pd.GAS_STANDARD4" placeholder="请输入合格标准"></input>
          </view>
<!--          <view class="cu-form-group ">-->
<!--            <view class="title">分析时间</view>-->
<!--            <ruiDatePicker-->
<!--                    v-if="showTime"-->
<!--                    fields="minute"-->
<!--                    :value="pd.ANALYZE_TIME?pd.ANALYZE_TIME:''"-->
<!--                    :end="currentTime"-->
<!--                    @change="changeStartDate"-->
<!--            ></ruiDatePicker>-->
<!--          </view>-->
        </view>
      </view>
      <view class="cu-bar btn-group" style="margin-top: 30upx;">
        <button class="cu-btn bg-green margin-tb-sm lg" @click="$noMultipleClicks(goSubmit)">气体分析</button>
      </view>
      <view class="padding flex flex-direction">
      </view>
    </scroll-view>
  </view>
</template>

<script>
import {
  basePath,corpinfoId,deptId,loginUser,formatDate,loginSession,baseImgPath
} from '@/common/tool.js';
import tkiTree from "@/components/select-tree/select-tree.vue"
import writingBoard from "@/components/writing-board/writing-board.vue"
import gcoord from '@/common/gcoord.js'
import ruiDatePicker from '@/components/rattenking-dtpicker/rattenking-dtpicker.vue';
export default {
  components: {
    tkiTree,ruiDatePicker,writingBoard
  },
  data() {
    return {
      noClick:true,
      pd:{},// 数据
      isShow:false,
      showTime:false,
      currentTime:formatDate(new Date(),'yyyy-MM-dd hh:mm')
    }
  },
  onLoad(event){
    this.pd.CONFINEDSPACE_ID = event.CONFINEDSPACE_ID;
    if(event.isShow) this.isShow = event.isShow
    this.pd.ANALYZE_USER = loginUser.NAME;
    loginSession();
    this.getData();
  },
  methods: {
    getData(action){
      uni.showLoading({
        title: '请稍候'
      })
      uni.request({
        url: basePath + 'app/confinedspacegaswh/goEdit',
        method: 'POST',
        dataType: 'json',
        header:{
          'Content-type':'application/x-www-form-urlencoded'
        },
        data: {
          CONFINEDSPACE_ID:this.pd.CONFINEDSPACE_ID,
          CORPINFO_ID:loginUser.CORPINFO_ID,
          USER_ID:loginUser.USER_ID,
        },
        success: (res) => {
          this.pd = res.data.pd || { CONFINEDSPACE_ID: this.pd.CONFINEDSPACE_ID };
          uni.hideLoading();
          console.log(this.pd.CONFINEDSPACEGASWH_ID)
          this.showTime = true

        }
      })
    },
    goSubmit(){
      var _this = this;
      if(!this.pd.GAS_NAME1 && !this.pd.GAS_NAME2 && !this.pd.GAS_NAME3 && !this.pd.GAS_NAME4){
        if(this.isShow){
          uni.showToast({
            title: '无气体检测信息',
            duration: 1500,
            icon: 'none'
          })
          return;
        }else{
          uni.showToast({
            title: '最少填写一项气体名称',
            duration: 1500,
            icon: 'none'
          })
          return;
        }
      }
      // if(!this.pd.ANALYZE_TIME){
      //   uni.showToast({
      //     title: '请输入气体分析时间',
      //     duration: 1500,
      //     icon: 'none'
      //   })
      //   return;
      // }
      if(this.pd.GAS_NAME1 && !this.pd.GAS_STANDARD1){
        uni.showToast({
          title: '请输入有毒有害气体名称1的合格标准',
          duration: 1500,
          icon: 'none'
        })
        return;
      }
      if(!this.pd.GAS_NAME1 && this.pd.GAS_STANDARD1){
        uni.showToast({
          title: '请输入有毒有害气体名称1的名称',
          duration: 1500,
          icon: 'none'
        })
        return;
      }
      if(this.pd.GAS_NAME2 && !this.pd.GAS_STANDARD2){
        uni.showToast({
          title: '请输入有毒有害气体名称2的合格标准',
          duration: 1500,
          icon: 'none'
        })
        return;
      }
      if(!this.pd.GAS_NAME2 && this.pd.GAS_STANDARD2){
        uni.showToast({
          title: '请输入有毒有害气体名称2的名称',
          duration: 1500,
          icon: 'none'
        })
        return;
      }
      if(this.pd.GAS_NAME3 && !this.pd.GAS_STANDARD3){
        uni.showToast({
          title: '请输入可燃气体名称1的合格标准',
          duration: 1500,
          icon: 'none'
        })
        return;
      }
      if(!this.pd.GAS_NAME3 && this.pd.GAS_STANDARD3){
        uni.showToast({
          title: '请输入可燃气体名称1的名称',
          duration: 1500,
          icon: 'none'
        })
        return;
      }
      if(this.pd.GAS_NAME4 && !this.pd.GAS_STANDARD4){
        uni.showToast({
          title: '请输入可燃气体名称2的合格标准',
          duration: 1500,
          icon: 'none'
        })
        return;
      }
      if(!this.pd.GAS_NAME4 && this.pd.GAS_STANDARD4){
        uni.showToast({
          title: '请输入可燃气体名称2的名称',
          duration: 1500,
          icon: 'none'
        })
        return;
      }
      uni.showLoading({
        title: '请稍候'
      })
      console.log(this.pd.CONFINEDSPACEGASWH_ID)
      let url = 'app/confinedspacegaswh/add';
      if(this.pd.CONFINEDSPACEGASWH_ID) url = 'app/confinedspacegaswh/edit'
      uni.request({
        url: basePath + url,
        method: 'POST',
        dataType: 'json',
        header:{
          'Content-type':'application/x-www-form-urlencoded'
        },
        data: {
          ..._this.pd,
          CORPINFO_ID:loginUser.CORPINFO_ID,
          USER_ID:loginUser.USER_ID,
        },
        success: (res) => {
          // if(action === 'goSubmit'){
            this.$nextTick(()=>{
              uni.navigateTo({
                url: '/pages/application/confinedspace/confinedspace-gas/gas-list?isShow='+this.isShow+'&CONFINEDSPACE_ID='+this.pd.CONFINEDSPACE_ID+'&addFlag=1&GAS_NAME1=' + (this.pd.GAS_NAME1 || '') + '&GAS_NAME2=' + (this.pd.GAS_NAME2 || '') + '&GAS_NAME3=' + (this.pd.GAS_NAME3 || '') + '&GAS_NAME4=' + (this.pd.GAS_NAME4 || '')
              });
            })
          // }
        },
        fail: (err) => {
          uni.hideLoading();
          uni.showModal({
            content: err.errMsg,
            showCancel: false
          });
        }
      })
    },
    changeStartDate(e) {
      this.pd.ANALYZE_TIME = e
      this.$forceUpdate();//强制刷新
    },
    goback(){
      uni.navigateBack({delta: 1});
      uni.hideLoading();
    },
  }
}
</script>

<style>

</style>
