| | |
| | | v-model="formState.bomId" |
| | | placeholder="请选择BOM" |
| | | clearable |
| | | :disabled="formState.selectedProducts.length !== 1 || bomOptions.length === 0" |
| | | :disabled="bomOptions.length === 0" |
| | | style="width: 100%" |
| | | > |
| | | <el-option |
| | |
| | | } |
| | | }; |
| | | |
| | | 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) => { |
| | | if (!products?.length) { |
| | | return; |
| | |
| | | formState.value.productModelId = undefined; |
| | | formState.value.productName = ""; |
| | | formState.value.productModelName = ""; |
| | | bomOptions.value = []; |
| | | await loadBomOptionsByProducts(products); |
| | | } |
| | | |
| | | showProductSelectDialog.value = false; |
| | |
| | | productModelName: formState.value.selectedProducts.length === 1 |
| | | ? formState.value.selectedProducts[0].model |
| | | : undefined, |
| | | bomId: formState.value.selectedProducts.length === 1 ? formState.value.bomId : undefined, |
| | | bomId: formState.value.bomId, |
| | | description: formState.value.description, |
| | | }) |
| | | .then(() => { |