<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="others">
            <Input v-model="formObj.others" placeholder="其他"></Input>
          </Form-item>
          <Form-item label="地点:" prop="location">
            <Input v-model="formObj.location" placeholder="地点"></Input>
          </Form-item>
        </Form>

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

export default {
  components: {
    ModalFooter
  },
  data() {
    return {
      ids: [], // 合同ids
      modalTitle: '检定条件',
      showBackModal: false,
      formObj: {
        temperature: '',
        humidity: '',
        others: '',
        location: ''
      },
      path: '',
      ruleValidate: {},
      footerList: [
        { id: '', name: '取消', type: '' },
        { id: '', name: '保存', type: 'primary' }
      ]
    }
  },
  methods: {
    _open(ids) {
      this.ids = ids // 合同id
      this.showBackModal = true
      this.formObj.type = 1
      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) {
          const data = {}
          data.ids = this.ids.join(',')
          this.$extend(data, this.formObj)
          console.log('要传的数据', data)
          this.showBackModal = false
          // this.$store.dispatch('FoodItem/judge', data).then(() => {
          //   if (this.$store.state.FoodItem.success) {
          //     this.$Message.success('判定成功')
          //     this.showBackModal = false
          //     this.$emit('on-result-change')
          //   }
          // })
        } else {
          this.$Message.error('表单验证失败!')
        }
      })
    }
  }
}
</script>
