<template>
  <div class="app-container">
    <!-- 查询条件区域 -->
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="100px" label-position="top">
      <el-form-item label="工单编码" prop="workOrderProjectNo">
        <el-input
          v-model="queryParams.workOrderProjectNo"
          placeholder="请输入工单编码"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="风机编号" prop="pcsDeviceName">
        <el-input
          v-model="queryParams.pcsDeviceName"
          placeholder="请输入风机编号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="场站" prop="pcsStationName">
        <el-input
          v-model="queryParams.pcsStationName"
          placeholder="请输入场站"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="维保中心" prop="gxtCenter" label-position="top">
        <el-select
            v-model="queryParams.gxtCenter"
            placeholder="请选择维保中心"
            clearable
            @change="handleMaintenanceCenterChange"
        >
          <el-option
              v-for="item in maintenanceCenterOptions"
              :key="item.deptId"
              :label="item.deptName"
              :value="item.deptName">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="场站" prop="pcsStationName" label-position="top">
        <el-select
            v-model="queryParams.pcsStationName"
            placeholder="请选择场站"
            clearable
            :disabled="!queryParams.gxtCenter"
        >
          <el-option
              v-for="item in stationOptions"
              :key="item.deptId"
              :label="item.deptName"
              :value="item.deptName">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工单类型" prop="orderType">
        <el-select v-model="queryParams.orderType" placeholder="请选择工单类型" clearable>
          <el-option
            v-for="dict in gxt_order_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="scoringStatus">
        <el-select v-model="queryParams.scoringStatus" placeholder="请选择状态" clearable>
          <el-option
              v-for="dict in gxt_scoring_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
    </el-form>

    <div style="float: right;">
      <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
    </div>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
<!--        <el-button
            type="danger"
            icon=""
            :disabled="!canAppeal"
            @click="handleAppeal"
            v-hasPermi="['gxt:orderScore:appeal']"
        >发起申诉</el-button>-->
      </el-col>
    </el-row>
    <!-- 工单评分列表 -->
    <el-table
      v-loading="loading"
      :data="orderScoreList"
      @selection-change="handleSelectionChange"
      style="width: 100%"
      :max-height="tableHeight"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="工单编码" align="center" prop="workOrderProjectNo" :show-overflow-tooltip="true" />
      <el-table-column label="工单类型" align="center" prop="orderType" >
        <template #default="scope">
          <dict-tag :options="gxt_order_type" :value="scope.row.orderType" />
        </template>
      </el-table-column>
<!--      <el-table-column label="状态" align="center" prop="workOrderStatus" />-->
      <el-table-column label="状态" align="center" prop="scoringStatus" >
        <template #default="scope">
          <dict-tag
            :options="gxt_scoring_status"
            :value="scope.row.scoringStatus" />
        </template>
      </el-table-column>
      <el-table-column label="风机编号" align="center" prop="pcsDeviceName" :show-overflow-tooltip="true" />
      <el-table-column label="场站" align="center" prop="pcsStationName" :show-overflow-tooltip="true" />
<!--      <el-table-column label="工作结束时间" align="center" prop="realEndTime" width="180">
        <template #default="scope">
          <span>{{ scope.row.realEndTime ? parseTime(scope.row.realEndTime, '{y}-{m}-{d} {h}:{i}') : '-' }}</span>
        </template>
      </el-table-column>-->
      <el-table-column label="工作结束时间" align="center" prop="realEndTime" width="180" />
      <el-table-column label="工作负责人" align="center" prop="teamLeaderName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button
            type="primary"
            link
            v-if="(scope.row.scoringStatus == 'to_self' || scope.row.scoringStatus == 'returned') && (scope.row.teamLeaderId == userStore.id || userStore.roles.includes('admin'))"
            @click="handleSelfEvaluation(scope.row)"
            v-hasPermi="['gxt:orderScore:selfEvaluation']"
          ><i class="fa fa-edit"></i>自评</el-button>
          <el-button
            type="warning"
            link
            v-if="scope.row.scoringStatus == 'to_re'"
            @click="handleReview(scope.row)"
            v-hasPermi="['gxt:orderScore:review']"
          ><i class="fa fa-check-square-o"></i>复评</el-button>
          <el-button
            type="danger"
            link
            v-if="scope.row.scoringStatus == 'to_confirm' && isUserTeamLeader(scope.row)"
            @click="handleConfirm(scope.row)"
            v-hasPermi="['gxt:orderScore:confirm']"
          ><i class="fa fa-check"></i>确认</el-button>
          <el-button
            type="success"
            link
            v-if="scope.row.scoringStatus == 'to_final' || scope.row.scoringStatus == 'appealing'"
            @click="handleFinalEvaluation(scope.row)"
            v-hasPermi="['gxt:orderScore:finalEvaluation']"
          ><i class="fa fa-flag-checkered"></i>终评</el-button>
          <el-button
              type="info"
              link
              @click="handleView(scope.row)"
              v-hasPermi="['gxt:orderScore:query']"
          ><i class="fa fa-eye"></i>查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 查看详情对话框 -->
    <el-dialog title="工单评分详情" v-model="viewDialogVisible" width="1000px" append-to-body>
      <el-row :gutter="20">
        <!-- 工单信息 -->
        <el-col :span="8">
          <div class="info-section">
            <h3 class="section-title">工单信息</h3>
            <div class="info-content">
              <el-form label-width="100px" label-position="top">
                <el-row :gutter="20">
                  <el-col :span="24">
                    <el-form-item label="工单编码">{{ viewForm.workOrderProjectNo }}</el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="工单类型">
                      <dict-tag :options="gxt_order_type" :value="viewForm.orderType" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="状态">
                      <dict-tag :options="gxt_scoring_status" :value="viewForm.scoringStatus" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="风机编号">{{ viewForm.pcsDeviceName }}</el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="场站">{{ viewForm.pcsStationName }}</el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="工作结束时间">{{ parseTime(viewForm.realEndTime, '{y}-{m}-{d} {h}:{i}') }}</el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="工作负责人">{{ viewForm.teamLeaderName }}</el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="外委人员数（人）">{{ viewForm.wwryNum }}</el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="外来人员数（人）">{{ viewForm.wlryNum }}</el-form-item>
                  </el-col>
                  <el-col :span="24" v-if="viewForm.orderType === 1">
                    <el-form-item label="故障代码">{{ viewForm.faultCode }}</el-form-item>
                  </el-col>
                  <el-col :span="24" v-if="viewForm.orderType === 1">
                    <el-form-item label="故障条文">{{ viewForm.faultBarcode }}</el-form-item>
                  </el-col>
                  <el-col :span="24" v-if="viewForm.orderType === 1">
                    <el-form-item label="故障描述">{{ viewForm.faultDesc }}</el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </div>
          </div>
        </el-col>

        <!-- 处理信息 -->
        <el-col :span="8">
          <div class="info-section">
            <h3 class="section-title">处理信息</h3>
            <div class="info-content">
              <el-form label-width="100px" label-position="top">
                <el-row :gutter="20">
                  <el-col :span="24">
                    <el-form-item :label="viewForm.orderType === 1 ? '检修类型' : '维保类型'">
                      <dict-tag v-if="viewForm.orderType === 1" :options="gxt_maintenance_type" :value="viewForm.maintenanceType" />
                      <dict-tag v-else :options="gxt_inspection_type" :value="viewForm.inspectionType" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="24" v-if="viewForm.orderType === 2">
                    <el-form-item label="分项完成系数">{{ viewForm.itemCompletionFactor }}</el-form-item>
                  </el-col>
                  <el-col :span="24" v-if="viewForm.orderType === 2">
                    <el-form-item label="分项完成系数和">{{ viewForm.itemCompletionFactorSum }}</el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item :label="viewForm.orderType === 1 ? '维修总结' : '维保总结'">{{ viewForm.workSummary }}</el-form-item>
                  </el-col>
                  <el-col :span="24" v-if="viewForm.orderType === 1 && viewForm.extraWork">
                    <el-form-item label="额外工作总结">{{ viewForm.extraWork }}</el-form-item>
                  </el-col>
                  <el-col :span="24" v-if="viewForm.scoringStatus === 'returned'">
                    <el-form-item label="退回理由">{{ viewForm.scoreReturnReason }}</el-form-item>
                  </el-col>
                  <el-col :span="24" v-if="viewForm.modifyReason">
                    <el-form-item label="修改理由">{{ viewForm.modifyReason }}</el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </div>
          </div>
        </el-col>

        <!-- 工单流转记录 -->
        <el-col :span="8">
          <div class="info-section">
            <h3 class="section-title">工单流转</h3>
            <div class="flow-history">
              <el-timeline>
                <el-timeline-item type="primary"
                                  v-for="(flow, index) in flowList"
                                  :key="index"
                                  :timestamp="parseTime(flow.actionTime, '{y}-{m}-{d} {h}:{i}')"
                >
                  <div class="flow-item">
                    <h4>
                      <dict-tag :options="gxt_repair_order_flow_action_type" :value="flow.actionType" />
                    </h4>
                    <p>{{ flow.operatorName }}</p>
                    <!-- 显示退回理由 -->
<!--                    <p v-if="flow.actionType === 'returnRating'">
                      {{ flow.actionRemark }}
                    </p>-->
                  </div>
                </el-timeline-item>
              </el-timeline>
            </div>
          </div>
        </el-col>
      </el-row>

      <el-form label-position="top">
        <el-row>
          <el-col :span="24">
            <el-form-item label="得分明细">
              <el-table :data="viewForm.scorePersonList" border style="width: 100%;">
                <el-table-column label="工作班成员" align="center" prop="nickName">
                  <template #default="scope">
                    <span>{{ scope.row.nickName }}<span v-if="scope.row.isLeader == 1"> (工作负责人)</span></span>
                  </template>
                </el-table-column>
                <el-table-column label="检修工分" align="center" prop="selfScore">
                  <template #default="scope">
                    <span>{{ scope.row.selfScore !== null && scope.row.selfScore !== undefined ? parseFloat(scope.row.selfScore).toFixed(2) : '' }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="复评得分" align="center" prop="reviewScore">
                  <template #default="scope">
                    <span>{{ scope.row.reviewScore !== null && scope.row.reviewScore !== undefined ? parseFloat(scope.row.reviewScore).toFixed(2) : '' }}</span>
                  </template>
                </el-table-column>
<!--                <el-table-column label="终评得分" align="center" prop="finalScore">
                  <template #default="scope">
                    <span>{{ scope.row.finalScore !== null && scope.row.finalScore !== undefined ? parseFloat(scope.row.finalScore).toFixed(2) : '' }}</span>
                  </template>
                </el-table-column>-->
                <!-- 额外工分和工单得分 - 仅当维修工单且有额外工作总结时显示 -->
                <el-table-column
                  label="额外工分"
                  align="center"
                  prop="extraScore"
                  v-if="viewForm.orderType === 1 && viewForm.extraWork && viewForm.extraWork.trim() !== ''"
                  style="width: 33%;">
                  <template #default="scope">
                    <span>{{ scope.row.extraScore !== null && scope.row.extraScore !== undefined ? parseFloat(scope.row.extraScore).toFixed(2) : '' }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="工单得分"
                  align="center"
                  prop="totalScore"
                  v-if="viewForm.orderType === 1 && viewForm.extraWork && viewForm.extraWork.trim() !== ''"
                  style="width: 33%;">
                  <template #default="scope">
                    <span>{{ scope.row.totalScore !== null && scope.row.totalScore !== undefined ? parseFloat(scope.row.totalScore).toFixed(2) : '' }}</span>
                  </template>
                </el-table-column>
                <!-- 额外工分和工单得分 - 仅当维保工单且维保类型包含其他/其它时显示 -->
                <el-table-column
                  label="额外工分"
                  align="center"
                  prop="extraScore"
                  v-if="viewForm.orderType === 2 && hasOtherOrQitaInspectionType()"
                  style="width: 33%;">
                  <template #default="scope">
                    <span>{{ scope.row.extraScore !== null && scope.row.extraScore !== undefined ? parseFloat(scope.row.extraScore).toFixed(2) : '' }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="工单得分"
                  align="center"
                  prop="totalScore"
                  v-if="viewForm.orderType === 2 && hasOtherOrQitaInspectionType()"
                  style="width: 33%;">
                  <template #default="scope">
                    <span>{{ scope.row.totalScore !== null && scope.row.totalScore !== undefined ? parseFloat(scope.row.totalScore).toFixed(2) : '' }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                    label="奖励得分"
                    align="center"
                    prop="runScore"
                    v-if="viewForm.restartTime !== null && viewForm.restartTime !== undefined"
                    style="width: 33%;">
                  <template #default="scope">
                    <span>{{ scope.row.runScore !== null && scope.row.runScore !== undefined ? parseFloat(scope.row.runScore).toFixed(2) : '' }}</span>
                  </template>
                </el-table-column>
                <el-table-column
                    label="停运扣分"
                    align="center"
                    prop="stopScore"
                    v-if="hasStopScore()"
                    style="width: 33%;">
                  <template #default="scope">
                    <span>{{ scope.row.stopScore !== null && scope.row.stopScore !== undefined ? parseFloat(scope.row.stopScore).toFixed(2) : '' }}</span>
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="closeViewDialog">关 闭</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 自评对话框 -->
    <el-dialog :title="selfEvaluationForm.orderType === 1 ? '维修工单自评' : '维保工单自评'" v-model="selfEvaluationDialogVisible" width="800px" append-to-body>
      <el-form ref="selfEvaluationRef" :model="selfEvaluationForm" :rules="selfEvaluationRules" label-width="120px" label-position="top">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="工单编码">
              <el-input v-model="selfEvaluationForm.workOrderProjectNo" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="风机编号">
              <el-input v-model="selfEvaluationForm.pcsDeviceName" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="场站">
              <el-input v-model="selfEvaluationForm.pcsStationName" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24" v-if="selfEvaluationForm.orderType === 1">
            <el-form-item label="检修类型" prop="maintenanceType">
              <el-select v-model="selfEvaluationForm.maintenanceType" placeholder="请选择检修类型" style="width: 100%" @change="handleMaintenanceTypeChangeForSelfEvaluation">
                <el-option
                    v-for="item in maintenanceTypeOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="24" v-if="selfEvaluationForm.orderType === 2">
            <el-form-item label="维保类型" prop="inspectionType">
              <el-select v-model="selfEvaluationForm.inspectionType" multiple placeholder="维保类型" style="width: 100%" disabled>
                <el-option
                    v-for="dict in gxt_inspection_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>
        <el-form-item :label="selfEvaluationForm.orderType === 1 ? '维修总结' : '维保总结'" prop="workSummary">
          <el-input
            v-model="selfEvaluationForm.workSummary"
            type="textarea"
            :placeholder="selfEvaluationForm.orderType === 1 ? '请输入维修总结' : '请输入维保总结'"
            maxlength="200"
            show-word-limit
            :rows="4"
          />
        </el-form-item>

        <!-- 额外工作总结 - 仅维修工单显示 -->
        <el-form-item
          label="额外工作总结"
          v-if="selfEvaluationForm.orderType === 1"
        >
          <el-input
            v-model="selfEvaluationForm.extraWork"
            type="textarea"
            placeholder="请输入额外工作总结"
            maxlength="200"
            show-word-limit
            :rows="4"
            @input="handleExtraWorkChange"
          />
        </el-form-item>
        <el-row :gutter="20" v-if="selfEvaluationForm.orderType === 2">
          <el-col :span="12">
            <el-form-item label="分项完成系数" prop="itemCompletionFactor">
              <el-input-number
                  v-model="selfEvaluationForm.itemCompletionFactor"
                  :min="0"
                  :max="1"
                  :step="0.1"
                  style="width: 100%"
                  controls-position="right"
                  @change="handleMaintenanceTypeChangeForSelfEvaluation"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="分项完成系数和" prop="itemCompletionFactorSum">
              <el-input-number
                  v-model="selfEvaluationForm.itemCompletionFactorSum"
                  :min="0"
                  :max="1"
                  :step="0.1"
                  style="width: 100%"
                  controls-position="right"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="外委人员数（人）">
              <el-input v-model="selfEvaluationForm.wwryNum" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="外来人员数（人）">
              <el-input v-model="selfEvaluationForm.wlryNum" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item :label="'得分明细 (' + (isMixedZeroNonZeroInspectionTypesForSelfEvaluation() ? '最少可评总分: ' : '可自评总分: ') + (getSelfEvaluationTotalScore() === 0 ? '未规定' : getSelfEvaluationTotalScore().toFixed(2) + '分') + ', 已自评总分: ' + getSelfEvaluatedTotalScore().toFixed(2) + '分)'">
          <el-table :data="selfEvaluationForm.scorePersonList" border style="width: 100%;">
            <el-table-column label="工作班成员" align="center" prop="nickName"  style="width: 33%;">
              <template #default="scope">
                <span>{{ scope.row.nickName }}<span v-if="scope.row.isLeader == 1"> (工作负责人)</span></span>
              </template>
            </el-table-column>
            <el-table-column label="检修工分" align="center" prop="selfScore"  style="width: 33%;">
              <template #default="scope">
                <el-input-number
                  v-model="scope.row.selfScore"
                  style="width: 100%;"
                  :min="0.01"
                  :max="100"
                  :step="0.01"
                  :precision="2"
                  @change="updateTotalScore(scope.row)"/>
              </template>
            </el-table-column>
            <!-- 额外工分和工单得分 - 仅当维修工单且有额外工作总结时显示 -->
            <el-table-column
              label="额外工分"
              align="center"
              prop="extraScore"
              v-if="selfEvaluationForm.orderType === 1 && selfEvaluationForm.extraWork && selfEvaluationForm.extraWork.trim() !== ''"
              style="width: 33%;">
              <template #default="scope">
                <el-input-number
                  v-model="scope.row.extraScore"
                  style="width: 100%;"
                  :min="0"
                  :max="100"
                  :step="0.01"
                  :precision="2"
                  @change="updateTotalScore(scope.row)"
                />
              </template>
            </el-table-column>
            <el-table-column
              label="工单得分"
              align="center"
              prop="totalScore"
              v-if="selfEvaluationForm.orderType === 1 && selfEvaluationForm.extraWork && selfEvaluationForm.extraWork.trim() !== ''"
              style="width: 33%;">
              <template #default="scope">
                <el-input-number
                  v-model="scope.row.totalScore"
                  style="width: 100%;"
                  :min="0.01"
                  :max="200"
                  :step="0.01"
                  :precision="2"
                  :disabled="true"
                />
              </template>
            </el-table-column>
            <!-- 额外工分和工单得分 - 仅当维保工单且维保类型包含其他/其它时显示 -->
            <el-table-column
              label="额外工分"
              align="center"
              prop="extraScore"
              v-if="selfEvaluationForm.orderType === 2 && hasOtherOrQitaInspectionType()"
              style="width: 33%;">
              <template #default="scope">
                <el-input-number
                  v-model="scope.row.extraScore"
                  style="width: 100%;"
                  :min="0"
                  :max="100"
                  :step="0.01"
                  :precision="2"
                  @change="updateTotalScore(scope.row)"
                />
              </template>
            </el-table-column>
            <el-table-column
              label="工单得分"
              align="center"
              prop="totalScore"
              v-if="selfEvaluationForm.orderType === 2 && hasOtherOrQitaInspectionType()"
              style="width: 33%;">
              <template #default="scope">
                <el-input-number
                  v-model="scope.row.totalScore"
                  style="width: 100%;"
                  :min="0.01"
                  :max="200"
                  :step="0.01"
                  :precision="2"
                  :disabled="true"
                />
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
      </el-form>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="closeSelfEvaluationDialog">取 消</el-button>
          <el-button type="primary" @click="submitSelfEvaluation">提交自评</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 复评对话框 -->
    <el-dialog :title="reviewForm.orderType === 1 ? '维修工单复评' : '维保工单复评'" v-model="reviewDialogVisible" width="800px" append-to-body>
      <el-form ref="reviewRef" :model="reviewForm" :rules="reviewRules" label-width="120px" label-position="top">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="工单编码">
              <el-input v-model="reviewForm.workOrderProjectNo" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="风机编号">
              <el-input v-model="reviewForm.pcsDeviceName" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="场站">
              <el-input v-model="reviewForm.pcsStationName" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12" v-if="reviewForm.orderType === 1">
            <el-form-item label="检修类型">
              <el-select v-model="reviewForm.maintenanceType" placeholder="请选择检修类型" style="width: 100%" disabled>
                <el-option
                    v-for="item in maintenanceTypeOptions"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!--          <el-col :span="3" v-if="reviewForm.orderType === 1">
           <el-button type="primary" style="margin-top: 30px;" @click="handleModifyType">修改</el-button>
         </el-col>-->
          <el-col :span="24" v-if="reviewForm.orderType === 2">
            <el-form-item label="维保类型">
<!--              <el-select v-model="reviewForm.inspectionType" multiple placeholder="维保类型" style="width: 100%" disabled>
                <el-option
                    v-for="item in inspectionTypeOptions"
                    :key="item.inspectionTypeId"
                    :label="item.score && item.score !== 0 ? getDictLabel(gxt_inspection_type, item.inspectionTypeId) + ' (' + item.score + '分)' : getDictLabel(gxt_inspection_type, item.inspectionTypeId)"
                    :value="item.inspectionTypeId.toString()">
                </el-option>
              </el-select>-->
              <el-select v-model="reviewForm.inspectionType" multiple placeholder="维保类型" style="width: 100%" disabled>
                <el-option
                    v-for="dict in gxt_inspection_type"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item :label="reviewForm.orderType === 1 ? '维修总结' : '维保总结'">
          <el-input
            v-model="reviewForm.workSummary"
            type="textarea"
            disabled
            :rows="4"
          />
        </el-form-item>
        <!-- 额外工作总结 - 仅维修工单显示 -->
        <el-form-item
            label="额外工作总结"
            v-if="reviewForm.orderType === 1"
        >
          <el-input
              v-model="reviewForm.extraWork"
              type="textarea"
              disabled
              :rows="4"
          />
        </el-form-item>
        <el-row :gutter="20">
<!--          <el-col :span="12" v-if="reviewForm.orderType === 1">
            <el-form-item label="质量系数(建议值)" prop="finalCoefficient">
              <el-input-number
                  v-model="reviewForm.finalCoefficient"
                  :min="0.5"
                  :max="1.5"
                  :step="0.01"
                  style="width: 100%"
                  controls-position="right"
              />
            </el-form-item>
          </el-col>-->
          <!-- 退回理由 - 仅在维修工单显示 -->
<!--          <el-col :span="24">
            <el-form-item
                label="退回理由"
                prop="scoreReturnReason">
              <el-input
                  v-model="reviewForm.scoreReturnReason"
                  type="textarea"
                  placeholder="请输入退回理由，输入后将显示退回按钮"
                  maxlength="500"
                  show-word-limit
                  :rows="6"
                  @input="onReturnReasonInput"
              />
            </el-form-item>
          </el-col>-->
        </el-row>
        <el-row :gutter="20" v-if="reviewForm.orderType === 2">
          <el-col :span="12">
            <el-form-item label="分项完成系数" prop="itemCompletionFactor">
<!--              <el-input-number
                v-model="reviewForm.itemCompletionFactor"
                :min="0"
                :max="1"
                :step="0.1"
                style="width: 100%"
                controls-position="right"
                :disabled="!isItemCompletionFactorEditable"
                @change="calculateMaintenanceReviewScores"
              />-->
              <el-input-number
                  v-model="reviewForm.itemCompletionFactor"
                  :min="0"
                  :max="1"
                  :step="0.1"
                  style="width: 100%"
                  controls-position="right"
                  @change="calculateMaintenanceReviewScores"
              />
            </el-form-item>
          </el-col>
<!--          <el-col :span="3" v-if="reviewForm.orderType === 2">
            <el-button type="primary" style="margin-top: 30px;" @click="handleModifyType">修改</el-button>
          </el-col>-->
          <el-col :span="12">
            <el-form-item label="分项完成系数和">
              <el-input-number
                v-model="reviewForm.itemCompletionFactorSum"
                :min="0"
                :max="1"
                :step="0.1"
                style="width: 100%"
                controls-position="right"
                disabled
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item v-if="showModifyReason" label="修改理由" prop="modifyReason">
          <el-input
              v-model="reviewForm.modifyReason"
              type="textarea"
              placeholder="请输入修改理由"
              maxlength="200"
              show-word-limit
              :rows="3"
          />
        </el-form-item>

        <!-- 反馈信息展示 -->
<!--        <el-form-item v-if="feedbackList && feedbackList.length > 0" label="反馈信息">
          <el-table :data="feedbackList" border style="width: 100%;">
            <el-table-column label="反馈人员" align="center" prop="nickName" width="150" />
            <el-table-column label="反馈理由" align="left" prop="feedbackReason">
              <template #default="scope">
                <el-input
                  v-model="scope.row.feedbackReason"
                  type="textarea"
                  :rows="3"
                  disabled
                />
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>-->
        <el-form-item v-if="reviewForm.orderType === 2 && reviewForm.feedbackReason" label="反馈理由" prop="feedbackReason">
          <el-input
              v-model="reviewForm.feedbackReason"
              type="textarea"
              :rows="3"
              disabled
          />
        </el-form-item>

        <!-- 退回理由 - 仅在维修工单的退回操作时显示 -->

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="外委人员数（人）">
              <el-input v-model="reviewForm.wwryNum" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="外来人员数（人）">
              <el-input v-model="reviewForm.wlryNum" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item :label="'得分明细 (' + (isMixedZeroNonZeroInspectionTypesForReview() ? '最少可评总分: ' : '可复评总分: ') + (getReviewEvaluationTotalScore() === 0 ? '未规定' : getReviewEvaluationTotalScore().toFixed(2) + '分') + ', 已复评总分: ' + getReviewedTotalScore().toFixed(2) + '分)'">
          <el-table :data="reviewForm.scorePersonList" border style="width: 100%;">
            <el-table-column label="工作班成员" align="center" prop="nickName"  style="width: 33%;">
              <template #default="scope">
                <span>{{ scope.row.nickName }}<span v-if="scope.row.isLeader == 1"> (工作负责人)</span></span>
              </template>
            </el-table-column>
            <el-table-column label="检修工分" align="center" prop="selfScore"  style="width: 33%;">
              <template #default="scope">
                <span>{{ scope.row.selfScore !== null && scope.row.selfScore !== undefined ? parseFloat(scope.row.selfScore).toFixed(2) : '' }}</span>
              </template>
            </el-table-column>
            <el-table-column label="复评得分" align="center" prop="reviewScore"  style="width: 33%;">
              <template #default="scope">
                <el-input-number
                  v-model="scope.row.reviewScore"
                  style="width: 100%;"
                  :min="0.01"
                  :max="100"
                  :step="0.01"
                  @input="onReviewScoreInputChange(scope.row)"/>
              </template>
            </el-table-column>
            <!-- 额外工分和工单得分 - 仅当维修工单且有额外工作总结时显示 -->
            <el-table-column
              label="额外工分"
              align="center"
              prop="extraScore"
              v-if="reviewForm.orderType === 1 && reviewForm.extraWork && reviewForm.extraWork.trim() !== ''"
              style="width: 33%;">
              <template #default="scope">
                <el-input
                  v-model="scope.row.extraScore"
                  style="width: 100%;"
                  :min="0"
                  :max="100"
                  :step="0.01"
                  :precision="2"
                  :disabled="true"
                />
              </template>
            </el-table-column>
            <el-table-column
              label="工单得分"
              align="center"
              prop="totalScore"
              v-if="reviewForm.orderType === 1 && reviewForm.extraWork && reviewForm.extraWork.trim() !== ''"
              style="width: 33%;">
              <template #default="scope">
                <el-input
                  v-model="scope.row.totalScore"
                  style="width: 100%;"
                  :min="0.01"
                  :max="200"
                  :step="0.01"
                  :precision="2"
                  :disabled="true"
                />
              </template>
            </el-table-column>
            <!-- 额外工分和工单得分 - 仅当维保工单且维保类型包含其他/其它时显示 -->
            <el-table-column
              label="额外工分"
              align="center"
              prop="extraScore"
              v-if="reviewForm.orderType === 2 && hasOtherOrQitaInspectionType()"
              style="width: 33%;">
              <template #default="scope">
                <el-input
                  v-model="scope.row.extraScore"
                  style="width: 100%;"
                  :min="0"
                  :max="100"
                  :step="0.01"
                  :precision="2"
                  :disabled="true"
                />
              </template>
            </el-table-column>
            <el-table-column
              label="工单得分"
              align="center"
              prop="totalScore"
              v-if="reviewForm.orderType === 2 && hasOtherOrQitaInspectionType()"
              style="width: 33%;">
              <template #default="scope">
                <el-input
                  v-model="scope.row.totalScore"
                  style="width: 100%;"
                  :min="0.01"
                  :max="200"
                  :step="0.01"
                  :precision="2"
                  :disabled="true"
                />
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
      </el-form>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="closeReviewDialog">取 消</el-button>
          <el-button
            v-if="hasReturnReason"
            type="warning"
            @click="submitReturn">
            退 回
          </el-button>
          <el-button
            v-if="!hasReturnReason"
            type="primary"
            @click="submitReview">
            提交复评
          </el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 终评对话框 -->
    <el-dialog :title="finalEvaluationForm.orderType === 1 ? '维修工单终评' : '维保工单终评'" v-model="finalEvaluationDialogVisible" width="800px" append-to-body>
      <el-form ref="finalEvaluationRef" :model="finalEvaluationForm" :rules="finalEvaluationRules" label-width="120px" label-position="top">
        <!-- 工单终评界面添加标签页 -->
        <el-tabs v-model="activeFinalEvalTab">
          <el-tab-pane label="终评信息" name="evaluation">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="工单编码">
                  <el-input v-model="finalEvaluationForm.workOrderProjectNo" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="风机编号">
                  <el-input v-model="finalEvaluationForm.pcsDeviceName" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="场站">
                  <el-input v-model="finalEvaluationForm.pcsStationName" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="12" v-if="finalEvaluationForm.orderType === 1">
                <el-form-item label="检修类型">
                  <el-select v-model="finalEvaluationForm.maintenanceType" disabled style="width: 100%">
                    <el-option
                        v-for="item in maintenanceTypeOptions"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12" v-if="finalEvaluationForm.orderType === 2">
<!--                <el-form-item label="维保类型">
                  <el-select v-model="finalEvaluationForm.inspectionType" multiple disabled style="width: 100%">
                    <el-option
                        v-for="item in inspectionTypeOptions"
                        :key="item.inspectionTypeId"
                        :label="item.score && item.score !== 0 ? getDictLabel(gxt_inspection_type, item.inspectionTypeId) + ' (' + item.score + '分)' : getDictLabel(gxt_inspection_type, item.inspectionTypeId)"
                        :value="item.inspectionTypeId.toString()">
                    </el-option>
                  </el-select>
                </el-form-item>-->
                <el-form-item label="维保类型">
                  <el-select v-model="finalEvaluationForm.inspectionType" multiple placeholder="维保类型" style="width: 100%" disabled>
                    <el-option
                        v-for="dict in gxt_inspection_type"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <!--              <el-col :span="12">
                              <el-form-item label="质量系数" prop="finalCoefficient">
                                <el-input-number
                                    v-model="finalEvaluationForm.finalCoefficient"
                                    :min="finalEvaluationForm.orderType === 1 ? 0.5 : 0.8"
                                    :max="finalEvaluationForm.orderType === 1 ? 1.5 : 1.2"
                                    :step="0.01"
                                    style="width: 100%"
                                    controls-position="right"
                                    @change="onFinalCoefficientChange"
                                />
                              </el-form-item>
                            </el-col>-->
            </el-row>
            <el-form-item :label="finalEvaluationForm.orderType === 1 ? '维修总结' : '维保总结'">
              <el-input
                  v-model="finalEvaluationForm.workSummary"
                  type="textarea"
                  disabled
                  :rows="4"
              />
            </el-form-item>
            <!-- 额外工作总结 - 仅维修工单显示 -->
            <el-form-item
                label="额外工作总结"
                v-if="finalEvaluationForm.orderType === 1"
            >
              <el-input
                  v-model="finalEvaluationForm.extraWork"
                  type="textarea"
                  disabled
                  :rows="4"
              />
            </el-form-item>

            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="外委人员数（人）">
                  <el-input v-model="finalEvaluationForm.wwryNum" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="外来人员数（人）">
                  <el-input v-model="finalEvaluationForm.wlryNum" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="得分明细">
              <el-table :data="finalEvaluationForm.scorePersonList" border style="width: 100%;">
                <el-table-column label="工作班成员" align="center" prop="nickName"  style="width: 50%;">
                  <template #default="scope">
                    <span>{{ scope.row.nickName }}<span v-if="scope.row.isLeader == 1"> (工作负责人)</span></span>
                  </template>
                </el-table-column>
                <el-table-column label="检修工分" align="center" prop="selfScore">
                  <template #default="scope">
                    <span>{{ scope.row.selfScore !== null && scope.row.selfScore !== undefined ? parseFloat(scope.row.selfScore).toFixed(2) : '' }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="复评得分" align="center" prop="reviewScore">
                  <template #default="scope">
                    <span>{{ scope.row.reviewScore !== null && scope.row.reviewScore !== undefined ? parseFloat(scope.row.reviewScore).toFixed(2) : '' }}</span>
                  </template>
                </el-table-column>
<!--                <el-table-column label="终评得分" align="center" prop="finalScore">
                  <template #default="scope">
                    <el-input v-model="scope.row.finalScore"
                      :value="calculateFinalScore(scope.row.reviewScore, finalEvaluationForm.finalCoefficient)"
                      readonly
                      style="width: 100%;"
                    />
                  </template>
                </el-table-column>-->
                <el-table-column label="终评得分" align="center" prop="finalScore">
                  <template #default="scope">
                    <el-input v-model="scope.row.finalScore"
                      readonly
                      style="width: 100%;"
                    />
                  </template>
                </el-table-column>
                <!-- 额外工分和工单得分 - 仅当维修工单且有额外工作总结时显示 -->
                <el-table-column
                  label="额外工分"
                  align="center"
                  prop="extraScore"
                  v-if="hasExtraWork()"
                  style="width: 33%;">
                  <template #default="scope">
                    <el-input
                      v-model="scope.row.extraScore"
                      style="width: 100%;"
                      :disabled="true"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="工单得分"
                  align="center"
                  prop="totalScore"
                  v-if="hasExtraWork()"
                  style="width: 33%;">
                  <template #default="scope">
                    <el-input
                      v-model="scope.row.totalScore"
                      style="width: 100%;"
                      :disabled="true"
                    />
                  </template>
                </el-table-column>
                <!-- 额外工分和工单得分 - 仅当维保工单且维保类型包含其他/其它时显示 -->
                <el-table-column
                  label="额外工分"
                  align="center"
                  prop="extraScore"
                  v-if="finalEvaluationForm.orderType === 2 && hasOtherOrQitaInspectionType()"
                  style="width: 33%;">
                  <template #default="scope">
                    <el-input
                      v-model="scope.row.extraScore"
                      style="width: 100%;"
                      :disabled="true"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="工单得分"
                  align="center"
                  prop="totalScore"
                  v-if="finalEvaluationForm.orderType === 2 && hasOtherOrQitaInspectionType()"
                  style="width: 33%;">
                  <template #default="scope">
                    <el-input
                      v-model="scope.row.totalScore"
                      style="width: 100%;"
                      :disabled="true"
                    />
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
            <div class="dialog-footer" style="text-align: right;">
              <el-button @click="closeFinalEvaluationDialog">取 消</el-button>
              <el-button type="primary" @click="submitFinalEvaluation">提交终评</el-button>
            </div>
          </el-tab-pane>
          <el-tab-pane label="申诉信息" name="appeal" v-if="finalEvaluationForm.orderType === 2">
            <el-form-item label="申诉理由">
              <el-input
                v-model="finalEvaluationForm.appealReason"
                type="textarea"
                :rows="4"
                disabled
              />
            </el-form-item>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="申诉人">
                  <el-input v-model="finalEvaluationForm.appealUserName" disabled />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="申诉时间">
                  <el-input v-model="finalEvaluationForm.appealTime" disabled />
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>

      </el-form>

<!--      <template #footer>
        <div class="dialog-footer">
        </div>
      </template>-->
    </el-dialog>

    <!-- 确认对话框 -->
    <el-dialog :title="confirmForm.orderType === 1 ? '维修工单确认' : '维保工单确认'" v-model="confirmDialogVisible" width="800px" append-to-body>
      <el-form ref="confirmRef" :model="confirmForm" :rules="confirmRules" label-width="120px" label-position="top">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="工单编码">
              <el-input v-model="confirmForm.workOrderProjectNo" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="风机编号">
              <el-input v-model="confirmForm.pcsDeviceName" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="场站">
              <el-input v-model="confirmForm.pcsStationName" disabled />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item :label="confirmForm.orderType === 1 ? '维修总结' : '维保总结'">
          <el-input
            v-model="confirmForm.workSummary"
            type="textarea"
            disabled
            :rows="4"
          />
        </el-form-item>

        <el-row :gutter="20">
          <el-col :span="12" v-if="confirmForm.orderType === 1">
            <el-form-item label="检修类型">
              <el-select v-model="confirmForm.maintenanceType" disabled style="width: 100%">
                <el-option
                  v-for="item in maintenanceTypeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="confirmForm.orderType === 1">
            <el-form-item label="&nbsp;">
              <el-button
                :type="showMaintenanceFeedback ? 'danger' : 'primary'"
                @click="toggleMaintenanceFeedback">
                {{ showMaintenanceFeedback ? '取消反馈' : '反馈' }}
              </el-button>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="confirmForm.orderType === 2">
            <el-form-item label="维保类型">
              <el-select v-model="confirmForm.inspectionType" multiple disabled style="width: 100%">
                <el-option
                  v-for="item in inspectionTypeOptions"
                  :key="item.inspectionTypeId"
                  :label="item.score && item.score !== 0 ? getDictLabel(gxt_inspection_type, item.inspectionTypeId) + ' (' + item.score + '分)' : getDictLabel(gxt_inspection_type, item.inspectionTypeId)"
                  :value="item.inspectionTypeId.toString()">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="9" v-if="confirmForm.orderType === 2">
            <el-form-item label="分项完成系数">
              <el-input-number
                v-model="confirmForm.itemCompletionFactor"
                :min="0"
                :max="1"
                :step="0.1"
                style="width: 100%"
                controls-position="right"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="3" v-if="confirmForm.orderType === 2">
            <el-form-item label="&nbsp;">
              <el-button
                :type="showCompletionFactorFeedback ? 'danger' : 'primary'"
                @click="toggleCompletionFactorFeedback">
                {{ showCompletionFactorFeedback ? '取消反馈' : '反馈' }}
              </el-button>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="confirmForm.orderType === 2">
            <el-form-item label="分项完成系数和">
              <el-input-number
                  v-model="confirmForm.itemCompletionFactorSum"
                  :min="0"
                  :max="1"
                  :step="0.1"
                  style="width: 100%"
                  controls-position="right"
                  disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="confirmForm.modifyReason">
            <el-form-item label="修改理由" prop="modifyReason">
              <el-input
                  v-model="confirmForm.modifyReason"
                  type="textarea"
                  placeholder="请输入修改理由"
                  maxlength="200"
                  show-word-limit
                  :rows="3"
                  disabled
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="反馈理由" v-if="showMaintenanceFeedback || showCompletionFactorFeedback" prop="feedbackReason">
          <el-input
            v-model="confirmForm.feedbackReason"
            type="textarea"
            placeholder="请输入反馈理由"
            maxlength="200"
            show-word-limit
            :rows="3"
          />
        </el-form-item>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="外委人员数（人）">
              <el-input v-model="confirmForm.wwryNum" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="外来人员数（人）">
              <el-input v-model="confirmForm.wlryNum" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="得分明细">
          <el-table :data="scorePersonList" border style="width: 100%;">
            <el-table-column label="工作班成员" align="center" prop="nickName">
              <template #default="scope">
                <span>{{ scope.row.nickName }}<span v-if="scope.row.isLeader == 1"> (工作负责人)</span></span>
              </template>
            </el-table-column>
            <el-table-column label="检修工分" align="center" prop="selfScore">
              <template #default="scope">
                <span>{{ scope.row.selfScore !== null && scope.row.selfScore !== undefined ? parseFloat(scope.row.selfScore).toFixed(2) : '' }}</span>
              </template>
            </el-table-column>
            <el-table-column label="复评得分" align="center" prop="reviewScore">
              <template #default="scope">
                <span>{{ scope.row.reviewScore !== null && scope.row.reviewScore !== undefined ? parseFloat(scope.row.reviewScore).toFixed(2) : '' }}</span>
              </template>
            </el-table-column>
          </el-table>
        </el-form-item>
      </el-form>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="closeConfirmDialog">取 消</el-button>
          <el-button
            type="primary"
            @click="submitFeedback"
            v-if="showMaintenanceFeedback || showCompletionFactorFeedback">
            提交反馈
          </el-button>
          <el-button
            type="primary"
            @click="submitConfirm"
            v-else >
            确 认
          </el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 申诉对话框 -->
    <el-dialog title="发起申诉" v-model="appealDialogVisible" width="800px" append-to-body>
      <el-form ref="appealRef" :model="appealForm" :rules="appealRules" label-width="120px" label-position="top">
        <el-alert type="info" :closable="false" style="margin-bottom: 20px;">
          发起申诉操作，请输入申诉理由
        </el-alert>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item label="工单编码">
              <el-input v-model="appealForm.workOrderProjectNo" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="风机编号">
              <el-input v-model="appealForm.pcsDeviceName" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="场站">
              <el-input v-model="appealForm.pcsStationName" disabled />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="appealForm.orderType === 1 ? '发生时间' : '创建时间'">
              <el-input v-if="appealForm.orderType === 1" v-model="appealForm.occurTime" disabled />
              <el-input v-else v-model="appealForm.createTime" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="原得分">
              <el-input v-model="appealForm.originalScore" disabled />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="申诉理由" prop="appealReason">
          <el-input
            v-model="appealForm.appealReason"
            type="textarea"
            placeholder="请输入申诉理由"
            maxlength="500"
            show-word-limit
            :rows="6"
          />
        </el-form-item>
      </el-form>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="closeAppealDialog">取 消</el-button>
          <el-button type="primary" @click="submitAppeal">提交申诉</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="OrderScore">
import {
  listOrderScore,
  getOrderScore,
  selfEvaluation,
  review,
  confirm,
  finalEvaluation,
  appeal
} from "@/api/gxt/orderScore";
import { listScoreproject } from "@/api/gxt/scoreproject";
import { listMaintenanceCenters, listStationsByMaintenanceCenter } from "@/api/gxt/equipment"
import { listInspectionTypesByFanType } from "@/api/gxt/fanInspectionScore";
import useUserStore from '@/store/modules/user'
import { useRoute } from 'vue-router'
const route = useRoute();

const { proxy } = getCurrentInstance();
const { gxt_maintenance_type, gxt_work_order_status, gxt_order_priority_type,gxt_repair_order_flow_action_type,gxt_order_suspend_reason,gxt_order_type,gxt_scoring_status,gxt_inspection_type,gxt_work_order_flow_action_type } = proxy.useDict("gxt_maintenance_type", "gxt_work_order_status", "gxt_order_priority_type","gxt_repair_order_flow_action_type","gxt_order_suspend_reason","gxt_order_type","gxt_scoring_status","gxt_inspection_type","gxt_work_order_flow_action_type")

const userStore = useUserStore();

// 数据列表相关
const orderScoreList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const tableHeight = ref(window.innerHeight - 300);
const isEditScore = ref(true);
const flowList = ref([]); // 添加流转记录列表

// 对话框显示控制
const viewDialogVisible = ref(false);
const selfEvaluationDialogVisible = ref(false);
const reviewDialogVisible = ref(false);
const confirmDialogVisible = ref(false);
const finalEvaluationDialogVisible = ref(false);
const appealDialogVisible = ref(false); // 申诉对话框

// 表单相关
const queryRef = ref(null);
const selfEvaluationRef = ref(null);
const reviewRef = ref(null);
const confirmRef = ref(null);
const finalEvaluationRef = ref(null);
const appealRef = ref(null); // 申诉表单引用

// 终评标签页控制
const activeFinalEvalTab = ref('evaluation');

// 各种表单数据
const viewForm = ref({});
const selfEvaluationForm = ref({});
const reviewForm = ref({});
const confirmForm = ref({});
const finalEvaluationForm = ref({});
const appealForm = ref({}); // 申诉表单

// 人员列表
const scorePersonList = ref([]);
const filteredScorePersonList = computed(() => {
  // 只显示当前用户的得分明细
  return scorePersonList.value.filter(person =>
    person.userId === userStore.id
  );
});

// 反馈列表
const feedbackList = computed(() => {
  // 只显示有反馈理由的数据
  if (!reviewForm.value.scorePersonList) return [];
  return reviewForm.value.scorePersonList.filter(person =>
    person.feedbackReason && person.feedbackReason.trim() !== ''
  );
});

// 检查当前用户是否在检修员列表中
const isCurrentUserInScoreList = computed(() => {
  return scorePersonList.value.some(person =>
    person.userId === userStore.id
  );
});

// 显示修改理由
const showModifyReason = ref(false);
const showFeedbackReason = ref(false);

// 方法：检查复评得分是否与自评得分不同
function checkReviewScoreChanged() {
  if (!reviewForm.value || !reviewForm.value.scorePersonList) {
    return false;
  }

  return reviewForm.value.scorePersonList.some(person => {
    const selfScore = person.selfScore !== null && person.selfScore !== undefined && person.selfScore !== ''
      ? parseFloat(person.selfScore)
      : null;
    const reviewScore = person.reviewScore !== null && person.reviewScore !== undefined && person.reviewScore !== ''
      ? parseFloat(person.reviewScore)
      : null;

    // 如果自评得分和复评得分都存在且不相等，则返回true
    if (selfScore !== null && reviewScore !== null) {
      return Math.abs(selfScore - reviewScore) > 0.005; // 使用容差避免浮点数精度问题
    }

    // 如果自评得分存在但复评得分不存在，或反之，也认为是不同
    return (selfScore !== null && reviewScore === null) || (selfScore === null && reviewScore !== null);
  });
}

// 方法：检查分项完成系数是否发生变化（仅适用于维保工单）
function checkItemCompletionFactorChanged() {
  if (!reviewForm.value || reviewForm.value.orderType !== 2) {
    // 不是维保工单，不需要检查分项完成系数
    return false;
  }

  const currentFactor = reviewForm.value.itemCompletionFactor;
  const initialFactor = reviewForm.value.initialItemCompletionFactor;

  if (currentFactor == null || initialFactor == null) {
    // 如果任一值为null，认为没有变化
    return false;
  }

  // 比较分项完成系数是否发生变化
  return Math.abs(parseFloat(currentFactor) - parseFloat(initialFactor)) > 0.005;
}

// 控制反馈按钮状态
const showMaintenanceFeedback = ref(false);
const showCompletionFactorFeedback = ref(false);

// 控制复评对话框中字段是否可编辑
const isMaintenanceTypeEditable = ref(false);
const isItemCompletionFactorEditable = ref(false);

// 控制是否显示退回理由
const showReturnReason = ref(false);

// 计算属性：判断是否有退回理由
const hasReturnReason = computed(() => {
  return reviewForm.value && reviewForm.value.scoreReturnReason && reviewForm.value.scoreReturnReason.trim() !== '';
});

// 查询参数
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  workOrderProjectNo: null,
  pcsDeviceName: null,
  pcsStationName: null,
  orderType: null,
  scoringStatus: null,
  gxtCenter: null
});

// 表单验证规则
const selfEvaluationRules = ref({
  workSummary: [
    { required: true, message: "总结不能为空", trigger: "blur" }
  ],
  maintenanceType: [
    { required: true, message: "请选择检修类型", trigger: "change" }
  ],
  inspectionType: [
  ],
  itemCompletionFactor: [
    { required: true, message: "分项完成系数不能为空", trigger: "change" }
  ],
  itemCompletionFactorSum: [
    { required: true, message: "分项完成系数和不能为空", trigger: "change" }
  ]
});

const reviewRules = ref({
  itemCompletionFactor: [
    { required: true, message: "分项完成系数不能为空", trigger: "change" }
  ],
  modifyReason: [
    { required: true, message: "修改理由不能为空", trigger: "blur" }
  ],
  /*scoreReturnReason: [
    { required: true, message: "退回理由不能为空", trigger: "blur" }
  ],
  finalCoefficient: [
    { required: true, message: "质量系数(建议值)不能为空", trigger: "change" },
  ]*/
});

const finalEvaluationRules = ref({
  finalCoefficient: [
    { required: true, message: "质量系数不能为空", trigger: "change" }
  ]
});

// 确认对话框表单验证规则
const confirmRules = ref({
  feedbackReason: [
    { required: true, message: "反馈理由不能为空", trigger: "blur" }
  ]
});

// 申诉对话框表单验证规则
const appealRules = ref({
  appealReason: [
    { required: true, message: "申诉理由不能为空", trigger: "blur" }
  ]
});

// 维保中心和场站选项
const maintenanceCenterOptions = ref([])
const stationOptions = ref([])

// 检修类型选项
const maintenanceTypeOptions = ref([])

// 维保类型选项
const inspectionTypeOptions = ref([])

// 监听窗口大小变化
function handleResize() {
  tableHeight.value = window.innerHeight - 300;
}

// 根据字典值获取标签
function getDictLabel(dictOptions, value) {
  if (!dictOptions || !value) return '';
  const dict = dictOptions.find(item => item.value == value);
  return dict ? dict.label : '';
}

// 判断是否可以选择并发起申诉
const canAppeal = computed(() => {
  // 只有当选择了且仅选择了一个工单，并且该工单状态为"待归档"或"已归档"时才允许发起申诉
  if (ids.value.length !== 1) return false;

  const selectedOrder = orderScoreList.value.find(item => item.id === ids.value[0]);
  if (!selectedOrder) return false;

  // 维修工单和维保工单都可以发起申诉
  // 只有待归档(to_archive)或已归档(archived)状态才能发起申诉
  return (selectedOrder.orderType === 1 || selectedOrder.orderType === 2) &&
         (selectedOrder.scoringStatus === 'to_archive' || selectedOrder.scoringStatus === 'archived');
});

function getFromRoute() {
  const fromRoute = sessionStorage.getItem('fromRoute');
  const workOrderNo = sessionStorage.getItem('workOrderProjectNo');
  if (workOrderNo && (fromRoute === '/homePage/repair' || fromRoute === '/homePage/maintenance')) {
    // 更新查询参数
    queryParams.value.workOrderProjectNo = workOrderNo;
    let repairOrderParams = {};
    let workOrderParams = {};
    repairOrderParams.workOrderProjectNo = workOrderNo;
    workOrderParams.workOrderProjectNo = workOrderNo;
    if (fromRoute === '/homePage/repair') {
      // 只查询维修工单
      queryParams.value.orderType = '1'
      repairOrderParams.orderType = '1';
      workOrderParams.id = -1; // 设置一个不可能匹配的条件
    }else {
      // 只查询维保工单
      queryParams.value.orderType = '2'
      workOrderParams.orderType = '2';
      repairOrderParams.id = -1; // 设置一个不可能匹配的条件
    }

    // 构造查询参数
    const params = {
      pageNum: queryParams.value.pageNum,
      pageSize: queryParams.value.pageSize,
      ...repairOrderParams,
      ...workOrderParams
    };

    listOrderScore(params).then(response => {
      if(response.rows && response.rows.length > 0) {
        handleView(response.rows[0]);
      }

    });

    // 清除sessionStorage中的临时数据
    sessionStorage.removeItem('fromRoute');
    sessionStorage.removeItem('workOrderProjectNo');
  }
}

onMounted(() => {
  getList();
  getMaintenanceCenterAndStationList();
  getMaintenanceTypeList();
  window.addEventListener('resize', handleResize);
  getFromRoute()
});

watch(() => route.query, (newQuery, oldQuery) => {
  getFromRoute()
}, { deep: true });

onUnmounted(() => {
  window.removeEventListener('resize', handleResize);
});

/** 查询工单评分列表 */
function getList() {
  loading.value = true;
  // 根据工单类型分别设置查询参数
  let repairOrderParams = {};
  let workOrderParams = {};

  if (queryParams.value.workOrderProjectNo) {
    repairOrderParams.workOrderProjectNo = queryParams.value.workOrderProjectNo;
    workOrderParams.workOrderProjectNo = queryParams.value.workOrderProjectNo;
  }

  if (queryParams.value.pcsDeviceName) {
    repairOrderParams.pcsDeviceName = queryParams.value.pcsDeviceName;
    workOrderParams.pcsDeviceName = queryParams.value.pcsDeviceName;
  }

  if (queryParams.value.pcsStationName) {
    repairOrderParams.pcsStationName = queryParams.value.pcsStationName;
    workOrderParams.pcsStationName = queryParams.value.pcsStationName;
  }

  if (queryParams.value.gxtCenter) {
    repairOrderParams.gxtCenter = queryParams.value.gxtCenter;
    workOrderParams.gxtCenter = queryParams.value.gxtCenter;
  }

  if (queryParams.value.scoringStatus) {
    repairOrderParams.scoringStatus = queryParams.value.scoringStatus;
    workOrderParams.scoringStatus = queryParams.value.scoringStatus;
  }

  // 工单类型筛选
  if (queryParams.value.orderType) {
    if (queryParams.value.orderType === '1') {
      // 只查询维修工单
      repairOrderParams.orderType = queryParams.value.orderType;
      workOrderParams.id = -1; // 设置一个不可能匹配的条件
    } else if (queryParams.value.orderType === '2') {
      // 只查询维保工单
      workOrderParams.orderType = queryParams.value.orderType;
      repairOrderParams.id = -1; // 设置一个不可能匹配的条件
    }
  }

  // 构造查询参数
  const params = {
    pageNum: queryParams.value.pageNum,
    pageSize: queryParams.value.pageSize,
    ...repairOrderParams,
    ...workOrderParams
  };

  listOrderScore(params).then(response => {
    orderScoreList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length !== 1;
  multiple.value = !selection.length;
}

/** 查看详情 */
function handleView(row) {
  getOrderScore(row.orderType, row.id).then(response => {
    const data = response.data;
    viewForm.value = data;
    viewForm.value.orderType = row.orderType;
    // 根据工单类型设置总结内容
    viewForm.value.workSummary = row.orderType === 1 ? data.content : data.realContent;
    viewForm.value.extraWork = row.orderType === 1 ? data.extraWork : null; // 额外工作总结
    // 特别处理维保工单的inspectionType字段
    if (row.orderType === 2) {
      viewForm.value.inspectionType = data.inspectionType ? (Array.isArray(data.inspectionType) ? data.inspectionType : data.inspectionType.split(',')) : [];
    }
    // 根据工单类型设置人员列表
    if (row.orderType === 1) {
      // 维修工单
      viewForm.value.scorePersonList = data.repairOrderPersonList || [];
      flowList.value = data.repairOrderFlowList || [];
    } else if (row.orderType === 2) {
      // 维保工单
      viewForm.value.scorePersonList = data.workOrderPersonList || [];
      flowList.value = data.workOrderFlowList || [];
    }
    viewDialogVisible.value = true;
  });
}

/** 关闭查看详情对话框 */
function closeViewDialog() {
  viewDialogVisible.value = false;
  viewForm.value = {};
}

/** 自评操作 */
function handleSelfEvaluation(row) {
  getOrderScore(row.orderType, row.id).then(response => {
    const data = response.data;

    // 重置维保类型选项
    inspectionTypeOptions.value = [];

    selfEvaluationForm.value = {
      orderType: row.orderType,
      id: row.id,
      workOrderProjectNo: row.workOrderProjectNo,
      pcsDeviceName: row.pcsDeviceName,
      pcsStationName: row.pcsStationName,
      workSummary: row.orderType === 1 ? data.content : data.realContent,
      extraWork: row.orderType === 1 ? data.extraWork : null, // 额外工作总结
      maintenanceType: row.orderType === 1 ? data.maintenanceType : null,
      inspectionType: row.orderType === 2 ? (Array.isArray(data.inspectionType) ? data.inspectionType : (data.inspectionType ? data.inspectionType.split(',') : [])) : null,
      itemCompletionFactor: row.orderType === 2 ? data.itemCompletionFactor : null,
      itemCompletionFactorSum: row.orderType === 2 ? data.itemCompletionFactorSum : null,
      scorePersonList: row.orderType === 1 ? (data.repairOrderPersonList || []) : (data.workOrderPersonList || []),
      wwryNum: data.wwryNum,
      wlryNum: data.wlryNum,
    };

    // 初始化自评分，如果之前已有自评分数则保留，否则初始化为空值
    if (selfEvaluationForm.value.scorePersonList && selfEvaluationForm.value.scorePersonList.length > 0) {
      selfEvaluationForm.value.scorePersonList.forEach(person => {
        // 保留之前已存在的自评分数，如果没有则初始化为null
        if (person.selfScore === undefined || person.selfScore === null) {
          person.selfScore = null;
        }
        // 保留之前已存在的额外工分，如果没有则初始化为null
        if (person.extraScore === undefined || person.extraScore === null) {
          person.extraScore = null;
        }
        // 保留之前已存在的总分，如果没有则初始化为null
        if (person.totalScore === undefined || person.totalScore === null) {
          person.totalScore = null;
        }
      });
    }

    // 如果是维保工单，根据风机型号获取维保类型选项
    if (row.orderType === 2) {
      listInspectionTypesByFanType(row.model).then(res => {
        inspectionTypeOptions.value = res.data;
      }).catch(error => {
        console.error('获取维保类型选项失败:', error);
        inspectionTypeOptions.value = [];
      });
    }

    selfEvaluationDialogVisible.value = true;
  });
}

/** 监听检修类型变化，清空自评分 */
function handleMaintenanceTypeChangeForSelfEvaluation() {
  /*if (selfEvaluationForm.value.orderType === 1) {
    // 维修工单
    calculateRepairScores();
  } else if (selfEvaluationForm.value.orderType === 2) {
    // 维保工单
    calculateMaintenanceScores();
  }*/
  //clearSelfScores();
  if (selfEvaluationForm.value.orderType === 1) {
    // 如果额外工作总结有值，重新计算总分
    if (selfEvaluationForm.value.extraWork && selfEvaluationForm.value.extraWork.trim() !== '') {
      if (selfEvaluationForm.value.scorePersonList && selfEvaluationForm.value.scorePersonList.length > 0) {
        selfEvaluationForm.value.scorePersonList.forEach(person => {
          updateTotalScore(person);
        });
      }
    }
  }
}

/** 更新总分（检修工分+额外工分） */
function updateTotalScore(row) {
  if (row.selfScore !== null && row.selfScore !== undefined &&
      row.extraScore !== null && row.extraScore !== undefined) {
    // 计算总分，保留两位小数
    const total = parseFloat((parseFloat(row.selfScore) + parseFloat(row.extraScore)).toFixed(2));
    row.totalScore = total;
  } else if (row.selfScore !== null && row.selfScore !== undefined) {
    // 如果额外工分为null或undefined，只显示检修工分
    row.totalScore = parseFloat(row.selfScore.toFixed(2));
  } else if (row.extraScore !== null && row.extraScore !== undefined) {
    // 如果检修工分为null或undefined，只显示额外工分
    row.totalScore = parseFloat(row.extraScore.toFixed(2));
  } else {
    // 都为null或undefined，则总分为null
    row.totalScore = null;
  }
}

/** 更新复评总分（复评得分+额外工分） */
function updateReviewTotalScore(row) {
  if (row.reviewScore !== null && row.reviewScore !== undefined &&
      row.extraScore !== null && row.extraScore !== undefined) {
    // 计算总分，保留两位小数
    const total = parseFloat((parseFloat(row.reviewScore) + parseFloat(row.extraScore)).toFixed(2));
    row.totalScore = total;
  } else if (row.reviewScore !== null && row.reviewScore !== undefined) {
    // 如果额外工分为null或undefined，只显示复评得分
    row.totalScore = parseFloat(row.reviewScore.toFixed(2));
  } else if (row.extraScore !== null && row.extraScore !== undefined) {
    // 如果复评得分为null或undefined，只显示额外工分
    row.totalScore = parseFloat(row.extraScore.toFixed(2));
  } else {
    // 都为null或undefined，则总分为null
    row.totalScore = null;
  }
}

// 防抖定时器
let debounceTimer = null;

/** 复评得分变化处理（带防抖） */
function onReviewScoreInputChange(row) {
  // 清除之前的定时器
  if (debounceTimer) {
    clearTimeout(debounceTimer);
  }

  // 设置新的定时器
  debounceTimer = setTimeout(() => {
    updateReviewTotalScore(row);

    // 检查是否需要显示修改理由
    const shouldShowModifyReason = checkReviewScoreChanged() || checkItemCompletionFactorChanged();

    if (shouldShowModifyReason && !showModifyReason.value) {
      // 需要显示修改理由，且当前未显示
      showModifyReason.value = true;
    } else if (!shouldShowModifyReason && showModifyReason.value) {
      // 不需要显示修改理由，但当前显示着
      showModifyReason.value = false;
    }
  }, 300); // 300ms 防抖延迟
}

/** 处理额外工作总结变化 */
function handleExtraWorkChange() {
  // 如果额外工作总结为空，清空额外工分和总分的值
  if (!selfEvaluationForm.value.extraWork || selfEvaluationForm.value.extraWork.trim() === '') {
    if (selfEvaluationForm.value.scorePersonList && selfEvaluationForm.value.scorePersonList.length > 0) {
      selfEvaluationForm.value.scorePersonList.forEach(person => {
        person.extraScore = null;
        person.totalScore = null;
      });
    }
  }
}

/** 计算维修工单人员得分 */
function calculateRepairScores() {
  const maintenanceType = selfEvaluationForm.value.maintenanceType;
  if (!maintenanceType) {
    // 清空得分
    selfEvaluationForm.value.scorePersonList.forEach(person => {
      person.selfScore = null;
    });
    return;
  }

  // 查找选中的检修类型对应的分值
  const selectedType = maintenanceTypeOptions.value.find(item => item.value === maintenanceType);
  if (!selectedType) {
    // 清空得分
    selfEvaluationForm.value.scorePersonList.forEach(person => {
      person.selfScore = null;
    });
    return;
  }

  // 获取分值
  const scoreMatch = selectedType.label.match(/\((\d+(\.\d+)?)分\)/);
  if (!scoreMatch) {
    // 清空得分
    selfEvaluationForm.value.scorePersonList.forEach(person => {
      person.selfScore = null;
    });
    return;
  }

  const totalScore = parseFloat(scoreMatch[1]);

  if (selfEvaluationForm.value.scorePersonList.length === 0) return;

  const personCount = selfEvaluationForm.value.scorePersonList.length +
      (parseInt(selfEvaluationForm.value.wwryNum) || 0) +
      (parseInt(selfEvaluationForm.value.wlryNum) || 0);

  // 计算基础分
  const baseScore = totalScore / personCount;

  // 设置得分
  selfEvaluationForm.value.scorePersonList.forEach(person => {
    if (person.isLeader == 1) {
      // 工作负责人额外加0.5分
      person.selfScore = (baseScore + 0.5).toFixed(2);
    } else {
      person.selfScore = baseScore.toFixed(2);
    }
  });

  // 如果额外工作总结有值，重新计算总分
  if (selfEvaluationForm.value.extraWork && selfEvaluationForm.value.extraWork.trim() !== '') {
    selfEvaluationForm.value.scorePersonList.forEach(person => {
      updateTotalScore(person);
    });
  }
}

/** 计算维保工单人员得分 */
function calculateMaintenanceScores() {
  if (selfEvaluationForm.value.scorePersonList.length === 0) return;
  const personCount = selfEvaluationForm.value.scorePersonList.length+
      (parseInt(selfEvaluationForm.value.wwryNum) || 0) +
      (parseInt(selfEvaluationForm.value.wlryNum) || 0);
  // 获取分项完成系数，默认为1
  const completionFactor = selfEvaluationForm.value.itemCompletionFactor || 1;

  // 获取选中的维保项目（现在是多选）
  const selectedInspectionTypes = selfEvaluationForm.value.inspectionType || [];

  // 计算所有选中维保项目的总分值
  let totalScoreFromDB = 0; // 默认值
  isEditScore.value = false;

  if (Array.isArray(selectedInspectionTypes) && selectedInspectionTypes.length > 0) {
    selectedInspectionTypes.forEach(typeId => {
      const selectedType = inspectionTypeOptions.value.find(item => item.inspectionTypeId.toString() === typeId);
      if (selectedType && selectedType.score) {
        totalScoreFromDB += selectedType.score;
        isEditScore.value = true;
      }
    });
  }

  // 计算基础分：基础分 = (所有选中维保类型组合的总得分 * 分项完成系数) / 组员人数
  const baseScore = (totalScoreFromDB * completionFactor) / personCount;

  // 设置得分
  selfEvaluationForm.value.scorePersonList.forEach(person => {
    if(!isEditScore.value){
      person.selfScore = null;
      return;
    }
    if (person.isLeader == 1) {
      // 工作负责人额外加0.5分
      person.selfScore = (baseScore + 0.5).toFixed(2);
    } else {
      person.selfScore = baseScore.toFixed(2);
    }
  });
}

/** 关闭自评对话框 */
function closeSelfEvaluationDialog() {
  selfEvaluationDialogVisible.value = false;
  proxy.resetForm("selfEvaluationRef");
}

/** 提交自评 */
function submitSelfEvaluation() {
  // 首先验证表单基础字段
  proxy.$refs["selfEvaluationRef"].validate(valid => {
    if (valid) {
      // 验证评分规则
      const validation = validateScoringRules();
      if (!validation.valid) {
        proxy.$modal.msgError(validation.message);
        return;
      }

      // 提交自评
      // 确保在提交前计算所有人员的总分
      if (selfEvaluationForm.value.scorePersonList && selfEvaluationForm.value.scorePersonList.length > 0) {
        selfEvaluationForm.value.scorePersonList.forEach(person => {
          updateTotalScore(person);
        });
      }

      // 在提交前将数组格式的inspectionType转换为字符串格式
      const submitData = { ...selfEvaluationForm.value };
      if (Array.isArray(submitData.inspectionType)) {
        submitData.inspectionType = submitData.inspectionType.join(',');
      }

      selfEvaluation(submitData).then(response => {
        proxy.$modal.msgSuccess("自评提交成功");
        selfEvaluationDialogVisible.value = false;
        getList();
      });
    }
  });
}

/** 复评操作 */
function handleReview(row) {
  getOrderScore(row.orderType, row.id).then(response => {
    const data = response.data;
    // 重置维保类型选项
    inspectionTypeOptions.value = [];
    reviewForm.value = {
      orderType: row.orderType,
      id: row.id,
      workOrderProjectNo: row.workOrderProjectNo,
      pcsDeviceName: row.pcsDeviceName,
      pcsStationName: row.pcsStationName,
      workSummary: row.orderType === 1 ? data.content : data.realContent,
      maintenanceType: row.orderType === 1 ? data.maintenanceType : null,
      inspectionType: row.orderType === 2 ? (Array.isArray(data.inspectionType) ? data.inspectionType : (data.inspectionType ? data.inspectionType.split(',') : [])) : null,
      itemCompletionFactor: row.orderType === 2 ? data.itemCompletionFactor : null,
      itemCompletionFactorSum: row.orderType === 2 ? data.itemCompletionFactorSum : null,
      modifyReason: data.modifyReason,
      reviewScoreNum: row.reviewScoreNum,
      scorePersonList: row.orderType === 1 ? (data.repairOrderPersonList || []) : (data.workOrderPersonList || []),
      feedbackReason: row.orderType === 2 ? data.feedbackReason : null,
      confirmStatus: data.confirmStatus,
      wwryNum: data.wwryNum,
      wlryNum: data.wlryNum,
      finalCoefficient: row.orderType === 1 ? (data.finalCoefficient ? data.finalCoefficient : 1.0) : null,
      scoreReturnReason: null,
      extraWork: row.orderType === 1 ? data.extraWork : null, // 额外工作总结
    };

    // 保存初始值，用于比较
    if (row.orderType === 1) {
      reviewForm.value.initialMaintenanceType = data.maintenanceType;
    } else {
      reviewForm.value.initialItemCompletionFactor = data.itemCompletionFactor;
    }

    // 初始化复评得分，默认使用自评得分作为初始值
    if (reviewForm.value.scorePersonList && reviewForm.value.scorePersonList.length > 0) {
      reviewForm.value.scorePersonList.forEach(person => {
        // 如果复评得分为空，则使用自评得分作为默认值
        if(person.reviewScore === null || person.reviewScore === undefined || person.reviewScore === ''){
          // 使用自评得分作为默认值
          if(person.selfScore !== null && person.selfScore !== undefined && person.selfScore !== '') {
            person.reviewScore = parseFloat(person.selfScore).toFixed(2);
          } else {
            person.reviewScore = null;
          }
        } else {
          // 如果复评得分已有值，则格式化为两位小数
          person.reviewScore = parseFloat(person.reviewScore).toFixed(2);
        }

        // 如果是维修工单且有额外工分，或维保工单且包含其他/其它选项且有额外工分，则计算总分
        // 注意：复评阶段额外工分为只读，不应当修改
        if (person.extraScore !== null && person.extraScore !== undefined && person.reviewScore !== null && person.reviewScore !== undefined){
          person.totalScore = parseFloat((parseFloat(person.reviewScore) + parseFloat(person.extraScore)).toFixed(2));
        }else if(person.reviewScore !== null && person.reviewScore !== undefined){
          person.totalScore = parseFloat(person.reviewScore);
        } else {
          person.totalScore = null;
        }
      });
    }

    // 重置编辑状态
    isMaintenanceTypeEditable.value = false;
    isItemCompletionFactorEditable.value = false;
    showReturnReason.value = false;
    showModifyReason.value = false;

    // 检查是否需要显示修改理由 - 检查复评得分是否与自评得分不同或分项完成系数是否变化
    // 在数据加载完成后检查是否需要显示修改理由
   /* const shouldShowModifyReason = checkReviewScoreChanged() || checkItemCompletionFactorChanged();

    if (shouldShowModifyReason && !showModifyReason.value) {
      showModifyReason.value = true;
    } else if (!shouldShowModifyReason && showModifyReason.value) {
      // 如果不需要显示修改理由，但当前显示着，则隐藏
      showModifyReason.value = false;
    }*/

    // 如果是维保工单，根据风机型号获取维保类型选项
    if (row.orderType === 2) {
      listInspectionTypesByFanType(row.model).then(res => {
        inspectionTypeOptions.value = res.data;
      }).catch(error => {
        console.error('获取维保类型选项失败:', error);
        inspectionTypeOptions.value = [];
      });
    }

    reviewDialogVisible.value = true;
  });
}

/** 确认操作 */
function handleConfirm(row) {
  getOrderScore(row.orderType, row.id).then(response => {
    const data = response.data;
    // 重置维保类型选项
    inspectionTypeOptions.value = [];
    confirmForm.value = {
      orderType: row.orderType,
      id: row.id,
      workOrderProjectNo: row.workOrderProjectNo,
      pcsDeviceName: row.pcsDeviceName,
      pcsStationName: row.pcsStationName,
      workSummary: row.orderType === 1 ? data.content : data.realContent,
      maintenanceType: row.orderType === 1 ? data.maintenanceType : null,
      inspectionType: row.orderType === 2 ? (Array.isArray(data.inspectionType) ? data.inspectionType : (data.inspectionType ? data.inspectionType.split(',') : [])) : null,
      feedbackReason: null,
      scorePersonList: row.orderType === 1 ? (data.repairOrderPersonList || []) : (data.workOrderPersonList || []),
      itemCompletionFactor: row.orderType === 2 ? data.itemCompletionFactor : null,
      itemCompletionFactorSum: row.orderType === 2 ? data.itemCompletionFactorSum : null,
      modifyReason: data.modifyReason,
      wwryNum: data.wwryNum,
      wlryNum: data.wlryNum,
    };

    // 设置人员列表
    scorePersonList.value = confirmForm.value.scorePersonList;

    // 如果是维保工单，根据风机型号获取维保类型选项
    if (row.orderType === 2) {
      listInspectionTypesByFanType(row.model).then(res => {
        inspectionTypeOptions.value = res.data;
      }).catch(error => {
        console.error('获取维保类型选项失败:', error);
        inspectionTypeOptions.value = [];
      });
    }

    // 默认不显示反馈理由输入框
    showFeedbackReason.value = false;

    confirmDialogVisible.value = true;
  });
}

/** 修改类型 */
function handleModifyType() {
  if (reviewForm.value.orderType === 1) {
    // 维修工单，允许修改检修类型
    isMaintenanceTypeEditable.value = true;
  } else {
    // 维保工单，允许修改分项完成系数
    isItemCompletionFactorEditable.value = true;
  }
}

// 监听检修类型变化
function handleMaintenanceTypeChange() {
  if (reviewForm.value.orderType === 1 && isMaintenanceTypeEditable.value) {
    // 维修工单且检修类型可编辑时，检查是否需要显示修改理由
    if (reviewForm.value.maintenanceType !== reviewForm.value.initialMaintenanceType) {
      showModifyReason.value = true;
    } else {
      showModifyReason.value = false;
    }
    // 不再自动计算复评得分，因为现在是手动输入
    // 计算维修工单复评得分
    //calculateRepairReviewScores();
  }
}

// 计算维修工单复评得分
function calculateRepairReviewScores() {
  const maintenanceType = reviewForm.value.maintenanceType;
  if (!maintenanceType) {
    // 清空得分
    reviewForm.value.scorePersonList.forEach(person => {
      person.reviewScore = null;
    });
    return;
  }

  // 查找选中的检修类型对应的分值
  const selectedType = maintenanceTypeOptions.value.find(item => item.value === maintenanceType);
  if (!selectedType) {
    // 清空得分
    reviewForm.value.scorePersonList.forEach(person => {
      person.reviewScore = null;
    });
    return;
  }

  // 获取分值
  const scoreMatch = selectedType.label.match(/\((\d+(\.\d+)?)分\)/);
  if (!scoreMatch) {
    // 清空得分
    reviewForm.value.scorePersonList.forEach(person => {
      person.reviewScore = null;
    });
    return;
  }

  const totalScore = parseFloat(scoreMatch[1]);

  if (reviewForm.value.scorePersonList.length === 0) return;

  const personCount = reviewForm.value.scorePersonList.length+
      (parseInt(reviewForm.value.wwryNum) || 0) +
      (parseInt(reviewForm.value.wlryNum) || 0);

  // 计算基础分
  const baseScore = totalScore / personCount;

  // 设置得分
  reviewForm.value.scorePersonList.forEach(person => {
    if (person.isLeader == 1) {
      // 工作负责人额外加0.5分
      person.reviewScore = (baseScore + 0.5).toFixed(2);
    } else {
      person.reviewScore = baseScore.toFixed(2);
    }
  });
}

// 监听分项完成系数变化
function calculateMaintenanceReviewScores() {
  // 检查是否需要显示修改理由
  if (reviewForm.value.initialItemCompletionFactor !== undefined &&
      reviewForm.value.itemCompletionFactor !== reviewForm.value.initialItemCompletionFactor) {
    showModifyReason.value = true;
  } else {
    showModifyReason.value = false;
  }
  // 不再自动计算复评得分，因为现在是手动输入
  /*if (reviewForm.value.scorePersonList.length === 0) return;
  const personCount = reviewForm.value.scorePersonList.length+
      (parseInt(reviewForm.value.wwryNum) || 0) +
      (parseInt(reviewForm.value.wlryNum) || 0);

  // 获取分项完成系数，默认为1
  const completionFactor = reviewForm.value.itemCompletionFactor || 1;

  // 获取选中的维保项目（现在是多选）
  const selectedInspectionTypes = reviewForm.value.inspectionType || [];

  // 计算所有选中维保项目的总分值
  let totalScoreFromDB = 0; // 默认值
  isEditScore.value = false;

  if (Array.isArray(selectedInspectionTypes) && selectedInspectionTypes.length > 0) {
    selectedInspectionTypes.forEach(typeId => {
      const selectedType = inspectionTypeOptions.value.find(item => item.inspectionTypeId.toString() === typeId);
      if (selectedType && selectedType.score) {
        totalScoreFromDB += selectedType.score;
        isEditScore.value = true;
      }
    });
  }

  // 计算基础分：基础分 = (所有选中维保类型组合的总得分 * 分项完成系数) / 组员人数
  const baseScore = (totalScoreFromDB * completionFactor) / personCount;

  // 设置得分
  reviewForm.value.scorePersonList.forEach(person => {
    if (person.isLeader == 1) {
      // 工作负责人额外加0.5分
      person.reviewScore = (baseScore + 0.5).toFixed(2);
    } else {
      person.reviewScore = baseScore.toFixed(2);
    }
  });*/
}

/** 关闭复评对话框 */
function closeReviewDialog() {
  reviewDialogVisible.value = false;
  showModifyReason.value = false;
  isMaintenanceTypeEditable.value = false;
  isItemCompletionFactorEditable.value = false;
  proxy.resetForm("reviewRef");
}

/** 提交退回 */
function submitReturn() {
  proxy.$refs["reviewRef"].validate(valid => {
    if (valid) {
      /*// 检查是否是维修工单
      if (reviewForm.value.orderType !== 1) {
        proxy.$modal.msgError("只有维修工单才能执行退回操作");
        return;
      }*/

      // 验证退回理由不为空
      if (!reviewForm.value.scoreReturnReason || reviewForm.value.scoreReturnReason.trim() === '') {
        proxy.$modal.msgError("退回理由不能为空");
        return;
      }

     /* const returnData = {
        orderType: reviewForm.value.orderType,
        id: reviewForm.value.id,
        scoreReturnReason: reviewForm.value.scoreReturnReason,
        // 保留其他必要的字段
        scorePersonList: reviewForm.value.scorePersonList,
        feedbackReason: reviewForm.value.feedbackReason,
        confirmStatus: reviewForm.value.confirmStatus,
        finalCoefficient: reviewForm.value.finalCoefficient
      };*/
      // 在提交前将数组格式的inspectionType转换为字符串格式
      const submitData = { ...reviewForm.value };
      if (Array.isArray(submitData.inspectionType)) {
        submitData.inspectionType = submitData.inspectionType.join(',');
      }
      review(submitData).then(response => {
        proxy.$modal.msgSuccess("退回成功");
        reviewDialogVisible.value = false;
        getList();
      }).catch(error => {
        proxy.$modal.msgError(error.message || "退回失败");
      });
    }
  });
}



/** 关闭确认对话框 */
function closeConfirmDialog() {
  confirmDialogVisible.value = false;
  showFeedbackReason.value = false;
  showMaintenanceFeedback.value = false;
  showCompletionFactorFeedback.value = false;
  proxy.resetForm("confirmRef");
}

/** 监听退回理由输入 */
function onReturnReasonInput() {
  // 当用户输入退回理由时，自动显示退回按钮
  // 这会触发计算属性hasReturnReason的更新
}

/** 提交复评 */
function submitReview() {
  proxy.$refs["reviewRef"].validate(valid => {
    if (valid) {
      // 验证评分规则
      const validation = validateReviewScoringRules();
      if (!validation.valid) {
        proxy.$modal.msgError(validation.message);
        return;
      }

      /*// 对于维修工单，如果检修类型被修改但未填写修改理由，则提示错误
      if (reviewForm.value.orderType === 1 &&
          isMaintenanceTypeEditable.value &&
          reviewForm.value.maintenanceType !== reviewForm.value.initialMaintenanceType &&
          !reviewForm.value.modifyReason) {
        proxy.$modal.msgError("修改了检修类型，请填写修改理由");
        return;
      }

      // 对于维保工单，如果分项完成系数被修改但未填写修改理由，则提示错误
      if (reviewForm.value.orderType === 2 &&
          isItemCompletionFactorEditable.value &&
          reviewForm.value.itemCompletionFactor !== reviewForm.value.initialItemCompletionFactor &&
          !reviewForm.value.modifyReason) {
        proxy.$modal.msgError("修改了分项完成系数，请填写修改理由");
        return;
      }*/

      // 验证质量系数不为空（仅维修工单）
      /*if (reviewForm.value.orderType === 1 && (!reviewForm.value.finalCoefficient || reviewForm.value.finalCoefficient === null)) {
        proxy.$modal.msgError("质量系数不能为空");
        return;
      }*/
      if(!showModifyReason.value){
        reviewForm.value.modifyReason = '';
      }
      reviewForm.value.scorePersonList.forEach(person => {
        if (person.extraScore !== null && person.extraScore !== undefined){
          person.totalScore = parseFloat((parseFloat(person.reviewScore) + parseFloat(person.extraScore)).toFixed(2));
        }else{
          person.totalScore = parseFloat(person.reviewScore)
        }
      });
      reviewForm.value.reviewScoreNum = reviewForm.value.reviewScoreNum + 1;
      // 在提交前将数组格式的inspectionType转换为字符串格式
      const submitData = { ...reviewForm.value };
      if (Array.isArray(submitData.inspectionType)) {
        submitData.inspectionType = submitData.inspectionType.join(',');
      }

      review(submitData).then(response => {
        proxy.$modal.msgSuccess("复评提交成功");
        reviewDialogVisible.value = false;
        getList();
      });
    }
  });
}

/** 提交确认 */
function submitConfirm() {
  // 重置反馈状态
  showMaintenanceFeedback.value = false;
  showCompletionFactorFeedback.value = false;

  const confirmData = {
    orderType: confirmForm.value.orderType,
    id: confirmForm.value.id,
    feedbackReason: null, // 确认时没有反馈理由
    scorePersonList: confirmForm.value.scorePersonList, //人员列表
    confirmStatus: 1, // 1表示已确认
  };

  confirm(confirmData).then(response => {
    proxy.$modal.msgSuccess("确认提交成功");
    confirmDialogVisible.value = false;
    getList();
  });
}

/** 切换检修类型反馈状态 */
function toggleMaintenanceFeedback() {
  showMaintenanceFeedback.value = !showMaintenanceFeedback.value;
  // 如果隐藏反馈，则清空反馈理由
  if (!showMaintenanceFeedback.value) {
    confirmForm.value.feedbackReason = '';
  }
}

/** 切换分项完成系数反馈状态 */
function toggleCompletionFactorFeedback() {
  showCompletionFactorFeedback.value = !showCompletionFactorFeedback.value;
  // 如果隐藏反馈，则清空反馈理由
  if (!showCompletionFactorFeedback.value) {
    confirmForm.value.feedbackReason = '';
  }
}

/** 提交反馈 */
function submitFeedback() {
  proxy.$refs["confirmRef"].validate(valid => {
    if (valid) {
      const confirmData = {
        orderType: confirmForm.value.orderType,
        id: confirmForm.value.id,
        feedbackReason: confirmForm.value.feedbackReason,
        scorePersonList: confirmForm.value.scorePersonList, //人员列表
        confirmStatus: 2 // 2表示已反馈
      };

      confirm(confirmData).then(response => {
        proxy.$modal.msgSuccess("反馈提交成功");
        confirmDialogVisible.value = false;
        showMaintenanceFeedback.value = false;
        showCompletionFactorFeedback.value = false;
        getList();
      });
    }
  });
}

/** 终评操作 */
function handleFinalEvaluation(row) {
  getOrderScore(row.orderType, row.id).then(response => {
    const data = response.data;
    // 重置维保类型选项
    inspectionTypeOptions.value = [];
    finalEvaluationForm.value = {
      orderType: row.orderType,
      id: row.id,
      workOrderProjectNo: row.workOrderProjectNo,
      pcsDeviceName: row.pcsDeviceName,
      pcsStationName: row.pcsStationName,
      workSummary: row.orderType === 1 ? data.content : data.realContent,
      extraWork: row.orderType === 1 ? data.extraWork : null, // 额外工作总结
      maintenanceType: row.orderType === 1 ? data.maintenanceType : null,
      inspectionType: row.orderType === 2 ? (Array.isArray(data.inspectionType) ? data.inspectionType : (data.inspectionType ? data.inspectionType.split(',') : [])) : null,
      finalCoefficient: row.orderType === 1 ? (data.finalCoefficient || 1.0) : 1.0, // 默认系数，维修工单使用班长建议值
      scorePersonList: row.orderType === 1 ? (data.repairOrderPersonList || []) : (data.workOrderPersonList || []),
      feedbackReason: row.orderType === 1 ? data.feedbackReason : null,
      confirmStatus: data.confirmStatus,
      // 申诉相关信息
      appealReason: data.appealReason,
      appealUserName: data.appealUserName,
      appealTime: data.appealTime ? proxy.parseTime(data.appealTime, '{y}-{m}-{d} {h}:{i}') : null,
      wwryNum: data.wwryNum,
      wlryNum: data.wlryNum,
    };

    // 如果是维保工单，根据风机型号获取维保类型选项
    if (row.orderType === 2) {
      listInspectionTypesByFanType(row.model).then(res => {
        inspectionTypeOptions.value = res.data;
      }).catch(error => {
        console.error('获取维保类型选项失败:', error);
        inspectionTypeOptions.value = [];
      });
    }

    // 默认显示终评信息标签页
    activeFinalEvalTab.value = 'evaluation';

    // 计算每个人的终评得分
    if (finalEvaluationForm.value.scorePersonList && finalEvaluationForm.value.scorePersonList.length > 0) {
      finalEvaluationForm.value.scorePersonList.forEach(person => {
        // 计算终评得分
        person.finalScore = calculateFinalScore(person.reviewScore, finalEvaluationForm.value.finalCoefficient);

        // 如果是维修工单且有额外工分，或维保工单且包含其他/其它选项且有额外工分，则计算总分
        if (person.extraScore !== null && person.extraScore !== undefined){
          person.totalScore = parseFloat((parseFloat(person.finalScore) + parseFloat(person.extraScore)).toFixed(2));
        }else{
          person.totalScore = parseFloat(person.finalScore);
        }
      });
    }

    finalEvaluationDialogVisible.value = true;
  });
}

/** 关闭终评对话框 */
function closeFinalEvaluationDialog() {
  finalEvaluationDialogVisible.value = false;
  proxy.resetForm("finalEvaluationRef");
}

/** 计算终评得分 */
function calculateFinalScore(reviewScore, finalCoefficient) {
  if (reviewScore && finalCoefficient) {
    return (parseFloat(reviewScore) * parseFloat(finalCoefficient)).toFixed(2);
  }
  return 0;
}

/** 检查是否有额外工作内容 */
function hasExtraWork() {
  // 检查当前终评表单中的额外工作总结是否为空（维修工单）或维保类型包含其他/其它选项（维保工单）
  if (finalEvaluationForm.value.orderType === 1) {
    return finalEvaluationForm.value.extraWork && finalEvaluationForm.value.extraWork.trim() !== '';
  } else if (finalEvaluationForm.value.orderType === 2) {
    return hasOtherOrQitaInspectionType();
  }
  return false;
}

/** 当质量系数变化时，重新计算终评得分和总分 */
function onFinalCoefficientChange() {
  if (finalEvaluationForm.value.scorePersonList && finalEvaluationForm.value.scorePersonList.length > 0) {
    finalEvaluationForm.value.scorePersonList.forEach(person => {
      // 重新计算终评得分
      person.finalScore = calculateFinalScore(person.reviewScore, finalEvaluationForm.value.finalCoefficient);

      // 如果是维修工单且有额外工分，或维保工单且包含其他/其它选项，则重新计算总分
      if (finalEvaluationForm.value.orderType === 1 && person.extraScore !== null && person.extraScore !== undefined){
        person.totalScore = parseFloat((parseFloat(person.finalScore) + parseFloat(person.extraScore)).toFixed(2));
      }
    });
  }
}

/** 提交终评 */
function submitFinalEvaluation() {
  proxy.$refs["finalEvaluationRef"].validate(valid => {
    if (valid) {
      // 计算每个人的终评得分
      finalEvaluationForm.value.scorePersonList.forEach(person => {
        if (finalEvaluationForm.value.orderType === 1){
          person.finalScore = calculateFinalScore(person.reviewScore, finalEvaluationForm.value.finalCoefficient);
        }
        // 如果是维修工单且有额外工分，或维保工单且包含其他/其它选项且有额外工分，则计算总分
        if (person.extraScore !== null && person.extraScore !== undefined){
          person.totalScore = parseFloat((parseFloat(person.finalScore) + parseFloat(person.extraScore)).toFixed(2));
        }else{
          person.totalScore = parseFloat(person.finalScore)
        }
      });
      // 在提交前将数组格式的inspectionType转换为字符串格式
      const submitData = { ...finalEvaluationForm.value };
      if (Array.isArray(submitData.inspectionType)) {
        submitData.inspectionType = submitData.inspectionType.join(',');
      }

      finalEvaluation(submitData).then(response => {
        proxy.$modal.msgSuccess("终评提交成功");
        finalEvaluationDialogVisible.value = false;
        getList();
      });
    }
  });
}

/** 发起申诉操作 */
function handleAppeal() {
  // 获取选中的工单
  const selectedOrder = orderScoreList.value.find(item => item.id === ids.value[0]);
  if (!selectedOrder) {
    proxy.$modal.msgError("未找到选中的工单");
    return;
  }

 /* // 检查工单类型是否为维修工单或维保工单
  if (selectedOrder.orderType !== 1 && selectedOrder.orderType !== 2) {
    proxy.$modal.msgError("只有维修工单或维保工单才能发起申诉");
    return;
  }*/

  // 检查工单类型是否为维保工单
  if (selectedOrder.orderType !== 2) {
    proxy.$modal.msgError("只有维保工单才能发起申诉");
    return;
  }

  // 检查工单状态是否为"待归档"或"已归档"
  if (selectedOrder.scoringStatus !== 'to_archive' && selectedOrder.scoringStatus !== 'archived') {
    proxy.$modal.msgError("只有状态为\"待归档\"或\"已归档\"的工单才能发起申诉");
    return;
  }

  // 检查申诉时效性（本月工单或上月工单延期5天）
  const now = new Date();
  // 维修工单使用 occurTime，维保工单使用 createTime
  const orderEndDate = new Date(selectedOrder.orderType === 1 ? selectedOrder.occurTime : selectedOrder.createTime);

  // 当前月份和年份
  const currentYear = now.getFullYear();
  const currentMonth = now.getMonth();
  const currentDay = now.getDate();

  // 工单完成月份和年份
  const orderYear = orderEndDate.getFullYear();
  const orderMonth = orderEndDate.getMonth();

  // 判断是否符合申诉时效
  let isValidAppealPeriod = false;
  if (currentYear === orderYear && currentMonth === orderMonth) {
    // 本月工单
    isValidAppealPeriod = true;
  } else if (currentYear === orderYear && currentMonth === orderMonth + 1) {
    // 上月工单，在本月5号之前可申诉
    if (currentDay <= 5) {
      isValidAppealPeriod = true;
    }
  } else if (currentYear === orderYear + 1 && currentMonth === 0 && orderMonth === 11) {
    // 跨年情况：当前1月，工单完成于上年12月，在1月5号之前可申诉
    if (currentDay <= 5) {
      isValidAppealPeriod = true;
    }
  }

  if (!isValidAppealPeriod) {
    proxy.$modal.msgError("超出申诉时效，不能发起申诉");
    return;
  }

  // 检查是否已经申诉过（通过confirmStatus字段判断）
  if(selectedOrder.confirmStatus == 3){
    proxy.$modal.msgError("该工单已申诉，不能发起申诉");
    return;
  }

  // 检查当前用户是否有权限发起申诉（工作负责人或工作班成员）
  const currentUserId = userStore.id;
  let hasPermission = false;
  hasPermission = isUserInScoreList(selectedOrder)

  if (!hasPermission) {
    proxy.$modal.msgError("您没有权限对此工单发起申诉");
    return;
  }

  // 获取工单详细信息
  getOrderScore(selectedOrder.orderType, selectedOrder.id).then(response => {
    const data = response.data;

    // 初始化申诉表单
    appealForm.value = {
      orderType: selectedOrder.orderType,
      id: selectedOrder.id,
      workOrderProjectNo: selectedOrder.workOrderProjectNo,
      pcsDeviceName: selectedOrder.pcsDeviceName,
      pcsStationName: selectedOrder.pcsStationName,
     /* occurTime: selectedOrder.orderType === 1 ?
        proxy.parseTime(selectedOrder.occurTime, '{y}-{m}-{d} {h}:{i}') :
        undefined,*/
      occurTime: selectedOrder.orderType === 1 ? selectedOrder.occurTime : undefined,
      createTime: selectedOrder.createTime,
      originalScore: getReviewerScore(data),
      appealReason: '',
      wwryNum: data.wwryNum,
      wlryNum: data.wlryNum,
    };
    appealDialogVisible.value = true;
  });
}

/** 关闭申诉对话框 */
function closeAppealDialog() {
  appealDialogVisible.value = false;
  proxy.resetForm("appealRef");
}

/** 提交申诉 */
function submitAppeal() {
  proxy.$refs["appealRef"].validate(valid => {
    if (valid) {
      // 将申诉理由作为feedbackReason传递给后端
      const appealData = {
        orderType: appealForm.value.orderType,
        id: appealForm.value.id,
        appealReason: appealForm.value.appealReason, // 使用appealReason字段存储申诉理由
      };

      appeal(appealData).then(response => {
        proxy.$modal.msgSuccess("申诉提交成功");
        appealDialogVisible.value = false;
        getList();
      }).catch(error => {
        proxy.$modal.msgError(error.message || "申诉提交失败");
      });
    }
  });
}

/** 判断用户是否在工单的评分人员列表中 */
function isUserInScoreList(row) {
  // 获取工单的评分人员列表
  const scorePersonList = row.scorePersonList || [];
  const userId = userStore.id;
  // 检查当前用户是否在评分人员列表中
  const result = scorePersonList.some(person =>
    person.userId == userId  // 使用 == 而不是 === 以避免类型不匹配问题
  );
  return result;
}

/** 判断用户是否是工单的工作负责人 */
function isUserTeamLeader(row) {
  return row.teamLeaderId == userStore.id;
}

/** 判断用户是否已经确认 */
function isUserConfirmed(row) {
  // 获取工单的评分人员列表
  const scorePersonList = row.scorePersonList || [];
  const userId = userStore.id;

  // 查找当前用户
  const currentUser = scorePersonList.find(person => person.userId == userId);

  // 如果找到当前用户且其confirmStatus不为空且不为0，则认为已确认
  if (currentUser && currentUser.confirmStatus != null && currentUser.confirmStatus != 0) {
    return true;
  }

  return false;
}

// 获取当前用户的复评分数
function getReviewerScore(data) {
  // 获取当前登录用户ID
  const currentUserId = userStore.id;

  // 检查维修工单人员列表
  if (data.repairOrderPersonList && Array.isArray(data.repairOrderPersonList)) {
    const person = data.repairOrderPersonList.find(p => p.userId == currentUserId);
    if (person && person.reviewScore !== null && person.reviewScore !== undefined) {
      return parseFloat(person.reviewScore).toFixed(2);
    }
  }

  // 检查维保工单人员列表
  if (data.workOrderPersonList && Array.isArray(data.workOrderPersonList)) {
    const person = data.workOrderPersonList.find(p => p.userId == currentUserId);
    if (person && person.reviewScore !== null && person.reviewScore !== undefined) {
      return parseFloat(person.reviewScore).toFixed(2);
    }
  }

  // 如果没找到复评分数，则返回空字符串
  return '';
}

function getMaintenanceCenterAndStationList() {
  listMaintenanceCenters().then(response => {
    maintenanceCenterOptions.value = response.data.map(item => {
      return { deptName: item, deptId: item };
    });

    // 如果已选择维保中心，则筛选出该维保中心下的场站
    if (queryParams.value.maintenanceCenter) {
      listStationsByMaintenanceCenter(queryParams.value.maintenanceCenter).then(res => {
        stationOptions.value = res.data.map(item => {
          return { deptName: item, deptId: item };
        });
      });
    } else {
      // 如果未选择维保中心，则清空场站选项
      stationOptions.value = [];
    }
  });
}

function getMaintenanceTypeList() {
  listScoreproject().then(response => {
    maintenanceTypeOptions.value = response.rows.map(item => {
      return {
        value: item.maintenanceType,
        label: item.projectName + '(' + item.scorePerCompletion + '分)'
      };
    });
  });
}

function handleMaintenanceCenterChange(selectedCenter) {
  // 清空场站选择
  queryParams.value.station = null;

  // 如果选择了维保中心，则加载对应的场站
  if (selectedCenter) {
    listStationsByMaintenanceCenter(selectedCenter).then(response => {
      stationOptions.value = response.data.map(item => {
        return { deptName: item, deptId: item };
      });
    });
  } else {
    // 如果未选择维保中心，则清空场站选项
    stationOptions.value = [];
  }
}

/** 清空自评分 */
function clearSelfScores() {
  if (selfEvaluationForm.value.scorePersonList && selfEvaluationForm.value.scorePersonList.length > 0) {
    selfEvaluationForm.value.scorePersonList.forEach(person => {
      person.selfScore = null;
    });
  }
}

/** 获取维修工单总分 - 通用函数 */
function getRepairTotalScore(formValue) {
  const maintenanceType = formValue.maintenanceType;
  if (!maintenanceType) {
    return 0;
  }

  const selectedType = maintenanceTypeOptions.value.find(item => item.value === maintenanceType);
  if (!selectedType) {
    return 0;
  }

  // 获取分值
  const scoreMatch = selectedType.label.match(/\((\d+(\.\d+)?)分\)/);
  if (!scoreMatch) {
    return 0;
  }

  return parseFloat(scoreMatch[1]);
}

/** 获取维保工单总分 - 通用函数 */
function getMaintenanceTotalScore(formValue) {
  if (formValue.scorePersonList.length === 0) return 0;

  // 获取分项完成系数，默认为1
  const completionFactor = formValue.itemCompletionFactor || 1;

  // 获取选中的维保项目（现在是多选）
  const selectedInspectionTypes = formValue.inspectionType || [];

  // 计算所有选中维保项目的总分值
  let totalScoreFromDB = 0; // 默认值

  if (Array.isArray(selectedInspectionTypes) && selectedInspectionTypes.length > 0) {
    selectedInspectionTypes.forEach(typeId => {
      const selectedType = inspectionTypeOptions.value.find(item => item.inspectionTypeId.toString() === typeId);
      if (selectedType && selectedType.score) {
        totalScoreFromDB += selectedType.score;
      }
    });
  }

  // 计算总分：总分 = 所有选中维保类型组合的总得分 * 分项完成系数
  return totalScoreFromDB * completionFactor;
}

/** 获取工单总分 - 通用函数 */
function getTotalScore(formValue) {
  if (formValue.orderType === 1) {
    // 维修工单
    return getRepairTotalScore(formValue);
  } else {
    // 维保工单
    return getMaintenanceTotalScore(formValue);
  }
}

/** 获取自评工单总分 */
function getTotalScoreForSelfEvaluation() {
  return getTotalScore(selfEvaluationForm.value);
}

/** 获取复评工单总分 */
function getTotalScoreForReview() {
  return getTotalScore(reviewForm.value);
}


/** 获取维修工单总分 - 用于验证 */
function getRepairTotalScoreForValidation() {
  // 从维护类型选项中获取当前选中的类型
  let currentMaintenanceType = null;
  let currentForm = null;

  if (selfEvaluationForm.value && selfEvaluationForm.value.maintenanceType) {
    currentForm = selfEvaluationForm.value;
    currentMaintenanceType = selfEvaluationForm.value.maintenanceType;
  } else if (reviewForm.value && reviewForm.value.maintenanceType) {
    currentForm = reviewForm.value;
    currentMaintenanceType = reviewForm.value.maintenanceType;
  }

  if (!currentMaintenanceType) {
    return 0;
  }

  const selectedType = maintenanceTypeOptions.value.find(item => item.value === currentMaintenanceType);
  if (!selectedType) {
    return 0;
  }

  // 获取分值
  const scoreMatch = selectedType.label.match(/\((\d+(\.\d+)?)分\)/);
  if (!scoreMatch) {
    return 0;
  }

  return parseFloat(scoreMatch[1]);
}

/** 获取维保工单总分 - 用于验证 */
function getMaintenanceTotalScoreForValidation(inspectionType, itemCompletionFactor) {
  // 获取分项完成系数，默认为1
  const completionFactor = itemCompletionFactor || 1;

  // 获取选中的维保项目（现在是多选）
  const selectedInspectionTypes = inspectionType || [];

  // 计算所有选中维保项目的总分值
  let totalScoreFromDB = 0; // 默认值

  if (Array.isArray(selectedInspectionTypes) && selectedInspectionTypes.length > 0) {
    selectedInspectionTypes.forEach(typeId => {
      const selectedType = inspectionTypeOptions.value.find(item => item.inspectionTypeId.toString() === typeId);
      if (selectedType && selectedType.score) {
        totalScoreFromDB += selectedType.score;
      }
    });
  }

  // 计算总分：总分 = 所有选中维保类型组合的总得分 * 分项完成系数
  return totalScoreFromDB * completionFactor;
}

/** 验证评分规则 - 通用函数 */
function validateScoringRulesCommon(formValue) {
  const { scorePersonList, orderType, inspectionType, itemCompletionFactor, wwryNum, wlryNum } = formValue;

  if (!scorePersonList || scorePersonList.length === 0) {
    return { valid: true, message: '' };
  }

  // 获取工单总分
  const totalScore = getTotalScore(formValue);

  // 计算总得分
  let totalScoreValue = 0;
  let hasEmptyScore = false;
  let leaderScore = null;

  // 根据当前验证的类型确定使用哪个字段
  // 如果是复评验证，使用reviewScore；如果是自评验证，使用selfScore
  const isReviewValidation = formValue === reviewForm.value;
  const scoreFieldKey = isReviewValidation ? 'reviewScore' : 'selfScore';

  for (const person of scorePersonList) {
    const scoreField = person[scoreFieldKey];
    if (scoreField === null || scoreField === undefined || scoreField === '') {
      hasEmptyScore = true;
    } else {
      const score = parseFloat(scoreField);
      if (!isNaN(score)) {
        // 检查得分是否大于0
        if (score <= 0) {
          return {
            valid: false,
            message: `每个人的得分必须大于0（${person.nickName}的得分为${score}）`
          };
        }
        totalScoreValue += score;
        if (person.isLeader == 1) {  // 工作负责人
          leaderScore = score;
        }
      }
    }
  }

  // 如果有人没评分，返回错误
  if (hasEmptyScore) {
    return {
      valid: false,
      message: '部分人员未评分'
    };
  }
  // 如果总分为0，则评分无上限
  if (totalScore === 0) {
    // 检查工作负责人得分-0.5后是否小于等于0
    if (leaderScore !== null) {
      const leaderScoreAfterReduction = leaderScore - 0.5;
      if (leaderScoreAfterReduction <= 0) {
        return {
        valid: false,
        message: `工作负责人得分减去0.5后不能小于等于0（当前：${leaderScore.toFixed(2)} - 0.5 = ${leaderScoreAfterReduction.toFixed(2)}）`
        };
      }
    }
    return { valid: true, message: '' };
  }

  // 对于维保工单且多选维保类型的情况，需要特殊处理
  if (orderType === 2 && Array.isArray(inspectionType) && inspectionType.length > 1) {
    // 获取选中的维保类型
    const selectedInspectionTypes = inspectionType || [];

    // 计算所有选中维保类型的总分值
    let minScoreFromDB = 0; // 最低分值（非零）
    let hasZeroScore = false; // 是否存在零分

    if (Array.isArray(selectedInspectionTypes) && selectedInspectionTypes.length > 0) {
      selectedInspectionTypes.forEach(typeId => {
        const selectedType = inspectionTypeOptions.value.find(item => item.inspectionTypeId.toString() === typeId);
        if (selectedType && selectedType.score !== undefined) {
          if (selectedType.score === 0) {
            hasZeroScore = true;
          } else if (selectedType.score > 0) {
            minScoreFromDB += selectedType.score;
          }
        }
      });
    }

    // 如果存在零分且存在非零分的情况
    if (hasZeroScore && minScoreFromDB > 0) {
      // 获取分项完成系数
      const completionFactor = itemCompletionFactor || 1;
      // 计算最低理论总分（非零项的总分 * 分项完成系数 + 0.5）
      const minExpectedTotal = (minScoreFromDB * completionFactor) + 0.5;

      // 总得分必须至少等于最低理论总分
      /*if (totalSelfScore < minExpectedTotal - 0.01) {  // 使用0.01作为容差
        return {
          valid: false,
          message: `总得分不得低于 ${minExpectedTotal.toFixed(2)} 分（当前：${totalSelfScore.toFixed(2)} 分）`
        };
      }*/

      // 检查工作负责人得分-0.5后是否小于等于0
      if (leaderScore !== null) {
        const leaderScoreAfterReduction = leaderScore - 0.5;
        if (leaderScoreAfterReduction <= 0) {
          return {
          valid: false,
          message: `工作负责人得分减去0.5后不能小于等于0（当前：${leaderScore.toFixed(2)} - 0.5 = ${leaderScoreAfterReduction.toFixed(2)}）`
          };
        }
      }

      return { valid: true, message: '' };
    }
  }

  // 计算理论总分（总分+0.5）
  const expectedTotal = totalScore + 0.5;

  // 总得分必须等于总分+0.5
  /*if (Math.abs(totalSelfScore - expectedTotal) > 0.01) {  // 使用0.01作为容差
    return {
      valid: false,
      message: `总得分必须等于 ${expectedTotal.toFixed(2)} 分（当前：${totalSelfScore.toFixed(2)} 分）`
    };
  }*/
  console.log("totalScoreValue",totalScoreValue)
  console.log("expectedTotal",expectedTotal)
  if (totalScoreValue - expectedTotal > 0.01) {  // 使用0.01作为容差
    return {
      valid: false,
      message: `总得分必须小于等于 ${expectedTotal.toFixed(2)} 分（当前：${totalScoreValue.toFixed(2)} 分）`
    };
  }

  // 检查工作负责人得分-0.5后是否小于等于0
  if (leaderScore !== null) {
    const leaderScoreAfterReduction = leaderScore - 0.5;
    if (leaderScoreAfterReduction <= 0) {
      return {
      valid: false,
      message: `工作负责人得分减去0.5后不能小于等于0（当前：${leaderScore.toFixed(2)} - 0.5 = ${leaderScoreAfterReduction.toFixed(2)}）`
      };
    }
  }

  return { valid: true, message: '' };
}

/** 验证自评评分规则 */
function validateScoringRules() {
  return validateScoringRulesCommon(selfEvaluationForm.value);
}

/** 验证复评评分规则 */
function validateReviewScoringRules() {
  return validateScoringRulesCommon(reviewForm.value);
}

/** 获取工单总分 - 用于验证 */
function getTotalScoreForValidation(orderType, inspectionType, itemCompletionFactor, formValue) {
  if (orderType === 1) {
    // 维修工单
    return getRepairTotalScoreForValidation(formValue);
  } else {
    // 维保工单
    return getMaintenanceTotalScoreForValidation(inspectionType, itemCompletionFactor);
  }
}

/** 获取可评总分 - 通用函数 */
function getEvaluationTotalScore(formValue) {
  // 获取工单总分
  const totalScore = getTotalScore(formValue);

  // 如果总分为0，返回0
  if (totalScore === 0) {
    // 特殊处理：对于维保工单且多选维保类型的情况，如果存在零分和非零分的混合情况
    if (formValue.orderType === 2 && Array.isArray(formValue.inspectionType) && formValue.inspectionType.length > 1) {
      // 获取选中的维保类型
      const selectedInspectionTypes = formValue.inspectionType || [];

      // 计算所有选中维保类型的非零分值
      let minScoreFromDB = 0; // 非零分值总和
      let hasZeroScore = false; // 是否存在零分

      if (Array.isArray(selectedInspectionTypes) && selectedInspectionTypes.length > 0) {
        selectedInspectionTypes.forEach(typeId => {
          const selectedType = inspectionTypeOptions.value.find(item => item.inspectionTypeId.toString() === typeId);
          if (selectedType && selectedType.score !== undefined) {
            if (selectedType.score === 0) {
              hasZeroScore = true;
            } else if (selectedType.score > 0) {
              minScoreFromDB += selectedType.score;
            }
          }
        });
      }

      // 如果存在零分且存在非零分的情况，返回非零分的总和加上工作负责人的0.5分
      if (hasZeroScore && minScoreFromDB > 0) {
        const completionFactor = formValue.itemCompletionFactor || 1;
        return (minScoreFromDB * completionFactor) + 0.5;
      }
    }
    return 0;
  }

  // 返回总分+0.5（工作负责人额外加0.5分）
  return totalScore + 0.5;
}

/** 获取可自评总分 */
function getSelfEvaluationTotalScore() {
  return getEvaluationTotalScore(selfEvaluationForm.value);
}

/** 获取复评可评总分 */
function getReviewEvaluationTotalScore() {
  return getEvaluationTotalScore(reviewForm.value);
}

/** 判断是否为多选维保类型且存在零分和非零分混合的情况 - 通用函数 */
function isMixedZeroNonZeroInspectionTypes(formValue) {
  if (formValue.orderType === 2 &&
      Array.isArray(formValue.inspectionType) &&
      formValue.inspectionType.length > 1) {

    const selectedInspectionTypes = formValue.inspectionType || [];
    let hasZeroScore = false;
    let hasNonZeroScore = false;

    if (Array.isArray(selectedInspectionTypes) && selectedInspectionTypes.length > 0) {
      selectedInspectionTypes.forEach(typeId => {
        const selectedType = inspectionTypeOptions.value.find(item => item.inspectionTypeId.toString() === typeId);
        if (selectedType && selectedType.score !== undefined) {
          if (selectedType.score === 0) {
            hasZeroScore = true;
          } else if (selectedType.score > 0) {
            hasNonZeroScore = true;
          }
        }
      });
    }

    // 如果既有零分又有非零分，则返回true
    return hasZeroScore && hasNonZeroScore;
  }
  return false;
}

/** 判断自评中是否为多选维保类型且存在零分和非零分混合的情况 */
function isMixedZeroNonZeroInspectionTypesForSelfEvaluation() {
  return isMixedZeroNonZeroInspectionTypes(selfEvaluationForm.value);
}

/** 判断复评中是否为多选维保类型且存在零分和非零分混合的情况 */
function isMixedZeroNonZeroInspectionTypesForReview() {
  return isMixedZeroNonZeroInspectionTypes(reviewForm.value);
}

/** 获取已复评总分 */
function getReviewedTotalScore() {
  const scorePersonList = reviewForm.value.scorePersonList;
  if (!scorePersonList || scorePersonList.length === 0) {
    return 0;
  }

  let totalReviewScore = 0;

  for (const person of scorePersonList) {
    if (person.reviewScore !== null && person.reviewScore !== undefined && person.reviewScore !== '') {
      const score = parseFloat(person.reviewScore);
      if (!isNaN(score)) {
        totalReviewScore += score;
      }
    }
  }

  return totalReviewScore;
}

/** 检查维保类型是否包含'其他'或'其它'选项 */
function hasOtherOrQitaInspectionType() {
  // 检查当前上下文中的表单对象，优先检查selfEvaluationForm
  let currentForm = null;
  let orderType = null;
  let inspectionType = null;

  if (selfEvaluationForm.value && selfEvaluationForm.value.orderType) {
    currentForm = selfEvaluationForm.value;
    orderType = selfEvaluationForm.value.orderType;
    inspectionType = selfEvaluationForm.value.inspectionType;
  } else if (reviewForm.value && reviewForm.value.orderType) {
    currentForm = reviewForm.value;
    orderType = reviewForm.value.orderType;
    inspectionType = reviewForm.value.inspectionType;
  } else if (finalEvaluationForm.value && finalEvaluationForm.value.orderType) {
    currentForm = finalEvaluationForm.value;
    orderType = finalEvaluationForm.value.orderType;
    inspectionType = finalEvaluationForm.value.inspectionType;
  } else if (confirmForm.value && confirmForm.value.orderType) {
    currentForm = confirmForm.value;
    orderType = confirmForm.value.orderType;
    inspectionType = confirmForm.value.inspectionType;
  } else if (viewForm.value && viewForm.value.orderType) {
    currentForm = viewForm.value;
    orderType = viewForm.value.orderType;
    inspectionType = viewForm.value.inspectionType;
  }

  if (orderType === 2 && Array.isArray(inspectionType) && inspectionType.length > 0) {

    const selectedInspectionTypes = inspectionType || [];
    const inspectionTypeArray =  gxt_inspection_type.value;
    for (const typeId of selectedInspectionTypes) {
      const dictItem = inspectionTypeArray.find(item => item && item.value == typeId);
      if (dictItem && dictItem.label) {
        const labelName = dictItem.label.trim();
        if (labelName === '其他' || labelName === '其它') {
          return true;
        }
      }
    }
  }
  return false;
}

/** 检查是否存在停运扣分 */
function hasStopScore() {
  // 检查当前查看的工单是否存在停运扣分
  if (viewForm.value && viewForm.value.scorePersonList && Array.isArray(viewForm.value.scorePersonList)) {
    return viewForm.value.scorePersonList.some(person =>
      person.stopScore !== null && person.stopScore !== undefined && person.stopScore !== ''
    );
  }
  return false;
}

/** 获取已自评总分 */
function getSelfEvaluatedTotalScore() {
  const scorePersonList = selfEvaluationForm.value.scorePersonList;
  if (!scorePersonList || scorePersonList.length === 0) {
    return 0;
  }

  let totalSelfScore = 0;

  for (const person of scorePersonList) {
    if (person.selfScore !== null && person.selfScore !== undefined && person.selfScore !== '') {
      const score = parseFloat(person.selfScore);
      if (!isNaN(score)) {
        totalSelfScore += score;
      }
    }
  }

  return totalSelfScore;
}

</script>
<style scoped>
/* 表单字段间距调整 */
:deep(.el-form-item) {
  margin-bottom: 18px;
}

/* 表单中的列间距调整 */
:deep(.el-col) {
  padding-left: 5px;
  padding-right: 5px;
}

/* 表单行间距调整 */
:deep(.el-row) {
  margin-left: -5px;
  margin-right: -5px;
}

.info-section {
  padding: 16px 0;
  height: 100%;
  box-sizing: border-box;
}

.section-title {
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #ebeef5;
}
.info-content {
  height: calc(100% - 30px);
  overflow-y: auto;
  overflow-x: hidden; /* 防止横向滚动 */
  padding: 0 10px; /* 添加内边距防止内容贴边 */
}

.info-item {
  margin-bottom: 12px;
}

.info-item label {
  display: block;
  font-size: 12px;
  color: #999;
  margin-bottom: 4px;
}

.info-item p {
  font-size: 14px;
  color: #333;
  margin: 0;
  line-height: 1.4;
}

.flow-history {
  height: 100%;
  padding: 0 10px; /* 添加内边距防止内容贴边 */
}

.flow-history .el-timeline {
  margin-left: 0;
  padding-left: 0;
}

.flow-item {
  /*padding: 10px;
  border-radius: 4px;*/
}

.flow-item h4 {
  margin: 0 0 5px 0;
  font-size: 14px;
  font-weight: bold;
}

.flow-item p {
  margin: 0;
  font-size: 12px;
  line-height: 1.4;
  color: #606266;
}

.content-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

.returned-status-hint {
  cursor: pointer;
}

.flow-remark {
  color: #909399;
  font-size: 12px;
  margin: 0;
  padding-left: 20px;
  font-style: italic;
}
</style>
