gongchunyi
10 天以前 b88332e0a2686e68023e26438af97f79247b1ddd
src/views/equipmentManagement/upkeep/index.vue
@@ -162,9 +162,6 @@
        @selection-change="handleSelectionChange"
        @pagination="changePage"
      >
        <template #maintenanceResultRef="{ row }">
          <div>{{ row.maintenanceResult || '-' }}</div>
        </template>
        <template #statusRef="{ row }">
          <el-tag v-if="row.status === 2" type="danger">失败</el-tag>
          <el-tag v-if="row.status === 1" type="success">完结</el-tag>
@@ -172,11 +169,11 @@
        </template>
        <template #operation="{ row }">
          <el-button
              type="primary"
              text
              @click="addMaintain(row)"
            type="primary"
            link
            @click="openDetail(row)"
          >
            新增保养
            详情
          </el-button>
          <el-button
            type="primary"
@@ -202,6 +199,13 @@
          >
            删除
          </el-button>
          <el-button
            type="primary"
            link
            @click="openFileDialog(row)"
          >
            附件
          </el-button>
        </template>
      </PIMTable>
        </div>
@@ -210,6 +214,20 @@
    <PlanModal ref="planModalRef" @ok="getTableData" />
        <MaintenanceModal ref="maintainModalRef" @ok="getTableData" />
        <FormDia ref="formDiaRef" @closeDia="getScheduledTableData" />
    <UpkeepDetailModal ref="upkeepDetailModalRef" :java-api="javaApi" />
    <FileListDialog
      ref="fileListDialogRef"
      v-model="fileDialogVisible"
      :title="currentRecordFinished ? '附件(已完结,仅可查看)' : '附件'"
      :show-upload-button="!currentRecordFinished"
      :show-delete-button="!currentRecordFinished"
      :delete-method="handleAttachmentDelete"
      :name-column-label="'附件名称'"
      :upload-url="maintenanceFileUploadUrl"
      :upload-data="maintenanceFileUploadData"
      :upload-direct-save="true"
      @upload="refreshFileList"
    />
  </div>
</template>
@@ -219,13 +237,19 @@
import { ElMessage, ElMessageBox } from 'element-plus'
import PlanModal from './Form/PlanModal.vue'
import MaintenanceModal from './Form/MaintenanceModal.vue'
import UpkeepDetailModal from './Form/UpkeepDetailModal.vue'
import FormDia from './Form/formDia.vue'
import FileListDialog from '@/components/Dialog/FileListDialog.vue'
import {
  getUpkeepPage,
  delUpkeep,
  deviceMaintenanceTaskList,
  deviceMaintenanceTaskDel,
} from '@/api/equipmentManagement/upkeep'
import {
  listMaintenanceTaskFiles,
  delMaintenanceTaskFile,
} from '@/api/equipmentManagement/maintenanceTaskFile'
import dayjs from 'dayjs'
const { proxy } = getCurrentInstance()
@@ -237,8 +261,40 @@
const planModalRef = ref()
// 保养弹窗控制器
const maintainModalRef = ref()
const upkeepDetailModalRef = ref()
// 定时任务弹窗控制器
const formDiaRef = ref()
// 附件弹窗
const fileListDialogRef = ref(null)
const fileDialogVisible = ref(false)
const currentMaintenanceTaskId = ref(null)
/** 当前附件所属记录是否已完结(status=1) */
const currentRecordFinished = ref(false)
const javaApi = import.meta.env.VITE_APP_BASE_API
const maintenanceFileUploadUrl = `${javaApi}/maintenanceTaskFile/upload`
const maintenanceFileUploadData = computed(() => ({
  deviceMaintenanceId: currentMaintenanceTaskId.value,
}))
const normalizeMaintenanceFileUrl = (rawUrl = "") => {
  let fileUrl = rawUrl || ""
  if (!fileUrl) return ""
  if (fileUrl.startsWith("http://") || fileUrl.startsWith("https://")) return fileUrl
  if (fileUrl.indexOf("\\") > -1) {
    const lowerPath = fileUrl.toLowerCase()
    const uploadPathIndex = lowerPath.indexOf("uploadpath")
    if (uploadPathIndex > -1) {
      fileUrl = fileUrl.substring(uploadPathIndex).replace(/\\/g, "/")
    } else {
      fileUrl = fileUrl.replace(/\\/g, "/")
    }
  }
  fileUrl = fileUrl.replace(/^\/?uploadPath/i, "/profile")
  if (!fileUrl.startsWith("/")) fileUrl = "/" + fileUrl
  if (!fileUrl.startsWith(javaApi)) fileUrl = javaApi + fileUrl
  return fileUrl
}
// 任务记录tab(原设备保养页面)相关变量
const filters = reactive({
@@ -311,6 +367,13 @@
      }
   },
   { prop: "registrant", label: "登记人", minWidth: 100 },
   { prop: "maintenancePerson", label: "保养人", minWidth: 100 },
   {
      prop: "maintenanceItems",
      label: "保养项目",
      minWidth: 180,
      showOverflowTooltip: true,
   },
   { prop: "registrationDate", label: "登记日期", minWidth: 100 },
   {
      fixed: "right",
@@ -333,6 +396,17 @@
      label: "规格型号",
      align: "center",
      prop: "deviceModel",
   },
   {
      label: "保养项目",
      align: "center",
      prop: "maintenanceLocation",
      showOverflowTooltip: true,
   },
   {
      label: "保养人",
      align: "center",
      prop: "maintenancePerson",
   },
   {
      label: "计划保养日期",
@@ -368,8 +442,8 @@
      label: "保养结果",
      align: "center",
      prop: "maintenanceResult",
      dataType: "slot",
      slot: "maintenanceResultRef",
      minWidth: 200,
      showOverflowTooltip: true,
   },
   {
      label: "状态",
@@ -384,7 +458,7 @@
      dataType: "slot",
      slot: "operation",
      align: "center",
      width: "300px",
    width: "400px",
   },
])
@@ -570,6 +644,70 @@
  getTableData()
}
// 附件相关方法
// 查询附件列表
const fetchMaintenanceTaskFiles = async (deviceMaintenanceId) => {
  try {
    const params = {
      current: 1,
      size: 100,
      deviceMaintenanceId,
    }
    const res = await listMaintenanceTaskFiles(params)
    const records = res?.data?.records || []
    const mapped = records.map(item => ({
      id: item.id,
      name: item.fileName || item.name,
      url: normalizeMaintenanceFileUrl(item.fileUrl || item.url),
      raw: item,
    }))
    fileListDialogRef.value?.setList(mapped)
  } catch (error) {
    ElMessage.error('获取附件列表失败')
  }
}
const openDetail = (row) => {
  upkeepDetailModalRef.value?.open(row)
}
// 打开附件弹窗
const openFileDialog = async (row) => {
  currentMaintenanceTaskId.value = row.id
  currentRecordFinished.value = row.status === 1
  fileDialogVisible.value = true
  await fetchMaintenanceTaskFiles(row.id)
}
// 刷新附件列表
const refreshFileList = async () => {
  if (!currentMaintenanceTaskId.value) return
  await fetchMaintenanceTaskFiles(currentMaintenanceTaskId.value)
}
// 删除附件(已完结不可删)
const handleAttachmentDelete = async (row) => {
  if (currentRecordFinished.value) {
    ElMessage.warning('该保养已完结,不可删除附件')
    return false
  }
  if (!row?.id) return false
  try {
    await ElMessageBox.confirm('确认删除该附件?', '提示', { type: 'warning' })
  } catch {
    return false
  }
  try {
    await delMaintenanceTaskFile(row.id)
    ElMessage.success('删除成功')
    await refreshFileList()
    return true
  } catch (error) {
    ElMessage.error('删除失败')
    return false
  }
}
onMounted(() => {
  // 根据默认激活的 Tab 调用对应的查询接口
  if (activeTab.value === 'scheduled') {