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,22 +58,20 @@
            @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
                type="primary"
                text
                icon="editPen"
                link
                @click="editScheduledTask(row)"
              >
                编辑
              </el-button>
              <el-button
                type="danger"
                text
                icon="delete"
                link
                @click="delScheduledTaskByIds(row.id)"
              >
                删除
@@ -135,14 +133,6 @@
          <div class="actions">
            <el-text class="mx-1" size="large">任务记录</el-text>
            <div>
              <el-button
                type="primary"
                icon="Plus"
                :disabled="multipleList.length !== 1"
                @click="addMaintain"
              >
                新增保养
              </el-button>
              <el-button type="success" icon="Van" @click="addPlan">
                新增计划
              </el-button>
@@ -152,7 +142,7 @@
              <el-button
                type="danger"
                icon="Delete"
                :disabled="multipleList.length <= 0"
                :disabled="multipleList.length <= 0 || hasFinishedStatus"
                @click="delRepairByIds(multipleList.map((item) => item.id))"
              >
                批量删除
@@ -172,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>
@@ -183,19 +170,41 @@
        <template #operation="{ row }">
          <el-button
            type="primary"
            text
            icon="editPen"
            link
            @click="openDetail(row)"
          >
            详情
          </el-button>
          <el-button
            type="primary"
            link
            :disabled="row.status === 1"
            @click="editPlan(row.id)"
          >
            编辑
          </el-button>
          <el-button
            type="success"
            link
            :disabled="row.status === 1"
            @click="addMaintain(row)"
          >
            保养
          </el-button>
          <el-button
            type="danger"
            text
            icon="delete"
            link
            :disabled="row.status === 1"
            @click="delRepairByIds(row.id)"
          >
            删除
          </el-button>
          <el-button
            type="primary"
            link
            @click="openFileDialog(row)"
          >
            附件
          </el-button>
        </template>
      </PIMTable>
@@ -205,22 +214,42 @@
    <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>
<script setup>
import { ref, onMounted, reactive, getCurrentInstance, nextTick } from 'vue'
import { ref, onMounted, reactive, getCurrentInstance, nextTick, computed } from 'vue'
import { Search } from '@element-plus/icons-vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import PlanModal from './Modal/PlanModal.vue'
import MaintenanceModal from './Modal/MaintenanceModal.vue'
import FormDia from './Modal/formDia.vue'
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()
@@ -232,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({
@@ -254,7 +315,7 @@
// 定时任务管理tab相关变量
const scheduledFilters = reactive({
  taskName: '',
  status: '',
  isActive: '',
})
const scheduledDataList = ref([])
@@ -306,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: "操作",
@@ -328,6 +404,17 @@
      label: "规格型号",
      align: "center",
      prop: "deviceModel",
   },
   {
      label: "保养项目",
      align: "center",
      prop: "maintenanceLocation",
      showOverflowTooltip: true,
   },
   {
      label: "保养人",
      align: "center",
      prop: "maintenancePerson",
   },
   {
      label: "计划保养日期",
@@ -363,8 +450,8 @@
      label: "保养结果",
      align: "center",
      prop: "maintenanceResult",
      dataType: "slot",
      slot: "maintenanceResultRef",
      minWidth: 200,
      showOverflowTooltip: true,
   },
   {
      label: "状态",
@@ -379,7 +466,7 @@
      dataType: "slot",
      slot: "operation",
      align: "center",
      width: "200px",
    width: "400px",
   },
])
@@ -399,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) {
@@ -413,7 +500,7 @@
const resetScheduledFilters = () => {
  scheduledFilters.taskName = ''
  scheduledFilters.status = ''
  scheduledFilters.isActive = ''
  getScheduledTableData()
}
@@ -494,14 +581,18 @@
  multipleList.value = selection
}
// 检查选中的记录中是否有完结状态的
const hasFinishedStatus = computed(() => {
  return multipleList.value.some(item => item.status === 1)
})
const changePage = (page) => {
  pagination.value.currentPage = page.page
  pagination.value.pageSize = page.limit
  getTableData()
}
const addMaintain = () => {
  const row = multipleList.value[0]
const addMaintain = (row) => {
  maintainModalRef.value.open(row.id, row)
}
@@ -514,6 +605,13 @@
}
const delRepairByIds = async (ids) => {
  // 检查是否有完结状态的记录
  const hasFinished = multipleList.value.some(item => item.status === 1)
  if (hasFinished) {
    ElMessage.warning('不能删除状态为完结的记录')
    return
  }
  try {
    await ElMessageBox.confirm('确认删除保养数据, 此操作不可逆?', '警告', {
      confirmButtonText: '确定',
@@ -554,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') {