gongchunyi
8 天以前 b95a00bf7ec7c667e16032bcabc4d97ef42909fc
src/views/equipmentManagement/upkeep/index.vue
@@ -16,9 +16,9 @@
              />
            </el-form-item>
            <el-form-item label="任务状态">
              <el-select v-model="scheduledFilters.status" placeholder="请选择任务状态" clearable style="width: 200px">
                <el-option label="启用" value="1" />
                <el-option label="停用" value="0" />
              <el-select v-model="scheduledFilters.isActive" placeholder="请选择任务状态" clearable style="width: 200px">
                <el-option label="启用" :value="1" />
                <el-option label="停用" :value="0" />
              </el-select>
            </el-form-item>
            <el-form-item>
@@ -58,8 +58,8 @@
            @pagination="changeScheduledPage"
          >
            <template #statusRef="{ row }">
              <el-tag v-if="row.status === 1" type="success">启用</el-tag>
              <el-tag v-if="row.status === 0" type="danger">停用</el-tag>
              <el-tag v-if="row.isActive === 1" type="success">启用</el-tag>
              <el-tag v-if="row.isActive === 0" type="danger">停用</el-tag>
            </template>
            <template #operation="{ row }">
              <el-button
@@ -162,15 +162,19 @@
        @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>
          <el-tag v-if="row.status === 0" type="warning">待保养</el-tag>
        </template>
        <template #operation="{ row }">
          <el-button
            type="primary"
            link
            @click="openDetail(row)"
          >
            详情
          </el-button>
          <el-button
            type="primary"
            link
@@ -195,6 +199,13 @@
          >
            删除
          </el-button>
          <el-button
            type="primary"
            link
            @click="openFileDialog(row)"
          >
            附件
          </el-button>
        </template>
      </PIMTable>
        </div>
@@ -203,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>
@@ -212,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()
@@ -230,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({
@@ -252,7 +315,7 @@
// 定时任务管理tab相关变量
const scheduledFilters = reactive({
  taskName: '',
  status: '',
  isActive: '',
})
const scheduledDataList = ref([])
@@ -304,7 +367,22 @@
      }
   },
   { prop: "registrant", label: "登记人", minWidth: 100 },
   { prop: "maintenancePerson", label: "保养人", minWidth: 100 },
   {
      prop: "maintenanceItems",
      label: "保养项目",
      minWidth: 180,
      showOverflowTooltip: true,
   },
   { prop: "registrationDate", label: "登记日期", minWidth: 100 },
   {
      label: "任务状态",
      prop: "isActive",
      minWidth: 100,
      dataType: "slot",
      slot: "statusRef",
      align: "center",
   },
   {
      fixed: "right",
      label: "操作",
@@ -326,6 +404,17 @@
      label: "规格型号",
      align: "center",
      prop: "deviceModel",
   },
   {
      label: "保养项目",
      align: "center",
      prop: "maintenanceLocation",
      showOverflowTooltip: true,
   },
   {
      label: "保养人",
      align: "center",
      prop: "maintenancePerson",
   },
   {
      label: "计划保养日期",
@@ -361,8 +450,8 @@
      label: "保养结果",
      align: "center",
      prop: "maintenanceResult",
      dataType: "slot",
      slot: "maintenanceResultRef",
      minWidth: 200,
      showOverflowTooltip: true,
   },
   {
      label: "状态",
@@ -377,7 +466,7 @@
      dataType: "slot",
      slot: "operation",
      align: "center",
      width: "200px",
    width: "400px",
   },
])
@@ -397,7 +486,7 @@
      current: scheduledPagination.currentPage,
      size: scheduledPagination.pageSize,
      taskName: scheduledFilters.taskName || undefined,
      status: scheduledFilters.status || undefined,
      isActive: scheduledFilters.isActive !== '' ? scheduledFilters.isActive : undefined,
    }
    const { code, data } = await deviceMaintenanceTaskList(params)
    if (code === 200) {
@@ -411,7 +500,7 @@
const resetScheduledFilters = () => {
  scheduledFilters.taskName = ''
  scheduledFilters.status = ''
  scheduledFilters.isActive = ''
  getScheduledTableData()
}
@@ -563,6 +652,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') {