三级前端修改
This commit is contained in:
@@ -116,7 +116,12 @@
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="材料类型" required>
|
||||
<el-select v-model="item.materialType" placeholder="请选择材料类型" style="width: 100%" :disabled="readonly">
|
||||
<el-select
|
||||
v-model="item.materialType"
|
||||
placeholder="请选择材料类型"
|
||||
style="width: 100%"
|
||||
:disabled="readonly"
|
||||
@change="handleMaterialTypeChange(item, index)">
|
||||
<el-option label="原料" value="原料" />
|
||||
<el-option label="成品" value="成品" />
|
||||
<el-option label="废品" value="废品" />
|
||||
@@ -308,65 +313,30 @@ export default {
|
||||
this.readonly = true;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
// 深度监听子卷列表中每个元素的 materialType 变化
|
||||
splitList: {
|
||||
handler(newList, oldList) {
|
||||
console.log('🔥 split.vue watch 触发! splitList 变化', {
|
||||
newList: newList.map(i => ({materialType: i.materialType, itemType: i.itemType})),
|
||||
oldList: oldList?.map(i => ({materialType: i.materialType, itemType: i.itemType}))
|
||||
});
|
||||
|
||||
newList.forEach((item, index) => {
|
||||
// 检查 materialType 是否变化
|
||||
const oldItem = oldList && oldList[index];
|
||||
const materialTypeChanged = !oldItem || oldItem.materialType !== item.materialType;
|
||||
|
||||
// 检查 itemType 是否需要设置(materialType有值但itemType为空)
|
||||
const needSetItemType = item.materialType && !item.itemType;
|
||||
|
||||
console.log(`👀 子卷${index} 检查:`, {
|
||||
materialTypeChanged,
|
||||
needSetItemType,
|
||||
'oldItem?.materialType': oldItem?.materialType,
|
||||
'item.materialType': item.materialType,
|
||||
'item.itemType': item.itemType
|
||||
});
|
||||
|
||||
if (materialTypeChanged) {
|
||||
console.log(`🔥 split.vue 子卷${index} materialType 变化:`, oldItem?.materialType, '->', item.materialType);
|
||||
}
|
||||
|
||||
// 如果 materialType 变化了,或者 itemType 需要设置
|
||||
if ((materialTypeChanged || needSetItemType) && item.materialType) {
|
||||
// 使用 Vue.set 确保响应式更新
|
||||
this.$set(item, 'itemId', null);
|
||||
|
||||
// 设置物料类型
|
||||
if (item.materialType === '成品') {
|
||||
this.$set(item, 'itemType', 'product');
|
||||
console.log(`✅ 子卷${index} 使用$set设置 itemType = product`);
|
||||
} else if (item.materialType === '原料' || item.materialType === '废品') {
|
||||
this.$set(item, 'itemType', 'raw_material');
|
||||
console.log(`✅ 子卷${index} 使用$set设置 itemType = raw_material`);
|
||||
}
|
||||
|
||||
console.log(`📊 子卷${index} 当前状态:`, {
|
||||
materialType: item.materialType,
|
||||
itemType: item.itemType,
|
||||
itemId: item.itemId
|
||||
});
|
||||
|
||||
// 验证数据是否正确
|
||||
console.log(`📦 原材料列表数量:`, this.rawMaterialList.length);
|
||||
console.log(`📦 产品列表数量:`, this.productList.length);
|
||||
}
|
||||
});
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
// 处理材料类型变化
|
||||
handleMaterialTypeChange(item, index) {
|
||||
console.log(`🔥 子卷${index+1} materialType变化:`, item.materialType);
|
||||
|
||||
// 清空物品选择
|
||||
this.$set(item, 'itemId', null);
|
||||
|
||||
// 根据材料类型设置物品类型
|
||||
if (item.materialType === '成品') {
|
||||
this.$set(item, 'itemType', 'product');
|
||||
console.log(`✅ 子卷${index+1} 设置 itemType = product`);
|
||||
} else if (item.materialType === '原料' || item.materialType === '废品') {
|
||||
this.$set(item, 'itemType', 'raw_material');
|
||||
console.log(`✅ 子卷${index+1} 设置 itemType = raw_material`);
|
||||
}
|
||||
|
||||
console.log(`📊 子卷${index+1} 更新后:`, {
|
||||
materialType: item.materialType,
|
||||
itemType: item.itemType,
|
||||
itemId: item.itemId
|
||||
});
|
||||
},
|
||||
|
||||
// 动态获取标签
|
||||
getItemLabel(materialType) {
|
||||
if (materialType === '成品') {
|
||||
|
||||
Reference in New Issue
Block a user