三级前端修改

This commit is contained in:
2025-11-11 14:21:46 +08:00
parent 8d4bc2de3c
commit 9867f07c64
3 changed files with 60 additions and 128 deletions

View File

@@ -148,7 +148,12 @@
<el-input v-model="targetCoil.team" placeholder="请输入班组名称" :disabled="readonly"></el-input>
</el-form-item>
<el-form-item label="材料类型">
<el-select v-model="targetCoil.materialType" placeholder="请选择材料类型" style="width: 100%" :disabled="readonly">
<el-select
v-model="targetCoil.materialType"
placeholder="请选择材料类型"
style="width: 100%"
:disabled="readonly"
@change="handleMaterialTypeChange">
<el-option label="原料" value="原料" />
<el-option label="成品" value="成品" />
<el-option label="废品" value="废品" />
@@ -331,40 +336,7 @@ export default {
}
},
watch: {
// 监听材料类型变化,自动设置物料类型
'targetCoil.materialType'(newVal, oldVal) {
console.log('🔥 merge.vue watch 触发! materialType 变化:', oldVal, '->', newVal);
// 先清空物品选择
this.$set(this.targetCoil, 'itemId', null);
// 设置物料类型
if (newVal === '成品') {
this.$set(this.targetCoil, 'itemType', 'product');
console.log('✅ 设置 itemType = product');
} else if (newVal === '原料' || newVal === '废品') {
this.$set(this.targetCoil, 'itemType', 'raw_material');
console.log('✅ 设置 itemType = raw_material');
}
console.log('📊 当前 targetCoil:', {
materialType: this.targetCoil.materialType,
itemType: this.targetCoil.itemType,
itemId: this.targetCoil.itemId
});
console.log('📦 数据列表:', {
rawMaterialList: this.rawMaterialList.length,
productList: this.productList.length
});
},
// 监听物品类型变化,加载对应的列表
'targetCoil.itemType'(newVal, oldVal) {
if (newVal !== oldVal && newVal) {
this.targetCoil.itemId = null; // 清空物品ID
this.loadItemList(newVal);
}
}
// 不再需要watch直接用@change事件处理
},
async created() {
console.log('🚀 merge.vue created 钩子执行');
@@ -428,6 +400,29 @@ export default {
}
},
methods: {
// 处理材料类型变化
handleMaterialTypeChange(value) {
console.log('🔥 merge.vue materialType变化:', value);
// 清空物品选择
this.$set(this.targetCoil, 'itemId', null);
// 根据材料类型设置物品类型
if (value === '成品') {
this.$set(this.targetCoil, 'itemType', 'product');
console.log('✅ 设置 itemType = product');
} else if (value === '原料' || value === '废品') {
this.$set(this.targetCoil, 'itemType', 'raw_material');
console.log('✅ 设置 itemType = raw_material');
}
console.log('📊 targetCoil更新后:', {
materialType: this.targetCoil.materialType,
itemType: this.targetCoil.itemType,
itemId: this.targetCoil.itemId
});
},
// 加载第一个钢卷(从待操作进入时)
async loadFirstCoil(coilId) {
try {

View File

@@ -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 === '成品') {

View File

@@ -330,40 +330,7 @@ export default {
}
},
watch: {
// 监听材料类型变化,自动设置物料类型
'updateForm.materialType'(newVal, oldVal) {
console.log('🔥 typing.vue watch 触发! materialType 变化:', oldVal, '->', newVal);
// 先清空物品选择
this.$set(this.updateForm, 'itemId', null);
// 设置物料类型
if (newVal === '成品') {
this.$set(this.updateForm, 'itemType', 'product');
console.log('✅ 设置 itemType = product');
} else if (newVal === '原料' || newVal === '废品') {
this.$set(this.updateForm, 'itemType', 'raw_material');
console.log('✅ 设置 itemType = raw_material');
}
console.log('📊 当前 updateForm:', {
materialType: this.updateForm.materialType,
itemType: this.updateForm.itemType,
itemId: this.updateForm.itemId
});
console.log('📦 数据列表:', {
rawMaterialList: this.rawMaterialList.length,
productList: this.productList.length
});
},
// 监听物品类型变化,加载对应的列表
'updateForm.itemType'(newVal, oldVal) {
if (newVal !== oldVal && newVal) {
this.updateForm.itemId = null;
this.loadItemList(newVal);
}
}
// 不再需要watch直接用@change事件处理
},
async created() {
console.log('🚀 typing.vue created 钩子执行');