<template>
  <div>
    <Modal v-model="showBackModal" :mask-closable="false" class="zIndex-1100">
      <p slot="header">{{modalTitle}}</p>
      <div>
        <Form ref="formObj" :model="formObj" :rules="ruleValidate" :label-width="90">
          <Form-item label="温度:" prop="temperature">
            <Input v-model="formObj.temperature" placeholder="请输入温度"></Input>
          </Form-item>
          <Form-item label="湿度:" prop="humidity">
            <Input v-model="formObj.humidity" placeholder="请输入湿度"></Input>
          </Form-item>
          <Form-item label="其他:" prop="remark">
            <Input v-model="formObj.remark" placeholder="其他"></Input>
          </Form-item>
          <Form-item label="地点:" prop="place">
            <Input v-model="formObj.place" placeholder="地点"></Input>
          </Form-item>
        </Form>

      </div>
      <div slot="footer">
        <ModalFooter ref="footerModal" :footer="footerList" @on-result-change="_footerResult"></ModalFooter>
      </div>
    </Modal>
  </div>
</template>
<script>
/**
 * 判定
 */
import ModalFooter from '../../../components/base/modalFooter'
import { meterSample } from '../../../api'

export default {
  components: {
    ModalFooter
  },
  data() {
    return {
      ids: '',
      modalTitle: '检定条件',
      showBackModal: false,
      formObj: {
        temperature: '',
        humidity: '',
        remark: '',
        place: ''
      },
      path: '',
      ruleValidate: {},
      footerList: [
        { id: '', name: '取消', type: '' },
        { id: '', name: '保存', type: 'primary' }
      ]
    }
  },
  methods: {
    _open(ids) {
      this.ids = ids
      this.showBackModal = true
      this.formObj = {}
      this.$refs.footerModal._hideLoading()
    },
    _cancel() {
      this.showBackModal = false
    },
    _footerResult(name) {
      switch (name) {
        case '取消':
          this._cancel()
          break
        case '保存':
          this._ok()
          break
      }
      this.$refs.footerModal._hideLoading()
    },
    _ok() {
      this.$refs.formObj.validate(valid => {
        if (valid) {
          this._saveSampleEnv({ ids: this.ids, obj: this.formObj })
        } else {
          this.$Message.error('表单验证失败!')
        }
      })
    },
    _saveSampleEnv: async function(data) {
      const result = await meterSample.saveSampleEnv(data)
      if (result) {
        this.$Message.success('检定条件信息填写成功!')
        this.showBackModal = false
        this.$emit('on-result-change')
      }
    }
  }
}
</script>
