src/views/inspectionManagement/index.vue
@@ -1,18 +1,10 @@
<template>
  <div class="app-container">
    <el-form :inline="true" :model="queryParams" class="search-form">
      <el-form-item label="时间">
      <el-form-item label="搜索">
        <el-input
            v-model="queryParams.supplierName"
            placeholder="请输入"
            clearable
            :style="{ width: '100%' }"
        />
      </el-form-item>
      <el-form-item label="设备名称">
        <el-input
            v-model="queryParams.coal"
            placeholder="请输入"
            v-model="queryParams.searchAll"
            placeholder="请输入关键字"
            clearable
            :style="{ width: '100%' }"
        />
@@ -45,7 +37,7 @@
        </el-radio-group>
        <!-- 操作按钮区 -->
        <el-space v-if="activeRadio !== 'task'">
          <el-button type="primary" :icon="Plus" @click="handleAdd">新建</el-button>
          <el-button type="primary" :icon="Plus" @click="handleAdd(undefined)">新建</el-button>
          <el-button type="danger" :icon="Delete" @click="handleDelete">删除</el-button>
          <!-- <el-button type="info" plain :icon="Download">导出</el-button> -->
        </el-space>
@@ -88,10 +80,10 @@
        </div>
        <pagination
            v-if="total>0"
            :page-num="pageNum"
            :page-size="pageSize"
            :page="pageNum"
            :limit="pageSize"
            :total="total"
            @pagination="handleQuery"
            @pagination="handlePagination"
            :layout="'total, prev, pager, next, jumper'"
        />
      </div>
@@ -104,48 +96,58 @@
</template>
<script setup>
import {Download, Delete, Plus} from "@element-plus/icons-vue";
import {onMounted, ref} from "vue";
const { proxy } = getCurrentInstance()
import { Delete, Plus } from "@element-plus/icons-vue";
import { onMounted, ref, reactive, getCurrentInstance, nextTick } from "vue";
// 组件引入
import Pagination from "@/components/Pagination/index.vue";
import ETable from "@/components/Table/ETable.vue";
import FormDia from "@/views/inspectionManagement/components/formDia.vue";
import QrCodeDia from "@/views/inspectionManagement/components/qrCodeDia.vue";
import ViewFiles from "@/views/inspectionManagement/components/viewFiles.vue";
import ViewQrCodeFiles from "@/views/inspectionManagement/components/viewQrCodeFiles.vue";
// 接口引入
import {
  delInspectionTask,
  delTimingTask,
  inspectionTaskList,
  timingTaskList
} from "@/api/inspectionManagement/index.js";
import ViewFiles from "@/views/inspectionManagement/components/viewFiles.vue";
import {delQrCode, qrCodeList, qrCodeScanRecordList} from "@/api/inspectionUpload/index.js";
import ViewQrCodeFiles from "@/views/inspectionManagement/components/viewQrCodeFiles.vue";
import {
  delQrCode,
  qrCodeList,
  qrCodeScanRecordList
} from "@/api/inspectionUpload/index.js";
const formDia = ref()
const qrCodeDia = ref()
const viewFiles = ref()
const viewQrCodeFiles = ref()
// 全局变量
const { proxy } = getCurrentInstance();
const formDia = ref();
const qrCodeDia = ref();
const viewFiles = ref();
const viewQrCodeFiles = ref();
// 查询参数
const queryParams = reactive({
  supplierName: "",
  coal: "",
})
// 当前标签
  searchAll: "",
});
// 标签页配置
const activeTab = ref("task");
const tabName = ref("task");
// 标签页数据
const tabs = reactive([
  { name: "task", label: "生产巡检" },
  { name: "qrCodeScanRecord", label: "现场巡检记录" },
]);
// 单选框
// 单选框配置
const activeRadio = ref("taskManage");
const radios = reactive([
  { name: "taskManage", label: "定时任务管理" },
  { name: "task", label: "定时任务记录" },
  { name: "qrCode", label: "二维码管理" },
]);
// 表格
// 表格数据
const selectedRows = ref([]);
const tableData = ref([]);
const operationsArr = ref([]);
@@ -154,16 +156,49 @@
const total = ref(0);
const pageNum = ref(1);
const pageSize = ref(10);
// 列配置
const columns = ref([
  { prop: "taskName", label: "巡检任务名称", minWidth: 160 },
  { prop: "port", label: "地点", minWidth: 120 },
  { prop: "inspectionLocation", label: "地点", minWidth: 120 },
  { prop: "remarks", label: "备注", minWidth: 150 },
  { prop: "inspector", label: "执行巡检人", minWidth: 150 },
  { prop: "inspector", label: "频次", minWidth: 150 },
  { prop: "inspector", label: "开始日期", minWidth: 150 },
  {
    prop: "frequencyType",
    label: "频次",
    minWidth: 150,
    formatter: (_, __, val) => ({
      DAILY: "每日",
      WEEKLY: "每周",
      MONTHLY: "每月",
      QUARTERLY: "季度"
    }[val] || "")
  },
  {
    prop: "frequencyDetail",
    label: "开始日期与时间",
    minWidth: 150,
    formatter: (row, column, cellValue) => {
      // 先判断是否是字符串
      if (typeof cellValue !== 'string') return '';
      let val = cellValue;
      const replacements = {
        MON: '周一',
        TUE: '周二',
        WED: '周三',
        THU: '周四',
        FRI: '周五',
        SAT: '周六',
        SUN: '周日'
      };
      // 使用正则一次性替换所有匹配项
      return val.replace(/MON|TUE|WED|THU|FRI|SAT|SUN/g, match => replacements[match]);
    }
  },
  { prop: "registrant", label: "登记人", minWidth: 100 },
  { prop: "createTime", label: "登记日期", minWidth: 100 },
]);
const columns1 = ref([
  { prop: "deviceName", label: "设备名称", minWidth: 160 },
  { prop: "location", label: "所在位置描述", minWidth: 120 },
@@ -174,110 +209,125 @@
onMounted(() => {
  radioChange('taskManage');
});
// 标签页点击
// 标签页点击事件
const handleTabClick = (tab) => {
  tabName.value = tab.props.name;
  tableData.value = [];
  getList();
};
// 单选变化
const radioChange = (value) => {
  if (value !== "task") {
  if (value === "taskManage") {
    tableColumns.value = columns.value;
    operationsArr.value = ['edit']
    operationsArr.value = ['edit'];
  } else if (value === "task") {
    tableColumns.value = columns.value;
    operationsArr.value = ['viewFile'];
  } else {
    tableColumns.value = columns1.value;
    operationsArr.value = ['viewFile']
    operationsArr.value = ['edit'];
  }
  pageNum.value = 1;
  pageSize.value = 10;
  getList();
}
// 点击查询
};
// 查询操作
const handleQuery = () => {
  pageNum.value = 1
  pageSize.value = 10
  getList()
}
  pageNum.value = 1;
  pageSize.value = 10;
  getList();
};
// 分页处理
const handlePagination = (val) => {
   pageNum.value = val.page;
   pageSize.value = val.limit;
   getList();
};
// 获取列表数据
const getList = () => {
  tableLoading.value = true;
  const params = { ...queryParams, size: pageSize.value, current: pageNum.value };
  let apiCall;
  if (tabName.value === 'task') {
    if (activeRadio.value === "task") {
      inspectionTaskList({...queryParams, size: pageSize.value, current: pageNum.value}).then(res => {
        tableLoading.value = false;
        tableData.value = res.data.records;
        total.value = res.data.total;
      })
    } else if (activeRadio.value === "qrCode") {
      qrCodeList({...queryParams, size: pageSize.value, current: pageNum.value}).then(res => {
        tableLoading.value = false;
        tableData.value = res.data.records;
        total.value = res.data.total;
      })
    } else {
      timingTaskList({...queryParams, size: pageSize.value, current: pageNum.value}).then(res => {
        tableLoading.value = false;
        tableData.value = res.data.records;
        total.value = res.data.total;
      })
    switch (activeRadio.value) {
      case "task":
        apiCall = inspectionTaskList(params);
        break;
      case "qrCode":
        apiCall = qrCodeList(params);
        break;
      default:
        apiCall = timingTaskList(params);
    }
  } else {
    qrCodeScanRecordList({size: pageSize.value, current: pageNum.value}).then(res => {
      tableLoading.value = false;
      tableData.value = res.data.records;
      total.value = res.data.total;
    })
    apiCall = qrCodeScanRecordList(params);
  }
  
  apiCall.then(res => {
    tableData.value = res.data.records || [];
    total.value = res.data.total || 0;
  }).finally(() => {
    tableLoading.value = false;
  });
};
// 重置查询
const resetQuery = () => {
  Object.keys(queryParams).forEach((key) => {
    if (key !== "pageNum" && key !== "pageSize") {
  for (const key in queryParams) {
    if (!["pageNum", "pageSize"].includes(key)) {
      queryParams[key] = "";
    }
  });
  }
  handleQuery();
};
// 新增、编辑
// 新增 / 编辑
const handleAdd = (row) => {
  const type = row === undefined ? 'add' : 'edit'
  const type = row ? 'edit' : 'add';
  nextTick(() => {
    if (tabName.value === 'task') {
      if (activeRadio.value === "taskManage") {
        formDia.value?.openDialog(type, row)
        formDia.value?.openDialog(type, row);
      } else if (activeRadio.value === "qrCode") {
        qrCodeDia.value?.openDialog(type, row)
        qrCodeDia.value?.openDialog(type, row);
      }
    } else {
      viewQrCodeFiles.value?.openDialog(row)
      viewQrCodeFiles.value?.openDialog(row);
    }
  })
  });
};
// 查看附件
const viewFile = (row) => {
  nextTick(() => {
    viewFiles.value?.openDialog(row)
  })
}
// 删除任务
    viewFiles.value?.openDialog(row);
  });
};
// 删除操作
const handleDelete = () => {
  if (selectedRows.value.length === 0) {
  if (!selectedRows.value.length) {
    proxy.$modal.msgWarning("请选择要删除的数据");
    return;
  }
  const deleteIds = selectedRows.value.map(item => item.id);
  proxy.$modal.confirm('是否确认删除所选数据项?').then(function() {
    if (activeRadio.value === "taskManage") {
      return delTimingTask(deleteIds)
    } else {
      return delQrCode(deleteIds)
    }
  const api = activeRadio.value === "taskManage" ? delTimingTask : delQrCode;
  proxy.$modal.confirm('是否确认删除所选数据项?').then(() => {
    return api(deleteIds);
  }).then(() => {
    handleQuery()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => {})
    proxy.$modal.msgSuccess("删除成功");
    handleQuery();
  }).catch(() => {});
};
// 选择行
// 多选变更
const handleSelectionChange = (selection) => {
  selectedRows.value = selection;
};