<template>
  <el-row>
    <el-col :span="24">
      <el-form
        :model="drugAllergensForm"
        ref="drugAllergensForm"
        class="sub-form"
        :validate-on-rule-change="false"
        :rules="rules"
      >
        <el-form-item label="药品类型" label-width="110px" prop="medtype">
          <el-select
            v-model="drugAllergensForm.medtype"
            placeholder="请选择药品类型"
            clearable
            @change="handleValue('medtype')"
            style="width: 100%"
            ref="dragType"
          >
            <el-option label="药品" value="药品"></el-option>
            <el-option label="药品类别" value="药品类别"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结果" label-width="110px" prop="result">
          <el-input
            v-model.trim="drugAllergensForm.result"
            placeholder="请输入结果"
            @blur="handleValue('result')"
          ></el-input>
        </el-form-item>
        <el-form-item label="名称" label-width="110px" prop="alias">
          <el-input
            v-model.trim="drugAllergensForm.alias"
            placeholder="请输入名称"
            @blur="handleValue('alias')"
          ></el-input>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</template>

<script>
export default {
  name: 'DrugAllergensForm',
  props: ['data'],
  data() {
    let checkFrequency = (rule, value, callback) => {
      let dragType = this.$refs.dragType.value;
      if (dragType === '' || dragType === null) {
        callback('请选择药品类型');
      } else {
        callback();
      }
    };

    return {
      drugAllergensForm: {
        medtype: '',
        result: '',
        alias: ''
      },
      rules: {
        medtype: [
          {
            required: true,
            validator: checkFrequency,
            trigger: ['blur', 'change']
          }
        ]
      }
    };
  },
  computed: {},
  created() {
    this._initData();
  },
  mounted() {},
  methods: {
    _initData() {
      this.drugAllergensForm.medtype = this.data.medtype;
      this.drugAllergensForm.result = this.data.result;
      this.drugAllergensForm.alias = this.data.alias;
    },
    // 传值
    handleValue(from) {
      this.$emit('handleInput', {
        type: from,
        value: this.drugAllergensForm[from]
      });
    }
  }
};
</script>

<style lang="less" scoped>
</style>