<template>
  <el-dialog
    title="选择检验项目"
    width="50%"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <div class="check">
      <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="auto">
        <el-row class="my-row">
          <el-col :span="12">
            <el-form-item label="检验项目" prop="inspectionProject">
              <el-input v-model="dataForm.inspectionProject" placeholder="检验项目"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" style="padding-left: 20px">
            <el-form-item label="技术指标" prop="technicalIndicators">
              <el-input v-model="dataForm.technicalIndicators" placeholder="技术指标"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="实测记录" prop="measuredRecords">
            <el-input v-model="dataForm.measuredRecords" placeholder="实测记录"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="备注/说明" prop="notes">
            <el-input type="textarea" v-model="dataForm.notes" placeholder="备注/说明"></el-input>
          </el-form-item>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
      </span>
    </div>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {},
        id: 0,
        dataRule: {
          inspectionProject: [{ required: true, message: '检验项目不能为空', trigger: 'blur' }],
          technicalIndicators: [{ required: true, message: '技术指标不能为空', trigger: 'blur' }],
          measuredRecords: [{ required: true, message: '实测记录不能为空', trigger: 'blur' }]
        }
      }
    },
    methods: {
      async init (row) {
        this.visible = true
        this.id = row ? row.id : Math.round(Math.random() * 1000000)
        if (!row) return
        this.dataForm = row
      },
      validateField (type) {
        this.$refs.dataForm.validateField(type)
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.visible = false
            this.dataForm.id = this.id
            this.$emit('addItem', this.dataForm)
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
