From 00ef76a2e286e338fa3c648ce183e3533ce006ad Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期一, 09 六月 2025 17:48:23 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev --- src/views/basicInformation/index.vue | 1093 ++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 655 insertions(+), 438 deletions(-) diff --git a/src/views/basicInformation/index.vue b/src/views/basicInformation/index.vue index c77fc2d..9f5927e 100644 --- a/src/views/basicInformation/index.vue +++ b/src/views/basicInformation/index.vue @@ -1,576 +1,793 @@ <template> - <div class="app-container"> - <el-form :inline="true" :model="queryParams" class="search-form"> - <el-form-item label="鎼滅储"> - <el-input - v-model="queryParams.searchText" - placeholder="璇疯緭鍏ュ叧閿瘝" - clearable - /> - </el-form-item> - <el-form-item label="渚涘簲鍟嗗悕绉�"> - <el-input - v-model="queryParams.supplierName" - placeholder="璇疯緭鍏�" - clearable - /> - </el-form-item> - <el-form-item label="缁熶竴浜鸿瘑鍒彿"> - <el-input - v-model="queryParams.identifyNumber" - placeholder="璇疯緭鍏�" - clearable - /> - </el-form-item> - <el-form-item label="缁忚惀鍦板潃"> - <el-input - v-model="queryParams.address" - placeholder="璇疯緭鍏�" - clearable - /> - </el-form-item> - <el-form-item> - <el-button type="primary" @click="handleQuery">鏌ヨ</el-button> - <el-button @click="resetQuery">閲嶇疆</el-button> - </el-form-item> - </el-form> + <div> <el-form :inline="true" :model="queryParams" class="search-form"> + <el-form-item label="鎼滅储" v-if="shouldShowSearch"> + <el-input v-model="queryParams.searchAll" :placeholder="searchPlaceholder" clearable /> + </el-form-item> + <el-form-item> + <el-button type="primary" @click="search">鏌ヨ</el-button> + <el-button @click="resetQuery">閲嶇疆</el-button> + </el-form-item> + </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 type="primary" :icon="Plus" @click="handleAdd" - >鏂板缓</el-button - > + <el-button type="primary" :icon="Plus" @click="handleAdd">鏂板缓</el-button> <el-button type="danger" :icon="Delete" @click="handleDelete">鍒犻櫎</el-button> - <el-button type="info" :icon="Download" @click="handleExport">瀵煎嚭</el-button> - </el-row> - <!-- 琛ㄦ牸缁勪欢 --> + <el-button type="info" :icon="Download" @click="handleExport" v-show="canExport">瀵煎嚭</el-button> + </el-row> <!-- 琛ㄦ牸缁勪欢 --> <div> - <data-table - :loading="loading" - :table-data="tableData" - :columns="columns" - @selection-change="handleSelectionChange" - @edit="handleEdit" - @delete="handleDeleteSuccess" - :show-selection="true" - :border="true" - :maxHeight="440" - /> + <data-table :loading="loading" :table-data="tableData" :columns="columns" + @selection-change="handleSelectionChange" @edit="handleEdit" :show-selection="true" :border="true"> <!-- 瀛楁鍚嶇О鍒楃殑鑷畾涔夋彃妲� - 鏄剧ず涓烘爣绛� --> + <template v-if="tabName === 'coalQualityMaintenance'" #coalFields="{ row }"> + <template v-if="typeof row.coalFields === 'string' && row.coalFields.includes(',')"> + <el-tag v-for="(field, index) in row.coalFields.split(',')" :key="index" type="primary" size="small" + style="margin-right: 4px; margin-bottom: 2px;"> + {{ getFieldDisplayName(field.trim()) }} + </el-tag> + </template> + <template v-else> + <el-tag type="primary" size="small"> + {{ getFieldDisplayName(row.coalFields) || '--' }} + </el-tag> + </template> + </template> + </data-table> </div> - <pagination - v-if="total>0" - :page-num="pageNum" - :page-size="pageSize" - :total="total" - @pagination="handleQuery" - :layout="'total, prev, pager, next, jumper'" - /> - <Supplier - v-if="tabName === 'supplier'" - v-model:supplierDialogFormVisible="dialogFormVisible" - :form="form" - :title="title" - @submit="handleSubmit" - @beforeClose="handleBeforeClose" - @update:dialogFormVisible="handleDialogFormVisible" - :addOrEdit="addOrEdit" - /> - <Customer - v-if="tabName === 'customer'" - v-model:customerDialogFormVisible="dialogFormVisible" - :form="form" - :title="title" - @submit="handleSubmit" - :addOrEdit="addOrEdit" - @beforeClose="handleBeforeClose" - /> - <Coal - v-if="tabName === 'coal'" - v-model:coalDialogFormVisible="dialogFormVisible" - :form="form" - :title="title" - :addOrEdit="addOrEdit" - @submit="handleSubmit" - /> - <coalQualityMaintenance - v-if="tabName === 'coalQualityMaintenance'" - v-model:coalQualityMaintenanceDialogFormVisible="dialogFormVisible" - :form="form" - :title="title" - :addOrEdit="addOrEdit" - @submit="handleSubmit" - /> + <pagination v-if="total > 0" :page="pageNum" :limit="pageSizes" :total="total" @pagination="handPagination" + :layout="'total, prev, pager, next, jumper'" /> + <Supplier v-if="tabName === 'supplier'" v-model:copyForm="copyForm" + v-model:supplierDialogFormVisible="dialogFormVisible" :form="form" :title="title" @submit="handleSubmit" + @beforeClose="handleBeforeClose" @update:dialogFormVisible="handleDialogFormVisible" :addOrEdit="addOrEdit" /> + <Customer v-if="tabName === 'customer'" v-model:copyForm="copyForm" + v-model:customerDialogFormVisible="dialogFormVisible" :form="form" :title="title" @submit="handleSubmit" + :addOrEdit="addOrEdit" @beforeClose="handleBeforeClose" /> + <Coal v-if="tabName === 'coal'" v-model:copyForm="copyForm" v-model:coalDialogFormVisible="dialogFormVisible" + :form="form" :title="title" :addOrEdit="addOrEdit" @submit="handleSubmit" /> + <coalQualityMaintenance v-if="tabName === 'coalQualityMaintenance'" v-model:copyForm="copyForm" + v-model:coalQualityMaintenanceDialogFormVisible="dialogFormVisible" :form="form" :title="title" + :addOrEdit="addOrEdit" @submit="handleSubmit" /> + <coalMeiZhiZiDuanWeiHu v-if="tabName === 'coalMeiZhiZiDuanWeiHu'" v-model:copyForm="copyForm" + v-model:coalMaintenanceFieldDialogVisible="dialogFormVisible" :form="form" :title="title" :addOrEdit="addOrEdit" + @submit="handleSubmit" /> </el-card> </div> </template> <script setup> -import { ref, reactive, onMounted } from "vue"; +// ===== 鏍稿績渚濊禆瀵煎叆 ===== +import { ref, reactive, onMounted, computed, getCurrentInstance } from "vue"; import { ElMessage, ElMessageBox } from "element-plus"; import { Plus, Edit, Delete, Download } from "@element-plus/icons-vue"; + +// ===== 缁勪欢瀵煎叆 ===== import DataTable from "@/components/Table/ETable.vue"; import Pagination from "@/components/Pagination"; import Supplier from "./mould/supplier.vue"; import Customer from "./mould/customer.vue"; import Coal from "./mould/coal.vue"; import coalQualityMaintenance from "./mould/coalQualityMaintenance.vue"; -const { proxy } = getCurrentInstance() -// 寮圭獥 -const coalQualityMaintenanceDialogFormVisible = ref(false); -const customerDialogFormVisible = ref(false); -const coalDialogFormVisible = ref(false); -const supplierDialogFormVisible = ref(false); +import coalMeiZhiZiDuanWeiHu from "./mould/coalMeiZhiZiDuanWeiHu.vue"; + +// ===== API 鏈嶅姟瀵煎叆 ===== +import { getSupply, delSupply } from "@/api/basicInformation/supplier.js"; +import { getCoalInfo, delCoalInfo } from "@/api/basicInformation/coal.js"; +import { testUserList } from "@/api/tool/publicInterface.js"; +import { getAreaOptions } from "@/api/system/area.js"; +import { getCustomerList, delCustomer } from "@/api/basicInformation/customer.js"; +import { coalField, deleteCoalField } from "@/api/basicInformation/coalFieldMaintenance.js"; +import { getCoalFieldList, getCoalPlanList } from "@/api/basicInformation/coalQualityMaintenance"; + +const { proxy } = getCurrentInstance(); + +// ===== 鍝嶅簲寮忕姸鎬佺鐞� ===== + +// 寮圭獥鎺у埗鐘舵�� const dialogFormVisible = ref(false); const form = ref({}); const title = ref(""); const copyForm = ref({}); -// 褰撳墠鏍囩 +const addOrEdit = ref("add"); + +// 鏁版嵁缂撳瓨鏄犲皠 +const userList = ref([]); +const userMap = ref({}); // 鐢ㄦ埛ID -> 鐢ㄦ埛鍚嶆槧灏勮〃 +const addressMap = ref({}); // 鍦板潃ID -> 鍦板潃淇℃伅鏄犲皠琛� +const coalFieldList = ref([]); // 鐓よ川瀛楁鍒楄〃 + +// 椤甸潰鐘舵�佹帶鍒� const tabName = ref("supplier"); -// 鐘舵�佸彉閲� const loading = ref(false); -const total = ref(0); -const pageNum = ref(1); -const pageSize = ref(10); const activeTab = ref("supplier"); + +// 鍒嗛〉鐘舵�佺鐞� +const pageNum = ref(1); +const pageSizes = ref(10); +const total = ref(0); + +// 琛ㄦ牸鐘舵�佺鐞� const selectedRows = ref([]); -// 鏌ヨ鍙傛暟 -const queryParams = reactive({ - searchText: "", - supplierName: "", - identifyNumber: "", - address: "", -}); -onMounted(() => { - handleTabClick({ props: { name: "supplier" } }); -}); +const tableData = ref([]); const columns = ref(); -// 鏍囩椤垫暟鎹� + +// 鏌ヨ鍙傛暟 +const queryParams = reactive({}); + +// 鍦板潃閫夋嫨鏁版嵁 +const addressSelectOptions = ref([]); + +// ===== 閰嶇疆甯搁噺 ===== + +// 鏍囩椤甸厤缃� const tabs = reactive([ { name: "supplier", label: "渚涘簲鍟嗕俊鎭�" }, { name: "customer", label: "瀹㈡埛淇℃伅" }, { name: "coal", label: "鐓ょ淇℃伅" }, - { name: "coalQualityMaintenance", label: "鐓よ川缁存姢" }, + { name: "coalQualityMaintenance", label: "鐓よ川鏂规" }, + { name: "coalMeiZhiZiDuanWeiHu", label: "鐓よ川瀛楁" } ]); -// 鏄惁缂栬緫 -const addOrEdit = ref("add"); -// 琛ㄦ牸鏁版嵁 -const tableData = ref([]); -// 鏂规硶瀹氫箟 -const handleQuery = () => { - loading.value = true; - setTimeout(() => { - loading.value = false; - }, 500); + +// ===== 宸ュ叿鍑芥暟 ===== + +/** + * 鑾峰彇鍦板潃閫夋嫨鏁版嵁骞舵瀯寤烘槧灏勮〃 + * @description 寮傛鑾峰彇鍦板潃鏁版嵁锛屾瀯寤哄揩閫熸煡鎵剧殑鏄犲皠琛� + */ +const fetchAreaOptions = async () => { + try { + addressSelectOptions.value = []; + const res = await getAreaOptions(); + if (res.code === 200) { + addressSelectOptions.value = res.data; + buildAddressMap(res.data); + } + } catch (error) { + console.error('鑾峰彇鍦板潃閫夐」澶辫触:', error); + } }; -// supplier 渚涘簲鍟嗘暟鎹� + +/** + * 鏋勫缓鍦板潃鏄犲皠琛� + * @param {Array} areaData - 鍦板潃鏁版嵁 + * @description 閫掑綊鏋勫缓鍦板潃鏄犲皠琛紝鏀寔澶氱骇鍦板潃鏌ユ壘 + */ +const buildAddressMap = (areaData) => { + const buildMap = (list, pathList = []) => { + list.forEach(item => { + const currentPath = [...pathList, item.label]; + addressMap.value[item.id] = { + name: item.label, + fullPath: currentPath.join(' / ') + }; + if (item.children && item.children.length > 0) { + buildMap(item.children, currentPath); + } + }); + }; + buildMap(areaData); +}; + +/** + * 鏍煎紡鍖栧湴鍧�鏁扮粍涓烘樉绀哄瓧绗︿覆 + * @param {Array} addressIds - 鍦板潃ID鏁扮粍 + * @returns {string} 鏍煎紡鍖栧悗鐨勫湴鍧�瀛楃涓� + * @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 '--'; + } + + const addressNames = addressIds.map(id => addressMap.value[id]?.name || '--'); + + if (addressNames.every(name => name === '--')) { + return '--'; + } + + return addressNames.filter(name => name !== '--').join(' / '); +}; + +/** + * 鑾峰彇鐢ㄦ埛鍒楄〃鏁版嵁骞舵瀯寤烘槧灏勮〃 + * @description 鑾峰彇鐢ㄦ埛鏁版嵁骞舵瀯寤篒D鍒扮敤鎴峰悕鐨勬槧灏勫叧绯� + */ +const getUserList = async () => { + try { + const res = await testUserList(); + if (res && res.data) { + userList.value = res.data; + userList.value.forEach(user => { + userMap.value[user.userId] = user.username; + }); + } + } catch (error) { + console.error('鑾峰彇鐢ㄦ埛鍒楄〃澶辫触:', error); + } +}; + +/** + * 鑾峰彇鐓よ川瀛楁鏁版嵁 + * @description 鑾峰彇鐓よ川瀛楁鍒楄〃锛岀敤浜庡瓧娈靛悕绉板尮閰� + */ +const coalFieldData = async () => { + try { + const { data, code } = await getCoalFieldList(); + if (code === 200) { + coalFieldList.value = data; + } + } catch (error) { + console.error('鑾峰彇鐓よ川瀛楁鏁版嵁澶辫触:', error); + } +}; + +/** + * 鏍规嵁瀛楁ID鑾峰彇瀛楁鏄剧ず鍚嶇О + * @param {string|number} fieldId - 瀛楁ID + * @returns {string} 瀛楁鏄剧ず鍚嶇О + * @description 閫氳繃瀛楁ID鍖归厤瀵瑰簲鐨勫瓧娈靛悕绉� + */ +const getFieldDisplayName = (fieldId) => { + if (!fieldId) return '--'; + + const numId = parseInt(fieldId); + const matchedField = coalFieldList.value.find(item => item.id === numId); + + return matchedField ? matchedField.fieldName : numId; +}; + +// ===== 璁$畻灞炴�� ===== + +/** + * 褰撳墠鏍囩椤垫槸鍚︽敮鎸佸鍑哄姛鑳� + */ +const canExport = computed(() => { + return ['supplier', 'customer'].includes(tabName.value); +}); + +/** + * 鎼滅储妗嗗崰浣嶇鏂囨湰 + */ +const searchPlaceholder = computed(() => { + const placeholderMap = { + supplier: "渚涘簲鍟�/璇嗗埆鐮�/璇︾粏鍦板潃", + customer: "渚涘簲鍟�/璇嗗埆鐮�/璇︾粏鍦板潃", + coal: "璇疯緭鍏ユ悳绱俊鎭�", + coalQualityMaintenance: "璇疯緭鍏ユ悳绱俊鎭�", + coalMeiZhiZiDuanWeiHu: "璇疯緭鍏ユ悳绱俊鎭�" + }; + return placeholderMap[tabName.value] || "璇疯緭鍏ユ悳绱俊鎭�"; +}); + +/** + * 鏄惁鏄剧ず鎼滅储妗� + */ +const shouldShowSearch = computed(() => { + return ['supplier', 'customer', 'coal', 'coalQualityMaintenance','coalMeiZhiZiDuanWeiHu'].includes(tabName.value); +}); + +/** + * 褰撳墠閫変腑琛屾暟閲� + */ +const selectedCount = computed(() => selectedRows.value.length); + +/** + * 鏄惁鏈夐�変腑鐨勮 + */ +const hasSelectedRows = computed(() => selectedCount.value > 0); + +// ===== 琛ㄦ牸鍒楅厤缃� ===== + +/** + * 渚涘簲鍟嗚〃鏍煎垪閰嶇疆 + */ const supplierColumns = ref([ - { prop: "supplierName", label: "渚涘簲鍟嗗悕绉�", minWidth: 200 }, - { prop: "identifyNumber", label: "缁熶竴浜鸿瘑鍒彿", minWidth: 120 }, - { prop: "address", label: "缁忚惀鍦板潃", minWidth: 150 }, - { prop: "detailedaddress", label: "璇︾粏鍦板潃", minWidth: 150 }, - { prop: "bank", label: "寮�鎴疯", minWidth: 120 }, - { prop: "bankAccount", label: "閾惰璐﹀彿", minWidth: 150 }, - { prop: "contacts", label: "鑱旂郴浜�", minWidth: 100 }, - { prop: "contactAddress", label: "鑱旂郴鍦板潃", minWidth: 150 }, - { prop: "maintainer", label: "缁存姢浜�", minWidth: 100 }, - { prop: "maintainDate", label: "缁存姢鏃ユ湡", minWidth: 100 }, + { prop: "supplierName", label: "渚涘簲鍟嗗悕绉�", minWidth: 100 }, + { prop: "taxpayerId", label: "缁熶竴浜鸿瘑鍒彿", minWidth: 170 }, + { + prop: "bids", + label: "缁忚惀鍦板潃", + minWidth: 150, + showOverflowTooltip: true, + 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: "cids", + label: "鑱旂郴浜哄湴鍧�", + minWidth: 150, + showOverflowTooltip: true, + formatter: (row) => { + const addressIds = [row.cprovinceId, row.ccityId, row.cdistrictId]; + return formatAddressArray(addressIds); + } + }, + { prop: "contactAddress", label: "鑱旂郴浜鸿缁嗗湴鍧�", minWidth: 120 }, + { prop: "createTime", label: "缁存姢鏃ユ湡", minWidth: 120 }, ]); -// customer 瀹㈡埛鏁版嵁 + +/** + * 瀹㈡埛琛ㄦ牸鍒楅厤缃� + */ const customerColumns = ref([ - { prop: "customerName", label: "瀹㈡埛鍚嶇О", minWidth: 200 }, - { prop: "identifyNumber", label: "缁熶竴浜鸿瘑鍒彿", minWidth: 120 }, - { prop: "address", label: "缁忚惀鍦板潃", minWidth: 150 }, - { prop: "detailedaddress", label: "璇︾粏鍦板潃", minWidth: 150 }, - { prop: "bank", 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]; + return formatAddressArray(addressIds); + } + }, + { prop: "businessAddress", label: "璇︾粏鍦板潃", minWidth: 150 }, + { prop: "bankName", label: "寮�鎴疯", minWidth: 120 }, { prop: "bankAccount", label: "閾惰璐﹀彿", minWidth: 150 }, - { prop: "contacts", label: "鑱旂郴浜�", minWidth: 100 }, - { prop: "contactAddress", label: "鑱旂郴鍦板潃", minWidth: 150 }, - { prop: "maintainer", label: "缁存姢浜�", minWidth: 100 }, - { prop: "maintainDate", label: "缁存姢鏃ユ湡", minWidth: 100 }, + { prop: "contactPerson", label: "鑱旂郴浜�", minWidth: 100 }, + { prop: "contactPhone", label: "鑱旂郴浜虹數璇�", minWidth: 100 }, + { + prop: "cids", + label: "鑱旂郴浜哄湴鍧�", + minWidth: 150, + showOverflowTooltip: true, + formatter: (row) => { + const addressIds = [row.provinceId, row.cityId, row.districtId]; + return formatAddressArray(addressIds); + } + }, + { prop: "contactAddress", label: "鑱旂郴浜鸿缁嗗湴鍧�", minWidth: 150 }, + { prop: "updateTime", label: "缁存姢鏃ユ湡", minWidth: 100 }, ]); -// coal 鐓ょ鏁版嵁 + +/** + * 鐓ょ琛ㄦ牸鍒楅厤缃� + */ const coalColumns = ref([ - { prop: "coalName", label: "鐓ょ鍚嶇О", minWidth: 200 }, - { prop: "maintainer", label: "缁存姢浜�", minWidth: 120 }, + { prop: "coal", label: "鐓ょ鍚嶇О", minWidth: 200 }, + { + prop: "maintainerId", + label: "缁存姢浜�", + minWidth: 120, + formatter: (row, column, cellValue) => { + if (!userMap.value || Object.keys(userMap.value).length === 0) { + return '--'; + } + if (cellValue === null || cellValue === undefined || cellValue === '') { + return '--'; + } + return userMap.value[cellValue] || '--'; + } + }, { prop: "maintenanceDate", label: "缁存姢鏃ユ湡", minWidth: 150 }, ]); -// coalQualityMaintenance 鐓よ川缁存姢鏁版嵁 + +/** + * 鐓よ川鏂规琛ㄦ牸鍒楅厤缃� + */ const coalQualityMaintenanceColumns = ref([ - { prop: "supplierName", label: "鍏ㄦ按(<)", minWidth: 200 }, - { prop: "identifyNumber", label: "姘村垎鏋�(<)", minWidth: 120 }, - { prop: "address", label: "鐏板垎", minWidth: 150 }, - { prop: "bank", label: "鎸ュ彂(>)", minWidth: 100 }, - { prop: "bankAccount", label: "纭�(<)", minWidth: 100 }, - { prop: "contacts", label: "鍥哄畾纰�", minWidth: 100 }, - { prop: "contactAddress", label: "楂樹綅鍙戠儹閲�", minWidth: 100 }, - { prop: "maintainer", label: "浣庝綅鍙戠儹閲�", minWidth: 100 }, + { prop: "plan", label: "鏂规鍚嶇О", minWidth: 100 }, + { + prop: "coalFields", + label: "瀛楁鍚嶇О", + minWidth: 200, + showOverflowTooltip: true, + slot: true, + formatter: (row, column, cellValue) => { + if (Array.isArray(cellValue)) { + return cellValue.map(item => item); + } + return cellValue || '--'; + } + }, + { prop: "schemeDesc", label: "瀛楁鎻忚堪", minWidth: 100 }, ]); -// 鏍囩椤电偣鍑� + +/** + * 鐓よ川瀛楁琛ㄦ牸鍒楅厤缃� + */ +const coalMeiZhiZiDuanWeiHuColumns = ref([ + { prop: "fieldName", label: "瀛楁鍚嶇О", minWidth: 200 }, + { prop: "fieldDescription", label: "瀛楁鎻忚堪", minWidth: 200 }, +]); +// ===== 浜嬩欢澶勭悊鍑芥暟 ===== + +/** + * 鏍囩椤靛垏鎹簨浠跺鐞� + * @param {Object} tab - 鏍囩椤靛璞� + * @description 澶勭悊鏍囩椤靛垏鎹紝閲嶇疆琛ㄥ崟鍜岀姸鎬侊紝鍔犺浇瀵瑰簲鏁版嵁 + */ const handleTabClick = (tab) => { + // 閲嶇疆琛ㄥ崟鍜岀姸鎬� form.value = {}; - getList(); addOrEdit.value = "add"; loading.value = true; tabName.value = tab.props.name; tableData.value = []; - getList(); - switch (tabName.value) { - case "supplier": + + // 鏍规嵁鏍囩椤电被鍨嬭缃搴旂殑鍒楅厤缃� + const tabConfig = { + supplier: () => { columns.value = supplierColumns.value; - dialogFormVisible.value = supplierDialogFormVisible.value; - break; - case "customer": + getList(); + }, + customer: () => { columns.value = customerColumns.value; - dialogFormVisible.value = customerDialogFormVisible.value; - break; - case "coal": + getList(); + }, + coal: () => { columns.value = coalColumns.value; - dialogFormVisible.value = coalDialogFormVisible.value; - break; - case "coalQualityMaintenance": + getList(); + }, + coalQualityMaintenance: () => { columns.value = coalQualityMaintenanceColumns.value; - dialogFormVisible.value = coalQualityMaintenanceDialogFormVisible.value; - break; + getList(); + coalFieldData(); // 鍔犺浇鐓よ川瀛楁鏁版嵁 + }, + coalMeiZhiZiDuanWeiHu: () => { + columns.value = coalMeiZhiZiDuanWeiHuColumns.value; + getList(); + } + }; + + // 鎵ц瀵瑰簲鐨勯厤缃嚱鏁� + const configFn = tabConfig[tabName.value]; + if (configFn) { + configFn(); } - setTimeout(() => { - loading.value = false; - }, 500); }; -// 閲嶇疆鏌ヨ + +/** + * 閲嶇疆鏌ヨ鏉′欢 + * @description 閲嶇疆鏌ヨ鍙傛暟骞堕噸鏂板姞杞芥暟鎹� + */ const resetQuery = () => { Object.keys(queryParams).forEach((key) => { - if (key !== "pageNum" && key !== "pageSize") { + if (key !== "pageNum" && key !== "pageSizes") { queryParams[key] = ""; } }); - handleQuery(); + getList(); }; -// 鏂板 + +/** + * 鎼滅储鍔熻兘 + * @description 閲嶇疆椤电爜骞舵墽琛屾悳绱� + */ +const search = () => { + pageNum.value = 1; + getList(); +}; + +/** + * 鏂板鎸夐挳鐐瑰嚮澶勭悊 + */ const handleAdd = () => { addOrEdit.value = "add"; handleAddEdit(tabName.value); }; -// 鏂板缂栬緫 -const handleAddEdit = (tabName) => { - addOrEdit.value == "add" ? title.value = "鏂板" : title.value = "缂栬緫"; - if (tabName === "supplier") { - dialogFormVisible.value = true; - title.value = title.value + "渚涘簲鍟嗕俊鎭�"; - openDialog(); - } else if (tabName === "customer") { - dialogFormVisible.value = true; - title.value = title.value + "瀹㈡埛淇℃伅"; - openDialog(); - } else if (tabName === "coal") { - dialogFormVisible.value = true; - title.value = title.value + "鐓ょ淇℃伅"; - openDialog(); - } else if (tabName === "coalQualityMaintenance") { - dialogFormVisible.value = true; - title.value = title.value + "鐓よ川缁存姢"; - openDialog(); - } + +/** + * 鏂板/缂栬緫寮圭獥澶勭悊 + * @param {string} currentTabName - 褰撳墠鏍囩椤靛悕绉� + * @description 鏍规嵁鏍囩椤电被鍨嬭缃脊绐楁爣棰樺苟鎵撳紑寮圭獥 + */ +const handleAddEdit = (currentTabName) => { + const actionText = addOrEdit.value === "add" ? "鏂板" : "缂栬緫"; + + const tabTitleMap = { + supplier: "渚涘簲鍟嗕俊鎭�", + customer: "瀹㈡埛淇℃伅", + coal: "鐓ょ淇℃伅", + coalQualityMaintenance: "鐓よ川鏂规缁存姢", + coalMeiZhiZiDuanWeiHu: "鐓よ川瀛楁缁存姢" + }; + + title.value = `${actionText}${tabTitleMap[currentTabName] || ''}`; + openDialog(); }; -// 鎵撳紑寮圭獥 + +/** + * 鎵撳紑寮圭獥 + * @description 鏍规嵁缂栬緫鐘舵�佸喅瀹氭槸鍚﹀鍒惰〃鍗曟暟鎹� + */ const openDialog = () => { if (addOrEdit.value === "edit") { copyForm.value = JSON.parse(JSON.stringify(form.value)); - dialogFormVisible.value = true; - return; + } else { + form.value = {}; } - form.value = {}; dialogFormVisible.value = true; }; -// 鎻愪氦琛ㄥ崟 -const handleSubmit = () => { - // 鎷垮埌鎻愪氦鏁版嵁 - dialogFormVisible.value = false; - if (addOrEdit.value === "add") { - ElMessage.success("鏂板鎴愬姛锛�" + copyForm.value.supplierName); - } else { - ElMessage.success("缂栬緫鎴愬姛锛�" + copyForm.value.supplierName); - } + +/** + * 鍒嗛〉澶勭悊 + * @param {Object} val - 鍒嗛〉鍙傛暟瀵硅薄 + */ +const handPagination = (val) => { + pageNum.value = val.page; + pageSizes.value = val.limit; getList(); }; + +/** + * 琛ㄥ崟鎻愪氦澶勭悊 + * @param {Object} val - 鎻愪氦缁撴灉瀵硅薄 + */ +const handleSubmit = async (val) => { + if (val.result.code !== 200) { + ElMessage.error("鎿嶄綔澶辫触锛�" + val.result.msg); + return; + } + ElMessage.success(val.title + val.result.msg); + dialogFormVisible.value = false; + getList(); +}; + +/** + * 寮圭獥鏄剧ず鐘舵�佸鐞� + * @param {boolean} value - 鏄剧ず鐘舵�� + */ const handleDialogFormVisible = (value) => { dialogFormVisible.value = value; }; -// 閫夋嫨琛� + +/** + * 琛ㄦ牸琛岄�夋嫨澶勭悊 + * @param {Array} selection - 閫変腑鐨勮鏁版嵁 + */ const handleSelectionChange = (selection) => { selectedRows.value = selection; }; -// 缂栬緫 +/** + * 缂栬緫鎸夐挳鐐瑰嚮澶勭悊 + * @param {Object} row - 琛屾暟鎹� + * @description 澶勭悊缂栬緫鎿嶄綔锛屾瀯寤哄湴鍧�鏁扮粍骞舵墦寮�缂栬緫寮圭獥 + */ const handleEdit = (row) => { - form.value = JSON.parse(JSON.stringify(row)); - addOrEdit.value = "edit"; - handleAddEdit(tabName.value); + 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 = "edit"; + handleAddEdit(tabName.value); }; -// 鎵归噺鍒犻櫎 -const handleDelete = () => { + +/** + * 鎵归噺鍒犻櫎澶勭悊 + * @description 鎵归噺鍒犻櫎閫変腑鐨勮褰� + */ +const handleDelete = async () => { if (selectedRows.value.length === 0) { ElMessage.warning("璇烽�夋嫨瑕佸垹闄ょ殑鏁版嵁"); return; } - ElMessageBox.confirm("纭畾鍒犻櫎閫変腑鐨勬暟鎹悧锛�", "鎻愮ず", { - confirmButtonText: "纭畾", - cancelButtonText: "鍙栨秷", - type: "warning", - }) - .then(() => { - ElMessage.success("鍒犻櫎鎴愬姛锛屽叡鍒犻櫎" + selectedRows.value.length + "鏉℃暟鎹�"); - selectedRows.value.forEach((row) => { - tableData.value = tableData.value.filter( - (item) => item !== row - ); - }); - total.value = tableData.value.length; - // 娓呯┖閫変腑琛� - selectedRows.value = []; - }).catch(() => { - ElMessage.info("宸插彇娑堝垹闄ゆ搷浣�"); - }); -} -// 琛ㄦ牸鍒犻櫎 -const handleDeleteSuccess = (row) => { - ElMessage.success("鍒犻櫎鎴愬姛锛�" + row.supplierName); + + const deleteIds = selectedRows.value.map(item => item.id); + + try { + await ElMessageBox.confirm("纭畾鍒犻櫎閫変腑鐨勬暟鎹悧锛�", "鎻愮ず", { + confirmButtonText: "纭畾", + cancelButtonText: "鍙栨秷", + type: "warning", + }); + + const deleteApiMap = { + supplier: delSupply, + coal: delCoalInfo, + coalQualityMaintenance: () => { throw new Error('delCoalQuality API not imported'); }, + customer: delCustomer, + coalMeiZhiZiDuanWeiHu: deleteCoalField + }; + + const deleteApi = deleteApiMap[tabName.value]; + if (!deleteApi) { + ElMessage.error("鍒犻櫎鎺ュ彛鏈厤缃�"); + return; + } + + 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 handleBeforeClose = () => { dialogFormVisible.value = false; form.value = {}; }; -const handleExport = (row) => { - proxy.download("system/post/export", { - ...queryParams.value - }, `post_${new Date().getTime()}.xlsx`) - ElMessage.success("瀵煎嚭鏁版嵁锛�" + row.supplierName); -}; -const getList = () => { - loading.value = true; - setTimeout(() => { - // 鏆傛椂寮曞叆娴嬭瘯鏁版嵁 - tableData.value = [ - { - supplierName: "涓浗鍐堕噾绉戝伐鑲′唤鏈夐檺鍏徃", - identifyNumber: "123412123123123111", - address: "灞辫タ鐪�", - bank: "浜ら�氶摱琛�", - bankAccount: "901234567890123456", - contacts: "鏉庨洩鑺�", - contactAddress: "XX鐪乆X甯俋X鍖篨X璺�", - maintainer: "鏉庨洩鑺�", - maintainDate: "2022-09-26", - contactsPhone: "19345678901", - }, - { - supplierName: "涓浗鍐堕噾绉戝伐鑲′唤鏈夐檺鍏徃", - identifyNumber: "123412123123123111", - address: "灞辫タ鐪�", - bank: "浜ら�氶摱琛�", - bankAccount: "901234567890123456", - contacts: "鏉庨洩鑺�", - contactAddress: "XX鐪乆X甯俋X鍖篨X璺�", - maintainer: "鏉庨洩鑺�", - maintainDate: "2022-09-26", - contactsPhone: "19345678901", - }, - { - supplierName: "涓浗鍐堕噾绉戝伐鑲′唤鏈夐檺鍏徃", - identifyNumber: "123412123123123111", - address: "灞辫タ鐪�", - bank: "浜ら�氶摱琛�", - bankAccount: "901234567890123456", - contacts: "鏉庨洩鑺�", - contactAddress: "XX鐪乆X甯俋X鍖篨X璺�", - maintainer: "鏉庨洩鑺�", - maintainDate: "2022-09-26", - contactsPhone: "19345678901", - }, - { - supplierName: "浜ら�氶摱琛岃偂浠芥湁闄愬叕鍙�", - identifyNumber: "042-26881314", - address: "姹熻タ鐪�", - bank: "骞冲畨閾惰", - bankAccount: "123456789012345678", - contacts: "鍛ㄧ櫧鐜�", - contactAddress: "XX鐪乆X甯俋X鍖篨X璺�", - maintainer: "鍛ㄧ櫧鐜�", - maintainDate: "2022-08-29", - }, - { - supplierName: "涓浗鍐堕噾绉戝伐鑲′唤鏈夐檺鍏徃", - identifyNumber: "019-65851198", - address: "灞辫タ鐪�", - bank: "浜ら�氶摱琛�", - bankAccount: "901234567890123456", - contacts: "鏉庨洩鑺�", - contactAddress: "XX鐪乆X甯俋X鍖篨X璺�", - maintainer: "鏉庨洩鑺�", - maintainDate: "2022-09-26", - }, - { - supplierName: "浜ら�氶摱琛岃偂浠芥湁闄愬叕鍙�", - identifyNumber: "042-26881314", - address: "姹熻タ鐪�", - bank: "骞冲畨閾惰", - bankAccount: "123456789012345678", - contacts: "鍛ㄧ櫧鐜�", - contactAddress: "XX鐪乆X甯俋X鍖篨X璺�", - maintainer: "鍛ㄧ櫧鐜�", - maintainDate: "2022-08-29", - }, - { - supplierName: "涓浗鍐堕噾绉戝伐鑲′唤鏈夐檺鍏徃", - identifyNumber: "019-65851198", - address: "灞辫タ鐪�", - bank: "浜ら�氶摱琛�", - bankAccount: "901234567890123456", - contacts: "鏉庨洩鑺�", - contactAddress: "XX鐪乆X甯俋X鍖篨X璺�", - maintainer: "鏉庨洩鑺�", - maintainDate: "2022-09-26", - }, - { - supplierName: "浜ら�氶摱琛岃偂浠芥湁闄愬叕鍙�", - identifyNumber: "042-26881314", - address: "姹熻タ鐪�", - bank: "骞冲畨閾惰", - bankAccount: "123456789012345678", - contacts: "鍛ㄧ櫧鐜�", - contactAddress: "XX鐪乆X甯俋X鍖篨X璺�", - maintainer: "鍛ㄧ櫧鐜�", - maintainDate: "2022-08-29", - }, - { - supplierName: "涓浗鍐堕噾绉戝伐鑲′唤鏈夐檺鍏徃", - identifyNumber: "019-65851198", - address: "灞辫タ鐪�", - bank: "浜ら�氶摱琛�", - bankAccount: "901234567890123456", - contacts: "鏉庨洩鑺�", - contactAddress: "XX鐪乆X甯俋X鍖篨X璺�", - maintainer: "鏉庨洩鑺�", - maintainDate: "2022-09-26", - }, - { - supplierName: "浜ら�氶摱琛岃偂浠芥湁闄愬叕鍙�", - identifyNumber: "042-26881314", - address: "姹熻タ鐪�", - bank: "骞冲畨閾惰", - bankAccount: "123456789012345678", - contacts: "鍛ㄧ櫧鐜�", - contactAddress: "XX鐪乆X甯俋X鍖篨X璺�", - maintainer: "鍛ㄧ櫧鐜�", - maintainDate: "2022-08-29", - }, - { - supplierName: "涓浗鍐堕噾绉戝伐鑲′唤鏈夐檺鍏徃", - identifyNumber: "019-65851198", - address: "灞辫タ鐪�", - bank: "浜ら�氶摱琛�", - bankAccount: "901234567890123456", - contacts: "鏉庨洩鑺�", - contactAddress: "XX鐪乆X甯俋X鍖篨X璺�", - maintainer: "鏉庨洩鑺�", - maintainDate: "2022-09-26", - }, - { - supplierName: "浜ら�氶摱琛岃偂浠芥湁闄愬叕鍙�", - identifyNumber: "042-26881314", - address: "姹熻タ鐪�", - bank: "骞冲畨閾惰", - bankAccount: "123456789012345678", - contacts: "鍛ㄧ櫧鐜�", - contactAddress: "XX鐪乆X甯俋X鍖篨X璺�", - maintainer: "鍛ㄧ櫧鐜�", - maintainDate: "2022-08-29", - }, - ]; - total.value = tableData.value.length; - loading.value = false; - }, 500); +/** + * 瀵煎嚭鍔熻兘澶勭悊 + */ +const handleExport = () => { + const exportConfig = { + 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]; + if (config) { + exportData(config.api, config.name); + } }; -getList(); + +/** + * 瀵煎嚭鏁版嵁 + * @param {string} api - 瀵煎嚭鎺ュ彛璺緞 + * @param {string} name - 瀵煎嚭鏂囦欢鍚嶅墠缂� + */ +const exportData = (api, name) => { + proxy.download(api, { ...queryParams }, `${name}${new Date().getTime()}.xlsx`); + ElMessage.success("瀵煎嚭鏁版嵁锛�" + name); +}; +// ===== 鏁版嵁鑾峰彇鍑芥暟 ===== + +/** + * 鏍规嵁褰撳墠鏍囩椤甸�夋嫨瀵瑰簲鐨凙PI鎺ュ彛 + * @returns {Promise} API璋冪敤Promise + * @description 缁熶竴鐨勬帴鍙i�夋嫨鍑芥暟锛屾牴鎹爣绛鹃〉绫诲瀷璋冪敤瀵瑰簲鐨凙PI + */ +const selectInterface = () => { + const apiParams = { + current: pageNum.value, + pageSize: pageSizes.value, + searchAll: queryParams.searchAll, + }; + + const apiMap = { + supplier: () => getSupply(apiParams), + customer: () => getCustomerList(apiParams), + coal: () => getCoalInfo(apiParams), + coalQualityMaintenance: () => getCoalPlanList(apiParams), + coalMeiZhiZiDuanWeiHu: () => coalField(apiParams) + }; + + const apiFunction = apiMap[tabName.value]; + return apiFunction ? apiFunction() : Promise.reject(new Error('鏈壘鍒板搴旂殑API鎺ュ彛')); +}; + +/** + * 鑾峰彇鍒楄〃鏁版嵁 + * @description 缁熶竴鐨勬暟鎹幏鍙栧嚱鏁帮紝澶勭悊鍔犺浇鐘舵�佸拰閿欒澶勭悊 + */ +const getList = async () => { + try { + loading.value = true; + const { data, code } = await selectInterface(); + + if (code !== 200) { + ElMessage.error("鑾峰彇鏁版嵁澶辫触锛�" + (data?.msg || '鏈煡閿欒')); + return; + } + + tableData.value = data.records || []; + total.value = data.total || 0; + } catch (error) { + console.error('鑾峰彇鍒楄〃鏁版嵁澶辫触:', error); + ElMessage.error("鑾峰彇鏁版嵁澶辫触锛岃绋嶅悗鍐嶈瘯"); + } finally { + loading.value = false; + } +}; + +// ===== 鐢熷懡鍛ㄦ湡閽╁瓙 ===== + +/** + * 缁勪欢鎸傝浇鍚庣殑鍒濆鍖栨搷浣� + */ +onMounted(async () => { + try { + // 骞惰鎵ц鍒濆鍖栨搷浣� + await Promise.all([ + handleTabClick({ props: { name: "supplier" } }), + fetchAreaOptions(), + getUserList() + ]); + } catch (error) { + console.error('缁勪欢鍒濆鍖栧け璐�:', error); + ElMessage.error("椤甸潰鍒濆鍖栧け璐ワ紝璇峰埛鏂伴噸璇�"); + } +}); </script> <style scoped> -.app-container { - padding: 20px; - background-color: #f5f7fa; - box-sizing: border-box; - min-height: calc(100vh - 84px); -} -.search-form { - background: #fff; - padding: 20px 20px 0 20px; - margin-bottom: 20px; - border-radius: 4px; - box-shadow: var(--el-box-shadow-light); -} -.el-form-item__label{ - padding: 0 5px 0 0 !important; - font-weight: 500; -} -.search-form :deep(.el-form-item) { - margin-bottom: 16px; - width: 100%; -} - /* 鍝嶅簲寮忓竷灞� */ @media screen and (min-width: 768px) { .search-form :deep(.el-form-item) { width: 50%; } } + @media screen and (min-width: 1200px) { .search-form :deep(.el-form-item) { width: 16%; } } -.info-tabs { - margin-bottom: 20px; -} + .table-toolbar { margin-bottom: 20px; display: flex; flex-wrap: wrap; gap: 10px; } + /* 鍝嶅簲寮忚〃鏍� */ @media screen and (max-width: 768px) { .table-toolbar { flex-direction: column; } + .table-toolbar .el-button { width: 100%; } } + /* 琛ㄦ牸宸ュ叿鏍� */ -.table-toolbar, .table-toolbar > * { +.table-toolbar, +.table-toolbar>* { margin: 0 0 0 0 !important; } -.table-toolbar{ + +.table-toolbar { margin-bottom: 20px !important; } + .el-form--inline .el-form-item { margin-right: 25px; } -.main-container{ + +.main-container { background: red !important; } </style> \ No newline at end of file -- Gitblit v1.9.3