WXL
2026-03-11 67ff7fff12b672fb4214488ea606728ba118cf2d
src/views/project/donatebaseinfo/EditCaseModal.vue
@@ -1,7 +1,8 @@
<template>
  <div>
  <el-dialog
    :title="title"
    :visible.sync="localVisible"
      :visible.sync="dialogVisible"
    width="1200px"
    :close-on-click-modal="false"
    @close="handleClose"
@@ -56,9 +57,9 @@
                v-model="formData.idcardtype"
                placeholder="请选择证件类型"
              >
                <el-option label="身份证" value="1" />
                <el-option label="军人证" value="2" />
                <el-option label="护照" value="3" />
                  <el-option label="身份证" :value="1" />
                  <el-option label="军人证" :value="2" />
                  <el-option label="护照" :value="3" />
              </el-select>
            </el-form-item>
          </el-col>
@@ -116,12 +117,18 @@
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="联系电话" prop="phone">
              <el-input v-model="formData.phone" placeholder="请输入联系电话" />
                <el-input
                  v-model="formData.phone"
                  placeholder="请输入联系电话"
                />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="学历" prop="education">
              <el-select v-model="formData.education" placeholder="请选择学历">
                <el-select
                  v-model="formData.education"
                  placeholder="请选择学历"
                >
                <el-option
                  v-for="dict in dictOptions.sys_education"
                  :key="dict.value"
@@ -133,7 +140,10 @@
          </el-col>
          <el-col :span="6">
            <el-form-item label="职业" prop="occupation">
              <el-select v-model="formData.occupation" placeholder="请选择职业">
                <el-select
                  v-model="formData.occupation"
                  placeholder="请选择职业"
                >
                <el-option
                  v-for="dict in dictOptions.sys_occupation"
                  :key="dict.value"
@@ -207,13 +217,12 @@
          </el-col>
          <el-col :span="12">
            <el-form-item label="Rh(D)" prop="rhyin">
              <el-radio-group v-model="form.rhyin">
                <el-radio-group v-model="formData.rhyin">
                <el-radio
                  v-for="dict in dict.type.sys_bloodtype_rhd || []"
                  :key="dict.value"
                  :label="dict.value"
                  >{{ dict.label }}</el-radio
                >
                  >{{ dict.label }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
@@ -221,7 +230,10 @@
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="当前医疗机构" prop="currentMedicalInstitution">
              <el-form-item
                label="当前医疗机构"
                prop="currentMedicalInstitution"
              >
              <el-input
                v-model="formData.currentMedicalInstitution"
                placeholder="请输入当前医疗机构"
@@ -445,7 +457,10 @@
          </el-col>
          <el-col :span="12">
            <el-form-item label="部门ID" prop="deptid">
              <el-input v-model="formData.deptid" placeholder="请输入部门ID" />
                <el-input
                  v-model="formData.deptid"
                  placeholder="请输入部门ID"
                />
            </el-form-item>
          </el-col>
        </el-row>
@@ -454,11 +469,16 @@
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" @click="handleSubmit" :loading="submitLoading">
        <el-button
          type="primary"
          @click="handleSubmit"
          :loading="submitLoading"
        >
        {{ isEdit ? "更新" : "保存" }}
      </el-button>
    </div>
  </el-dialog>
  </div>
</template>
<script>
@@ -498,7 +518,6 @@
  },
  data() {
    return {
      localVisible: this.visible,
      isEdit: false,
      submitLoading: false,
      residenceAddress: {},
@@ -539,31 +558,49 @@
  computed: {
    title() {
      return this.isEdit ? "编辑案例信息" : "新增捐献案例";
    },
    dialogVisible: {
      get() {
        return this.visible;
      },
      set(value) {
        this.$emit('update:visible', value);
        if (!value) {
          this.handleClose();
        }
      }
    }
  },
  watch: {
    visible(newVal) {
      this.localVisible = newVal;
      console.log("visible变化:", newVal);
      if (newVal) {
        this.$nextTick(() => {
        this.initForm();
        });
      } else {
        this.handleClose();
      }
    },
    localVisible(newVal) {
      this.$emit("update:visible", newVal);
    },
    editData: {
      immediate: true,
      deep: true,
      handler(newVal) {
        if (newVal && newVal.id) {
          this.isEdit = true;
          this.$nextTick(() => {
            // 确保 DOM 已经更新后再进行表单操作
            this.initForm(newVal);
          });
        console.log("editData变化:", newVal);
        this.isEdit = !!(newVal && newVal.id);
      }
        }
      },
      deep: true,
      immediate: true
    }
  created() {
    console.log('EditCaseModal created');
    console.log('visible:', this.visible);
    console.log('editData:', this.editData);
  },
  mounted() {
    console.log('EditCaseModal mounted');
    console.log('visible:', this.visible);
    console.log('editData:', this.editData);
    console.log('isEdit:', this.isEdit);
  },
  methods: {
    getDefaultFormData() {
@@ -640,13 +677,14 @@
    },
    async initForm() {
      console.log(this.isEdit);
      if (this.isEdit) {
      console.log('初始化表单,isEdit:', this.isEdit);
      try {
        if (this.isEdit && this.editData && this.editData.id) {
          console.log('加载编辑数据,id:', this.editData.id);
        await this.loadEditData();
      } else {
          console.log('新增模式,初始化表单');
        this.formData = this.getDefaultFormData();
        // 设置默认值
        this.formData.nationality = "中国";
        this.formData.bloodtype = "0";
        this.formData.rhyin = "0";
@@ -654,15 +692,23 @@
        this.formData.acquisitiontissueno = "ZJOPO";
        this.formData.acquisitiontissuename = "浙江省人体器官获取组织";
      }
      } catch (error) {
        console.error("初始化表单失败:", error);
        this.$message.error("初始化表单失败");
      } finally {
      this.$nextTick(() => {
        this.$refs.formRef?.clearValidate();
          if (this.$refs.formRef) {
            this.$refs.formRef.clearValidate();
          }
      });
      }
    },
    async loadEditData() {
      try {
        const response = await getDonatebaseinfo(this.editData.id);
        const data = response.data;
        console.log('加载到的数据:', data);
        // 处理数组字段
        const arrayFields = [
@@ -683,6 +729,7 @@
        });
        this.formData = { ...this.getDefaultFormData(), ...data };
        console.log('合并后的formData:', this.formData);
        // 设置地址信息
        if (data.residenceprovince) {
@@ -703,13 +750,13 @@
        this.calculateAge(data.birthday);
      } catch (error) {
        console.error("获取案例数据失败:", error);
        this.$message.error("获取案例数据失败");
        this.handleClose();
      }
    },
    handleIdCardBlur() {
      // 身份证自动填充逻辑
      this.updateMessage();
    },
@@ -817,7 +864,7 @@
    },
    handleClose() {
      this.localVisible = false;
      console.log('关闭弹框');
      this.isEdit = false;
      this.submitLoading = false;
      this.formData = this.getDefaultFormData();
@@ -833,6 +880,7 @@
      this.submitLoading = true;
      try {
        const submitData = this.processSubmitData();
        console.log('提交数据:', submitData);
        const result = await updateDonatebaseinfo(submitData);
        if (result.code === 200) {
@@ -843,6 +891,7 @@
          this.$message.error(result.msg || "操作失败");
        }
      } catch (error) {
        console.error("操作失败:", error);
        this.$message.error("操作失败");
      } finally {
        this.submitLoading = false;