WXL
2026-05-17 3453ba7e5243022ad4388da1515dc75ad8d81f94
src/views/business/course/components/OrganUtilizationStage.vue
@@ -1,812 +1,1851 @@
<template>
  <base-stage :stage-data="stageData" :case-info="caseInfo">
    <!-- 头部警告信息 -->
    <template #header>
      <el-alert
        :title="`器官利用 - ${getStatusText()}`"
        :type="getAlertType()"
        :description="getAlertDescription()"
        show-icon
        :closable="false"
      />
    </template>
  <div class="organ-utilization-detail">
    <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>
    <!-- 统计概览行 -->
    <el-row :gutter="20" style="margin-top: 20px;">
      <el-col :span="6">
        <el-card>
          <div slot="header" class="card-header">
            <span>利用概况</span>
          </div>
          <div class="utilization-overview">
            <div class="overview-item">
              <div class="overview-icon" style="color: #67C23A;">
                <i class="el-icon-success"></i>
              </div>
              <div class="overview-content">
                <div class="value">{{ utilizationStats.transplanted }}</div>
                <div class="label">已移植器官</div>
              </div>
            </div>
            <div class="overview-item">
              <div class="overview-icon" style="color: #E6A23C;">
                <i class="el-icon-time"></i>
              </div>
              <div class="overview-content">
                <div class="value">{{ utilizationStats.inProgress }}</div>
                <div class="label">移植中</div>
              </div>
            </div>
            <div class="overview-item">
              <div class="overview-icon" style="color: #F56C6C;">
                <i class="el-icon-warning"></i>
              </div>
              <div class="overview-content">
                <div class="value">{{ utilizationStats.failed }}</div>
                <div class="label">移植失败</div>
              </div>
            </div>
          </div>
        </el-card>
      </el-col>
        </div>
      <el-col :span="6">
        <el-card>
          <div slot="header" class="card-header">
            <span>成功率统计</span>
          </div>
          <div class="success-stats">
            <div class="success-item">
              <span class="label">移植成功率:</span>
              <el-progress
                :percentage="utilizationStats.successRate"
                :status="utilizationStats.successRate > 85 ? 'success' : 'warning'"
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="负责人" prop="responsibleusername">
              <el-input
                v-model="form.responsibleusername"
                placeholder="请输入负责人姓名"
              />
            </div>
            <div class="success-item">
              <span class="label">器官利用率:</span>
              <el-progress
                :percentage="utilizationStats.utilizationRate"
                status="success"
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="协调员一" prop="coordinatedusernameo">
              <el-input
                v-model="form.coordinatedusernameo"
                placeholder="请输入协调员一姓名"
              />
            </div>
            <div class="success-item">
              <span class="label">患者存活率:</span>
              <el-progress
                :percentage="utilizationStats.survivalRate"
                status="success"
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="协调员二" prop="coordinatedusernamet">
              <el-input
                v-model="form.coordinatedusernamet"
                placeholder="请输入协调员二姓名"
              />
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card>
          <div slot="header" class="card-header">
            <span>时间跟踪</span>
          </div>
          <div class="time-tracking">
            <div class="time-item">
              <span class="label">获取到移植:</span>
              <span class="value">{{ timeTracking.procurementToTransplant }}</span>
            </div>
            <div class="time-item">
              <span class="label">冷缺血时间:</span>
              <span class="value">{{ timeTracking.coldIschemiaTime }}</span>
            </div>
            <div class="time-item">
              <span class="label">手术时长:</span>
              <span class="value">{{ timeTracking.surgeryDuration }}</span>
            </div>
            <div class="time-item">
              <span class="label">ICU停留:</span>
              <span class="value">{{ timeTracking.icuStay }}</span>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="6">
        <el-card>
          <div slot="header" class="card-header">
            <span>质量评估</span>
          </div>
          <div class="quality-assessment">
            <div class="quality-item">
              <span class="label">器官质量评分:</span>
              <el-rate
                v-model="qualityStats.organQuality"
                disabled
                show-score
                text-color="#ff9900"
                score-template="{value}"
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="完成时间" prop="completetime">
              <el-date-picker
                v-model="form.completetime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%"
              />
            </div>
            <div class="quality-item">
              <span class="label">手术质量:</span>
              <el-rate
                v-model="qualityStats.surgeryQuality"
                disabled
                show-score
                text-color="#ff9900"
                score-template="{value}"
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="登记人" prop="createBy">
              <el-input v-model="form.createBy" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="登记时间" prop="createTime">
              <el-date-picker
                v-model="form.createTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%"
              />
            </div>
            <div class="quality-item">
              <span class="label">随访完成率:</span>
              <el-progress
                :percentage="qualityStats.followupCompletionRate"
                status="success"
            </el-form-item>
          </el-col>
        </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="18" v-if="form.isbodydonation == 1">
            <el-form-item
              align="left"
              label="接收单位"
              prop="receivingunitname"
            >
              <el-input
                v-model="form.receivingunitname"
                placeholder="请输入接收单位"
              />
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <!-- 数据可视化部分 -->
    <el-row :gutter="20" style="margin-top: 20px;">
      <!-- 器官利用分布图 -->
      <el-col :span="12">
        <el-card>
          <div slot="header" class="card-header">
            <span>器官利用分布</span>
            <el-radio-group v-model="chartView" size="small" @change="updateCharts">
              <el-radio-button label="bar">柱状图</el-radio-button>
              <el-radio-button label="pie">饼图</el-radio-button>
            </el-radio-group>
          </div>
          <div class="chart-container">
            <div ref="organDistributionChart" style="width: 100%; height: 300px;"></div>
          </div>
        </el-card>
      </el-col>
      <!-- 成功率趋势图 -->
      <el-col :span="12">
        <el-card>
          <div slot="header" class="card-header">
            <span>移植成功率趋势</span>
          </div>
          <div class="chart-container">
            <div ref="successTrendChart" style="width: 100%; height: 300px;"></div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <el-row :gutter="20" style="margin-top: 20px;">
      <!-- 随访数据统计 -->
      <el-col :span="12">
        <el-card>
          <div slot="header" class="card-header">
            <span>随访数据统计</span>
          </div>
          <div class="chart-container">
            <div ref="followupStatsChart" style="width: 100%; height: 300px;"></div>
          </div>
        </el-card>
      </el-col>
      <!-- 并发症分析 -->
      <el-col :span="12">
        <el-card>
          <div slot="header" class="card-header">
            <span>并发症分析</span>
          </div>
          <div class="chart-container">
            <div ref="complicationChart" style="width: 100%; height: 300px;"></div>
          </div>
        </el-card>
      </el-col>
    </el-row>
    <!-- 详细数据表格 -->
    <el-card style="margin-top: 20px;">
      <div slot="header" class="card-header">
        <span>器官利用详情</span>
        <el-button type="primary" size="small" @click="exportData">
          导出数据
        </el-button>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-else>
            <el-form-item align="left" label="接收家属" prop="relationname">
              <el-input
                v-model="form.relationname"
                placeholder="请输入接收家属"
              />
            </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;">
          <dict-tag
            :options="dict.type.utilize_statue"
            :value="form.completeState"
          />
        </div>
      </div>
      <el-table :data="organUtilizationData" v-loading="loading" border>
        <el-table-column label="器官名称" prop="organName" width="120" align="center" />
        <el-table-column label="移植状态" width="100" align="center">
          <template slot-scope="scope">
            <el-tag :type="getTransplantStatusTag(scope.row.status)">
              {{ scope.row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="受体信息" width="150">
          <template slot-scope="scope">
            <div>{{ scope.row.recipientName }}</div>
            <div style="font-size: 12px; color: #909399;">{{ scope.row.recipientAge }}岁/{{ scope.row.recipientGender }}</div>
          </template>
        </el-table-column>
        <el-table-column label="移植医院" prop="hospital" min-width="180" />
        <el-table-column label="移植时间" width="160" align="center">
          <template slot-scope="scope">
            {{ formatTime(scope.row.transplantTime) }}
          </template>
        </el-table-column>
        <el-table-column label="随访次数" width="100" align="center">
          <template slot-scope="scope">
            <el-tag :type="scope.row.followupCount > 0 ? 'success' : 'info'">
              {{ scope.row.followupCount }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="当前状态" width="120" align="center">
          <template slot-scope="scope">
            <el-tag :type="getRecipientStatusTag(scope.row.recipientStatus)">
              {{ scope.row.recipientStatus }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="150" align="center">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleViewDetails(scope.row)">
              查看详情
            </el-button>
            <el-button type="text" size="small" @click="handleAddFollowup(scope.row)">
              添加随访
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-form
        ref="utilizationForm"
        :rules="utilizationRules"
        :model="utilizationData"
        label-position="right"
      >
        <el-row>
          <el-col>
            <el-form-item label-width="100px" label="移植器官">
              <el-checkbox-group
                v-model="selectedOrgans"
                @change="handleOrganSelectionChange"
              >
                <el-checkbox
                  v-for="dict in dict.type.sys_Organ || []"
                  :key="dict.value"
                  :label="dict.value"
                >
                  {{ dict.label }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item>
              <el-table
                :data="utilizationData.serviceDonatecomporganList"
                v-loading="loading"
                border
                style="width: 100%"
                :row-class-name="getOrganRowClassName"
                :expand-row-keys="expandedRows"
                @expand-change="handleExpandChange"
                row-key="organno"
              >
                <el-table-column type="expand" width="60">
                  <template slot-scope="scope">
                    <!-- 展开行内容 - 受者详细信息 -->
                    <div class="recipient-detail-expand">
                      <div class="recipient-header">
                        <span class="recipient-title">受者详细信息</span>
                        <el-tag
                          v-if="scope.row.transplantstate === '1'"
                          type="success"
                          size="small"
                        >
                          已移植
                        </el-tag>
                        <el-tag
                          v-else-if="scope.row.transplantstate === '0'"
                          type="warning"
                          size="small"
                        >
                          未移植
                        </el-tag>
                        <el-tag v-else type="info" size="small">
                          移植中
                        </el-tag>
                      </div>
                      <el-form
                        :model="scope.row"
                        label-width="140px"
                        class="recipient-form"
                      >
                        <!-- 基本信息部分 -->
                        <div class="form-section">
                          <h4 class="section-title">基本信息</h4>
                          <el-row :gutter="20">
                            <el-col :span="8">
                              <el-form-item label="受者姓名">
                                <el-input
                                  v-model="scope.row.name"
                                  placeholder="请输入受者姓名"
                                />
                              </el-form-item>
                            </el-col>
                            <el-col :span="8">
                              <el-form-item label="出生日期">
                                <el-date-picker
                                  v-model="scope.row.birthday"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  placeholder="选择出生日期"
                                  style="width: 100%"
                                />
                              </el-form-item>
                            </el-col>
                            <el-col :span="8">
                              <el-form-item label="性别">
                                <el-select
                                  v-model="scope.row.sex"
                                  placeholder="请选择性别"
                                  style="width: 100%"
                                >
                                  <el-option label="男" :value="0" />
                                  <el-option label="女" :value="1" />
                                </el-select>
                              </el-form-item>
                            </el-col>
                          </el-row>
                          <el-row :gutter="20">
                            <el-col :span="8">
                              <el-form-item label="年龄">
                                <el-input
                                  v-model="scope.row.age"
                                  placeholder="年龄"
                                />
                              </el-form-item>
                            </el-col>
                            <el-col :span="8">
                              <el-form-item label="证件类型">
                                <el-select
                                  v-model="scope.row.idcardtype"
                                  placeholder="请选择证件类型"
                                  style="width: 100%"
                                >
                                  <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>
                            <el-col :span="8">
                              <el-form-item label="证件号码">
                                <el-input
                                  v-model="scope.row.idcardno"
                                  placeholder="证件号码"
                                />
                              </el-form-item>
                            </el-col>
                          </el-row>
                        </div>
                        <!-- 联系信息部分 -->
                        <div class="form-section">
                          <h4 class="section-title">联系信息</h4>
                          <el-row :gutter="20">
                            <el-col :span="12">
                              <el-form-item label="移植中心名称">
                                <el-input
                                  v-model="scope.row.hospitalname"
                                  placeholder="请输入移植中心名称"
                                />
                              </el-form-item>
                            </el-col>
                            <el-col :span="12">
                              <el-form-item label="联系电话">
                                <el-input
                                  v-model="scope.row.phone"
                                  placeholder="联系电话"
                                />
                              </el-form-item>
                            </el-col>
                          </el-row>
                          <el-row :gutter="20">
                            <el-col :span="24">
                              <el-form-item label="现住地址">
                                <el-input
                                  type="textarea"
                                  :rows="2"
                                  v-model="scope.row.residenceaddress"
                                  placeholder="请输入详细地址"
                                />
                              </el-form-item>
                            </el-col>
                          </el-row>
                        </div>
                        <!-- 移植信息部分 -->
                        <div
                          class="form-section"
                          v-if="scope.row.transplantstate === '1'"
                        >
                          <h4 class="section-title">移植信息</h4>
                          <el-row :gutter="20">
                            <el-col :span="12">
                              <el-form-item label="移植时间">
                                <el-date-picker
                                  v-model="scope.row.transplanttime"
                                  type="datetime"
                                  value-format="yyyy-MM-dd HH:mm:ss"
                                  placeholder="选择移植日期"
                                  style="width: 100%"
                                />
                              </el-form-item>
                            </el-col>
                            <el-col :span="12">
                              <el-form-item label="移植医生">
                                <el-input
                                  v-model="scope.row.transplantdoct"
                                  placeholder="请输入移植医生"
                                />
                              </el-form-item>
                            </el-col>
                          </el-row>
                        </div>
                        <!-- 未移植原因 -->
                        <div
                          class="form-section"
                          v-if="scope.row.transplantstate === '0'"
                        >
                          <h4 class="section-title">未移植信息</h4>
                          <el-row :gutter="20">
                            <el-col :span="24">
                              <el-form-item label="未移植原因">
                                <el-input
                                  type="textarea"
                                  :rows="3"
                                  v-model="scope.row.abandonreason"
                                  placeholder="请输入未移植原因"
                                />
                              </el-form-item>
                            </el-col>
                          </el-row>
                        </div>
                      </el-form>
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  label="器官名称"
                  align="center"
                  prop="organname"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.organname"
                      placeholder="器官名称"
                      :disabled="true"
                    />
                  </template>
                </el-table-column>
                <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
                  label="移植医院"
                  align="center"
                  width="260"
                  prop="hospitalno"
                >
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.hospitalno"
                      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>
                  </template>
                </el-table-column>
                <el-table-column
                  label="移植状态"
                  align="center"
                  prop="transplantstate"
                >
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.transplantstate"
                      placeholder="请选择移植状态"
                      style="width: 100%"
                      @change="handleTransplantStatusChange(scope.row, $event)"
                    >
                      <el-option
                        v-for="dict in transplantStatusList"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      />
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column
                  label="移植时间"
                  align="center"
                  width="220"
                  prop="transplanttime"
                >
                  <template slot-scope="scope">
                    <el-date-picker
                      clearable
                      size="small"
                      style="width: 100%"
                      v-model="scope.row.transplanttime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择移植时间"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="移植医生"
                  align="center"
                  prop="transplantdoct"
                >
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.transplantdoct"
                      placeholder="医师姓名"
                    />
                  </template>
                </el-table-column>
                <el-table-column label="受者姓名" align="center" prop="name">
                  <template slot-scope="scope">
                    <el-input v-model="scope.row.name" placeholder="受者姓名" />
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 统计信息 -->
        <div
          v-if="
            !utilizationData.serviceDonatecomporganList ||
              utilizationData.serviceDonatecomporganList.length == 0
          "
          class="empty-utilization"
        >
          <el-empty description="暂无利用记录" :image-size="80">
            <span>请先选择要利用的器官</span>
          </el-empty>
        </div>
      </el-form>
    </el-card>
    <!-- 行动按钮 -->
    <template #footer>
      <div class="action-buttons" style="margin-top: 20px; text-align: center;">
        <el-button type="primary" @click="handleGenerateReport">
          生成利用报告
        </el-button>
        <el-button type="success" @click="handleCompleteUtilization">
          完成器官利用
        </el-button>
        <el-button type="warning" @click="handleStatistics">
          统计数据分析
        </el-button>
    <!-- 附件管理部分 -->
    <!-- 附件管理部分 - 优化为完整功能 -->
    <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>
    </template>
  </base-stage>
      <!-- 使用 UploadAttachment 组件 -->
      <UploadAttachment
        ref="uploadAttachment"
        :file-list="attachmentFileList"
        :limit="attachmentLimit"
        :accept="attachmentAccept"
        :multiple="true"
        @change="handleAttachmentChange"
        @upload-success="handleUploadSuccess"
        @upload-error="handleUploadError"
        @remove="handleAttachmentRemove"
      />
      <!-- 附件列表展示 -->
      <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>
      </div>
    </el-card>
    <!-- 文件预览对话框 -->
    <FilePreviewDialog
      :visible="filePreviewVisible"
      :file="currentPreviewFile"
      @close="filePreviewVisible = false"
      @download="handleDownloadAttachment"
    />
  </div>
</template>
<script>
import BaseStage from './BaseStage.vue';
import * as echarts from 'echarts';
import {
  completionList,
  completionadd,
  completionedit
} from "@/api/businessApi";
import UploadAttachment from "@/components/UploadAttachment"; // 新增导入
import FilePreviewDialog from "@/components/FilePreviewDialog"; // 新增导入
import CaseBasicInfo from "@/components/CaseBasicInfo";
import dayjs from "dayjs"; // 新增导入,用于时间处理
export default {
  name: 'OrganUtilizationStage',
  components: { BaseStage },
  props: {
    stageData: {
      type: Object,
      default: () => ({})
    },
    caseInfo: {
      type: Object,
      default: () => ({})
  name: "OrganUtilizationDetail",
  components: {
    UploadAttachment,
    FilePreviewDialog,
    CaseBasicInfo
  },
  dicts: ["sys_BloodType", "sys_Organ", "sys_0_1", "utilize_statue"],
    props: {
    infoid: {
      type: String,
      default: true
    }
  },
  data() {
    return {
      chartView: 'bar',
      caseId: null,
      // 表单数据 - 根据接口参数调整
      form: {
        id: undefined,
        infoid: undefined,
        inpatientno: "",
        completeState: "2",
        caseNo: "",
        donorno: "",
        treatmenthospitalname: "",
        treatmenthospitalno: "",
        sex: "",
        name: "",
        age: "",
        bloodtype: "",
        idcardno: "",
        diagnosisname: "",
        completetime: "",
        responsibleuserid: "",
        responsibleusername: "",
        coordinateduserido: "",
        coordinatedusernameo: "",
        coordinateduseridt: "",
        coordinatedusernamet: "",
        assessannex: "",
        donateorgan: "",
        isbodydonation: "0",
        receivingunitname: "",
        createBy: "",
        createTime: "",
        updateBy: "",
        updateTime: "",
        attachments: []
      },
      // 表单验证规则
      rules: {
        name: [
          { required: true, message: "捐献者姓名不能为空", trigger: "blur" }
        ],
        diagnosisname: [
          { required: true, message: "疾病诊断不能为空", trigger: "blur" }
        ],
        donorno: [
          { required: true, message: "捐献者编号不能为空", trigger: "blur" }
        ]
      },
      // 利用记录验证规则
      utilizationRules: {},
      // 保存加载状态
      saveLoading: false,
      confirmLoading: false,
      // 加载状态
      loading: false,
      utilizationStats: {
        transplanted: 3,
        inProgress: 0,
        failed: 0,
        successRate: 95,
        utilizationRate: 100,
        survivalRate: 92
      },
      timeTracking: {
        procurementToTransplant: '4.5小时',
        coldIschemiaTime: '肝脏:6h,肾脏:8h,心脏:3h',
        surgeryDuration: '肝脏:4h,肾脏:3h,心脏:5h',
        icuStay: '肝脏:3天,肾脏:2天,心脏:5天'
      },
      qualityStats: {
        organQuality: 4.5,
        surgeryQuality: 4.8,
        followupCompletionRate: 85
      },
      organUtilizationData: [
        {
          organName: '肝脏',
          status: '移植成功',
          recipientName: '王先生',
          recipientAge: 45,
          recipientGender: '男',
          hospital: '北京协和医院移植中心',
          transplantTime: '2025-12-04 16:00:00',
          followupCount: 3,
          recipientStatus: '恢复良好'
        },
        {
          organName: '肾脏',
          status: '移植成功',
          recipientName: '李女士',
          recipientAge: 38,
          recipientGender: '女',
          hospital: '上海瑞金医院移植中心',
          transplantTime: '2025-12-04 17:30:00',
          followupCount: 2,
          recipientStatus: '稳定恢复'
        },
        {
          organName: '心脏',
          status: '移植成功',
          recipientName: '陈先生',
          recipientAge: 52,
          recipientGender: '男',
          hospital: '广州中山医院心脏中心',
          transplantTime: '2025-12-04 18:15:00',
          followupCount: 1,
          recipientStatus: '密切观察'
        }
      // 选中的器官
      selectedOrgans: [],
      // 医院列表
      hospitalList: [],
      // 移植状态列表
      transplantStatusList: [
        { value: "1", label: "已移植" },
        { value: "0", label: "未移植" },
        { value: "2", label: "移植中" }
      ],
      // 图表实例
      organDistributionChart: null,
      successTrendChart: null,
      followupStatsChart: null,
      complicationChart: null
      // 利用记录数据
      utilizationData: {
        serviceDonatecomporganList: []
      },
      // 随访记录数据
      followupData: {
        records: []
      },
      // 附件数据
      attachments: [],
      // 展开的行keys
      expandedRows: [],
      // 编辑对话框
      editDialogVisible: false,
      currentRecord: {},
      currentEditIndex: -1,
      // 附件相关配置 - 新增
      attachmentFileList: [],
      attachmentLimit: 10,
      attachmentAccept:
        ".pdf,.jpg,.jpeg,.png,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt",
      // 文件预览相关 - 新增
      filePreviewVisible: false,
      currentPreviewFile: null,
      currentFollowup: {},
      isEditingFollowup: false
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initCharts();
    });
  computed: {
    // 当前用户信息
    currentUser() {
      return JSON.parse(sessionStorage.getItem("user") || "{}");
    },
    // 已移植数量
    transplantedCount() {
      if (!this.utilizationData.serviceDonatecomporganList) return 0;
      return this.utilizationData.serviceDonatecomporganList.filter(
        record => record.transplantstate === "1"
      ).length;
    },
    // 唯一医院数量
    uniqueHospitals() {
      if (!this.utilizationData.serviceDonatecomporganList) return 0;
      const hospitals = this.utilizationData.serviceDonatecomporganList
        .map(record => record.hospitalno)
        .filter(Boolean);
      return new Set(hospitals).size;
    },
    // 获取器官字典
    organDict() {
      return this.dict.type.sys_Organ || [];
    }
  },
  beforeDestroy() {
    // 销毁图表实例
    if (this.organDistributionChart) {
      this.organDistributionChart.dispose();
    }
    if (this.successTrendChart) {
      this.successTrendChart.dispose();
    }
    if (this.followupStatsChart) {
      this.followupStatsChart.dispose();
    }
    if (this.complicationChart) {
      this.complicationChart.dispose();
  created() {
    this.initData();
  },
  watch: {
    // 监听附件数据变化 - 新增
    attachments: {
      handler(newAttachments) {
        this.attachmentFileList = newAttachments.map(item => ({
          uid: item.id || Math.random(),
          name: item.fileName,
          fileSize: item.fileSize,
          url: item.path || item.fileUrl,
          uploadTime: item.uploadTime,
          status: "success"
        }));
      },
      deep: true
    }
  },
  methods: {
    // 初始化图表
    initCharts() {
      this.initOrganDistributionChart();
      this.initSuccessTrendChart();
      this.initFollowupStatsChart();
      this.initComplicationChart();
    // 初始化数据
    initData() {
      this.caseId = this.infoid;
      if (!this.caseId) {
        this.$message.error("缺少必要的路由参数 infoid");
        this.$router.back();
        return;
      }
      this.form.infoid = this.caseId;
      this.form.createBy =
        this.currentUser.username || this.currentUser.name || "当前用户";
      this.form.createTime = new Date()
        .toISOString()
        .replace("T", " ")
        .substring(0, 19);
      this.generateDonorNo();
      this.getDetail();
      this.getHospitalData();
    },
    // 初始化器官分布图表
    initOrganDistributionChart() {
      this.organDistributionChart = echarts.init(this.$refs.organDistributionChart);
      const option = {
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        legend: {
          orient: 'vertical',
          right: 10,
          top: 'center',
          data: ['肝脏', '肾脏', '心脏', '肺脏', '角膜', '其他']
        },
        series: [
          {
            name: '器官利用',
            type: 'pie',
            radius: ['50%', '70%'],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: '18',
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: [
              { value: 35, name: '肝脏' },
              { value: 30, name: '肾脏' },
              { value: 15, name: '心脏' },
              { value: 10, name: '肺脏' },
              { value: 8, name: '角膜' },
              { value: 2, name: '其他' }
            ]
          }
        ]
      };
      this.organDistributionChart.setOption(option);
    // 生成捐献者编号
    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);
    },
    // 初始化成功率趋势图表
    initSuccessTrendChart() {
      this.successTrendChart = echarts.init(this.$refs.successTrendChart);
      const option = {
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['肝脏移植', '肾脏移植', '心脏移植', '平均成功率']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月']
        },
        yAxis: {
          type: 'value',
          min: 80,
          max: 100
        },
        series: [
          {
            name: '肝脏移植',
            type: 'line',
            smooth: true,
            data: [92, 93, 94, 95, 96, 95, 96]
          },
          {
            name: '肾脏移植',
            type: 'line',
            smooth: true,
            data: [94, 95, 95, 96, 95, 96, 97]
          },
          {
            name: '心脏移植',
            type: 'line',
            smooth: true,
            data: [88, 89, 90, 91, 92, 91, 92]
          },
          {
            name: '平均成功率',
            type: 'line',
            smooth: true,
            lineStyle: {
              type: 'dashed'
            },
            data: [91.3, 92.3, 93, 94, 94.3, 94, 95]
    // 获取详情
    async getDetail() {
      this.loading = true;
      try {
        const response = await completionList({ infoid: this.caseId });
        if (
          response.code === 200 &&
          response.data &&
          response.data.length > 0
        ) {
          const data = response.data[0];
          if (!data.completeState || data.completeState == 1) {
            data.completeState = "2";
          }
        ]
      };
      this.successTrendChart.setOption(option);
    },
          // 填充表单数据
          Object.assign(this.form, data);
    // 初始化随访统计图表
    initFollowupStatsChart() {
      this.followupStatsChart = echarts.init(this.$refs.followupStatsChart);
      const option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          // 处理捐献器官字段
          if (data.donateorgan) {
            const organArray = Array.isArray(data.donateorgan)
              ? data.donateorgan
              : (data.donateorgan || "").split(",").filter(item => item);
            this.selectedOrgans = organArray;
          }
        },
        legend: {
          data: ['计划随访', '已完成', '逾期未完成']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'value'
        },
        yAxis: {
          type: 'category',
          data: ['1个月', '3个月', '6个月', '1年', '2年', '5年']
        },
        series: [
          {
            name: '计划随访',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            data: [120, 132, 101, 134, 90, 60]
          },
          {
            name: '已完成',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            data: [115, 125, 95, 120, 85, 55]
          },
          {
            name: '逾期未完成',
            type: 'bar',
            stack: 'total',
            label: {
              show: true
            },
            emphasis: {
              focus: 'series'
            },
            data: [5, 7, 6, 14, 5, 5]
          }
        ]
      };
      this.followupStatsChart.setOption(option);
    },
    // 初始化并发症分析图表
    initComplicationChart() {
      this.complicationChart = echarts.init(this.$refs.complicationChart);
      const option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          // 处理器官利用记录
          if (data.serviceDonatecomporganList) {
            this.utilizationData.serviceDonatecomporganList = Array.isArray(
              data.serviceDonatecomporganList
            )
              ? data.serviceDonatecomporganList.map(record => ({
                  ...record,
                  transplanttime: record.transplanttime || "",
                  transplantstate: record.transplantstate
                    ? record.transplantstate.toString()
                    : "1"
                }))
              : [];
          }
        },
        radar: {
          indicator: [
            { name: '感染风险', max: 100 },
            { name: '排斥反应', max: 100 },
            { name: '血管并发症', max: 100 },
            { name: '胆道并发症', max: 100 },
            { name: '代谢异常', max: 100 },
            { name: '其他并发症', max: 100 }
          ]
        },
        series: [
          {
            type: 'radar',
            data: [
              {
                value: [85, 90, 78, 82, 75, 70],
                name: '肝脏移植',
                areaStyle: {}
              },
              {
                value: [78, 85, 72, 65, 80, 68],
                name: '肾脏移植',
                areaStyle: {}
              },
              {
                value: [90, 88, 85, 60, 82, 75],
                name: '心脏移植',
                areaStyle: {}
              }
            ]
          }
        ]
      };
      this.complicationChart.setOption(option);
    },
          console.log(this.utilizationData.serviceDonatecomporganList);
    // 更新图表视图
    updateCharts() {
      if (this.chartView === 'bar') {
        this.updateToBarChart();
      } else {
        this.initOrganDistributionChart(); // 切回饼图
          // 初始化附件
          if (this.form.assessannex) {
            this.form.attachments = JSON.parse(this.form.assessannex);
            this.attachments = Array.isArray(this.form.attachments)
              ? [...this.form.attachments]
              : [];
          }
          this.$message.success("数据加载成功");
        } else {
          this.$message.warning("未找到对应的器官利用数据");
        }
      } catch (error) {
        console.error("获取器官利用详情失败:", error);
        this.$message.error("获取详情失败");
      } finally {
        this.loading = false;
      }
    },
    // 更新为柱状图
    updateToBarChart() {
      const option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          data: ['肝脏', '肾脏', '心脏', '肺脏', '角膜', '其他']
        },
        yAxis: {
          type: 'value',
          name: '数量'
        },
        series: [
          {
            name: '器官利用数量',
            type: 'bar',
            data: [35, 30, 15, 10, 8, 2],
            itemStyle: {
              color: function(params) {
                const colorList = ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272'];
                return colorList[params.dataIndex];
              }
    // 获取医院数据
    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
      );
      // 处理互斥逻辑
      this.handleExclusiveSelections(selectedValues);
      // 更新捐献器官字段
      this.form.donateorgan = selectedValues.join(",");
      // 新增选择的器官
      selectedValues.forEach(organValue => {
        if (!currentOrganValues.includes(organValue)) {
          this.createOrganRecord(organValue);
        }
      });
      // 移除取消选择的器官
      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;
            }
          }
        ]
      };
      this.organDistributionChart.setOption(option);
        }
      );
    },
    // 获取状态文本
    getStatusText() {
      const status = this.stageData.status;
      return status === 'completed' ? '已完成' :
             status === 'in_progress' ? '进行中' : '未开始';
    },
    // 获取警告类型
    getAlertType() {
      const status = this.stageData.status;
      return status === 'completed' ? 'success' :
             status === 'in_progress' ? 'warning' : 'info';
    },
    // 获取警告描述
    getAlertDescription() {
      const status = this.stageData.status;
      if (status === 'completed') {
        return '器官利用阶段已完成,所有器官均已成功移植并开始随访';
      } else if (status === 'in_progress') {
        return '器官利用进行中,移植手术已完成,正在进行术后随访';
    // 处理互斥选择
    handleExclusiveSelections(selectedValues) {
      // 如果选择了"双肾"(假设字典值为C64),自动取消单独的"左肾"(C64L)和"右肾"(C64R)选择
      if (selectedValues.includes("C64")) {
        this.selectedOrgans = selectedValues.filter(
          item => item !== "C64L" && item !== "C64R"
        );
      }
      return '等待开始器官利用流程';
      // 如果选择了"左肾"或"右肾",取消"双肾"选择
      else if (
        selectedValues.includes("C64L") ||
        selectedValues.includes("C64R")
      ) {
        this.selectedOrgans = selectedValues.filter(item => item !== "C64");
      }
      // 如果选择了"全肺"(假设字典值为C34),自动取消单独的"左肺"(C34L)和"右肺"(C34R)选择
      if (selectedValues.includes("C34")) {
        this.selectedOrgans = selectedValues.filter(
          item => item !== "C34L" && item !== "C34R"
        );
      }
      // 如果选择了"左肺"或"右肺",取消"全肺"选择
      else if (
        selectedValues.includes("C34L") ||
        selectedValues.includes("C34R")
      ) {
        this.selectedOrgans = selectedValues.filter(item => item !== "C34");
      }
    },
    // 获取移植状态标签
    getTransplantStatusTag(status) {
      const map = {
        '移植成功': 'success',
        '移植中': 'warning',
        '移植失败': 'danger'
      };
      return map[status] || 'info';
    },
    // 创建器官记录
    createOrganRecord(organValue) {
      const organName = this.getOrganLabel(organValue);
    // 获取受体状态标签
    getRecipientStatusTag(status) {
      const map = {
        '恢复良好': 'success',
        '稳定恢复': 'warning',
        '密切观察': 'danger'
      };
      return map[status] || 'info';
    },
    // 查看详情
    handleViewDetails(row) {
      this.$message.info(`查看${row.organName}移植详情`);
    },
    // 添加随访
    handleAddFollowup(row) {
      this.$message.info(`为${row.recipientName}添加随访记录`);
    },
    // 生成报告
    handleGenerateReport() {
      this.$message.info('生成器官利用分析报告');
    },
    // 完成利用
    handleCompleteUtilization() {
      this.$confirm('确认完成器官利用阶段吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'success'
      }).then(() => {
        this.$message.success('器官利用阶段已完成');
      this.utilizationData.serviceDonatecomporganList.push({
        organname: organName,
        organno: organValue,
        caseNo: "",
        hospitalno: "",
        hospitalname: "",
        name: "",
        transplantdoct: "",
        transplanttime: "",
        transplantstate: "1",
        abandonreason: "",
        sex: "",
        age: "",
        birthday: "",
        phone: "",
        residenceaddress: "",
        residenceprovince: "",
        residenceprovincename: "",
        residencecity: "",
        residencecityname: "",
        residencetown: "",
        residencetownname: "",
        residencecommunity: "",
        residencecommunityname: "",
        residencecountycode: "",
        residencecountyname: "",
        idcardtype: "",
        idcardno: "",
        ageunit: ""
      });
    },
    // 统计数据分析
    handleStatistics() {
      this.$message.info('打开统计分析面板');
    // 根据字典value获取label
    getOrganLabel(organValue) {
      const dictItem = this.organDict.find(item => item.value === organValue);
      return dictItem ? dictItem.label : organValue;
    },
    // 导出数据
    exportData() {
      this.$message.info('导出器官利用数据');
    // 医院选择变化
    handleHospitalChange(row, hospitalNo) {
      const hospital = this.hospitalList.find(
        item => item.hospitalNo === hospitalNo
      );
      if (hospital) {
        row.hospitalname = hospital.hospitalName;
      }
    },
    // 移植状态变化处理
    handleTransplantStatusChange(row, status) {
      if (status === "0") {
        // 如果状态为未移植,清除相关字段
        // row.transplanttime = "";
        // row.transplantdoct = "";
        // row.hospitalno = "";
        // row.hospitalname = "";
      } else if (status === "1") {
        // 如果状态为已移植,自动设置移植时间为当前时间
        if (!row.transplanttime) {
          row.transplanttime = new Date().toISOString().split("T")[0];
        }
      }
    },
    // 行展开事件
    handleExpandChange(row, expandedRows) {
      this.expandedRows = expandedRows.map(item => item.organno);
    },
    // 删除器官记录
    handleRemoveOrgan(index) {
      this.$confirm("确认删除这条器官记录吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          const organno = this.utilizationData.serviceDonatecomporganList[index]
            .organno;
          this.utilizationData.serviceDonatecomporganList.splice(index, 1);
          // 从选中的器官中移除
          const idx = this.selectedOrgans.indexOf(organno);
          if (idx > -1) {
            this.selectedOrgans.splice(idx, 1);
          }
          this.$message.success("器官记录删除成功");
        })
        .catch(() => {});
    },
    // 器官行样式
    getOrganRowClassName({ row }) {
      if (
        row.transplantstate === "1" &&
        (!row.caseNo || !row.hospitalno || !row.name || !row.transplanttime)
      ) {
        return "warning-row";
      }
      if (row.transplantstate === "0" && !row.abandonreason) {
        return "warning-row";
      }
      return "";
    },
    // 获取状态标签类型
    getStatusTagType(status) {
      const typeMap = {
        3: "success",
        2: "warning",
        1: "info"
      };
      return typeMap[status] || "info";
    },
    // 获取状态文本
    getStatusText(status) {
      const textMap = {
        3: "已完成",
        2: "进行中",
        1: "待处理"
      };
      return textMap[status] || "未知";
    },
    // 获取随访类型标签
    getFollowupTypeTag(type) {
      const typeMap = {
        routine: "success",
        emergency: "danger",
        special: "warning"
      };
      return typeMap[type] || "info";
    },
    // 获取随访类型文本
    getFollowupTypeText(type) {
      const textMap = {
        routine: "常规随访",
        emergency: "紧急随访",
        special: "特殊随访"
      };
      return textMap[type] || "未知";
    },
    // 保存基本信息
    async handleSave() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          this.saveLoading = true;
          try {
            const saveData = {
              ...this.form,
              assessannex: JSON.stringify(this.attachments),
              donateorgan: this.selectedOrgans.join(","),
              serviceDonatecomporganList:
                this.utilizationData.serviceDonatecomporganList || []
            };
            const apiMethod = this.form.id ? completionedit : completionadd;
            const response = await apiMethod(saveData);
            if (response.code === 200) {
              this.$message.success("保存成功");
              if (!this.form.id && response.data && response.data.id) {
                this.form.id = response.data.id;
                this.$router.replace({
                  query: { ...this.$route.query, id: this.form.id }
                });
              }
            } else {
              this.$message.error("保存失败:" + (response.msg || "未知错误"));
            }
          } catch (error) {
            console.error("保存失败:", error);
            this.$message.error("保存失败");
          } finally {
            this.saveLoading = false;
          }
        }
      });
    },
    // 保存利用记录
    async handleSaveUtilization() {
      if (
        !this.utilizationData.serviceDonatecomporganList ||
        this.utilizationData.serviceDonatecomporganList.length === 0
      ) {
        this.$message.warning("请先添加利用记录");
        return;
      }
      this.saveLoading = true;
      try {
        const saveData = {
          ...this.form,
          attachments: this.attachments,
          donateorgan: this.selectedOrgans.join(","),
          serviceDonatecomporganList:
            this.utilizationData.serviceDonatecomporganList || []
        };
        const response = await completionedit(saveData);
        if (response.code === 200) {
          this.$message.success("利用记录保存成功");
        } else {
          this.$message.error(
            "保存利用记录失败:" + (response.msg || "未知错误")
          );
        }
      } catch (error) {
        console.error("保存利用记录失败:", error);
        this.$message.error("保存利用记录失败");
      } finally {
        this.saveLoading = false;
      }
    },
    // 确认完成利用
    async handleConfirmUtilization() {
      // 检查利用记录是否完整
      const incompleteRecords = this.utilizationData.serviceDonatecomporganList.filter(
        record => {
          if (record.transplantstate === "1") {
            return (
              !record.caseNo ||
              !record.hospitalno ||
              !record.name ||
              !record.transplanttime
            );
          } else if (record.transplantstate === "0") {
            return !record.abandonreason;
          }
          return false;
        }
      );
      if (incompleteRecords.length > 0) {
        this.$message.warning("请先完善所有利用记录的信息");
        return;
      }
      this.$confirm("确认完成器官利用吗?完成后将无法修改利用信息。", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(async () => {
          this.confirmLoading = true;
          this.form.completeState = "3";
          this.form.completetime =
            this.form.completetime ||
            new Date()
              .toISOString()
              .replace("T", " ")
              .substring(0, 19);
          try {
            const saveData = {
              ...this.form,
              attachments: this.attachments,
              donateorgan: this.selectedOrgans.join(","),
              serviceDonatecomporganList:
                this.utilizationData.serviceDonatecomporganList || []
            };
            const response = await completionedit(saveData);
            if (response.code === 200) {
              this.$message.success("器官利用已完成");
            } else {
              this.$message.error(
                "确认利用失败:" + (response.msg || "未知错误")
              );
              this.form.completeState = "2";
              this.form.completetime = "";
            }
          } catch (error) {
            console.error("确认利用失败:", error);
            this.$message.error("确认利用失败");
            this.form.completeState = "2";
            this.form.completetime = "";
          } finally {
            this.confirmLoading = false;
          }
        })
        .catch(() => {});
    },
    // 完成利用
    handleComplete() {
      this.handleConfirmUtilization();
    },
    // 保存随访记录
    handleSaveFollowup() {
      if (!this.currentFollowup.organNo) {
        this.$message.warning("请选择器官");
        return;
      }
      if (!this.currentFollowup.followupTime) {
        this.$message.warning("请选择随访时间");
        return;
      }
      this.saveLoading = true;
      // 获取器官名称
      const organRecord = this.utilizationData.serviceDonatecomporganList.find(
        item => item.organno === this.currentFollowup.organNo
      );
      const organName = organRecord ? organRecord.organname : "";
      const followupData = {
        ...this.currentFollowup,
        organName: organName,
        utilizationId: this.form.id
      };
      // TODO: 替换为实际的随访记录保存接口
      setTimeout(() => {
        if (this.isEditingFollowup) {
          // 更新现有记录
          const index = this.followupData.records.findIndex(
            item => item.id === this.currentFollowup.id
          );
          if (index !== -1) {
            this.followupData.records[index] = {
              ...followupData,
              id: this.currentFollowup.id
            };
          }
        } else {
          // 添加新记录
          this.followupData.records.push({ ...followupData, id: Date.now() });
        }
        this.$message.success("随访记录保存成功");
        this.followupDialogVisible = false;
        this.saveLoading = false;
      }, 1000);
    },
    /** 附件变化处理 */
    handleAttachmentChange(fileList) {
      this.attachmentFileList = fileList;
    },
    /** 附件移除处理 */
    handleAttachmentRemove(file) {
      if (file.url) {
        const index = this.attachments.findIndex(
          item => item.path === file.url || item.fileUrl === file.url
        );
        if (index > -1) {
          this.attachments.splice(index, 1);
          this.$message.success("附件删除成功");
        }
      }
    },
    /** 上传成功处理 */
    handleUploadSuccess({ file, fileList, response }) {
      if (response.code === 200) {
        const attachmentObj = {
          fileName: file.name,
          path: response.fileUrl || file.url,
          fileUrl: response.fileUrl || file.url,
          fileType: this.getFileExtension(file.name),
          fileSize: file.size,
          uploadTime: dayjs().format("YYYY-MM-DD HH:mm:ss")
        };
        if (!Array.isArray(this.attachments)) {
          this.attachments = [];
        }
        this.attachments.push(attachmentObj);
        this.attachmentFileList = fileList;
        this.$message.success("文件上传成功");
      }
    },
    /** 上传错误处理 */
    handleUploadError({ file, fileList, error }) {
      console.error("附件上传失败:", error);
      this.$message.error("文件上传失败,请重试");
    },
    /** 手动删除附件 */
    handleRemoveAttachment(index) {
      this.attachments.splice(index, 1);
      this.attachmentFileList.splice(index, 1);
      this.$message.success("附件删除成功");
    },
    /** 文件预览 */
    handlePreview(file) {
      this.currentPreviewFile = {
        fileName: file.fileName,
        fileUrl: file.path || file.fileUrl,
        fileType: this.getFileType(file.fileName)
      };
      this.filePreviewVisible = true;
    },
    /** 文件下载 */
    handleDownloadAttachment(file) {
      const fileUrl = file.path || file.fileUrl;
      const fileName = file.fileName;
      if (fileUrl) {
        const link = document.createElement("a");
        link.href = fileUrl;
        link.download = fileName;
        link.style.display = "none";
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
        this.$message.success("开始下载文件");
      } else {
        this.$message.warning("文件路径不存在,无法下载");
      }
    },
    /** 获取文件类型 */
    getFileType(fileName) {
      if (!fileName) return "other";
      const extension = fileName
        .split(".")
        .pop()
        .toLowerCase();
      const imageTypes = ["jpg", "jpeg", "png", "gif", "bmp", "webp"];
      const pdfTypes = ["pdf"];
      const officeTypes = ["doc", "docx", "xls", "xlsx", "ppt", "pptx"];
      if (imageTypes.includes(extension)) return "image";
      if (pdfTypes.includes(extension)) return "pdf";
      if (officeTypes.includes(extension)) return "office";
      return "other";
    },
    /** 获取文件图标颜色 */
    getFileIconColor(fileName) {
      const type = this.getFileType(fileName);
      const colorMap = {
        image: "#67C23A",
        pdf: "#F56C6C",
        office: "#409EFF",
        other: "#909399"
      };
      return colorMap[type] || "#909399";
    },
    /** 获取文件标签类型 */
    getFileTagType(fileName) {
      const type = this.getFileType(fileName);
      const typeMap = {
        image: "success",
        pdf: "danger",
        office: "primary",
        other: "info"
      };
      return typeMap[type] || "info";
    },
    /** 获取文件类型文本 */
    getFileTypeText(fileName) {
      const type = this.getFileType(fileName);
      const textMap = {
        image: "图片",
        pdf: "PDF",
        office: "文档",
        other: "其他"
      };
      return textMap[type] || "未知";
    },
    /** 检查是否可预览 */
    isPreviewable(fileName) {
      const type = this.getFileType(fileName);
      return ["image", "pdf"].includes(type);
    },
    /** 获取文件扩展名 */
    getFileExtension(filename) {
      return filename
        .split(".")
        .pop()
        .toLowerCase();
    },
    /** 格式化文件大小 */
    formatFileSize(bytes) {
      if (!bytes || bytes === 0) return "0 B";
      const k = 1024;
      const sizes = ["B", "KB", "MB", "GB"];
      const i = Math.floor(Math.log(bytes) / Math.log(k));
      return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
    },
    /** 日期时间格式化 */
    formatDateTime(dateTime) {
      if (!dateTime) return "";
      try {
        const date = new Date(dateTime);
        if (isNaN(date.getTime())) return dateTime;
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, "0");
        const day = String(date.getDate()).padStart(2, "0");
        const hours = String(date.getHours()).padStart(2, "0");
        const minutes = String(date.getMinutes()).padStart(2, "0");
        return `${year}-${month}-${day} ${hours}:${minutes}`;
      } catch (error) {
        return dateTime;
      }
    }
  }
};
</script>
<style scoped>
.utilization-overview {
  padding: 10px 0;
<style lang="scss" scoped>
.organ-utilization-detail {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}
.overview-item {
.detail-card,
.utilization-card,
.followup-card,
.attachment-card {
  margin-bottom: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  border: 1px solid #e4e7ed;
}
/* 新增附件头部样式 */
.attachment-header {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid #ebeef5;
}
.overview-icon {
  font-size: 24px;
  margin-right: 15px;
}
.overview-content .value {
  font-size: 24px;
  font-weight: bold;
.attachment-title {
  font-weight: 600;
  color: #303133;
  font-size: 16px;
}
.overview-content .label {
.attachment-tip {
  font-size: 12px;
  color: #909399;
  margin-left: auto;
}
.success-stats, .time-tracking, .quality-assessment {
  padding: 10px 0;
}
.success-item, .time-item, .quality-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
}
.success-item .label, .time-item .label, .quality-item .label {
  color: #606266;
  font-size: 14px;
  min-width: 80px;
}
.time-item .value {
  font-weight: 600;
  color: #409EFF;
}
.chart-container {
  position: relative;
  min-height: 300px;
}
.action-buttons {
  display: flex;
  justify-content: center;
  gap: 15px;
.attachment-list {
  margin-top: 20px;
}
.card-header {
.list-title {
  font-weight: bold;
  margin-bottom: 12px;
  color: #303133;
  font-size: 14px;
}
.file-name {
  font-size: 13px;
  margin-left: 8px;
  color: #606266;
}
/* 文件图标样式 */
.el-icon-document {
  font-size: 16px;
  vertical-align: middle;
}
/* 保持原有样式 */
.detail-title {
  font-size: 18px;
  font-weight: 600;
  color: #303133;
  line-height: 1.4;
}
/* 表格整体样式 */
:deep(.el-table) {
  border-radius: 8px;
  overflow: hidden;
}
:deep(.el-table th) {
  background-color: #f5f7fa;
  color: #606266;
  font-weight: 600;
}
:deep(.el-table .cell) {
  padding: 12px 8px;
  line-height: 1.5;
}
/* 斑马纹表格行 */
:deep(.el-table__row.warning-row) {
  background-color: #fdf6ec;
}
:deep(.el-table__row.default-row) {
  background-color: #f0f9ff;
}
/* 鼠标悬停效果 */
:deep(.el-table--enable-row-hover .el-table__body tr:hover > td) {
  background-color: #f5f7fa !important;
}
/* 统计信息样式 */
.utilization-stats {
  margin-top: 20px;
  padding: 15px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 8px;
  color: white;
}
.stat-item {
  display: flex;
  justify-content: space-between;
  flex-direction: column;
  align-items: center;
  padding: 10px;
  text-align: center;
}
.stat-label {
  font-size: 12px;
  opacity: 0.9;
  margin-bottom: 5px;
  color: rgba(255, 255, 255, 0.9);
}
.stat-value {
  font-size: 18px;
  font-weight: bold;
  color: white;
}
/* 展开行样式 */
.recipient-detail-expand {
  padding: 20px;
  background: #fafafa;
  border-radius: 8px;
  margin: 10px 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.recipient-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 2px solid #e4e7ed;
}
.recipient-title {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
}
/* 表单部分样式 */
.recipient-form {
  background: white;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
/* 表单部分标题 */
.form-section {
  margin-bottom: 25px;
  padding-bottom: 20px;
  border-bottom: 1px solid #f0f0f0;
  &:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
  }
}
.section-title {
  font-size: 15px;
  font-weight: 600;
  color: #409eff;
  margin: 0 0 15px 0;
  padding-left: 10px;
  border-left: 4px solid #409eff;
  line-height: 1.2;
}
/* 表单行间距 */
:deep(.el-form-item) {
  margin-bottom: 20px;
  .el-form-item__label {
    font-weight: 500;
    color: #606266;
    padding-right: 10px;
  }
  .el-form-item__content {
    line-height: 1.5;
  }
}
/* 表单输入框样式 */
:deep(.el-input__inner) {
  height: 36px;
  line-height: 36px;
  border-radius: 4px;
  transition: all 0.3s ease;
  &:focus {
    border-color: #409eff;
    box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
  }
  &:disabled {
    background-color: #f5f7fa;
    border-color: #e4e7ed;
    color: #c0c4cc;
    cursor: not-allowed;
  }
}
/* 文本域样式 */
:deep(.el-textarea__inner) {
  min-height: 80px;
  border-radius: 4px;
  transition: all 0.3s ease;
  &:focus {
    border-color: #409eff;
    box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
  }
  &:disabled {
    background-color: #f5f7fa;
    border-color: #e4e7ed;
    color: #c0c4cc;
    cursor: not-allowed;
  }
}
/* 选择框样式 */
:deep(.el-select) {
  width: 100%;
  .el-input__inner {
    border-radius: 4px;
  }
  &.is-disabled {
    .el-input__inner {
      background-color: #f5f7fa;
      border-color: #e4e7ed;
      color: #c0c4cc;
    }
  }
}
/* 日期选择器样式 */
:deep(.el-date-editor) {
  width: 100%;
  &.el-input__inner {
    border-radius: 4px;
  }
  &.is-disabled {
    .el-input__inner {
      background-color: #f5f7fa;
      border-color: #e4e7ed;
      color: #c0c4cc;
    }
  }
}
/* 响应式调整 */
@media (max-width: 768px) {
  .recipient-detail-expand {
    padding: 15px;
  }
  .recipient-form {
    padding: 15px;
  }
  .attachment-header {
    flex-wrap: wrap;
  }
  .attachment-tip {
    width: 100%;
    margin-top: 8px;
    margin-left: 0;
  }
  .form-section {
    margin-bottom: 20px;
    padding-bottom: 15px;
  }
  :deep(.el-form-item) {
    margin-bottom: 15px;
  }
  .section-title {
    font-size: 14px;
    margin-bottom: 12px;
  }
}
:deep(.el-divider) {
  margin: 20px 0;
  background-color: #e4e7ed;
}
/* 表单标签和输入框样式 */
:deep(.el-form-item__label) {
  font-weight: 500;
  color: #606266;
}
:deep(.el-input__inner:focus) {
  border-color: #409eff;
  box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
}
/* 按钮样式优化 */
:deep(.el-button--primary) {
  background: linear-gradient(135deg, #409eff 0%, #3375e0 100%);
  border: none;
  border-radius: 4px;
  transition: all 0.3s ease;
}
:deep(.el-button--primary:hover) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(64, 158, 255, 0.4);
}
/* 底部操作按钮 */
.dialog-footer {
  margin-top: 20px;
  text-align: center;
  padding-top: 20px;
  border-top: 1px solid #e4e7ed;
}
.dialog-footer .el-button {
  margin: 0 10px;
  min-width: 120px;
}
/* 空状态样式 */
.empty-utilization {
  text-align: center;
  padding: 40px 0;
  color: #909399;
  background: #fafafa;
  border-radius: 4px;
  margin: 20px 0;
}
/* 文件信息样式 */
.file-info {
  display: flex;
  align-items: center;
  padding: 5px 0;
}
.file-info i {
  font-size: 18px;
  margin-right: 10px;
}
/* 平板设备适配 */
@media (max-width: 1024px) {
  .organ-utilization-detail {
    padding: 15px;
  }
  :deep(.el-col) {
    margin-bottom: 10px;
  }
}
/* 手机设备适配 */
/* 超小屏幕设备 */
@media (max-width: 480px) {
  .organ-utilization-detail {
    padding: 5px;
  }
  :deep(.el-card__header) {
    padding: 10px 15px;
  }
}
</style>