WXL
3 天以前 c8e9849cb5f24848df0174c13bfbbff37bb08a5a
src/views/business/OrganUtilization/OrganUtilizationInfo.vue
@@ -1,50 +1,12 @@
<template>
  <div class="organ-utilization-detail">
    <case-basic-info :case-id="caseId" :show-attachment="true" />
    <!-- 基本信息 -->
    <el-card class="detail-card">
      <div slot="header" class="clearfix">
        <span class="detail-title">器官利用基本信息</span>
        <div style="float: right;">
          <el-button type="primary" @click="handleSave" :loading="saveLoading">
            保存
          </el-button>
          <el-button
            type="success"
            @click="handleComplete"
            :disabled="form.recordstate === 'completed'"
            :loading="confirmLoading"
          >
            完成利用
          </el-button>
    <el-form :model="form" ref="form" :rules="rules" label-width="120px">
      <!-- 基本信息 -->
      <el-card class="detail-card">
        <div slot="header" class="clearfix">
          <span class="detail-title">器官利用基本信息</span>
        </div>
      </div>
      <el-form :model="form" ref="form" :rules="rules" label-width="120px">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item align="left" label="遗体捐献" prop="isbodydonation">
              <el-radio-group v-model="form.isbodydonation">
                <el-radio
                  v-for="dict in dict.type.sys_0_1 || []"
                  :key="dict.value"
                  :label="dict.value"
                  >{{ dict.label }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="18">
            <el-form-item align="left" label="接收单位" prop="receivingunit">
              <el-input
                v-model="form.receivingunit"
                placeholder="请输入接收单位"
                :disabled="form.isbodydonation !== '1'"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="6">
@@ -78,16 +40,15 @@
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%"
                :disabled="form.recordstate === 'completed'"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
        <!-- <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="登记人" prop="createBy">
              <el-input v-model="form.createBy" readonly />
              <el-input v-model="form.createBy" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
@@ -97,22 +58,64 @@
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%"
                readonly
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
        </el-row> -->
      </el-card>
      <el-card class="detail-card">
        <div slot="header" class="clearfix">
          <span class="detail-title">遗体捐献信息</span>
        </div>
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item align="left" label="遗体接收" prop="isbodydonation">
              <el-radio-group v-model="form.isbodydonation">
                <el-radio
                  v-for="dict in dict.type.sys_0_1 || []"
                  :key="dict.value"
                  :label="dict.value"
                  >{{ dict.label }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item align="left" label="接收家属" prop="relationname">
              <el-input
                v-model="form.relationname"
                placeholder="请输入接收家属"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="与捐献者关系" prop="signfamilyrelations">
              <el-select
                v-model="form.signfamilyrelations"
                placeholder="请选择与捐献者关系"
              >
                <el-option
                  v-for="dict in dict.type.sys_FamilyRelation || []"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
    </el-form>
    <!-- 器官利用记录部分 - 整合受者详情 -->
    <el-card class="utilization-card">
      <div slot="header" class="clearfix">
        <span class="detail-title">器官利用记录</span>
        <div style="float: right;">
          <el-tag :type="getStatusTagType(form.recordstate)">
            {{ getStatusText(form.recordstate) }}
          </el-tag>
          <dict-tag
            :options="dict.type.utilize_statue"
            :value="form.completeState"
          />
        </div>
      </div>
@@ -133,7 +136,6 @@
                  v-for="dict in dict.type.sys_Organ || []"
                  :key="dict.value"
                  :label="dict.value"
                  :disabled="form.recordstate === 'completed'"
                >
                  {{ dict.label }}
                </el-checkbox>
@@ -146,7 +148,7 @@
          <el-col>
            <el-form-item>
              <el-table
                :data="utilizationData.serviceDonatecomporganList"
                :data="displayOrgans"
                v-loading="loading"
                border
                style="width: 100%"
@@ -194,7 +196,6 @@
                                <el-input
                                  v-model="scope.row.name"
                                  placeholder="请输入受者姓名"
                                  :disabled="form.recordstate === 'completed'"
                                />
                              </el-form-item>
                            </el-col>
@@ -206,7 +207,6 @@
                                  value-format="yyyy-MM-dd"
                                  placeholder="选择出生日期"
                                  style="width: 100%"
                                  :disabled="form.recordstate === 'completed'"
                                />
                              </el-form-item>
                            </el-col>
@@ -216,10 +216,9 @@
                                  v-model="scope.row.sex"
                                  placeholder="请选择性别"
                                  style="width: 100%"
                                  :disabled="form.recordstate === 'completed'"
                                >
                                  <el-option label="男" value="0" />
                                  <el-option label="女" value="1" />
                                  <el-option label="男" :value="0" />
                                  <el-option label="女" :value="1" />
                                </el-select>
                              </el-form-item>
                            </el-col>
@@ -231,7 +230,6 @@
                                <el-input
                                  v-model="scope.row.age"
                                  placeholder="年龄"
                                  :disabled="form.recordstate === 'completed'"
                                />
                              </el-form-item>
                            </el-col>
@@ -241,12 +239,11 @@
                                  v-model="scope.row.idcardtype"
                                  placeholder="请选择证件类型"
                                  style="width: 100%"
                                  :disabled="form.recordstate === 'completed'"
                                >
                                  <el-option label="身份证" value="1" />
                                  <el-option label="护照" value="2" />
                                  <el-option label="军官证" value="3" />
                                  <el-option label="其他" value="4" />
                                  <el-option label="身份证" :value="1" />
                                  <el-option label="护照" :value="2" />
                                  <el-option label="军官证" :value="3" />
                                  <el-option label="其他" :value="4" />
                                </el-select>
                              </el-form-item>
                            </el-col>
@@ -255,7 +252,6 @@
                                <el-input
                                  v-model="scope.row.idcardno"
                                  placeholder="证件号码"
                                  :disabled="form.recordstate === 'completed'"
                                />
                              </el-form-item>
                            </el-col>
@@ -271,7 +267,6 @@
                                <el-input
                                  v-model="scope.row.hospitalname"
                                  placeholder="请输入移植中心名称"
                                  :disabled="form.recordstate === 'completed'"
                                />
                              </el-form-item>
                            </el-col>
@@ -280,7 +275,6 @@
                                <el-input
                                  v-model="scope.row.phone"
                                  placeholder="联系电话"
                                  :disabled="form.recordstate === 'completed'"
                                />
                              </el-form-item>
                            </el-col>
@@ -294,7 +288,6 @@
                                  :rows="2"
                                  v-model="scope.row.residenceaddress"
                                  placeholder="请输入详细地址"
                                  :disabled="form.recordstate === 'completed'"
                                />
                              </el-form-item>
                            </el-col>
@@ -313,10 +306,9 @@
                                <el-date-picker
                                  v-model="scope.row.transplanttime"
                                  type="datetime"
                                  value-format="YYYY-MM-DD HH:mm:ss"
                                  value-format="yyyy-MM-dd HH:mm:ss"
                                  placeholder="选择移植日期"
                                  style="width: 100%"
                                  :disabled="form.recordstate === 'completed'"
                                />
                              </el-form-item>
                            </el-col>
@@ -325,7 +317,6 @@
                                <el-input
                                  v-model="scope.row.transplantdoct"
                                  placeholder="请输入移植医生"
                                  :disabled="form.recordstate === 'completed'"
                                />
                              </el-form-item>
                            </el-col>
@@ -346,7 +337,6 @@
                                  :rows="3"
                                  v-model="scope.row.abandonreason"
                                  placeholder="请输入未移植原因"
                                  :disabled="form.recordstate === 'completed'"
                                />
                              </el-form-item>
                            </el-col>
@@ -371,14 +361,14 @@
                  </template>
                </el-table-column>
                <el-table-column label="系统编号" align="center" prop="caseNo">
                <!-- <el-table-column label="系统编号" align="center" prop="caseNo">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.caseNo"
                      placeholder="系统编号"
                    />
                  </template>
                </el-table-column>
                </el-table-column> -->
                <el-table-column
                  label="移植医院"
@@ -387,22 +377,15 @@
                  prop="hospitalno"
                >
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.hospitalno"
                      placeholder="请选择移植医院"
                    <el-autocomplete
                      v-model="scope.row.hospitalname"
                      :fetch-suggestions="queryHospitalSearch"
                      placeholder="请选择或输入移植医院"
                      style="width: 100%"
                      @change="handleHospitalChange(scope.row, $event)"
                    >
                      <el-option
                        v-for="hospital in hospitalList"
                        :key="hospital.hospitalNo"
                        :label="hospital.hospitalName"
                        :value="hospital.hospitalNo"
                      />
                    </el-select>
                      clearable
                    ></el-autocomplete>
                  </template>
                </el-table-column>
                <el-table-column
                  label="移植状态"
                  align="center"
@@ -438,7 +421,7 @@
                      style="width: 100%"
                      v-model="scope.row.transplanttime"
                      type="datetime"
                      value-format="YYYY-MM-DD HH:mm:ss"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择移植时间"
                    />
                  </template>
@@ -459,39 +442,7 @@
                <el-table-column label="受者姓名" align="center" prop="name">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.name"
                      placeholder="受者姓名"
                      :disabled="form.recordstate === 'completed'"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="操作"
                  align="center"
                  class-name="small-padding fixed-width"
                  v-if="form.recordstate !== 'completed'"
                >
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-edit"
                      @click="handleEditUtilization(scope.row)"
                    >
                      编辑
                    </el-button>
                    <el-button
                      size="mini"
                      type="text"
                      icon="el-icon-delete"
                      style="color: #F56C6C;"
                      @click="handleRemoveOrgan(scope.$index)"
                      v-if="!scope.row.id"
                    >
                      删除
                    </el-button>
                    <el-input v-model="scope.row.name" placeholder="受者姓名" />
                  </template>
                </el-table-column>
              </el-table>
@@ -516,159 +467,129 @@
    </el-card>
    <!-- 附件管理部分 -->
    <!-- 附件管理部分 - 优化为完整功能 -->
    <!-- 附件管理部分 - 分类Tab展示 -->
    <el-card class="attachment-card">
      <div class="attachment-header">
        <i class="el-icon-paperclip"></i>
        <span class="attachment-title">相关附件</span>
        <span class="attachment-tip"
          >支持上传器官利用相关文件 (最多{{ attachmentLimit }}个)</span
        >
      <div slot="header" class="clearfix">
        <span class="detail-title">相关附件</span>
      </div>
      <!-- 使用 UploadAttachment 组件 -->
      <UploadAttachment
        ref="uploadAttachment"
        :file-list="attachmentFileList"
        :limit="attachmentLimit"
        :accept="attachmentAccept"
        :multiple="true"
        @change="handleAttachmentChange"
        @upload-success="handleUploadSuccess"
        @upload-error="handleUploadError"
        @remove="handleAttachmentRemove"
      />
      <!-- 上传区域(无分类选择,由Tab控制) -->
      <div class="upload-wrapper">
        <UploadAttachment
          ref="uploadAttachment"
          :file-list="attachmentFileList"
          :limit="attachmentLimit"
          :accept="attachmentAccept"
          :multiple="true"
          @change="handleAttachmentChange"
          @upload-success="handleUploadSuccess"
          @upload-error="handleUploadError"
          @remove="handleAttachmentRemove"
        />
        <div style="font-size:12px; color:#909399; margin-top:4px;">
          当前上传分类:<el-tag size="small" type="info">{{
            activeTab === "未分类" ? "未分类" : activeTab
          }}</el-tag>
          (切换 Tab 可改变上传分类)
        </div>
      </div>
      <!-- 附件列表展示 -->
      <!-- 附件列表 - 分类Tab展示,支持修改分类 -->
      <div class="attachment-list" v-if="attachments && attachments.length > 0">
        <div class="list-title">已上传附件 ({{ attachments.length }})</div>
        <el-table :data="attachments" style="width: 100%" size="small">
          <el-table-column label="文件名" min-width="200">
            <template slot-scope="scope">
              <i
                class="el-icon-document"
                :style="{ color: getFileIconColor(scope.row.fileName) }"
              ></i>
              <span class="file-name">{{ scope.row.fileName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="文件类型" width="100">
            <template slot-scope="scope">
              <el-tag :type="getFileTagType(scope.row.fileName)" size="small">
                {{ getFileTypeText(scope.row.fileName) }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="上传时间" width="200">
            <template slot-scope="scope">
              <span>{{ formatDateTime(scope.row.uploadTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="文件大小" width="180">
            <template slot-scope="scope">
              <span>{{ formatFileSize(scope.row.fileSize) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="260" fixed="right">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="primary"
                @click="handlePreview(scope.row)"
                :disabled="!isPreviewable(scope.row.fileName)"
              >
                预览
              </el-button>
              <el-button
                size="mini"
                type="success"
                @click="handleDownloadAttachment(scope.row)"
              >
                下载
              </el-button>
              <el-button
                size="mini"
                type="danger"
                @click="handleRemoveAttachment(scope.$index)"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-tabs v-model="activeTab" type="border-card">
          <el-tab-pane
            v-for="category in categories"
            :key="category"
            :label="category + '(' + getCategoryCount(category) + ')'"
            :name="category"
          >
            <el-table
              :data="getCategoryFiles(category)"
              style="width: 100%"
              size="small"
              border
            >
              <el-table-column label="文件名" min-width="180">
                <template #default="scope">
                  <i
                    class="el-icon-document"
                    style="margin-right: 8px; color: #409EFF;"
                  ></i>
                  <span class="file-name">{{ scope.row.fileName }}</span>
                </template>
              </el-table-column>
              <!-- 可编辑分类下拉 -->
              <el-table-column label="分类" width="150">
                <template #default="scope">
                  <el-select
                    v-model="scope.row.fileType"
                    size="small"
                    @change="updateAttachmentCategory(scope.row, $event)"
                    placeholder="选择分类"
                  >
                    <el-option label="原表拍照" value="原表拍照" />
                    <el-option label="接受确认书" value="接受确认书" />
                    <el-option label="弃用说明" value="弃用说明" />
                    <el-option label="捐献证书照片" value="捐献证书照片" />
                    <el-option label="未分类" value="" />
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column label="文件类型" width="100">
                <template #default="scope">
                  <el-tag size="small">{{
                    getFileTypeText(scope.row.fileName)
                  }}</el-tag>
                </template>
              </el-table-column>
              <el-table-column label="上传时间" width="160">
                <template #default="scope">
                  <span>{{ formatDateTime(scope.row.uploadTime) }}</span>
                </template>
              </el-table-column>
              <el-table-column label="文件大小" width="120">
                <template #default="scope">
                  <span>{{ formatFileSize(scope.row.fileSize) }}</span>
                </template>
              </el-table-column>
              <el-table-column label="操作" width="180" fixed="right">
                <template #default="scope">
                  <el-button
                    size="mini"
                    type="primary"
                    @click="handlePreview(scope.row)"
                    >预览</el-button
                  >
                  <el-button
                    size="mini"
                    type="danger"
                    @click="handleRemoveAttachmentByFile(scope.row)"
                    >删除</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
          </el-tab-pane>
        </el-tabs>
      </div>
      <!-- 无附件时显示 -->
      <div v-else style="text-align:center; padding:20px; color:#909399;">
        暂无附件,请上传
      </div>
    </el-card>
    <!-- 编辑利用记录对话框 -->
    <el-dialog
      title="编辑器官利用记录"
      :visible.sync="editDialogVisible"
      width="600px"
    >
      <el-form :model="currentRecord" label-width="120px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="器官名称">
              <el-input v-model="currentRecord.organname" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="移植状态">
              <el-select
                v-model="currentRecord.transplantstate"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in transplantStatusList"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item
          label="未移植原因"
          v-if="currentRecord.transplantstate === '0'"
        >
          <el-input
            type="textarea"
            :rows="3"
            v-model="currentRecord.abandonreason"
            placeholder="请输入未移植原因"
          />
        </el-form-item>
        <el-form-item
          label="移植医院"
          v-if="currentRecord.transplantstate === '1'"
        >
          <el-select
            v-model="currentRecord.hospitalno"
            placeholder="请选择移植医院"
            style="width: 100%"
          >
            <el-option
              v-for="hospital in hospitalList"
              :key="hospital.hospitalNo"
              :label="hospital.hospitalName"
              :value="hospital.hospitalNo"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          label="受者姓名"
          v-if="currentRecord.transplantstate === '1'"
        >
          <el-input v-model="currentRecord.name" placeholder="请输入受者姓名" />
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="editDialogVisible = false">取消</el-button>
        <el-button type="primary" @click="handleEditConfirm">确认</el-button>
      </div>
    </el-dialog>
    <div style="text-align: center; margin: 30px 0;">
      <el-button type="primary" @click="handleSave" :loading="saveLoading">
        保存
      </el-button>
      <el-button
        type="success"
        @click="handleComplete"
        :loading="confirmLoading"
      >
        完成利用
      </el-button>
    </div>
    <!-- 文件预览对话框 -->
    <FilePreviewDialog
      :visible="filePreviewVisible"
@@ -697,17 +618,25 @@
    FilePreviewDialog,
    CaseBasicInfo
  },
  dicts: ["sys_BloodType", "sys_Organ", "sys_0_1"],
  dicts: [
    "Geta_hospital",
    "sys_BloodType",
    "sys_Organ",
    "sys_FamilyRelation",
    "sys_0_1",
    "utilize_statue"
  ],
  data() {
    return {
      caseId: null,
      activeTab: "原表拍照", // 当前激活的附件分类Tab
      presetCategories: ["原表拍照", "接受确认书", "弃用说明", "捐献证书照片"], // 预设分类
      // 表单数据 - 根据接口参数调整
      form: {
        id: undefined,
        infoid: undefined,
        inpatientno: "",
        recordstate: "pending",
        completeState: "2",
        caseNo: "",
        donorno: "",
        treatmenthospitalname: "",
@@ -727,8 +656,8 @@
        coordinatedusernamet: "",
        assessannex: "",
        donateorgan: "",
        isbodydonation: "0",
        receivingunit: "",
        isbodydonation: "1",
        receivingunitname: "",
        createBy: "",
        createTime: "",
        updateBy: "",
@@ -762,8 +691,13 @@
      transplantStatusList: [
        { value: "1", label: "已移植" },
        { value: "0", label: "未移植" },
        { value: "2", label: "移植中" }
        { value: "2", label: "移植中" },
        { value: "3", label: "库存" }
      ],
      organExpansionMap: {
        C64: { subItems: ["C64L", "C64R"], subNames: ["左肾", "右肾"] },
        C34: { subItems: ["C34L", "C34R"], subNames: ["左肺", "右肺"] }
      },
      // 利用记录数据
      utilizationData: {
        serviceDonatecomporganList: []
@@ -798,6 +732,11 @@
    currentUser() {
      return JSON.parse(sessionStorage.getItem("user") || "{}");
    },
    categories() {
     // 始终返回所有预设分类 + 未分类,即使没有数据也显示
    const allCategories = ['原表拍照', '接受确认书', '弃用说明', '捐献证书照片', '未分类'];
    return allCategories;
    },
    // 已移植数量
    transplantedCount() {
      if (!this.utilizationData.serviceDonatecomporganList) return 0;
@@ -812,6 +751,22 @@
        .map(record => record.hospitalno)
        .filter(Boolean);
      return new Set(hospitals).size;
    },
    organReverseMap() {
      const map = {};
      for (const key in this.organExpansionMap) {
        const { subItems } = this.organExpansionMap[key];
        subItems.forEach(item => {
          map[item] = key;
        });
      }
      return map;
    },
    // 过滤掉 delFlag=1 的记录(用于表格展示)
    displayOrgans() {
      return (this.utilizationData.serviceDonatecomporganList || []).filter(
        item => item.delFlag !== 1
      );
    },
    // 获取器官字典
    organDict() {
@@ -856,19 +811,33 @@
        .replace("T", " ")
        .substring(0, 19);
      this.generateDonorNo();
      this.getDetail();
      this.getHospitalData();
    },
    syncOrgansFromSelection() {
      const records = this.utilizationData.serviceDonatecomporganList || [];
      const targetNos = [];
      this.selectedOrgans.forEach(val => {
        if (this.organExpansionMap[val]) {
          targetNos.push(...this.organExpansionMap[val].subItems);
        } else {
          targetNos.push(val);
        }
      });
    // 生成捐献者编号
    generateDonorNo() {
      const timestamp = Date.now().toString();
      this.form.donorno = "D" + timestamp.slice(-8);
      this.form.caseNo = "CASE" + timestamp.slice(-6);
      this.form.inpatientno = "IP" + timestamp.slice(-6);
      targetNos.forEach(no => {
        const existing = records.find(r => r.organno === no);
        if (existing) {
          if (existing.delFlag === 1) existing.delFlag = 0;
        } else {
          // 使用创建方法,自动包含 delFlag:0
          this.createOrganRecord(no);
        }
      });
      // 强制所有记录 delFlag=0(加载时应该全部有效)
      records.forEach(r => (r.delFlag = 0));
      this.form.donateorgan = this.selectedOrgans.join(",");
    },
    // 获取详情
    async getDetail() {
      this.loading = true;
@@ -880,9 +849,13 @@
          response.data.length > 0
        ) {
          const data = response.data[0];
          if (!data.completeState || data.completeState == 1) {
            data.completeState = "2";
          }
          this.form = data;
          // 填充表单数据
          Object.assign(this.form, data);
          // Object.assign(this.form, data);
          this.form.signfamilyrelations = this.form.signfamilyrelations || "";
          // 处理捐献器官字段
          if (data.donateorgan) {
            const organArray = Array.isArray(data.donateorgan)
@@ -898,22 +871,41 @@
            )
              ? data.serviceDonatecomporganList.map(record => ({
                  ...record,
                  transplanttime: record.transplanttime || "",
                  transplantstate: record.transplantstate
                    ? record.transplantstate.toString()
                    : "1"
                }))
              : [];
          }
          console.log(this.utilizationData.serviceDonatecomporganList);
          // 初始化附件
          // 改为(确保每个附件都有 fileType 字段)
          if (this.form.assessannex) {
            this.form.attachments = JSON.parse(this.form.assessannex);
            this.attachments = Array.isArray(this.form.attachments)
              ? [...this.form.attachments]
              : [];
            const parsed = JSON.parse(this.form.assessannex);
            this.attachments = parsed.map(item => ({
              ...item,
              fileType: item.fileType || "" // 默认空字符串表示未分类
            }));
            this.form.attachments = this.attachments;
            // 同步 attachmentFileList
            this.attachmentFileList = this.attachments.map(item => ({
              uid: item.id || Math.random(),
              name: item.fileName,
              url: item.path || item.fileUrl,
              fileSize: item.fileSize,
              uploadTime: item.uploadTime,
              status: "success",
              raw: item
            }));
          } else {
            this.attachments = [];
            this.attachmentFileList = [];
          }
          this.$message.success("数据加载成功");
          this.syncOrgansFromSelection();
        } else {
          this.$message.warning("未找到对应的器官利用数据");
        }
@@ -926,81 +918,125 @@
    },
    // 获取医院数据
    async getHospitalData() {
      try {
        // TODO: 替换为实际的医院列表接口
        // 暂时使用模拟数据
        this.hospitalList = [
          { hospitalNo: "H001", hospitalName: "北京协和医院" },
          { hospitalNo: "H002", hospitalName: "上海华山医院" },
          { hospitalNo: "H003", hospitalName: "上海瑞金医院" },
          { hospitalNo: "H004", hospitalName: "广州中山医院" },
          { hospitalNo: "H005", hospitalName: "武汉同济医院" },
          { hospitalNo: "H006", hospitalName: "成都华西医院" }
        ];
      } catch (error) {
        console.error("获取医院数据失败:", error);
        this.$message.error("获取医院数据失败");
      }
    },
    // async getHospitalData() {
    //   try {
    //     // TODO: 替换为实际的医院列表接口
    //     // 暂时使用模拟数据
    //     this.hospitalList = [
    //       { hospitalNo: "H001", hospitalName: "北京协和医院" },
    //       { hospitalNo: "H002", hospitalName: "上海华山医院" },
    //       { hospitalNo: "H003", hospitalName: "上海瑞金医院" },
    //       { hospitalNo: "H004", hospitalName: "广州中山医院" },
    //       { hospitalNo: "H005", hospitalName: "武汉同济医院" },
    //       { hospitalNo: "H006", hospitalName: "成都华西医院" }
    //     ];
    //   } catch (error) {
    //     console.error("获取医院数据失败:", error);
    //     this.$message.error("获取医院数据失败");
    //   }
    // },
    // 器官选择状态变化
    handleOrganSelectionChange(selectedValues) {
      if (!this.utilizationData.serviceDonatecomporganList) {
        this.utilizationData.serviceDonatecomporganList = [];
      }
      const currentOrganValues = this.utilizationData.serviceDonatecomporganList.map(
        item => item.organno
      );
      // 处理互斥逻辑
    async handleOrganSelectionChange(selectedValues) {
      // 1. 处理互斥逻辑(修改 this.selectedOrgans)
      this.handleExclusiveSelections(selectedValues);
      // 更新捐献器官字段
      this.form.donateorgan = selectedValues.join(",");
      const finalSelected = this.selectedOrgans;
      const records = this.utilizationData.serviceDonatecomporganList || [];
      // 新增选择的器官
      selectedValues.forEach(organValue => {
        if (!currentOrganValues.includes(organValue)) {
          this.createOrganRecord(organValue);
      // 2. 构建目标器官编号列表(展开组合器官)
      const targetOrganNos = [];
      finalSelected.forEach(val => {
        if (this.organExpansionMap[val]) {
          targetOrganNos.push(...this.organExpansionMap[val].subItems);
        } else {
          targetOrganNos.push(val);
        }
      });
      // 移除取消选择的器官
      this.utilizationData.serviceDonatecomporganList = this.utilizationData.serviceDonatecomporganList.filter(
        record => {
          if (selectedValues.includes(record.organno)) {
            return true;
          } else {
            if (record.id) {
              this.$confirm(
                "删除器官利用数据后将无法恢复,您确认删除该条记录吗?",
                "提示",
                {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning"
                }
              )
                .then(() => {
                  this.utilizationData.serviceDonatecomporganList = this.utilizationData.serviceDonatecomporganList.filter(
                    r => r.organno !== record.organno
                  );
                  this.$message.success("删除成功");
                })
                .catch(() => {
                  this.selectedOrgans.push(record.organno);
                });
              return true;
            } else {
              return false;
            }
      // 3. 新增或恢复记录(无需弹窗)
      targetOrganNos.forEach(no => {
        const existing = records.find(r => r.organno === no);
        if (existing) {
          if (existing.delFlag === 1) {
            existing.delFlag = 0; // 恢复显示
          }
        } else {
          this.createOrganRecord(no); // 新增记录(包含 delFlag:0)
        }
      );
    },
      });
      // 4. 找出需要取消的记录(不在目标集合中的)
      const toRemove = records.filter(r => !targetOrganNos.includes(r.organno));
      const toRemoveSaved = toRemove.filter(r => r.id); // 已保存,需确认
      const toRemoveUnsaved = toRemove.filter(r => !r.id); // 未保存,直接移除
      // 4.1 直接移除未保存的记录
      toRemoveUnsaved.forEach(r => {
        const idx = records.indexOf(r);
        if (idx !== -1) records.splice(idx, 1);
      });
      // 4.2 处理已保存的记录:弹窗确认
      if (toRemoveSaved.length > 0) {
        const organNames = toRemoveSaved.map(r => r.organname).join("、");
        try {
          await this.$confirm(
            `您确定要取消以下已保存的器官利用记录吗?\n${organNames}\n取消后,这些记录将从列表中移除(数据仍保留,可恢复)。`,
            "提示",
            {
              confirmButtonText: "确定移除",
              cancelButtonText: "取消",
              type: "warning"
            }
          );
          // 用户确认:标记 delFlag=1
          toRemoveSaved.forEach(r => {
            r.delFlag = 1;
          });
        } catch (error) {
          // 用户取消:恢复选中状态
          // 将取消的器官重新加入 this.selectedOrgans
          const parentToRestore = new Set();
          toRemoveSaved.forEach(r => {
            const parent = this.organReverseMap[r.organno];
            if (parent) {
              parentToRestore.add(parent);
            } else {
              parentToRestore.add(r.organno);
            }
          });
          parentToRestore.forEach(val => {
            if (!this.selectedOrgans.includes(val)) {
              this.selectedOrgans.push(val);
            }
          });
          // 提示用户操作已取消
          this.$message.info("已取消删除操作");
          // 更新表单字段(保持一致性)
          this.form.donateorgan = this.selectedOrgans.join(",");
          // 注意:此时 records 中已新增了目标器官,并且之前的记录未被标记删除,状态一致。
          // 但是,我们还需要移除之前新增但用户可能不想保留的记录?不会,因为新增的是目标器官,用户是想保留的。
          // 因此直接返回即可。
          return;
        }
      }
      // 5. 更新表单字段
      this.form.donateorgan = this.selectedOrgans.join(",");
    },
    // 移植医院模糊搜索
    queryHospitalSearch(queryString, cb) {
      const hospitals = this.dict.type.Geta_hospital || [];
      const results = queryString
        ? hospitals.filter(item =>
            item.label.toLowerCase().includes(queryString.toLowerCase())
          )
        : hospitals;
      // el-autocomplete 需要 value 字段
      cb(results.map(item => ({ value: item.label })));
    },
    // 处理互斥选择
    handleExclusiveSelections(selectedValues) {
      // 如果选择了"双肾"(假设字典值为C64),自动取消单独的"左肾"(C64L)和"右肾"(C64R)选择
@@ -1047,6 +1083,7 @@
        transplanttime: "",
        transplantstate: "1",
        abandonreason: "",
        delFlag: 0, // 新增
        sex: "",
        age: "",
        birthday: "",
@@ -1074,16 +1111,6 @@
      return dictItem ? dictItem.label : organValue;
    },
    // 医院选择变化
    handleHospitalChange(row, hospitalNo) {
      const hospital = this.hospitalList.find(
        item => item.hospitalNo === hospitalNo
      );
      if (hospital) {
        row.hospitalname = hospital.hospitalName;
      }
    },
    // 移植状态变化处理
    handleTransplantStatusChange(row, status) {
      if (status === "0") {
@@ -1103,31 +1130,6 @@
    // 行展开事件
    handleExpandChange(row, expandedRows) {
      this.expandedRows = expandedRows.map(item => item.organno);
    },
    // 编辑利用记录
    handleEditUtilization(row) {
      const index = this.utilizationData.serviceDonatecomporganList.findIndex(
        item => item.organno === row.organno
      );
      if (index !== -1) {
        this.currentRecord = { ...row };
        this.currentEditIndex = index;
        this.editDialogVisible = true;
      }
    },
    // 确认编辑
    handleEditConfirm() {
      if (this.currentEditIndex !== -1) {
        this.utilizationData.serviceDonatecomporganList[
          this.currentEditIndex
        ] = {
          ...this.currentRecord
        };
        this.$message.success("利用记录更新成功");
        this.editDialogVisible = false;
      }
    },
    // 删除器官记录
@@ -1157,7 +1159,7 @@
    getOrganRowClassName({ row }) {
      if (
        row.transplantstate === "1" &&
        (!row.caseNo || !row.hospitalno || !row.name || !row.transplanttime)
        (!row.hospitalno || !row.name || !row.transplanttime)
      ) {
        return "warning-row";
      }
@@ -1170,9 +1172,9 @@
    // 获取状态标签类型
    getStatusTagType(status) {
      const typeMap = {
        completed: "success",
        processing: "warning",
        pending: "info"
        3: "success",
        2: "warning",
        1: "info"
      };
      return typeMap[status] || "info";
    },
@@ -1180,9 +1182,9 @@
    // 获取状态文本
    getStatusText(status) {
      const textMap = {
        completed: "已完成",
        processing: "进行中",
        pending: "待处理"
        3: "已完成",
        2: "进行中",
        1: "待处理"
      };
      return textMap[status] || "未知";
    },
@@ -1288,12 +1290,7 @@
      const incompleteRecords = this.utilizationData.serviceDonatecomporganList.filter(
        record => {
          if (record.transplantstate === "1") {
            return (
              !record.caseNo ||
              !record.hospitalno ||
              !record.name ||
              !record.transplanttime
            );
            return !record.hospitalno || !record.name || !record.transplanttime;
          } else if (record.transplantstate === "0") {
            return !record.abandonreason;
          }
@@ -1313,7 +1310,7 @@
      })
        .then(async () => {
          this.confirmLoading = true;
          this.form.recordstate = "completed";
          this.form.completeState = "3";
          this.form.completetime =
            this.form.completetime ||
            new Date()
@@ -1338,13 +1335,13 @@
              this.$message.error(
                "确认利用失败:" + (response.msg || "未知错误")
              );
              this.form.recordstate = "pending";
              this.form.completeState = "2";
              this.form.completetime = "";
            }
          } catch (error) {
            console.error("确认利用失败:", error);
            this.$message.error("确认利用失败");
            this.form.recordstate = "pending";
            this.form.completeState = "2";
            this.form.completetime = "";
          } finally {
            this.confirmLoading = false;
@@ -1426,11 +1423,13 @@
    /** 上传成功处理 */
    handleUploadSuccess({ file, fileList, response }) {
      if (response.code === 200) {
        // 根据当前激活的 Tab 决定分类(未分类 Tab 对应空字符串)
        const category = this.activeTab === "未分类" ? "" : this.activeTab;
        const attachmentObj = {
          fileName: file.name,
          path: response.fileUrl || file.url,
          fileUrl: response.fileUrl || file.url,
          fileType: this.getFileExtension(file.name),
          fileType: category, // 关键:记录分类
          fileSize: file.size,
          uploadTime: dayjs().format("YYYY-MM-DD HH:mm:ss")
        };
@@ -1438,13 +1437,71 @@
        if (!Array.isArray(this.attachments)) {
          this.attachments = [];
        }
        this.attachments.push(attachmentObj);
        this.attachmentFileList = fileList;
        this.attachmentFileList = fileList; // 保持同步
        this.$message.success("文件上传成功");
      }
    },
    // 获取某分类的文件数量
    getCategoryCount(category) {
      return this.attachments.filter(item => {
        const type = item.fileType || "";
        if (category === "未分类") {
          return !this.presetCategories.includes(type);
        }
        return type === category;
      }).length;
    },
    // 获取某分类的文件列表
    getCategoryFiles(category) {
      return this.attachments.filter(item => {
        const type = item.fileType || "";
        if (category === "未分类") {
          return !this.presetCategories.includes(type);
        }
        return type === category;
      });
    },
    // 更新附件分类(下拉修改时触发)
    updateAttachmentCategory(row, newVal) {
      const target = this.attachments.find(item => item === row);
      if (target) {
        target.fileType = newVal; // 可能为空字符串
        // 同步更新 attachmentFileList
        const fileItem = this.attachmentFileList.find(
          f => f.raw === row || f.url === row.fileUrl
        );
        if (fileItem) {
          fileItem.raw.fileType = newVal;
          fileItem.fileType = newVal || "未分类";
        }
        // 如果当前激活的tab没有文件了,自动切换到第一个有文件的tab
        const currentTabHasFiles =
          this.getCategoryFiles(this.activeTab).length > 0;
        if (!currentTabHasFiles) {
          const firstCategory = this.categories[0];
          if (firstCategory) this.activeTab = firstCategory;
        }
      }
    },
    // 按文件对象删除(用于表格中的删除按钮)
    handleRemoveAttachmentByFile(file) {
      const index = this.attachments.findIndex(item => item === file);
      if (index > -1) {
        this.attachments.splice(index, 1);
        // 同步删除 attachmentFileList
        const fileIndex = this.attachmentFileList.findIndex(
          f => f.raw === file || f.url === file.fileUrl
        );
        if (fileIndex > -1) {
          this.attachmentFileList.splice(fileIndex, 1);
        }
        this.$message.success("附件删除成功");
      }
    },
    /** 上传错误处理 */
    handleUploadError({ file, fileList, error }) {
      console.error("附件上传失败:", error);
@@ -1453,9 +1510,8 @@
    /** 手动删除附件 */
    handleRemoveAttachment(index) {
      this.attachments.splice(index, 1);
      this.attachmentFileList.splice(index, 1);
      this.$message.success("附件删除成功");
      // 直接调用新的删除方法
      this.handleRemoveAttachmentByFile(file.raw || file);
    },
    /** 文件预览 */
@@ -1864,6 +1920,7 @@
  .recipient-form {
    padding: 15px;
  }
  .attachment-header {
    flex-wrap: wrap;
  }
@@ -1873,6 +1930,7 @@
    margin-top: 8px;
    margin-left: 0;
  }
  .form-section {
    margin-bottom: 20px;
    padding-bottom: 15px;