| | |
| | | <el-dialog |
| | | v-model="visible" |
| | | title="领料" |
| | | width="1000px" |
| | | width="1400px" |
| | | top="3vh" |
| | | :close-on-click-modal="false" |
| | | destroy-on-close |
| | |
| | | <el-table-column prop="productName" label="产品名称" min-width="150" /> |
| | | <el-table-column prop="model" label="型号" min-width="150" /> |
| | | <el-table-column prop="unit" label="单位" width="80" align="center" /> |
| | | <!-- <el-table-column prop="qualitity" label="可领用数量" width="100" align="center"> |
| | | <template #default="{ row }"> |
| | | {{ row.qualitity || 0 }} |
| | | </template> |
| | | </el-table-column> --> |
| | | <el-table-column prop="customer" label="供应商" min-width="160" show-overflow-tooltip /> |
| | | <el-table-column prop="batchNo" label="批号" min-width="180" show-overflow-tooltip /> |
| | | <el-table-column prop="requisitionQty" label="领用数量" width="120" align="center"> |
| | | <template #default="{ row }"> |
| | | <el-input-number |
| | |
| | | <el-dialog |
| | | v-model="addDialogVisible" |
| | | title="选择原材料" |
| | | width="800px" |
| | | width="1000px" |
| | | top="5vh" |
| | | :close-on-click-modal="false" |
| | | append-to-body |
| | | > |
| | | <div class="material-filter" style="margin-bottom: 20px;"> |
| | | <el-select |
| | | v-model="filterSupplier" |
| | | placeholder="供应商" |
| | | clearable |
| | | filterable |
| | | style="width: 220px" |
| | | > |
| | | <el-option |
| | | v-for="opt in supplierFilterOptions" |
| | | :key="opt" |
| | | :label="opt" |
| | | :value="opt" |
| | | /> |
| | | </el-select> |
| | | <el-select |
| | | v-model="filterBatchNo" |
| | | placeholder="批号" |
| | | clearable |
| | | filterable |
| | | style="width: 220px; margin-left: 12px" |
| | | > |
| | | <el-option |
| | | v-for="opt in batchFilterOptions" |
| | | :key="opt" |
| | | :label="opt" |
| | | :value="opt" |
| | | /> |
| | | </el-select> |
| | | </div> |
| | | <el-table |
| | | :data="availableMaterials" |
| | | :data="filteredMaterials" |
| | | border |
| | | style="width: 100%" |
| | | height="50vh" |
| | |
| | | <el-table-column prop="productName" label="产品名称" min-width="150" /> |
| | | <el-table-column prop="model" label="型号" min-width="150" /> |
| | | <el-table-column prop="unit" label="单位" width="80" align="center" /> |
| | | <el-table-column prop="customer" label="供应商" min-width="160" show-overflow-tooltip /> |
| | | <el-table-column prop="batchNo" label="批号" min-width="180" show-overflow-tooltip /> |
| | | <!-- <el-table-column prop="qualitity" label="可领用数量" width="100" align="center"> |
| | | <template #default="{ row }"> |
| | | {{ row.qualitity || 0 }} |
| | |
| | | const availableMaterials = ref([]); |
| | | const selectedMaterials = ref([]); |
| | | |
| | | // 选择弹窗筛选条件(供应商/批号) |
| | | const filterSupplier = ref(''); |
| | | const filterBatchNo = ref(''); |
| | | |
| | | // 将后端可能返回的字段做一下归一化:供应商/批号字段名可能不一致 |
| | | const normalizeMaterial = (m) => { |
| | | return { |
| | | ...m, |
| | | customer: m.customer ?? m.supplierName ?? '', |
| | | batchNo: m.batchNo ?? m.batchNumber ?? m.batch_number ?? m.lotNo ?? '', |
| | | }; |
| | | }; |
| | | |
| | | const supplierFilterOptions = computed(() => { |
| | | return Array.from(new Set(availableMaterials.value.map((m) => m.customer).filter(Boolean))); |
| | | }); |
| | | |
| | | const batchFilterOptions = computed(() => { |
| | | const list = filterSupplier.value |
| | | ? availableMaterials.value.filter((m) => m.customer === filterSupplier.value) |
| | | : availableMaterials.value; |
| | | return Array.from(new Set(list.map((m) => m.batchNo).filter(Boolean))); |
| | | }); |
| | | |
| | | const filteredMaterials = computed(() => { |
| | | return availableMaterials.value.filter((m) => { |
| | | if (filterSupplier.value && m.customer !== filterSupplier.value) return false; |
| | | if (filterBatchNo.value && m.batchNo !== filterBatchNo.value) return false; |
| | | return true; |
| | | }); |
| | | }); |
| | | |
| | | watch(filterSupplier, () => { |
| | | // 如果当前“批号”不属于所选供应商,则清空 |
| | | if (filterBatchNo.value && !batchFilterOptions.value.includes(filterBatchNo.value)) { |
| | | filterBatchNo.value = ''; |
| | | } |
| | | }); |
| | | |
| | | // 监听弹框打开,加载数据 |
| | | watch(() => props.modelValue, (val) => { |
| | | if (val && props.orderData) { |
| | |
| | | if (bomId) { |
| | | try { |
| | | const res = await getMaterials({ bomId }); |
| | | materialsFromApi = res.data || []; |
| | | materialsFromApi = (res.data || []).map(normalizeMaterial); |
| | | } catch (error) { |
| | | console.error('查询原材料列表失败:', error); |
| | | } |
| | |
| | | return { |
| | | ...savedItem, |
| | | qualitity: apiItem?.qualitity ?? savedItem.qualitity ?? 0, |
| | | requisitionQty: savedItem.requisitionQty || 0 |
| | | requisitionQty: savedItem.requisitionQty || 0, |
| | | customer: savedItem.customer ?? savedItem.supplierName ?? apiItem?.customer ?? '', |
| | | batchNo: savedItem.batchNo ?? savedItem.batchNumber ?? apiItem?.batchNo ?? '', |
| | | }; |
| | | }); |
| | | } catch (e) { |
| | |
| | | const res = await getMaterials({ bomId }); |
| | | console.log('getMaterials返回数据:', res.data); |
| | | // 直接展示所有数据,不过滤 |
| | | availableMaterials.value = res.data || []; |
| | | availableMaterials.value = (res.data || []).map(normalizeMaterial); |
| | | filterSupplier.value = ''; |
| | | filterBatchNo.value = ''; |
| | | selectedMaterials.value = []; |
| | | addDialogVisible.value = true; |
| | | } catch (error) { |
| | |
| | | .map(item => ({ |
| | | ...item, |
| | | requisitionQty: 0, |
| | | remark: '' |
| | | remark: '', |
| | | })); |
| | | |
| | | if (newItems.length === 0) { |
| | |
| | | visible.value = false; |
| | | materialList.value = []; |
| | | activeTab.value = 'material'; |
| | | emit('confirm'); |
| | | } catch (error) { |
| | | console.error('保存领料失败:', error); |
| | | ElMessage.error('保存领料失败'); |