From 1c4e88c1cb0639663f77a33dbab26c3cac71ad93 Mon Sep 17 00:00:00 2001 From: zhang_12370 <z2864490065@outlook.com> Date: 星期四, 26 六月 2025 13:28:05 +0800 Subject: [PATCH] 开发通用 删除 优化文档管理模块 --- src/views/basicInformation/index.vue | 503 ++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 313 insertions(+), 190 deletions(-) diff --git a/src/views/basicInformation/index.vue b/src/views/basicInformation/index.vue index b41cf57..907d60d 100644 --- a/src/views/basicInformation/index.vue +++ b/src/views/basicInformation/index.vue @@ -2,7 +2,11 @@ <div class="app-container"> <el-form :inline="true" :model="queryParams" class="search-form"> <el-form-item v-if="shouldShowSearch" label="鎼滅储"> - <el-input v-model="queryParams.searchAll" :placeholder="searchPlaceholder" clearable/> + <el-input + v-model="queryParams.searchAll" + :placeholder="searchPlaceholder" + clearable + /> </el-form-item> <el-form-item> <el-button type="primary" @click="search">鏌ヨ</el-button> @@ -11,63 +15,149 @@ </el-form> <el-card> <!-- 鏍囩椤� --> - <el-tabs v-model="activeTab" class="info-tabs" @tab-click="handleTabClick"> - <el-tab-pane v-for="tab in tabs" :key="tab.name" :label="tab.label" :name="tab.name"/> + <el-tabs + v-model="activeTab" + class="info-tabs" + @tab-click="handleTabClick" + > + <el-tab-pane + v-for="tab in tabs" + :key="tab.name" + :label="tab.label" + :name="tab.name" + /> </el-tabs> <!-- 鎿嶄綔鎸夐挳鍖� --> <el-row :gutter="24" class="table-toolbar"> - <el-button :icon="Plus" type="primary" @click="handleAdd">鏂板缓</el-button> - <el-button :icon="Delete" type="danger" @click="handleDelete">鍒犻櫎</el-button> - <el-button @click="jump">admins</el-button> - <el-button v-show="canExport" :icon="Download" type="info" @click="handleExport">瀵煎嚭</el-button> - </el-row> <!-- 琛ㄦ牸缁勪欢 --> + <el-button :icon="Plus" type="primary" @click="handleAdd" + >鏂板缓</el-button + > + <el-button :icon="Delete" type="danger" @click="handleDelete" + >鍒犻櫎</el-button + > + <el-button + v-show="canExport" + :icon="Download" + type="info" + @click="handleExport" + >瀵煎嚭</el-button + > + </el-row> + <!-- 琛ㄦ牸缁勪欢 --> <div> - <data-table :border="true" :columns="columns" :loading="loading" style="width: 100%;height: calc(100vh - 29em)" - :show-selection="true" :table-data="tableData" @edit="handleEdit" @selection-change="handleSelectionChange"> + <data-table + :border="true" + :columns="columns" + :loading="loading" + style="width: 100%; height: calc(100vh - 29em)" + :show-selection="true" + :table-data="tableData" + @edit="handleEdit" + @viewRow="handleView" + @selection-change="handleSelectionChange" + :operations="['edit', 'viewRow']" + :operationsWidth="200" + > <!-- 瀛楁鍚嶇О鍒楃殑鑷畾涔夋彃妲� - 鏄剧ず涓烘爣绛� --> - <template v-if="tabName === 'coalQualityMaintenance'" #fieldIds="{ row }"> - <template v-if="typeof row.fieldIds === 'string' && row.fieldIds.includes(',')"> - <el-tag v-for="(field, index) in row.fieldIds.split(',')" :key="index" size="small" style="margin-right: 4px; margin-bottom: 2px;" - type="primary"> + <template + v-if="tabName === 'coalQualityMaintenance'" + #fieldIds="{ row }" + > + <template + v-if=" + typeof row.fieldIds === 'string' && row.fieldIds.includes(',') + " + > + <el-tag + v-for="(field, index) in row.fieldIds.split(',')" + :key="index" + size="small" + style="margin-right: 4px; margin-bottom: 2px" + type="primary" + > {{ getFieldDisplayName(field.trim()) }} </el-tag> </template> <template v-else> <el-tag size="small" type="primary"> - {{ getFieldDisplayName(row.fieldIds) || '--' }} + {{ getFieldDisplayName(row.fieldIds) || "--" }} </el-tag> </template> </template> </data-table> </div> - <pagination v-if="total > 0" :layout="'total, prev, pager, next, jumper'" :limit="pageSizes" :page="pageNum" :total="total" - @pagination="handPagination"/> - <Supplier v-if="tabName === 'supplier'" v-model:copyForm="copyForm" - v-model:supplierDialogFormVisible="dialogFormVisible" :addOrEdit="addOrEdit" :form="form" :title="title" - @beforeClose="handleBeforeClose" @submit="handleSubmit" - @update:dialogFormVisible="handleDialogFormVisible"/> - <Customer v-if="tabName === 'customer'" v-model:copyForm="copyForm" - v-model:customerDialogFormVisible="dialogFormVisible" :addOrEdit="addOrEdit" :form="form" :title="title" - @beforeClose="handleBeforeClose" @submit="handleSubmit"/> - <Coal v-if="tabName === 'coal'" v-model:coalDialogFormVisible="dialogFormVisible" v-model:copyForm="copyForm" - :addOrEdit="addOrEdit" :form="form" :title="title" @submit="handleSubmit"/> - <coalQualityMaintenance v-if="tabName === 'coalQualityMaintenance'" v-model:coalQualityMaintenanceDialogFormVisible="dialogFormVisible" - v-model:copyForm="copyForm" :addOrEdit="addOrEdit" - :form="form" - :title="title" @submit="handleSubmit"/> - <coalMeiZhiZiDuanWeiHu v-if="tabName === 'coalMeiZhiZiDuanWeiHu'" v-model:coalMaintenanceFieldDialogVisible="dialogFormVisible" - v-model:copyForm="copyForm" :addOrEdit="addOrEdit" :form="form" - :title="title" - @submit="handleSubmit"/> + <pagination + v-if="total > 0" + :layout="'total, prev, pager, next, jumper'" + :limit="pageSizes" + :page="pageNum" + :total="total" + @pagination="handPagination" + /> + <Supplier + v-if="tabName === 'supplier'" + v-model:copyForm="copyForm" + v-model:supplierDialogFormVisible="dialogFormVisible" + :addOrEdit="addOrEdit" + :form="form" + :title="title" + @beforeClose="handleBeforeClose" + @submit="handleSubmit" + @update:dialogFormVisible="handleDialogFormVisible" + /> + <Customer + v-if="tabName === 'customer'" + v-model:copyForm="copyForm" + v-model:customerDialogFormVisible="dialogFormVisible" + :addOrEdit="addOrEdit" + :form="form" + :title="title" + @beforeClose="handleBeforeClose" + @submit="handleSubmit" + /> + <Coal + v-if="tabName === 'coal'" + v-model:coalDialogFormVisible="dialogFormVisible" + v-model:copyForm="copyForm" + :addOrEdit="addOrEdit" + :form="form" + :title="title" + @submit="handleSubmit" + /> + <coalQualityMaintenance + v-if="tabName === 'coalQualityMaintenance'" + v-model:coalQualityMaintenanceDialogFormVisible="dialogFormVisible" + v-model:copyForm="copyForm" + :addOrEdit="addOrEdit" + :form="form" + :title="title" + @submit="handleSubmit" + /> + <coalMeiZhiZiDuanWeiHu + v-if="tabName === 'coalMeiZhiZiDuanWeiHu'" + v-model:coalMaintenanceFieldDialogVisible="dialogFormVisible" + v-model:copyForm="copyForm" + :addOrEdit="addOrEdit" + :form="form" + :title="title" + @submit="handleSubmit" + /> </el-card> </div> </template> <script setup> -import {computed, getCurrentInstance, onMounted, reactive, ref, nextTick} from "vue"; -import {ElMessage, ElMessageBox} from "element-plus"; -import {Delete, Download, Plus} from "@element-plus/icons-vue"; +import { + computed, + getCurrentInstance, + onMounted, + reactive, + ref, + nextTick, +} from "vue"; +import { ElMessage, ElMessageBox } from "element-plus"; +import { Delete, Download, Plus } from "@element-plus/icons-vue"; // ===== 缁勪欢瀵煎叆 ===== import DataTable from "@/components/Table/ETable.vue"; @@ -79,21 +169,27 @@ import coalMeiZhiZiDuanWeiHu from "./mould/coalMeiZhiZiDuanWeiHu.vue"; // ===== API 鏈嶅姟瀵煎叆 ===== -import {delSupply, getSupply} from "@/api/basicInformation/supplier.js"; -import {delCoalInfo, getCoalInfo} from "@/api/basicInformation/coal.js"; -import {testUserList} from "@/api/tool/publicInterface.js"; -import {getAreaOptions} from "@/api/system/area.js"; -import {delCustomer, getCustomerList} from "@/api/basicInformation/customer.js"; -import {coalField, deleteCoalField} from "@/api/basicInformation/coalFieldMaintenance.js"; -import {getCoalFieldList, getCoalPlanList} from "@/api/basicInformation/coalQualityMaintenance"; - -const {proxy} = getCurrentInstance(); -import router from "@/router"; +import { delSupply, getSupply } from "@/api/basicInformation/supplier.js"; +import { delCoalInfo, getCoalInfo } from "@/api/basicInformation/coal.js"; +import { testUserList } from "@/api/tool/publicInterface.js"; +import { getAreaOptions } from "@/api/system/area.js"; +import { + delCustomer, + getCustomerList, +} from "@/api/basicInformation/customer.js"; +import { + coalField, + deleteCoalField, +} from "@/api/basicInformation/coalFieldMaintenance.js"; +import { + getCoalFieldList, + getCoalPlanList, + delCoalPlan, +} from "@/api/basicInformation/coalQualityMaintenance"; +import { useDelete } from "@/hooks/useDelete.js"; +const { proxy } = getCurrentInstance(); // ===== 鍝嶅簲寮忕姸鎬佺鐞� ===== -const jump = () => { -}; -// 寮圭獥鎺у埗鐘舵�� const dialogFormVisible = ref(false); const form = ref({}); const title = ref(""); @@ -131,11 +227,11 @@ // 鏍囩椤甸厤缃� const tabs = reactive([ - {name: "supplier", label: "渚涘簲鍟嗕俊鎭�"}, - {name: "customer", label: "瀹㈡埛淇℃伅"}, - {name: "coal", label: "鐓ょ淇℃伅"}, - {name: "coalQualityMaintenance", label: "鐓よ川鏂规"}, - {name: "coalMeiZhiZiDuanWeiHu", label: "鐓よ川瀛楁"} + { name: "supplier", label: "渚涘簲鍟嗕俊鎭�" }, + { name: "customer", label: "瀹㈡埛淇℃伅" }, + { name: "coal", label: "鐓ょ淇℃伅" }, + { name: "coalQualityMaintenance", label: "鐓よ川鏂规" }, + { name: "coalMeiZhiZiDuanWeiHu", label: "鐓よ川瀛楁" }, ]); // ===== 宸ュ叿鍑芥暟 ===== @@ -153,7 +249,7 @@ buildAddressMap(res.data); } } catch (error) { - console.error('鑾峰彇鍦板潃閫夐」澶辫触:', error); + console.error("鑾峰彇鍦板潃閫夐」澶辫触:", error); } }; @@ -164,11 +260,11 @@ */ const buildAddressMap = (areaData) => { const buildMap = (list, pathList = []) => { - list.forEach(item => { + list.forEach((item) => { const currentPath = [...pathList, item.label]; addressMap.value[item.id] = { name: item.label, - fullPath: currentPath.join(' / ') + fullPath: currentPath.join(" / "), }; if (item.children && item.children.length > 0) { buildMap(item.children, currentPath); @@ -185,19 +281,26 @@ * @description 灏嗗湴鍧�ID鏁扮粍杞崲涓哄彲璇荤殑鍦板潃瀛楃涓� */ const formatAddressArray = (addressIds) => { - if (!addressMap.value || Object.keys(addressMap.value).length === 0 || - !addressIds || !Array.isArray(addressIds) || addressIds.length === 0 || - addressIds.every(id => !id)) { - return '--'; + if ( + !addressMap.value || + Object.keys(addressMap.value).length === 0 || + !addressIds || + !Array.isArray(addressIds) || + addressIds.length === 0 || + addressIds.every((id) => !id) + ) { + return "--"; } - const addressNames = addressIds.map(id => addressMap.value[id]?.name || '--'); + const addressNames = addressIds.map( + (id) => addressMap.value[id]?.name || "--" + ); - if (addressNames.every(name => name === '--')) { - return '--'; + if (addressNames.every((name) => name === "--")) { + return "--"; } - return addressNames.filter(name => name !== '--').join(' / '); + return addressNames.filter((name) => name !== "--").join(" / "); }; /** @@ -209,12 +312,12 @@ const res = await testUserList(); if (res && res.data) { userList.value = res.data; - userList.value.forEach(user => { + userList.value.forEach((user) => { userMap.value[user.userId] = user.username; }); } } catch (error) { - console.error('鑾峰彇鐢ㄦ埛鍒楄〃澶辫触:', error); + console.error("鑾峰彇鐢ㄦ埛鍒楄〃澶辫触:", error); } }; @@ -224,12 +327,12 @@ */ const coalFieldData = async () => { try { - const {data, code} = await getCoalFieldList(); + const { data, code } = await getCoalFieldList(); if (code === 200) { coalFieldList.value = data; } } catch (error) { - console.error('鑾峰彇鐓よ川瀛楁鏁版嵁澶辫触:', error); + console.error("鑾峰彇鐓よ川瀛楁鏁版嵁澶辫触:", error); } }; @@ -240,21 +343,19 @@ * @description 閫氳繃瀛楁ID鍖归厤瀵瑰簲鐨勫瓧娈靛悕绉� */ const getFieldDisplayName = (fieldId) => { - if (!fieldId) return '--'; + if (!fieldId) return "--"; const numId = parseInt(fieldId); - const matchedField = coalFieldList.value.find(item => item.id === numId); + const matchedField = coalFieldList.value.find((item) => item.id === numId); return matchedField ? matchedField.fieldName : numId; }; - -// ===== 璁$畻灞炴�� ===== /** * 褰撳墠鏍囩椤垫槸鍚︽敮鎸佸鍑哄姛鑳� */ const canExport = computed(() => { - return ['supplier', 'customer'].includes(tabName.value); + return ["supplier", "customer"].includes(tabName.value); }); /** @@ -262,11 +363,11 @@ */ const searchPlaceholder = computed(() => { const placeholderMap = { - supplier: "渚涘簲鍟�/璇嗗埆鐮�/璇︾粏鍦板潃", - customer: "渚涘簲鍟�/璇嗗埆鐮�/璇︾粏鍦板潃", - coal: "璇疯緭鍏ユ悳绱俊鎭�", - coalQualityMaintenance: "璇疯緭鍏ユ悳绱俊鎭�", - coalMeiZhiZiDuanWeiHu: "璇疯緭鍏ユ悳绱俊鎭�" + supplier: "渚涘簲鍟�/缁熶竴璇嗗埆鐮�/璇︾粏鍦板潃", + customer: "渚涘簲鍟�/缁熶竴璇嗗埆鐮�/璇︾粏鍦板潃", + coal: "璇疯緭鍏ョ叅绉嶄俊鎭�", + coalQualityMaintenance: "璇疯緭鍏ョ叅璐ㄦ柟妗堜俊鎭�", + coalMeiZhiZiDuanWeiHu: "璇疯緭鍏ョ叅璐ㄥ瓧娈典俊鎭�", }; return placeholderMap[tabName.value] || "璇疯緭鍏ユ悳绱俊鎭�"; }); @@ -275,7 +376,13 @@ * 鏄惁鏄剧ず鎼滅储妗� */ const shouldShowSearch = computed(() => { - return ['supplier', 'customer', 'coal', 'coalQualityMaintenance', 'coalMeiZhiZiDuanWeiHu'].includes(tabName.value); + return [ + "supplier", + "customer", + "coal", + "coalQualityMaintenance", + "coalMeiZhiZiDuanWeiHu", + ].includes(tabName.value); }); /** @@ -283,19 +390,14 @@ */ const selectedCount = computed(() => selectedRows.value.length); -/** - * 鏄惁鏈夐�変腑鐨勮 - */ -const hasSelectedRows = computed(() => selectedCount.value > 0); - // ===== 琛ㄦ牸鍒楅厤缃� ===== /** * 渚涘簲鍟嗚〃鏍煎垪閰嶇疆 */ const supplierColumns = ref([ - {prop: "supplierName", label: "渚涘簲鍟嗗悕绉�", minWidth: 100}, - {prop: "taxpayerId", label: "缁熶竴浜鸿瘑鍒彿", minWidth: 170}, + { prop: "supplierName", label: "渚涘簲鍟嗗悕绉�", minWidth: 100 }, + { prop: "taxpayerId", label: "缁熶竴浜鸿瘑鍒彿", minWidth: 170 }, { prop: "bids", label: "缁忚惀鍦板潃", @@ -304,12 +406,11 @@ formatter: (row) => { const addressIds = [row.bprovinceId, row.bcityId, row.bdistrictId]; return formatAddressArray(addressIds); - } + }, }, - {prop: "businessAddress", label: "缁忚惀璇︾粏鍦板潃", minWidth: 150}, - {prop: "bankAccount", label: "寮�鎴疯", minWidth: 120}, - {prop: "bankName", label: "閾惰璐﹀彿", minWidth: 150}, - {prop: "contactPerson", label: "鑱旂郴浜�", minWidth: 100}, + { prop: "businessAddress", label: "缁忚惀璇︾粏鍦板潃", minWidth: 150 }, + { prop: "bankAccount", label: "寮�鎴疯", minWidth: 120 }, + { prop: "contactPerson", label: "鑱旂郴浜�", minWidth: 100 }, { prop: "cids", label: "鑱旂郴浜哄湴鍧�", @@ -318,33 +419,36 @@ formatter: (row) => { const addressIds = [row.cprovinceId, row.ccityId, row.cdistrictId]; return formatAddressArray(addressIds); - } + }, }, - {prop: "contactAddress", label: "鑱旂郴浜鸿缁嗗湴鍧�", minWidth: 120}, - {prop: "updateTime", label: "缁存姢鏃ユ湡", minWidth: 120}, + { prop: "contactAddress", label: "鑱旂郴浜鸿缁嗗湴鍧�", minWidth: 120 }, ]); /** * 瀹㈡埛琛ㄦ牸鍒楅厤缃� */ const customerColumns = ref([ - {prop: "customerName", label: "瀹㈡埛鍚嶇О", minWidth: 100}, - {prop: "taxpayerId", label: "缁熶竴浜鸿瘑鍒彿", minWidth: 120}, + { prop: "customerName", label: "瀹㈡埛鍚嶇О", minWidth: 100 }, + { prop: "taxpayerId", label: "缁熶竴浜鸿瘑鍒彿", minWidth: 120 }, { prop: "bids", label: "缁忚惀鍦板潃", minWidth: 150, showOverflowTooltip: true, formatter: (row) => { - const addressIds = [row.businessProvinceId, row.businessCityId, row.businessDistrictId]; + const addressIds = [ + row.businessProvinceId, + row.businessCityId, + row.businessDistrictId, + ]; return formatAddressArray(addressIds); - } + }, }, - {prop: "businessAddress", label: "璇︾粏鍦板潃", minWidth: 150}, - {prop: "bankName", label: "寮�鎴疯", minWidth: 120}, - {prop: "bankAccount", label: "閾惰璐﹀彿", minWidth: 150}, - {prop: "contactPerson", label: "鑱旂郴浜�", minWidth: 100}, - {prop: "contactPhone", label: "鑱旂郴浜虹數璇�", minWidth: 100}, + { prop: "businessAddress", label: "璇︾粏鍦板潃", minWidth: 150 }, + { prop: "bankName", label: "寮�鎴疯", minWidth: 120 }, + { prop: "bankAccount", label: "閾惰璐﹀彿", minWidth: 150 }, + { prop: "contactPerson", label: "鑱旂郴浜�", minWidth: 100 }, + { prop: "contactPhone", label: "鑱旂郴浜虹數璇�", minWidth: 100 }, { prop: "cids", label: "鑱旂郴浜哄湴鍧�", @@ -353,39 +457,39 @@ formatter: (row) => { const addressIds = [row.provinceId, row.cityId, row.districtId]; return formatAddressArray(addressIds); - } + }, }, - {prop: "contactAddress", label: "鑱旂郴浜鸿缁嗗湴鍧�", minWidth: 150}, - {prop: "updateTime", label: "缁存姢鏃ユ湡", minWidth: 100}, + { prop: "contactAddress", label: "鑱旂郴浜鸿缁嗗湴鍧�", minWidth: 150 }, + { prop: "updateTime", label: "缁存姢鏃ユ湡", minWidth: 100 }, ]); /** * 鐓ょ琛ㄦ牸鍒楅厤缃� */ const coalColumns = ref([ - {prop: "coal", label: "鐓ょ鍚嶇О", minWidth: 200}, + { prop: "coal", label: "鐓ょ鍚嶇О", minWidth: 200 }, { prop: "maintainerId", label: "缁存姢浜�", minWidth: 120, formatter: (row, column, cellValue) => { if (!userMap.value || Object.keys(userMap.value).length === 0) { - return '--'; + return "--"; } - if (cellValue === null || cellValue === undefined || cellValue === '') { - return '--'; + if (cellValue === null || cellValue === undefined || cellValue === "") { + return "--"; } - return userMap.value[cellValue] || '--'; - } + return userMap.value[cellValue] || "--"; + }, }, - {prop: "maintenanceDate", label: "缁存姢鏃ユ湡", minWidth: 150}, + { prop: "maintenanceDate", label: "缁存姢鏃ユ湡", minWidth: 150 }, ]); /** * 鐓よ川鏂规琛ㄦ牸鍒楅厤缃� */ const coalQualityMaintenanceColumns = ref([ - {prop: "plan", label: "鏂规鍚嶇О", minWidth: 100}, + { prop: "plan", label: "鏂规鍚嶇О", minWidth: 100 }, { prop: "fieldIds", label: "瀛楁鍚嶇О", @@ -394,20 +498,20 @@ slot: true, formatter: (row, column, cellValue) => { if (Array.isArray(cellValue)) { - return cellValue.map(item => item); + return cellValue.map((item) => item); } - return cellValue || '--'; - } + return cellValue || "--"; + }, }, - {prop: "schemeDesc", label: "瀛楁鎻忚堪", minWidth: 100}, + { prop: "schemeDesc", label: "瀛楁鎻忚堪", minWidth: 100 }, ]); /** * 鐓よ川瀛楁琛ㄦ牸鍒楅厤缃� */ const coalMeiZhiZiDuanWeiHuColumns = ref([ - {prop: "fieldName", label: "瀛楁鍚嶇О", minWidth: 200}, - {prop: "fieldDescription", label: "瀛楁鎻忚堪", minWidth: 200}, + { prop: "fieldName", label: "瀛楁鍚嶇О", minWidth: 200 }, + { prop: "fieldDescription", label: "瀛楁鎻忚堪", minWidth: 200 }, ]); // ===== 浜嬩欢澶勭悊鍑芥暟 ===== @@ -449,7 +553,7 @@ coalMeiZhiZiDuanWeiHu: () => { columns.value = coalMeiZhiZiDuanWeiHuColumns.value; getList(); - } + }, }; // 鎵ц瀵瑰簲鐨勯厤缃嚱鏁� @@ -495,17 +599,22 @@ * @description 鏍规嵁鏍囩椤电被鍨嬭缃脊绐楁爣棰樺苟鎵撳紑寮圭獥 */ const handleAddEdit = (currentTabName) => { - const actionText = addOrEdit.value === "add" ? "鏂板" : "缂栬緫"; + const actionText = + addOrEdit.value === "add" + ? "鏂板" + : addOrEdit.value === "edit" + ? "缂栬緫" + : "鏌ョ湅"; const tabTitleMap = { supplier: "渚涘簲鍟嗕俊鎭�", customer: "瀹㈡埛淇℃伅", coal: "鐓ょ淇℃伅", coalQualityMaintenance: "鐓よ川鏂规缁存姢", - coalMeiZhiZiDuanWeiHu: "鐓よ川瀛楁缁存姢" + coalMeiZhiZiDuanWeiHu: "鐓よ川瀛楁缁存姢", }; - title.value = `${actionText}${tabTitleMap[currentTabName] || ''}`; + title.value = `${actionText}${tabTitleMap[currentTabName] || ""}`; openDialog(); }; @@ -514,7 +623,7 @@ * @description 鏍规嵁缂栬緫鐘舵�佸喅瀹氭槸鍚﹀鍒惰〃鍗曟暟鎹� */ const openDialog = () => { - if (addOrEdit.value === "edit") { + if (addOrEdit.value === "edit" || addOrEdit.value === "viewRow") { copyForm.value = JSON.parse(JSON.stringify(form.value)); } else { form.value = {}; @@ -580,8 +689,16 @@ } // 鏋勫缓瀹㈡埛涓氬姟鍦板潃鏁扮粍 - if (form.value.businessCityId && form.value.businessDistrictId && form.value.businessProvinceId) { - form.value.bids = [row.businessProvinceId, row.businessCityId, row.businessDistrictId]; + if ( + form.value.businessCityId && + form.value.businessDistrictId && + form.value.businessProvinceId + ) { + form.value.bids = [ + row.businessProvinceId, + row.businessCityId, + row.businessDistrictId, + ]; } // 鏋勫缓瀹㈡埛鑱旂郴鍦板潃鏁扮粍 @@ -593,61 +710,27 @@ handleAddEdit(tabName.value); }; + /** * 鎵归噺鍒犻櫎澶勭悊 * @description 鎵归噺鍒犻櫎閫変腑鐨勮褰� */ -const handleDelete = async () => { - if (selectedRows.value.length === 0) { - ElMessage.warning("璇烽�夋嫨瑕佸垹闄ょ殑鏁版嵁"); - return; - } - - const deleteIds = selectedRows.value.map(item => item.id); - - try { - await ElMessageBox.confirm("纭畾鍒犻櫎閫変腑鐨勬暟鎹悧锛�", "鎻愮ず", { - confirmButtonText: "纭畾", - cancelButtonText: "鍙栨秷", - type: "warning", - }); - - const deleteApiMap = { + const deleteApiMap = { supplier: delSupply, coal: delCoalInfo, - coalQualityMaintenance: () => { - throw new Error('delCoalQuality API not imported'); - }, + coalQualityMaintenance: delCoalPlan, customer: delCustomer, - coalMeiZhiZiDuanWeiHu: deleteCoalField + coalMeiZhiZiDuanWeiHu: deleteCoalField, }; - - const deleteApi = deleteApiMap[tabName.value]; - if (!deleteApi) { - ElMessage.error("鍒犻櫎鎺ュ彛鏈厤缃�"); - return; - } - console.log(deleteIds) - const res = await deleteApi(deleteIds); - - if (res.code !== 200 && res.msg !== "鎿嶄綔鎴愬姛") { - ElMessage.error("鍒犻櫎澶辫触锛�" + res.msg); - return; - } - - ElMessage.success("鍒犻櫎鎴愬姛"); - await getList(); - } catch (error) { - if (error.message !== 'cancel') { - console.error('鍒犻櫎鎿嶄綔澶辫触:', error); - ElMessage.error("鍒犻櫎澶辫触锛岃绋嶅悗鍐嶈瘯"); - } else { - ElMessage.info("宸插彇娑堝垹闄ゆ搷浣�"); - } - } finally { - selectedRows.value = []; - } -}; +const {handleDeleteBatch :handleDelete} = useDelete({ + deleteApi: () => deleteApiMap[tabName.value], + selectedRows: selectedRows, + getList: () => getList, + tableData: tableData, + total: total, + confirmText: "纭鍒犻櫎閫変腑鐨勬暟鎹悧锛�", + successText: "鍒犻櫎鎴愬姛", +}) /** * 鍏抽棴寮圭獥澶勭悊 @@ -662,10 +745,10 @@ */ const handleExport = () => { const exportConfig = { - supplier: {api: "/supply/export", name: "渚涘簲鍟嗕俊鎭�"}, - customer: {api: "/customer/export", name: "瀹㈡埛淇℃伅"}, - coal: {api: "/supply/export", name: "鐓ょ淇℃伅"}, - coalQualityMaintenance: {api: "/supply/export", name: "鐓よ川缁存姢淇℃伅"} + supplier: { api: "/supply/export", name: "渚涘簲鍟嗕俊鎭�" }, + customer: { api: "/customer/export", name: "瀹㈡埛淇℃伅" }, + coal: { api: "/supply/export", name: "鐓ょ淇℃伅" }, + coalQualityMaintenance: { api: "/supply/export", name: "鐓よ川缁存姢淇℃伅" }, }; const config = exportConfig[tabName.value]; @@ -680,7 +763,11 @@ * @param {string} name - 瀵煎嚭鏂囦欢鍚嶅墠缂� */ const exportData = (api, name) => { - proxy.download(api, {...queryParams}, `${name}${new Date().getTime()}.xlsx`); + proxy.download( + api, + { ...queryParams }, + `${name}${new Date().getTime()}.xlsx` + ); ElMessage.success("瀵煎嚭鏁版嵁锛�" + name); }; // ===== 鏁版嵁鑾峰彇鍑芥暟 ===== @@ -702,11 +789,13 @@ customer: () => getCustomerList(apiParams), coal: () => getCoalInfo(apiParams), coalQualityMaintenance: () => getCoalPlanList(apiParams), - coalMeiZhiZiDuanWeiHu: () => coalField(apiParams) + coalMeiZhiZiDuanWeiHu: () => coalField(apiParams), }; const apiFunction = apiMap[tabName.value]; - return apiFunction ? apiFunction() : Promise.reject(new Error('鏈壘鍒板搴旂殑API鎺ュ彛')); + return apiFunction + ? apiFunction() + : Promise.reject(new Error("鏈壘鍒板搴旂殑API鎺ュ彛")); }; /** @@ -716,22 +805,56 @@ const getList = async () => { try { loading.value = true; - const {data, code} = await selectInterface(); + const { data, code } = await selectInterface(); if (code !== 200) { - ElMessage.error("鑾峰彇鏁版嵁澶辫触锛�" + (data?.msg || '鏈煡閿欒')); + ElMessage.error("鑾峰彇鏁版嵁澶辫触锛�" + (data?.msg || "鏈煡閿欒")); return; } tableData.value = data.records || []; total.value = data.total || 0; } catch (error) { - console.error('鑾峰彇鍒楄〃鏁版嵁澶辫触:', error); + console.error("鑾峰彇鍒楄〃鏁版嵁澶辫触:", error); ElMessage.error("鑾峰彇鏁版嵁澶辫触锛岃绋嶅悗鍐嶈瘯"); } finally { loading.value = false; } }; + +const handleView = (row) => { + form.value = JSON.parse(JSON.stringify(row)); + // 鏋勫缓渚涘簲鍟嗕笟鍔″湴鍧�鏁扮粍 + if (form.value.bprovinceId && form.value.bdistrictId && form.value.bcityId) { + form.value.bids = [row.bprovinceId, row.bcityId, row.bdistrictId]; + } + + // 鏋勫缓渚涘簲鍟嗚仈绯诲湴鍧�鏁扮粍 + if (form.value.cprovinceId && form.value.cdistrictId && form.value.ccityId) { + form.value.cids = [row.cprovinceId, row.ccityId, row.cdistrictId]; + } + + // 鏋勫缓瀹㈡埛涓氬姟鍦板潃鏁扮粍 + if ( + form.value.businessCityId && + form.value.businessDistrictId && + form.value.businessProvinceId + ) { + form.value.bids = [ + row.businessProvinceId, + row.businessCityId, + row.businessDistrictId, + ]; + } + + // 鏋勫缓瀹㈡埛鑱旂郴鍦板潃鏁扮粍 + if (form.value.cityId && form.value.districtId && form.value.provinceId) { + form.value.cids = [row.provinceId, row.cityId, row.districtId]; + } + addOrEdit.value = "viewRow"; + handleAddEdit(tabName.value); +}; + // ===== 鐢熷懡鍛ㄦ湡閽╁瓙 ===== @@ -742,12 +865,12 @@ try { // 骞惰鎵ц鍒濆鍖栨搷浣� await Promise.all([ - handleTabClick({props: {name: "supplier"}}), + handleTabClick({ props: { name: "supplier" } }), fetchAreaOptions(), - getUserList() + getUserList(), ]); } catch (error) { - console.error('缁勪欢鍒濆鍖栧け璐�:', error); + console.error("缁勪欢鍒濆鍖栧け璐�:", error); ElMessage.error("椤甸潰鍒濆鍖栧け璐ワ紝璇峰埛鏂伴噸璇�"); } }); @@ -802,4 +925,4 @@ .main-container { background: red !important; } -</style> \ No newline at end of file +</style> -- Gitblit v1.9.3