<template>
  <el-row>
    <el-col :span="24">
      <el-form
        :model="drugGeneNameForm"
        ref="drugGeneNameForm"
        class="sub-form"
        :validate-on-rule-change="false"
        :rules="rules"
      >
        <el-form-item label="注册剂型" label-width="110px" prop="reg_JiXin">
          <el-input
            v-model.trim="drugGeneNameForm.reg_JiXin"
            placeholder="请输入注册剂型"
            ref="reg_JiXin"
            @blur="handleValue('reg_JiXin')"
          ></el-input>
        </el-form-item>
        <el-form-item label="标准注册剂型" label-width="110px" prop="stand_reg_JiXin">
          <el-input
            v-model.trim="drugGeneNameForm.stand_reg_JiXin"
            placeholder="请输入标准注册剂型"
            @blur="handleValue('stand_reg_JiXin')"
          ></el-input>
        </el-form-item>
        <el-form-item label="注册规格" label-width="110px" prop="reg_GuiGe">
          <el-input
            v-model.trim="drugGeneNameForm.reg_GuiGe"
            placeholder="请输入注册规格"
            @blur="handleValue('reg_GuiGe')"
          ></el-input>
        </el-form-item>
        <el-form-item label="包装材质" label-width="110px" prop="pack_CaiLiao">
          <el-input
            v-model.trim="drugGeneNameForm.pack_CaiLiao"
            placeholder="请输入包装材质"
            @blur="handleValue('pack_CaiLiao')"
          ></el-input>
        </el-form-item>
        <el-form-item label="最小包装数量" label-width="110px" prop="min_pack_num">
          <el-input
            v-model="drugGeneNameForm.min_pack_num"
            placeholder="请输入最小包装数量"
            @blur="handleValue('min_pack_num')"
            ref="min_pack_num"
          ></el-input>
        </el-form-item>
        <el-form-item label="最小制剂单位" label-width="110px" prop="min_prod_unit">
          <el-input
            v-model.trim="drugGeneNameForm.min_prod_unit"
            placeholder="请输入最小制剂单位"
            @blur="handleValue('min_prod_unit')"
          ></el-input>
        </el-form-item>
        <el-form-item label="最小包装单位" label-width="110px" prop="min_pack_unit">
          <el-input
            v-model.trim="drugGeneNameForm.min_pack_unit"
            placeholder="请输入最小包装单位"
            @blur="handleValue('min_pack_unit')"
          ></el-input>
        </el-form-item>
        <el-form-item label="药品企业" label-width="110px" prop="producer">
          <el-input
            v-model.trim="drugGeneNameForm.producer"
            placeholder="请输入药品企业"
            @blur="handleValue('producer')"
          ></el-input>
        </el-form-item>
        <el-form-item label="批准文号" label-width="110px" prop="license_num">
          <el-input
            v-model.trim="drugGeneNameForm.license_num"
            placeholder="请输入批准文号"
            @blur="handleValue('license_num')"
          ></el-input>
        </el-form-item>
        <el-form-item label="药品本位码" label-width="110px" prop="benWei_Code">
          <el-input
            v-model.trim="drugGeneNameForm.benWei_Code"
            placeholder="请输入药品本位码"
            @blur="handleValue('benWei_Code')"
          ></el-input>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</template>

<script>
export default {
  name: 'DrugGeneNameForm',
  props: ['data'],
  data() {
    let checkFrequency = (rule, value, callback) => {
      let reg_JiXin = this.$refs.reg_JiXin.value;
      if (reg_JiXin === '') {
        callback('请输入注册剂型');
      } else {
        callback();
      }
    };

    let validatePass = (rule, value, callback) => {
      let min_pack_num = this.$refs.min_pack_num.value;
      if (min_pack_num === '' || min_pack_num === null) {
        callback();
      }
      let numReg = /^(([0-9])|([1-9]([0-9]+)))(.[0-9]+)?$/;
      if (!numReg.test(min_pack_num)) {
        callback('最小包装数量只支持输入数值类型的内容');
      } else {
        callback();
      }
    };

    return {
      drugGeneNameForm: {
        min_pack_num: null, //最小包装数量（药品代码通用名属性）
        reg_JiXin: '', //注册剂型（药品代码通用名属性）
        benWei_Code: '', //药品本位码（药品代码通用名属性）
        min_pack_unit: '', //最小包装单位（药品代码通用名属性）
        reg_GuiGe: '', //注册规格（药品代码通用名属性）
        pack_CaiLiao: '', //包装材质（药品代码通用名属性）
        producer: '', //药品企业（药品代码通用名属性）
        license_num: '', //批准文号（药品代码通用名属性）
        min_prod_unit: '', //最小制剂单位（药品代码通用名属性）
        stand_reg_JiXin: '' //标准注册剂型（药品代码通用名属性）
      },
      rules: {
        reg_JiXin: [
          {
            required: true,
            validator: checkFrequency,
            trigger: ['blur', 'change']
          }
        ],
        min_pack_num: [
          {
            validator: validatePass,
            trigger: ['blur', 'change']
          }
        ]
      }
    };
  },
  computed: {},
  created() {
    this._initData();
  },
  mounted() {},
  methods: {
    _initData() {
      this.drugGeneNameForm.min_pack_num = this.data.min_pack_num;
      this.drugGeneNameForm.reg_JiXin = this.data.reg_JiXin;
      this.drugGeneNameForm.benWei_Code = this.data.benWei_Code;
      this.drugGeneNameForm.min_pack_unit = this.data.min_pack_unit;
      this.drugGeneNameForm.reg_GuiGe = this.data.reg_GuiGe;
      this.drugGeneNameForm.pack_CaiLiao = this.data.pack_CaiLiao;
      this.drugGeneNameForm.producer = this.data.producer;
      this.drugGeneNameForm.license_num = this.data.license_num;
      this.drugGeneNameForm.min_prod_unit = this.data.min_prod_unit;
      this.drugGeneNameForm.stand_reg_JiXin = this.data.stand_reg_JiXin;
    },
    // 传值
    handleValue(from) {
      this.$emit('handleInput', {
        type: from,
        value: this.drugGeneNameForm[from]
      });
    }
  }
};
</script>

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