| | |
| | | getCoalInfoList, |
| | | deleteProductionInventory, |
| | | } from "@/api/production/index.js"; |
| | | import { getSupplyList } from "@/api/procureMent/index.js" |
| | | import {validateFormData, validateNumber, deepClone, createDefaultProductionRow} from "@/utils/production"; |
| | | import {useCoalData} from "./useCoalData"; |
| | | import useUserStore from "@/store/modules/user"; |
| | |
| | | const currentRow = ref(null); |
| | | const copyForm = ref(null); |
| | | const coalList = ref([]) |
| | | const supplierList = ref({}); |
| | | const supplierList = ref([]); |
| | | // 表格列配置 |
| | | const columns = [ |
| | | {prop: "coalId", label: "煤种", minwidth: 60,slot:false, |
| | | {prop: "coalId", label: "煤种", minwidth: 60, |
| | | formatter: (row) => { |
| | | return coalList.value.find(coal => coal.id === row.coalId)?.coal || "--"; |
| | | } |
| | |
| | | ]; |
| | | |
| | | const formalDatabaseColumns = ref([ |
| | | {prop: "supplierName", label: "供应商名称", minwidth: 150 |
| | | // ,formatter: (row) => { |
| | | // console.log(row); |
| | | // return supplierList.value[row.supplierId] || "--"; |
| | | // } |
| | | }, |
| | | {prop: "coalId", label: "煤种", minwidth: 60, |
| | | formatter: (row) => { |
| | | // return coalList.value[row.coalId].coal || "--"; |
| | | return coalList.value.find(coal => coal.id === row.coalId)?.coal || "--"; |
| | | } |
| | | }, |
| | |
| | | currentRow.value = row; |
| | | }; |
| | | |
| | | // 获取基础数据(煤种和供应商) |
| | | const loadBasicData = async () => { |
| | | try { |
| | | const [coalResponse, supplierResponse] = await Promise.all([ |
| | | getCoalInfoList(), |
| | | getSupplyList() |
| | | ]); |
| | | |
| | | coalList.value = coalResponse.data || []; |
| | | supplierList.value = supplierResponse.data || []; |
| | | } catch (error) { |
| | | ElMessage.error("获取基础数据失败"); |
| | | } |
| | | }; |
| | | |
| | | // 获取配置数据 |
| | | const handlData = async () => { |
| | | innerVisible.value = true; |
| | | let getSupplier = await getOfficialAll(); |
| | | let getCoalName = await getCoalInfoList(); |
| | | coalList.value = getCoalName.data || []; |
| | | supplierList.value = getSupplier.data || []; |
| | | if (getSupplier.code === 200) { |
| | | formalDatabaseData.value = getSupplier.data; |
| | | const existingOfficialIds = tableData.value |
| | | .map((item) => item.officialId) |
| | | .filter((id) => id); |
| | | selectedIds.value = existingOfficialIds; |
| | | debugIdMatching(); |
| | | nextTick(() => { |
| | | setTimeout(() => { |
| | | if (etableRef.value && existingOfficialIds.length > 0) { |
| | | etableRef.value.setDefaultSelection(); |
| | | } |
| | | }, 100); |
| | | }); |
| | | } else { |
| | | |
| | | // 确保基础数据已加载 |
| | | if (coalList.value.length === 0 || supplierList.value.length === 0) { |
| | | await loadBasicData(); |
| | | } |
| | | |
| | | try { |
| | | const OfficialAll = await getOfficialAll(); |
| | | |
| | | if (OfficialAll.code === 200) { |
| | | formalDatabaseData.value = OfficialAll.data; |
| | | const existingOfficialIds = tableData.value |
| | | .map((item) => item.officialId) |
| | | .filter((id) => id); |
| | | selectedIds.value = existingOfficialIds; |
| | | debugIdMatching(); |
| | | nextTick(() => { |
| | | setTimeout(() => { |
| | | if (etableRef.value && existingOfficialIds.length > 0) { |
| | | etableRef.value.setDefaultSelection(); |
| | | } |
| | | }, 100); |
| | | }); |
| | | } else { |
| | | ElMessage.error("获取配置数据失败"); |
| | | } |
| | | } catch (error) { |
| | | ElMessage.error("获取配置数据失败"); |
| | | } |
| | | }; |
| | |
| | | }; |
| | | |
| | | // 初始化和编辑初始化 |
| | | const Initialization = () => { |
| | | const Initialization = async () => { |
| | | tableData.value = []; |
| | | detailsTableData.value = []; |
| | | copyForm.value = null; |
| | | dialogType.value = "add"; |
| | | |
| | | // 加载基础数据 |
| | | await loadBasicData(); |
| | | }; |
| | | |
| | | const editInitialization = (type,data) => { |
| | | const editInitialization = async (type, data) => { |
| | | copyForm.value = deepClone(data); |
| | | tableData.value = data.productionInventoryList || []; |
| | | detailsTableData.value = data.productionList || []; |
| | |
| | | .map((item) => item.officialId) |
| | | .filter((id) => id); |
| | | selectedIds.value = existingOfficialIds; |
| | | |
| | | // 加载基础数据 |
| | | await loadBasicData(); |
| | | }; |
| | | // 监听对话框状态,在打开时设置选中状态 |
| | | watch(innerVisible, (newVal) => { |
| | |
| | | } |
| | | }; |
| | | |
| | | // 获取用户信息 |
| | | // 获取用户信息并加载基础数据 |
| | | onMounted(async () => { |
| | | try { |
| | | userInfo = await userStore.getInfo(); |
| | | await loadBasicData(); |
| | | } catch (error) { |
| | | ElMessage.error("获取用户信息失败,请重试"); |
| | | ElMessage.error("初始化失败,请重试"); |
| | | } |
| | | }); |
| | | |