From c6d13e58d85fbaaceb49d4c24401b50143050173 Mon Sep 17 00:00:00 2001 From: zhang_12370 <z2864490065@outlook.com> Date: 星期四, 26 六月 2025 18:01:24 +0800 Subject: [PATCH] 调整 基础管理煤种生产人 更改采购数计算逻辑 处理供应商数据回显问题 --- src/views/production/index.vue | 426 ++++++++++++++++++++++++----------------------------- 1 files changed, 192 insertions(+), 234 deletions(-) diff --git a/src/views/production/index.vue b/src/views/production/index.vue index 8872835..fa77e22 100644 --- a/src/views/production/index.vue +++ b/src/views/production/index.vue @@ -1,261 +1,197 @@ <template> - <div class="production-container"> - <el-form :inline="true" :model="searchForm" class="search-form" style="width: 100%"> - <el-form-item label="鎼滅储"> - <el-input v-model="searchForm.searchAll" placeholder="璇疯緭鍏ュ叧閿瘝" clearable /> - </el-form-item> - <el-form-item> - <el-button type="primary" @click="handleSearch">鏌ヨ</el-button> - <el-button @click="handleReset">閲嶇疆</el-button> - </el-form-item> - </el-form> + <div class="app-container"> + <!-- 鎼滅储琛ㄥ崟 --> + <el-form :inline="true" :model="queryParams" class="search-form"> + <el-form-item label="鎼滅储"> + <el-input + v-model="queryParams.searchAll" + placeholder="璇疯緭鍏ュ叧閿瘝" + clearable + /> + </el-form-item> + <el-form-item> + <el-button type="primary" @click="handleSearch">鏌ヨ</el-button> + <el-button @click="handleReset">閲嶇疆</el-button> + </el-form-item> + </el-form> + + <!-- 涓昏鍐呭鍖哄煙 --> <el-card> - <el-button type="success" :icon="Plus" @click="handleAddBatch">鏂板鍔犲伐</el-button> - <el-button type="danger" :icon="Delete">鍒犻櫎</el-button> - <el-button type="info" :icon="Download">瀵煎嚭</el-button> - <ETable :loading="loading" :table-data="tableData" :columns="columns" @selection-change="handleSelectionChange" - @edit="handleEdit" @view-detail="handleViewDetail" :show-selection="true" :border="true" :maxHeight="480" /> - <Pagination v-model:currentPage="pagination.currentPage" v-model:pageSize="pagination.pageSize" - :total="pagination.total" @current-change="handleCurrentChange" @size-change="handleSizeChange" /> + <!-- 鎿嶄綔鎸夐挳 --> + <div class="toolbar"> + <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> + </div> + <!-- 鏁版嵁琛ㄦ牸 --> + <ETable + :showOverflowTooltip="false" + :loading="loading" + :table-data="tableData" + :columns="columns" + :current-page="queryParams.current" + :page-size="queryParams.size" + @selection-change="handleSelectionChange" + @edit="(row) => openDialog('edit', row)" + :show-selection="true" + :border="true" + @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"> + <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> + <!-- 鍒嗛〉缁勪欢 --> + <Pagination + :layout="'total, prev, pager, next, jumper'" + :total="total" + v-model:page="queryParams.current" + :limit="queryParams.size" + @pagination="handlePageChange" + /> </el-card> - <ProductionDialog v-model:visible="dialogVisible" ref="childRef" :type="dialogType" - @success="handleDialogSuccess" /> + + <!-- 鐢熶骇瀵硅瘽妗� --> + <!-- handleProductionAndProcessing --> + <ProductionDialog + v-model:visible="dialogVisible" + ref="dialogRef" + :type="dialogType" + @update:productionAndProcessing="handleProductionAndProcessing" + @success="handleDialogSuccess" + /> </div> </template> <script setup> -import { ref, reactive, onMounted } from "vue"; -import { ElMessage, ElMessageBox } from "element-plus"; -import { Plus, Delete, Download, List } from "@element-plus/icons-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"; -const childRef = ref(null); +import { getProductionMasterList, delPM } 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: "category", label: "鐓ょ", width: 150 }, - { prop: "unit", label: "鍗曚綅", width: 120 }, - { prop: "productionVolume", label: "鐢熶骇鏁伴噺", width: 150 }, - { prop: "laborCost", label: "浜哄伐鎴愭湰", width: 150 }, - { prop: "materialCost", label: "鍘熸枡鎴愭湰", width: 120 }, - { prop: "equipmentCost", label: "璁惧璐圭敤", width: 143 }, - { prop: "totalCost", label: "鎬绘垚鏈�", width: 150 }, - { prop: "totalPrice", label: "鎬诲敭浠�", width: 150 }, - { prop: "profit", label: "鍒╂鼎", width: 100 }, - { prop: "reviewer", label: "澶嶈浜�", width: 120 }, - { prop: "date", label: "鏃ユ湡", width: 150 }, + { 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 }, ]; -// 鎼滅储琛ㄥ崟鏁版嵁 -const searchForm = reactive({ - searchAll:"" -}); +// 浣跨敤琛ㄦ牸鏁版嵁缁勫悎寮忓嚱鏁� +const { + tableData, + loading, + total, + selectedRows, + queryParams, + getList, + handleSearch, + handleReset, + handlePageChange, + handleSelectionChange, + deleteSelected, +} = useTableData(getProductionMasterList, { pageSize: 10 }); -// 琛ㄦ牸鏁版嵁 -const tableData = ref([]); -const loading = ref(false); +// 浣跨敤瀵硅瘽妗嗙粍鍚堝紡鍑芥暟 +const { + dialogVisible, + dialogType, + dialogRef, + openDialog, + viewRow, + handleDialogSuccess: onDialogSuccess, +} = useDialog(); -// 鍒嗛〉鏁版嵁 -const pagination = reactive({ - currentPage: 1, - pageSize: 10, - total: 0, -}); +// 浣跨敤鐓ょ鏁版嵁缁勫悎寮忓嚱鏁� +const { getCoalNameById, getCoalData } = useCoalData(); -// 閫変腑鐨勮鏁版嵁 -const selectedRows = ref([]); +// 鑾峰彇鐓ょ鏄剧ず鍚嶇О锛堝甫澶囩敤閫昏緫锛� +const getDisplayCoalName = (coalId) => { + // 浼樺厛浣跨敤 useCoalData 鐨勬柟娉� + let name = getCoalNameById(coalId); -// 寮圭獥鐩稿叧 -const dialogVisible = ref(false); -const dialogType = ref("add"); -const currentRow = ref(null); + // 濡傛灉娌℃湁鎵惧埌锛屽皾璇曚粠 coalInfoList 涓煡鎵� + if (name === coalId && coalInfoList.value.length > 0) { + const found = coalInfoList.value.find((item) => item.id == coalId); + name = found ? found.coal : coalId; + } -// 鐢熶骇鏄庣粏瀵硅瘽妗嗘帶鍒� -const detailDialogVisible = ref(false); -const currentDetailRow = ref(null); + return name || coalId; +}; -// 鑾峰彇琛ㄦ牸鏁版嵁 -const getList = async () => { - loading.value = true; - try { - const params = { - ...searchForm, - pageNum: pagination.currentPage, - pageSize: pagination.pageSize, - }; - // const res = await getProductionList(params) - // 鍋囨暟鎹� - const res = { - data: { - list: [ - { - sequence: 1, - category: "鏃犵儫鐓�", - unit: "鍚�", - productionVolume: 100, - laborCost: "300", - materialCost: "200", - equipmentCost: "100", - totalCost: "600", - totalPrice: "800", - profit: "200", - reviewer: "寮犱笁", - date: "2023-10-01", - }, - { - sequence: 12, - category: "鏃犵儫鐓�", - unit: "鍚�", - productionVolume: 100, - laborCost: "3100", - materialCost: "2020", - equipmentCost: "1300", - totalCost: "6030", - totalPrice: "8300", - profit: "2300", - reviewer: "寮犱笁", - date: "2025-10-02", - }, - ], - total: 2, - }, - }; - - tableData.value = res.data.list; - pagination.total = res.data.total; - } catch (error) { - ElMessage.error("鑾峰彇鏁版嵁澶辫触"); - } finally { - loading.value = false; +// 澶勭悊鐢熶骇鏁版嵁鏇存柊 +const handleProductionAndProcessing = (row, rows) => { + const index = tableData.value.findIndex((item) => item.id === rows.id); + if (index !== -1) { + tableData.value[index] = { ...tableData.value[index], ...row }; } }; -// 澶勭悊琛ㄦ牸閫夋嫨鍙樺寲 -const handleSelectionChange = (selection) => { - selectedRows.value = selection; -}; - -// 鎼滅储鏂规硶 -const handleSearch = () => { - pagination.currentPage = 1; - getList(); -}; - -// 閲嶇疆鎼滅储 -const handleReset = () => { - searchForm.keyword = ""; - searchForm.addUser = ""; - handleSearch(); -}; - -// 鏂板鍔犲伐 -const handleAddBatch = () => { - dialogType.value = "add"; - dialogVisible.value = true; - childRef.value.Initialization(); -}; - -// 缂栬緫 -const handleEdit = (row) => { - currentRow.value = row; - dialogType.value = "edit"; - dialogVisible.value = true; -}; - -// 鎵撳紑鐢熶骇鏄庣粏瀵硅瘽妗� -const handleViewDetail = (row) => { - currentDetailRow.value = row; - detailDialogVisible.value = true; -}; - -// 澶勭悊寮圭獥鎻愪氦 -const handleDialogSuccess = async (formData) => { - try { - if (dialogType.value === "add") { - await addProduction(formData); - ElMessage.success("鏂板鎴愬姛"); - } else { - await updateProduction({ - ...formData, - id: currentRow.value.id, - }); - ElMessage.success("鏇存柊鎴愬姛"); - } +// 瀵硅瘽妗嗘垚鍔熷洖璋� +const handleDialogSuccess = () => { + onDialogSuccess(() => { getList(); - } catch (error) { - ElMessage.error(dialogType.value === "add" ? "鏂板澶辫触" : "鏇存柊澶辫触"); - } -}; - -// 澶勭悊鐢熶骇鏄庣粏寮圭獥鎻愪氦 -const handleDetailDialogSuccess = async (formData) => { - try { - ElMessage.success("淇濆瓨鎴愬姛"); - getList(); - } catch (error) { - ElMessage.error("淇濆瓨澶辫触"); - } -}; - -// 鍒犻櫎 -const handleDelete = (row) => { - ElMessageBox.confirm("纭鍒犻櫎璇ヨ褰曞悧锛�", "鎻愮ず", { - confirmButtonText: "纭畾", - cancelButtonText: "鍙栨秷", - type: "warning", - }) - .then(async () => { - try { - await deleteProduction(row.id); - ElMessage.success("鍒犻櫎鎴愬姛"); - getList(); - } catch (error) { - console.error("鍒犻櫎澶辫触:", error); - ElMessage.error("鍒犻櫎澶辫触"); - } - }) - .catch(() => { - ElMessage.info("宸插彇娑堝垹闄�"); - }); -}; - -// 瀵煎嚭 -const handleExport = async (row) => { - try { - const res = await exportProduction({ id: row.id }); - const blob = new Blob([res], { type: "application/vnd.ms-excel" }); - const fileName = `鐢熶骇鍔犲伐璁板綍_${new Date().getTime()}.xlsx`; - if ("download" in document.createElement("a")) { - const elink = document.createElement("a"); - elink.download = fileName; - elink.style.display = "none"; - elink.href = URL.createObjectURL(blob); - document.body.appendChild(elink); - elink.click(); - URL.revokeObjectURL(elink.href); - document.body.removeChild(elink); - } else { - navigator.msSaveBlob(blob, fileName); - } - } catch (error) { - ElMessage.error("瀵煎嚭澶辫触"); - } -}; - -// 澶勭悊姣忛〉鏄剧ず鏁伴噺鍙樺寲 -const handleSizeChange = (val) => { - pagination.pageSize = val; - getList(); -}; - -// 澶勭悊椤电爜鍙樺寲 -const handleCurrentChange = (val) => { - pagination.currentPage = val; - getList(); + ElMessage.success("鎿嶄綔鎴愬姛"); + }); }; // 缁勪欢鎸傝浇鏃跺姞杞芥暟鎹� -onMounted(() => { - getList(); +onMounted(async () => { + try { + // 骞惰鍔犺浇鐓ょ鏁版嵁鍜岃〃鏍兼暟鎹� + await Promise.all([ + getCoalData(), // 棰勫姞杞界叅绉嶆暟鎹� + (async () => { + const res = await getCoalInfoList(); + if (res.code === 200) { + coalInfoList.value = res.data; + } + })(), + ]); + + // 鍔犺浇琛ㄦ牸鏁版嵁 + getList(); + } catch (error) { + ElMessage.error("鏁版嵁鍔犺浇澶辫触锛岃鍒锋柊椤甸潰閲嶈瘯"); + } }); </script> @@ -277,9 +213,10 @@ width: 20%; } } -.search-form{ + +.search-form { display: flex; - justify-content: space-between; + justify-content: flex-start; align-items: center; margin-bottom: 20px; @@ -291,4 +228,25 @@ margin-left: 10px; } } + +.coal-tags { + display: flex; + flex-wrap: wrap; + gap: 4px; + 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