<template>
  <view class="content">
    <view class="card">
      <u-form labelPosition="left" :model="form" :rules="rules" ref="formRef" labelWidth="140px">
        <u-form-item label="有毒有害气体名称1" prop="GAS_NAME1" borderBottom>
          <u-input :disabled="this.isView === '1'" v-model="form.GAS_NAME1" border="none"/>
        </u-form-item>
        <u-form-item label="合格标准" prop="GAS_STANDARD1" borderBottom>
          <u-input :disabled="this.isView === '1'" v-model="form.GAS_STANDARD1" border="none"/>
        </u-form-item>
        <u-form-item label="有毒有害气体名称2" prop="GAS_NAME2" borderBottom>
          <u-input :disabled="this.isView === '1'" v-model="form.GAS_NAME2" border="none"/>
        </u-form-item>
        <u-form-item label="合格标准" prop="GAS_STANDARD2" borderBottom>
          <u-input :disabled="this.isView === '1'" v-model="form.GAS_STANDARD2" border="none"/>
        </u-form-item>
        <u-form-item label="可燃气体名称1" prop="GAS_NAME3" borderBottom>
          <u-input :disabled="this.isView === '1'" v-model="form.GAS_NAME3" border="none"/>
        </u-form-item>
        <u-form-item label="合格标准" prop="GAS_STANDARD3" borderBottom>
          <u-input :disabled="this.isView === '1'" v-model="form.GAS_STANDARD3" border="none"/>
        </u-form-item>
        <u-form-item label="可燃气体名称2" prop="GAS_NAME4" borderBottom>
          <u-input :disabled="this.isView === '1'" v-model="form.GAS_NAME4" border="none"/>
        </u-form-item>
        <u-form-item label="合格标准" prop="GAS_STANDARD4" borderBottom>
          <u-input :disabled="this.isView === '1'" v-model="form.GAS_STANDARD4" border="none"/>
        </u-form-item>
      </u-form>
      <view class="mt-10">
        <u-button type="primary" text="气体分析" @click="$u.debounce(fnSubmit, 1000,true)"/>
      </view>
    </view>
  </view>
</template>

<script>
import {
  getConfinedSpaceGasInfo,
  setConfinedSpaceGasInfoSave,
} from "@/api";

export default {
  data() {
    return {
      EW_RU_JOB_ID: '',
      EW_RU_TASK_ID: '',
      form: {
        GAS_NAME1: '',
        GAS_STANDARD1: '',
        GAS_NAME2: '',
        GAS_STANDARD2: '',
        GAS_NAME3: '',
        GAS_STANDARD3: '',
        GAS_NAME4: '',
        GAS_STANDARD4: '',
      },
      rules: {},
      isView: ''
    }
  },
  onLoad(query) {
    this.EW_RU_TASK_ID = query.taskId
    this.EW_RU_JOB_ID = query.EW_RU_JOB_ID
    if (query.isView === '1') this.isView = '1'
  },
  onShow() {
    this.fnGetData()
  },
  methods: {
    async fnGetData() {
      let resData = await getConfinedSpaceGasInfo({
        EW_RU_TASK_ID: this.EW_RU_TASK_ID,
        EW_RU_JOB_ID: this.EW_RU_JOB_ID,
        postMethod: 'application/json',
      })
      this.form = resData.data.aux[0] || {}
    },
    async fnSubmit() {
      if (this.isView === '1') {
        uni.$u.route({
          url: '/pages/eight_assignments/confined_space/gas/list',
          params: {
            isView: this.isView,
            GAS_NAME1: this.form.GAS_NAME1,
            GAS_NAME2: this.form.GAS_NAME2,
            GAS_NAME3: this.form.GAS_NAME3,
            GAS_NAME4: this.form.GAS_NAME4,
            EW_RU_TASK_ID: this.EW_RU_TASK_ID,
            EW_RU_JOB_ID: this.EW_RU_JOB_ID
          }
        })
      } else {
        if (!this.form.GAS_NAME1 && !this.form.GAS_NAME2 && !this.form.GAS_NAME3 && !this.form.GAS_NAME4) {
          uni.$u.toast('最少填写一项气体名称')
          return
        }
        for (let i = 0; i < 4; i++) {
          if (this.form['GAS_NAME' + (i + 1)] && !this.form['GAS_STANDARD' + (i + 1)]) {
            uni.$u.toast('请填写气体名称（' + this.form['GAS_NAME' + (i + 1)] + '）的合格标准')
            return
          }
          if (this.form['GAS_STANDARD' + (i + 1)] && !this.form['GAS_NAME' + (i + 1)]) {
            uni.$u.toast('请填写合格标准（' + this.form['GAS_STANDARD' + (i + 1)] + '）的气体名称')
            return
          }
        }
        await setConfinedSpaceGasInfoSave({
          wh: {...this.form},
          EW_RU_TASK_ID: this.EW_RU_TASK_ID,
          EW_RU_JOB_ID: this.EW_RU_JOB_ID,
          postMethod: 'application/json',
        })
        uni.$u.route({
          url: '/pages/eight_assignments/confined_space/gas/list',
          params: {
            GAS_NAME1: this.form.GAS_NAME1,
            GAS_NAME2: this.form.GAS_NAME2,
            GAS_NAME3: this.form.GAS_NAME3,
            GAS_NAME4: this.form.GAS_NAME4,
            EW_RU_TASK_ID: this.EW_RU_TASK_ID,
            EW_RU_JOB_ID: this.EW_RU_JOB_ID,
          }
        })
      }

    }
  },
}
</script>

<style scoped lang="scss">

</style>
