From 908555743c2c36d7e13a129f4ad78f3f69602489 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期四, 16 十月 2025 09:14:17 +0800
Subject: [PATCH] 生产管控-生产订单添加随机排产功能
---
src/views/production/index.vue | 130 +++++++++++++++++++++++++++++++++++--------
1 files changed, 106 insertions(+), 24 deletions(-)
diff --git a/src/views/production/index.vue b/src/views/production/index.vue
index 4827925..e9198ea 100644
--- a/src/views/production/index.vue
+++ b/src/views/production/index.vue
@@ -1,5 +1,5 @@
<template>
- <div class="production-container">
+ <div class="app-container">
<!-- 鎼滅储琛ㄥ崟 -->
<el-form :inline="true" :model="queryParams" class="search-form">
<el-form-item label="鎼滅储">
@@ -22,10 +22,19 @@
<el-button type="success" :icon="Plus" @click="openDialog('add')">
鏂板鍔犲伐
</el-button>
- <el-button type="danger" :icon="Delete" :disabled="!selectedRows.length" @click="() => deleteSelected(delPM)">
+ <el-button
+ type="danger"
+ :icon="Delete"
+ :disabled="!selectedRows.length"
+ @click="() => deleteSelected(delPM)"
+ >
鍒犻櫎
</el-button>
- </div> <!-- 鏁版嵁琛ㄦ牸 -->
+ <el-button type="primary" @click="handleRandomScheduling">
+ 闅忔満鎺掍骇
+ </el-button>
+ </div>
+ <!-- 鏁版嵁琛ㄦ牸 -->
<ETable
:showOverflowTooltip="false"
:loading="loading"
@@ -34,19 +43,33 @@
:current-page="queryParams.current"
:page-size="queryParams.size"
@selection-change="handleSelectionChange"
- @edit="row => openDialog('edit', row)"
+ @edit="(row) => openDialog('edit', row)"
:show-selection="true"
:border="true"
- :maxHeight="480"
- > <template #coal="{ row }">
+ @viewRow="(row) => (viewRow('viewRow', row))"
+ :operations="['edit', 'viewRow']"
+ :operationsWidth="200"
+ :show-overflow-tooltip="false"
+ style="width: 100%; height: calc(100vh - 26em)"
+ >
+ <template #coalId="{ row }">
<div class="coal-tags">
- <el-tag v-for="coal in parseCoalArray(row.coal)" :key="coal" size="small">
- {{ getCoalNameById(coal) }}
- </el-tag>
- <span v-if="!row.coal">--</span>
+ <template v-if="row.coalId">
+ <el-tag
+ v-for="coal in parseCoalArray(row.coalId)"
+ :key="coal"
+ size="small"
+ type="primary"
+ class="coal-tag"
+ >
+ {{ getDisplayCoalName(coal) }}
+ </el-tag>
+ </template>
+ <span v-else class="no-data">--</span>
</div>
</template>
- </ETable> <!-- 鍒嗛〉缁勪欢 -->
+ </ETable>
+ <!-- 鍒嗛〉缁勪欢 -->
<Pagination
:layout="'total, prev, pager, next, jumper'"
:total="total"
@@ -69,27 +92,30 @@
</template>
<script setup>
-import { onMounted } from "vue";
+import { onMounted, ref } from "vue";
import { ElMessage } from "element-plus";
import { Plus, Delete } from "@element-plus/icons-vue";
import ProductionDialog from "./components/ProductionDialog.vue";
import ETable from "@/components/Table/ETable.vue";
import Pagination from "@/components/Pagination/index.vue";
-import { getProductionMasterList, delPM } from "@/api/production";
+import { getProductionMasterList, delPM, randomScheduling } from "@/api/production";
import { parseCoalArray } from "@/utils/production";
import { useTableData } from "./components/useTableData.js";
import { useDialog } from "./components/useDialog.js";
import { useCoalData } from "./components/useCoalData.js";
+import { getCoalInfoList } from "@/api/production";
+
+// 鐓ょ淇℃伅鍒楄〃
+const coalInfoList = ref([]);
// 琛ㄦ牸鍒楅厤缃�
const columns = [
- { prop: "coal", label: "鐓ょ", minWidth: 150, slot: 'coal' },
+ { prop: "coalId", label: "鐓ょ", minWidth: 150, slot: true },
{ prop: "productionQuantity", label: "鐢熶骇鏁伴噺", minWidth: 120 },
{ prop: "laborCost", label: "浜哄伐鎴愭湰", minWidth: 150 },
{ prop: "energyConsumptionCost", label: "鑳借�楁垚鏈�", minWidth: 120 },
{ prop: "equipmentDepreciation", label: "璁惧鎶樻棫", minWidth: 143 },
{ prop: "totalCost", label: "鎬绘垚鏈�", minWidth: 150 },
- { prop: "producer", label: "鐢熶骇浜�", minWidth: 150 },
];
// 浣跨敤琛ㄦ牸鏁版嵁缁勫悎寮忓嚱鏁�
@@ -104,7 +130,7 @@
handleReset,
handlePageChange,
handleSelectionChange,
- deleteSelected
+ deleteSelected,
} = useTableData(getProductionMasterList, { pageSize: 10 });
// 浣跨敤瀵硅瘽妗嗙粍鍚堝紡鍑芥暟
@@ -113,15 +139,30 @@
dialogType,
dialogRef,
openDialog,
- handleDialogSuccess: onDialogSuccess
+ viewRow,
+ handleDialogSuccess: onDialogSuccess,
} = useDialog();
// 浣跨敤鐓ょ鏁版嵁缁勫悎寮忓嚱鏁�
const { getCoalNameById, getCoalData } = useCoalData();
+// 鑾峰彇鐓ょ鏄剧ず鍚嶇О锛堝甫澶囩敤閫昏緫锛�
+const getDisplayCoalName = (coalId) => {
+ // 浼樺厛浣跨敤 useCoalData 鐨勬柟娉�
+ let name = getCoalNameById(coalId);
+
+ // 濡傛灉娌℃湁鎵惧埌锛屽皾璇曚粠 coalInfoList 涓煡鎵�
+ if (name === coalId && coalInfoList.value.length > 0) {
+ const found = coalInfoList.value.find((item) => item.id == coalId);
+ name = found ? found.coal : coalId;
+ }
+
+ return name || coalId;
+};
+
// 澶勭悊鐢熶骇鏁版嵁鏇存柊
const handleProductionAndProcessing = (row, rows) => {
- const index = tableData.value.findIndex(item => item.id === rows.id);
+ const index = tableData.value.findIndex((item) => item.id === rows.id);
if (index !== -1) {
tableData.value[index] = { ...tableData.value[index], ...row };
}
@@ -134,10 +175,43 @@
ElMessage.success("鎿嶄綔鎴愬姛");
});
};
+
+// 闅忔満鎺掍骇澶勭悊鍑芥暟
+const handleRandomScheduling = async () => {
+ try {
+ const { ElMessage } = await import('element-plus');
+ const res = await randomScheduling();
+ if (res.code === 200) {
+ ElMessage.success('闅忔満鎺掍骇鎴愬姛');
+ getList(); // 鍒锋柊鍒楄〃
+ } else {
+ ElMessage.error(res.msg || '闅忔満鎺掍骇澶辫触');
+ }
+ } catch (error) {
+ const { ElMessage } = await import('element-plus');
+ ElMessage.error('璇锋眰澶辫触锛岃绋嶅悗閲嶈瘯');
+ }
+};
+
// 缁勪欢鎸傝浇鏃跺姞杞芥暟鎹�
onMounted(async () => {
- await getCoalData(); // 棰勫姞杞界叅绉嶆暟鎹�
- getList();
+ try {
+ // 骞惰鍔犺浇鐓ょ鏁版嵁鍜岃〃鏍兼暟鎹�
+ await Promise.all([
+ getCoalData(), // 棰勫姞杞界叅绉嶆暟鎹�
+ (async () => {
+ const res = await getCoalInfoList();
+ if (res.code === 200) {
+ coalInfoList.value = res.data;
+ }
+ })(),
+ ]);
+
+ // 鍔犺浇琛ㄦ牸鏁版嵁
+ getList();
+ } catch (error) {
+ ElMessage.error("鏁版嵁鍔犺浇澶辫触锛岃鍒锋柊椤甸潰閲嶈瘯");
+ }
});
</script>
@@ -159,9 +233,10 @@
width: 20%;
}
}
+
.search-form {
display: flex;
- justify-content: space-between;
+ justify-content: flex-start;
align-items: center;
margin-bottom: 20px;
@@ -173,18 +248,25 @@
margin-left: 10px;
}
}
+
.coal-tags {
display: flex;
flex-wrap: wrap;
gap: 4px;
-
- .el-tag {
+ align-items: center;
+
+ .coal-tag {
margin-right: 4px;
margin-bottom: 4px;
-
+
&:last-child {
margin-right: 0;
}
}
+
+ .no-data {
+ color: #999;
+ font-style: italic;
+ }
}
</style>
--
Gitblit v1.9.3