解决bomId为空时会查询所有bom的bug

This commit is contained in:
砂糖
2025-08-01 12:57:30 +08:00
parent 7725a588ee
commit 5b619eca0a
9 changed files with 119 additions and 51 deletions

View File

@@ -5,11 +5,6 @@
{{ item.attrValue }}
</el-descriptions-item>
</el-descriptions>
<div v-else-if="mini">
<el-tooltip :content="bomInfo.map(item => item.attrKey + ':' + item.attrValue).join(',')" class="bom-info" placement="top">
<span>{{ bomInfo.map(item => item.attrKey).join(',') }}</span>
</el-tooltip>
</div>
<div v-else>
<el-empty description="暂无BOM信息" />
</div>
@@ -17,6 +12,7 @@
</template>
<script>
// 如果传递了bomId直接使用bomId, 如果没有传递则根据itemType和itemId获取bomId
import { listBomItem } from '@/api/wms/bomItem';
import { mapState } from 'vuex';
@@ -44,13 +40,23 @@ export default {
computed: {
...mapState('category', ['bomMap', 'productMap', 'rawMaterialMap']),
},
created() {
this.getBomInfo();
watch: {
bomId: {
handler: function (newVal) {
this.getBomInfo();
},
immediate: true
},
itemId: {
handler: function (newVal) {
this.getBomInfo();
},
immediate: true
}
},
methods: {
getBomInfo() {
const bomMap = this.$store.getters.bomMap;
console.log(bomMap)
if (!this.bomId && !this.itemType && !this.itemId) {
return;
}
@@ -62,13 +68,17 @@ export default {
bomId = this.rawMaterialMap[this.itemId].bomId;
}
}
if (!bomId) {
return;
}
if (bomMap[bomId]) {
this.bomInfo = bomMap[bomId];
} else {
listBomItem({ bomId: bomId }).then(res => {
listBomItem({ bomId }).then(res => {
this.bomInfo = res.rows;
})
}
console.log(this.bomInfo, bomId, bomMap)
}
}
}

View File

@@ -40,17 +40,26 @@ export default {
computed: {
...mapState('category', ['bomMap', 'productMap', 'rawMaterialMap']),
},
created() {
this.getBomInfo();
watch: {
bomId: {
handler: function (newVal) {
this.getBomInfo();
},
immediate: true
},
itemId: {
handler: function (newVal) {
this.getBomInfo();
},
immediate: true
}
},
methods: {
getBomInfo() {
const bomMap = this.$store.getters.bomMap;
console.log(bomMap)
if (!this.bomId && !this.itemType && !this.itemId) {
return;
}
console.log(this.itemType, this.itemId)
let bomId = this.bomId;
if (!bomId) {
if (this.itemType === 'product') {
@@ -59,10 +68,13 @@ export default {
bomId = this.rawMaterialMap[this.itemId].bomId;
}
}
if (!bomId) {
return;
}
if (bomMap[bomId]) {
this.bomInfo = bomMap[bomId];
} else {
listBomItem({ bomId: bomId }).then(res => {
listBomItem({ bomId }).then(res => {
this.bomInfo = res.rows;
})
}

View File

@@ -56,11 +56,7 @@ export default {
},
methods: {
clickHandle() {
console.log('clickHandle');
this.showDetail = true;
},
getStatusText(status) {
return status === 1 ? '启用中' : '已禁用';
}
},
watch: {

View File

@@ -48,7 +48,6 @@ export default {
materialId: {
handler: function (newVal) {
const res = this.materialMap ? this.materialMap[this.materialId] : {};
console.log(this.materialMap, this.materialId, 'materialMap', 'materialId', res);
this.material = res;
},
immediate: true