/** * @desc 新增、查看弹窗 * @author linyuanjie * @date 2021/6/1 */

<template>
  <el-dialog
    :title="dialogType === 'add' ? '新增' : '查看'"
    :visible.sync="showDialog"
    width="50%"
    :before-close="handleClose"
    center
  >
    <el-form
      :model="addForm"
      :rules="addRule"
      :disabled="dialogType === 'view'"
      :hide-required-asterisk="dialogType === 'view'"
      ref="addForm"
      label-width="120px"
      class="demo-ruleForm"
    >
      <div class="mb20 pb10 fwb f14 bb">
        处方单信息
      </div>
      <el-row>
        <el-col :span="12">
          <el-form-item label="医生姓名" prop="temp1">
            <el-input v-model="addForm.temp1" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="患者名称" prop="temp2">
            <el-input v-model="addForm.temp2"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="处方单编号" prop="temp3">
            <el-input v-model="addForm.temp3"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="开具处方时间" prop="temp4">
            <el-date-picker
              class="w100"
              v-model="addForm.temp4"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择日期时间"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="患教服务费" prop="temp5">
            <el-input v-model="addForm.temp5"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-form-item label="诊断" prop="temp6">
          <el-input type="textarea" v-model="addForm.temp6"></el-input>
        </el-form-item>
      </el-row>
      <div class="mb20 pb10 fwb f14 bb">
        处方单明细
      </div>
      <el-row>
        <el-col :span="12">
          <el-form-item label="医生姓名" prop="temp1">
            <el-input v-model="addForm.temp1" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="剂型" prop="temp7">
            <el-input v-model="addForm.temp7"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="审方药师" prop="temp8">
            <el-input v-model="addForm.temp8"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="发货方" prop="temp9">
            <el-input v-model="addForm.temp9"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-form-item label="产品" prop="temp10">
          <el-input type="textarea" v-model="addForm.temp10"></el-input>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="用法用量" prop="temp11">
          <el-input type="textarea" v-model="addForm.temp11"></el-input>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="补充说明">
          <el-input type="textarea" v-model="addForm.temp12"></el-input>
        </el-form-item>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">关 闭</el-button>
      <el-button
        v-if="dialogType === 'add'"
        type="primary"
        @click="sumbitBtn('addForm')"
        >确 定</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
import { saveTaskPrescription } from "@/api/specialTask/patientEdu/prescriptionUpload";

export default {
  name: "addDialog",
  props: {
    dialogType: {
      type: String
    },
    showDialog: {
      type: Boolean
    },
    docname: {
      type: String
    },
    scorePackageId: {
      type: String
    },
    rowData: {
      type: Object
    }
  },
  data() {
    return {
      addForm: {
        temp1: ""
      },
      addRule: {
        temp1: [{ required: true, message: "请输入医生姓名", trigger: "blur" }],
        temp2: [{ required: true, message: "请输入患者姓名", trigger: "blur" }],
        temp3: [
          { required: true, message: "请输入处方单编号", trigger: "blur" }
        ],
        temp4: [
          { required: true, message: "请输入开具处方时间", trigger: "change" }
        ],
        temp5: [
          { required: true, message: "请输入患教服务费", trigger: "blur" }
        ],
        temp6: [{ required: true, message: "请输入诊断", trigger: "blur" }],
        temp7: [{ required: true, message: "请输入剂型", trigger: "blur" }],
        temp8: [{ required: true, message: "请输入审方药师", trigger: "blur" }],
        temp9: [{ required: true, message: "请输入发货方", trigger: "blur" }],
        temp10: [{ required: true, message: "请输入产品", trigger: "blur" }],
        temp11: [
          { required: true, message: "请输入用法用量", trigger: "blur" }
        ],
        temp12: [{ required: true, message: "请输入补充说明", trigger: "blur" }]
      }
    };
  },
  watch: {
    docname: {
      handler: function(newVal) {
        this.addForm.temp1 = newVal;
      },
      immediate: true
    }
  },
  methods: {
    handleClose(val) {
      this.$emit("handleClose", val);
    },
    sumbitBtn(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          let wmTaskContent = Object.assign({}, this.addForm);
          const params = {
            scorePackageId: this.scorePackageId,
            wmTaskContent
          };
          saveTaskPrescription(params).then(res => {
            this.$message.success("新增成功!");
            this.handleClose("success");
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  },
  mounted() {
    if (this.dialogType === "view") {
      this.addForm = this.rowData;
    }
  }
};
</script>

<style scoped></style>
