<template>
  <div class="dialog-wrap">
    <el-dialog title="用药情况" :visible.sync="showDialog">
      <el-form :model="formChosedMedical" ref="choseMed" :rules="rules">
        <el-form-item label="药物名称" :label-width="formLabelWidth" prop="medicinesName">
          <el-input v-model="formChosedMedical.medicinesName" autocomplete="off" placeholder="请输入药物名称"></el-input>
        </el-form-item>
        <el-form-item label="用法" :label-width="formLabelWidth" prop="dosageDay">
          <el-input v-model="formChosedMedical.dosageDay" autocomplete="off" placeholder="请输入每日几次">
            <template slot="append">次/日</template>
          </el-input>
        </el-form-item>
        <el-form-item label="用量" :label-width="formLabelWidth" prop="dosageNum">
          <el-input v-model="formChosedMedical.dosageNum" autocomplete="off" placeholder="请输入每次用量">
            <template slot="append">>每次</template>
          </el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeDialog">取 消</el-button>
        <el-button type="primary" @click="confirmSubmit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    data(){
      return {
        showDialog: true,
        formLabelWidth: '120px',
        formChosedMedical: {
          medicinesName: '',  // 药物名称
          dosageDay: '',  // 每日次数
          dosageNum: '',  // 每次的剂量
        },
        rules: {
          medicinesName: [{ required: true, message: '请输入药物名称', trigger: 'change' }],
          dosageDay: [{ required: true, message: '请输入每日几次', trigger: 'change' }],
          dosageNum: [{ required: true, message: '请输入每次用量', trigger: 'change' }],
        },
      }
    },
    watch: {
      showDialog(val){
        this.$emit('closeDialog',val)
      }
    },
    methods: {
      closeDialog(){
        this.$emit('closeDialog',false)
      },
      confirmSubmit(){
        this.$refs['choseMed'].validate((valid) => {
          if(valid){
            this.$emit('closeDialog',false);
            this.$emit('setMedication',this.formChosedMedical);
          }
        });
      }
    }
  }
</script>

<style scoped lang="scss">

</style>
