From fc62e83f73b4b8ff4714f995da4eafbb7f525d1a Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期二, 18 八月 2026 23:30:10 +0800
Subject: [PATCH] feat(table): 统一表格日期字段展示格式为YYYY-MM-DD
---
src/views/equipmentManagement/inspectionManagement/index.vue | 486 ++++++++++++++++++++++++-----------------------------
1 files changed, 222 insertions(+), 264 deletions(-)
diff --git a/src/views/equipmentManagement/inspectionManagement/index.vue b/src/views/equipmentManagement/inspectionManagement/index.vue
index 44103ac..da8ac99 100644
--- a/src/views/equipmentManagement/inspectionManagement/index.vue
+++ b/src/views/equipmentManagement/inspectionManagement/index.vue
@@ -24,7 +24,6 @@
:label="tab.label"
:value="tab.name" />
</el-radio-group>
- <!-- 鎿嶄綔鎸夐挳鍖� -->
<el-space v-if="activeRadio !== 'task'">
<el-button type="primary"
:icon="Plus"
@@ -38,7 +37,9 @@
<el-button @click="handleOut">瀵煎嚭</el-button>
</el-space>
</div>
- <div>
+
+ <!-- 宸℃浠诲姟 -->
+ <div v-show="activeRadio === 'taskManage'">
<PIMTable :table-loading="tableLoading"
:table-data="tableData"
:column="tableColumns"
@@ -52,11 +53,10 @@
total: total,
layout: 'total, sizes, prev, pager, next, jumper'
}"
- :table-style="{ width: '100%', height: 'calc(100vh - 23em)' }">
+ height="calc(100vh - 23em)"
+ :table-style="{ width: '100%' }">
<template #inspector="{ row }">
<div class="person-tags">
- <!-- 璋冭瘯淇℃伅锛屼笂绾挎椂鍒犻櫎 -->
- <!-- {{ console.log('inspector data:', row.inspector) }} -->
<template v-if="row.inspector && row.inspector.length > 0">
<el-tag v-for="(person, index) in row.inspector"
:key="index"
@@ -66,59 +66,135 @@
{{ person }}
</el-tag>
</template>
- <span v-else
- class="no-data">--</span>
+ <span v-else class="no-data">--</span>
</div>
</template>
<template #isEnabled="{ row }">
- <el-tag :type="row.isEnabled === 1 ? 'success' : 'danger'" size="small">
+ <el-tag :type="row.isEnabled === 1 ? 'success' : 'danger'"
+ size="small">
{{ row.isEnabled == 1 ? '鏄�' : '鍚�' }}
</el-tag>
</template>
</PIMTable>
</div>
+
+ <!-- 宸℃璁板綍 - 鏃ユ湡鍒嗙粍鎶樺彔 -->
+ <div v-show="activeRadio === 'task'">
+ <el-table
+ :data="groupedInspectionList"
+ border
+ v-loading="tableLoading"
+ :expand-row-keys="inspectionExpandedRowKeys"
+ :row-key="(row) => row.date"
+ @expand-change="onInspectionExpandChange"
+ height="calc(100vh - 23em)"
+ >
+ <el-table-column type="expand">
+ <template #default="props">
+ <el-table :data="props.row.children" border row-key="id">
+ <el-table-column label="宸℃浠诲姟鍚嶇О" prop="taskName" align="center" min-width="180" />
+ <el-table-column label="宸℃椤圭洰" prop="inspectionProject" align="center" min-width="160" />
+ <el-table-column label="宸℃浜�" align="center" min-width="150">
+ <template #default="{ row }">
+ <template v-if="row.inspector && row.inspector.length > 0">
+ <el-tag v-for="(p, i) in row.inspector" :key="i" size="small" type="primary" class="person-tag">{{ p }}</el-tag>
+ </template>
+ <span v-else>--</span>
+ </template>
+ </el-table-column>
+ <el-table-column label="宸℃鐘舵��" align="center" width="100">
+ <template #default="{ row }">
+ <el-tag :type="row.status === 1 ? 'success' : 'warning'" size="small">
+ {{ row.status === 1 ? '宸插畬鎴�' : '寰呭贰妫�' }}
+ </el-tag>
+ </template>
+ </el-table-column>
+ <el-table-column label="宸℃缁撴灉" prop="inspectionResult" align="center" min-width="120" />
+ <el-table-column label="澶囨敞" prop="remarks" align="center" min-width="150" />
+ <el-table-column label="寮傚父鎻忚堪" prop="abnormalDescription" align="center" min-width="150" />
+ <el-table-column label="鎿嶄綔" align="center" width="200">
+ <template #default="{ row }">
+ <el-button type="primary" link @click="openUploadDialog(row)">涓婁紶</el-button>
+ <el-button type="success" link @click="viewFile(row)">鏌ョ湅闄勪欢</el-button>
+ <el-button type="warning" link v-if="row.status === 0" @click="handleSingleComplete(row)">宸℃瀹屾垚</el-button>
+ </template>
+ </el-table-column>
+ </el-table>
+ </template>
+ </el-table-column>
+ <el-table-column label="宸℃鏃ユ湡" prop="date" align="center" />
+ <el-table-column label="宸℃璁板綍鏁�" prop="count" align="center" />
+ <el-table-column label="寰呭贰妫�鏁�" align="center" width="120">
+ <template #default="{ row }">
+ {{ row.children.filter(c => c.status === 0).length }}
+ </template>
+ </el-table-column>
+ <el-table-column label="鎿嶄綔" align="center" width="200">
+ <template #default="{ row }">
+ <el-button
+ type="primary"
+ size="small"
+ :disabled="!row.children.some(c => c.status === 0)"
+ @click="handleBatchInspection(row.date)"
+ >
+ 涓�閿贰妫�瀹屾垚
+ </el-button>
+ </template>
+ </el-table-column>
+ </el-table>
+ <Pagination
+ v-show="total > 0"
+ :total="total"
+ layout="total, sizes, prev, pager, next, jumper"
+ :page="pageNum"
+ :limit="pageSize"
+ @pagination="handlePagination"
+ />
+ </div>
</el-card>
<form-dia ref="formDia"
@closeDia="handleQuery"></form-dia>
<view-files ref="viewFiles"></view-files>
+ <upload-files ref="uploadFiles"
+ @success="handleQuery"
+ @closeDia="handleQuery"></upload-files>
+
</div>
</template>
<script setup>
import { Delete, Plus } from "@element-plus/icons-vue";
- import { onMounted, ref, reactive, getCurrentInstance, nextTick } from "vue";
- import { ElMessageBox } from "element-plus";
+ import { onMounted, ref, reactive, getCurrentInstance, nextTick, computed } from "vue";
+ import { ElMessage, ElMessageBox } from "element-plus";
+ import dayjs from "dayjs";
- // 缁勪欢寮曞叆
import PIMTable from "@/components/PIMTable/PIMTable.vue";
import FormDia from "@/views/equipmentManagement/inspectionManagement/components/formDia.vue";
+ import UploadFiles from "@/views/equipmentManagement/inspectionManagement/components/uploadFiles.vue";
import ViewFiles from "@/views/equipmentManagement/inspectionManagement/components/viewFiles.vue";
- // 鎺ュ彛寮曞叆
import {
delTimingTask,
inspectionTaskList,
timingTaskList,
+ completeInspection,
+ batchCompleteInspection,
} from "@/api/inspectionManagement/index.js";
+ import Pagination from "@/components/PIMTable/Pagination.vue";
- // 鍏ㄥ眬鍙橀噺
const { proxy } = getCurrentInstance();
const formDia = ref();
const viewFiles = ref();
+ const uploadFiles = ref();
- // 鏌ヨ鍙傛暟
- const queryParams = reactive({
- taskName: "",
- });
+ const queryParams = reactive({ taskName: "" });
- // 鍗曢�夋閰嶇疆
const activeRadio = ref("taskManage");
const radios = reactive([
- { name: "taskManage", label: "瀹氭椂浠诲姟绠$悊" },
- { name: "task", label: "瀹氭椂浠诲姟璁板綍" },
+ { name: "taskManage", label: "宸℃浠诲姟" },
+ { name: "task", label: "宸℃璁板綍" },
]);
- // 琛ㄦ牸鏁版嵁
const selectedRows = ref([]);
const tableData = ref([]);
const operationsArr = ref([]);
@@ -126,283 +202,165 @@
const tableLoading = ref(false);
const total = ref(0);
const pageNum = ref(1);
- const pageSize = ref(10);
+ const pageSize = ref(100);
- // 鍒楅厤缃�
const columns = ref([
- { prop: "taskName", label: "宸℃浠诲姟鍚嶇О", minWidth: 160 },
- { prop: "inspectionProject", label: "宸℃椤圭洰", minWidth: 150 },
- { prop: "remarks", label: "澶囨敞", minWidth: 150 },
- { prop: "inspector", label: "鎵ц宸℃浜�", minWidth: 150, slot: "inspector" },
+ { prop: "taskName", label: "宸℃浠诲姟鍚嶇О", minWidth: 200 },
+ { prop: "inspectionProject", label: "宸℃椤圭洰", minWidth: 180 },
+ { prop: "remarks", label: "澶囨敞", minWidth: 180 },
+ { prop: "inspector", label: "鎵ц宸℃浜�", minWidth: 180, slot: "inspector" },
+ { prop: "isEnabled", label: "鏄惁鍚敤", minWidth: 100, dataType: "slot", slot: "isEnabled" },
{
- prop: "isEnabled",
- label: "鏄惁鍚敤",
- minWidth: 100,
- dataType: "slot",
- slot: "isEnabled"
+ prop: "frequencyType", label: "棰戞", minWidth: 120,
+ formatData: params => ({ DAILY: "姣忔棩", WEEKLY: "姣忓懆", MONTHLY: "姣忔湀", QUARTERLY: "瀛e害" }[params] || ""),
},
{
- prop: "frequencyType",
- label: "棰戞",
- minWidth: 150,
- // formatter: (_, __, val) => ({
- // DAILY: "姣忔棩",
- // WEEKLY: "姣忓懆",
- // MONTHLY: "姣忔湀",
- // QUARTERLY: "瀛e害"
- // }[val] || "")
- formatData: params => {
- return params === "DAILY"
- ? "姣忔棩"
- : params === "WEEKLY"
- ? "姣忓懆"
- : params === "MONTHLY"
- ? "姣忔湀"
- : params === "QUARTERLY"
- ? "瀛e害"
- : "";
- },
- },
- {
- prop: "frequencyDetail",
- label: "寮�濮嬫棩鏈熶笌鏃堕棿",
- minWidth: 150,
+ prop: "frequencyDetail", label: "寮�濮嬫棩鏈熶笌鏃堕棿", minWidth: 200,
formatter: (row, column, cellValue) => {
- // 鍏堝垽鏂槸鍚︽槸瀛楃涓�
if (typeof cellValue !== "string") return "";
- let val = cellValue;
- const replacements = {
- MON: "鍛ㄤ竴",
- TUE: "鍛ㄤ簩",
- WED: "鍛ㄤ笁",
- THU: "鍛ㄥ洓",
- FRI: "鍛ㄤ簲",
- SAT: "鍛ㄥ叚",
- SUN: "鍛ㄦ棩",
- };
- // 浣跨敤姝e垯涓�娆℃�ф浛鎹㈡墍鏈夊尮閰嶉」
- return val.replace(
- /MON|TUE|WED|THU|FRI|SAT|SUN/g,
- match => replacements[match]
- );
+ return cellValue.replace(/MON|TUE|WED|THU|FRI|SAT|SUN/g, match => ({ MON: "鍛ㄤ竴", TUE: "鍛ㄤ簩", WED: "鍛ㄤ笁", THU: "鍛ㄥ洓", FRI: "鍛ㄤ簲", SAT: "鍛ㄥ叚", SUN: "鍛ㄦ棩" }[match]));
},
},
- { prop: "registrant", label: "鐧昏浜�", minWidth: 100 },
- { prop: "createTime", label: "鐧昏鏃ユ湡", minWidth: 100 },
+ { prop: "registrant", label: "鐧昏浜�", minWidth: 120 },
+ {
+ prop: "createTime", label: "鐧昏鏃ユ湡", minWidth: 180,
+ formatData: cell => { if (!cell) return "-"; try { return dayjs(cell).format("YYYY-MM-DD HH:mm:ss"); } catch { return cell; } },
+ },
+ { prop: "abnormalDescription", label: "寮傚父鎻忚堪", minWidth: 150 },
]);
- // 鎿嶄綔鍒楅厤缃�
const getOperationColumn = operations => {
if (!operations || operations.length === 0) return null;
-
- const operationConfig = {
- label: "鎿嶄綔",
- width: 130,
- fixed: "right",
- dataType: "action",
- operation: operations
- .map(op => {
- switch (op) {
- case "edit":
- return {
- name: "缂栬緫",
- clickFun: handleAdd,
- color: "#409EFF",
- };
- case "viewFile":
- return {
- name: "鏌ョ湅闄勪欢",
- clickFun: viewFile,
- color: "#67C23A",
- };
- default:
- return null;
- }
- })
- .filter(Boolean),
+ return {
+ label: "鎿嶄綔", width: operations.length > 1 ? 180 : 130, fixed: "right", align: "center", dataType: "action",
+ operation: operations.map(op => {
+ switch (op) {
+ case "edit": return { name: "缂栬緫", clickFun: handleAdd, color: "#409EFF" };
+ case "upload": return { name: "涓婁紶", clickFun: openUploadDialog, color: "#409EFF" };
+ case "viewFile": return { name: "鏌ョ湅闄勪欢", clickFun: viewFile, color: "#67C23A" };
+ default: return null;
+ }
+ }).filter(Boolean),
};
-
- return operationConfig;
};
- onMounted(() => {
- radioChange("taskManage");
- });
+ // 宸℃璁板綍 - 鏃ユ湡鍒嗙粍
+ const inspectionExpandedRowKeys = ref([]);
- // 鍗曢�夊彉鍖�
+ const groupInspectionByDate = (list) => {
+ const map = {};
+ list.forEach(item => {
+ const date = item.dateStr || (item.createTime ? dayjs(item.createTime).format('YYYY-MM-DD') : '鏈煡鏃ユ湡');
+ if (!map[date]) map[date] = [];
+ map[date].push(item);
+ });
+ return Object.entries(map).map(([date, children]) => ({ date, children, count: children.length }));
+ };
+
+ const groupedInspectionList = computed(() => groupInspectionByDate(tableData.value));
+
+ const onInspectionExpandChange = (row, expandedRows) => {
+ inspectionExpandedRowKeys.value = expandedRows.map(r => r.date);
+ };
+
+ // 鍗曟潯宸℃瀹屾垚
+ const handleSingleComplete = async (row) => {
+ try {
+ await ElMessageBox.confirm('纭灏嗚宸℃璁板綍鏍囪涓哄畬鎴愶紵', '鎻愮ず', { type: 'warning' });
+ const res = await completeInspection(row.id);
+ if (res.code === 200) {
+ ElMessage.success('宸℃瀹屾垚');
+ getList();
+ } else {
+ ElMessage.error(res.msg || '鎿嶄綔澶辫触');
+ }
+ } catch { /* 鍙栨秷 */ }
+ };
+
+ // 涓�閿贰妫�瀹屾垚
+ const handleBatchInspection = async (dateStr) => {
+ try {
+ await ElMessageBox.confirm(`纭灏� ${dateStr} 鐨勬墍鏈夊緟宸℃璁板綍鏍囪涓哄畬鎴愶紵`, '鎻愮ず', { type: 'warning' });
+ const res = await batchCompleteInspection(dateStr);
+ if (res.code === 200) {
+ ElMessage.success(res.msg || '鎵归噺瀹屾垚鎴愬姛');
+ getList();
+ } else {
+ ElMessage.error(res.msg || '鎿嶄綔澶辫触');
+ }
+ } catch { /* 鍙栨秷 */ }
+ };
+
+ onMounted(() => { radioChange("taskManage"); });
+
const radioChange = value => {
+ inspectionExpandedRowKeys.value = [];
if (value === "taskManage") {
const operationColumn = getOperationColumn(["edit"]);
- tableColumns.value = [
- ...columns.value,
- ...(operationColumn ? [operationColumn] : []),
- ];
+ tableColumns.value = [...columns.value, ...(operationColumn ? [operationColumn] : [])];
operationsArr.value = ["edit"];
} else if (value === "task") {
- const operationColumn = getOperationColumn(["viewFile"]);
- // 瀹氭椂浠诲姟璁板綍涓嶅睍绀�"鏄惁鍚敤"鍒�
+ const operationColumn = getOperationColumn(["upload", "viewFile"]);
const taskColumns = columns.value.filter(col => col.prop !== "isEnabled");
- tableColumns.value = [
- ...taskColumns,
- ...(operationColumn ? [operationColumn] : []),
- ];
- operationsArr.value = ["viewFile"];
+ tableColumns.value = [...taskColumns, ...(operationColumn ? [operationColumn] : [])];
+ operationsArr.value = ["upload", "viewFile"];
}
pageNum.value = 1;
- pageSize.value = 10;
getList();
};
- // 鏌ヨ鎿嶄綔
- const handleQuery = () => {
- pageNum.value = 1;
- pageSize.value = 10;
- getList();
- };
- // 鍒嗛〉澶勭悊
- const handlePagination = val => {
- pageNum.value = val.page;
- pageSize.value = val.limit;
- getList();
- };
- // 鑾峰彇鍒楄〃鏁版嵁
+ const handleQuery = () => { pageNum.value = 1; 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 (activeRadio.value === "task") {
- apiCall = inspectionTaskList(params);
- } else {
- apiCall = timingTaskList(params);
- }
-
- apiCall
- .then(res => {
- const rawData = res.data.records || [];
- // 澶勭悊 inspector 瀛楁锛屽皢瀛楃涓茶浆鎹负鏁扮粍锛堥�傜敤浜庢墍鏈夋儏鍐碉級
- tableData.value = rawData.map(item => {
- const processedItem = { ...item };
-
- // 澶勭悊 inspector 瀛楁
- if (processedItem.inspector) {
- if (typeof processedItem.inspector === "string") {
- // 瀛楃涓叉寜閫楀彿鍒嗗壊
- processedItem.inspector = processedItem.inspector
- .split(",")
- .map(s => s.trim())
- .filter(s => s);
- } else if (!Array.isArray(processedItem.inspector)) {
- // 闈炴暟缁勮浆涓烘暟缁�
- processedItem.inspector = [processedItem.inspector];
- }
- } else {
- // 绌哄�艰涓虹┖鏁扮粍
- processedItem.inspector = [];
+ const params = { ...queryParams, size: pageSize.value, current: pageNum.value };
+ const apiCall = activeRadio.value === "task" ? inspectionTaskList(params) : timingTaskList(params);
+ apiCall.then(res => {
+ const rawData = res.data.records || [];
+ tableData.value = rawData.map(item => {
+ const processedItem = { ...item };
+ if (processedItem.inspector) {
+ if (typeof processedItem.inspector === "string") {
+ processedItem.inspector = processedItem.inspector.split(",").map(s => s.trim()).filter(s => s);
+ } else if (!Array.isArray(processedItem.inspector)) {
+ processedItem.inspector = [processedItem.inspector];
}
-
- return processedItem;
- });
- total.value = res.data.total || 0;
- })
- .finally(() => {
- tableLoading.value = false;
- });
- };
-
- // 閲嶇疆鏌ヨ
- const resetQuery = () => {
- for (const key in queryParams) {
- if (!["pageNum", "pageSize"].includes(key)) {
- queryParams[key] = "";
- }
- }
- handleQuery();
- };
-
- // 鏂板 / 缂栬緫
- const handleAdd = row => {
- const type = row ? "edit" : "add";
- nextTick(() => {
- formDia.value?.openDialog(type, row);
- });
- };
-
- // 鏌ョ湅闄勪欢
- const viewFile = row => {
- nextTick(() => {
- viewFiles.value?.openDialog(row);
- });
- };
-
- // 鍒犻櫎鎿嶄綔
- const handleDelete = () => {
- if (!selectedRows.value.length) {
- proxy.$modal.msgWarning("璇烽�夋嫨瑕佸垹闄ょ殑鏁版嵁");
- return;
- }
-
- const deleteIds = selectedRows.value.map(item => item.id);
-
- proxy.$modal
- .confirm("鏄惁纭鍒犻櫎鎵�閫夋暟鎹」锛�")
- .then(() => {
- return delTimingTask(deleteIds);
- })
- .then(() => {
- proxy.$modal.msgSuccess("鍒犻櫎鎴愬姛");
- handleQuery();
- })
- .catch(() => {});
- };
-
- // 澶氶�夊彉鏇�
- const handleSelectionChange = selection => {
- selectedRows.value = selection;
- };
-
- // 瀵煎嚭
- const handleOut = () => {
- ElMessageBox.confirm("閫変腑鐨勫唴瀹瑰皢琚鍑猴紝鏄惁纭瀵煎嚭锛�", "瀵煎嚭", {
- confirmButtonText: "纭",
- cancelButtonText: "鍙栨秷",
- type: "warning",
- })
- .then(() => {
- // 鏍规嵁褰撳墠閫変腑鐨勬爣绛鹃〉璋冪敤涓嶅悓鐨勫鍑烘帴鍙�
- if (activeRadio.value === "taskManage") {
- // 瀹氭椂浠诲姟绠$悊
- proxy.download("/timingTask/export", {}, "瀹氭椂浠诲姟绠$悊.xlsx");
- } else if (activeRadio.value === "task") {
- // 瀹氭椂浠诲姟璁板綍
- proxy.download("/inspectionTask/export", {}, "瀹氭椂浠诲姟璁板綍.xlsx");
+ } else {
+ processedItem.inspector = [];
}
- })
- .catch(() => {
- proxy.$modal.msg("宸插彇娑�");
+ return processedItem;
});
+ total.value = res.data.total || 0;
+ }).finally(() => { tableLoading.value = false; });
+ };
+
+ const resetQuery = () => { queryParams.taskName = ""; handleQuery(); };
+
+ const handleAdd = row => { nextTick(() => { formDia.value?.openDialog(row ? "edit" : "add", row); }); };
+ const viewFile = row => { nextTick(() => { viewFiles.value?.openDialog(row); }); };
+ const openUploadDialog = row => { nextTick(() => { uploadFiles.value?.openDialog(row); }); };
+
+ const handleDelete = () => {
+ if (!selectedRows.value.length) { proxy.$modal.msgWarning("璇烽�夋嫨瑕佸垹闄ょ殑鏁版嵁"); return; }
+ proxy.$modal.confirm("鏄惁纭鍒犻櫎鎵�閫夋暟鎹」锛�").then(() => delTimingTask(selectedRows.value.map(item => item.id)))
+ .then(() => { proxy.$modal.msgSuccess("鍒犻櫎鎴愬姛"); handleQuery(); }).catch(() => {});
+ };
+
+ const handleSelectionChange = selection => { selectedRows.value = selection; };
+
+ const handleOut = () => {
+ ElMessageBox.confirm("閫変腑鐨勫唴瀹瑰皢琚鍑猴紝鏄惁纭瀵煎嚭锛�", "瀵煎嚭", { confirmButtonText: "纭", cancelButtonText: "鍙栨秷", type: "warning" })
+ .then(() => {
+ if (activeRadio.value === "taskManage") proxy.download("/timingTask/export", {}, "宸℃浠诲姟.xlsx");
+ else proxy.download("/inspectionTask/export", {}, "宸℃璁板綍.xlsx");
+ }).catch(() => { proxy.$modal.msg("宸插彇娑�"); });
};
</script>
<style scoped>
- .person-tags {
- display: flex;
- flex-wrap: wrap;
- gap: 4px;
- }
-
- .person-tag {
- margin-right: 4px;
- margin-bottom: 2px;
- }
-
- .no-data {
- color: #909399;
- font-size: 14px;
- }
-</style>
\ No newline at end of file
+ .person-tags { display: flex; flex-wrap: wrap; gap: 4px; }
+ .person-tag { margin-right: 4px; margin-bottom: 2px; }
+ .no-data { color: #909399; font-size: 14px; }
+</style>
--
Gitblit v1.9.3