| | |
| | | <script setup> |
| | | import { computed, getCurrentInstance, ref } from "vue"; |
| | | import { add } from "@/api/productionManagement/processRoute.js"; |
| | | import { getByModel } from "@/api/productionManagement/productBom.js"; |
| | | import { getByModelList } from "@/api/productionManagement/productBom.js"; |
| | | import ProductSelectDialog from "@/views/basicData/product/ProductSelectDialog.vue"; |
| | | |
| | | const props = defineProps({ |
| | |
| | | isShow.value = false; |
| | | }; |
| | | |
| | | const loadBomList = async (productModelId) => { |
| | | if (!productModelId) { |
| | | const loadBomList = async (productModelIds) => { |
| | | if (!productModelIds?.length) { |
| | | bomOptions.value = []; |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | const res = await getByModel(productModelId); |
| | | const res = await getByModelList(productModelIds); |
| | | if (Array.isArray(res)) { |
| | | bomOptions.value = res; |
| | | return; |
| | |
| | | } catch (error) { |
| | | bomOptions.value = []; |
| | | } |
| | | }; |
| | | |
| | | const loadBomOptionsByProducts = async (products) => { |
| | | if (!products?.length) { |
| | | bomOptions.value = []; |
| | | return; |
| | | } |
| | | |
| | | const bomGroups = await Promise.all( |
| | | products.map(async (product) => { |
| | | try { |
| | | const res = await getByModel(product.id); |
| | | if (Array.isArray(res)) { |
| | | return res; |
| | | } |
| | | if (res && res.data) { |
| | | return Array.isArray(res.data) ? res.data : [res.data]; |
| | | } |
| | | return res && typeof res === "object" ? [res] : []; |
| | | } catch (error) { |
| | | return []; |
| | | } |
| | | }) |
| | | ); |
| | | |
| | | const bomMap = new Map(); |
| | | bomGroups.flat().forEach((item) => { |
| | | if (item?.id && !bomMap.has(item.id)) { |
| | | bomMap.set(item.id, item); |
| | | } |
| | | }); |
| | | bomOptions.value = Array.from(bomMap.values()); |
| | | }; |
| | | |
| | | const handleProductSelect = async (products) => { |
| | |
| | | formState.value.productModelId = product.id; |
| | | formState.value.productName = product.productName; |
| | | formState.value.productModelName = product.model; |
| | | await loadBomList(product.id); |
| | | await loadBomList([product.id]); |
| | | } else { |
| | | formState.value.productId = undefined; |
| | | formState.value.productModelId = undefined; |
| | | formState.value.productName = ""; |
| | | formState.value.productModelName = ""; |
| | | await loadBomOptionsByProducts(products); |
| | | await loadBomList(products.map((product) => product.id)); |
| | | } |
| | | |
| | | showProductSelectDialog.value = false; |