Files
GEAR-OA/gear-ui3/src/store/modules/product.js

42 lines
986 B
JavaScript
Raw Normal View History

2025-08-28 13:07:28 +08:00
import { listProduct } from '@/api/oa/product';
import { listBomItem } from '@/api/oa/bomItem';
const useProductStore = defineStore('product', {
state: () => ({
productMap: {},
bomMap: {},
}),
actions: {
setProductMap(productMap) {
this.productMap = productMap;
},
setBomMap(bomMap) {
this.bomMap = bomMap;
},
async getBomInfo(bomId) {
try {
if (!this.bomMap[bomId]) {
const res = await listBomItem({ bomId });
this.bomMap[bomId] = res.rows;
}
return this.bomMap[bomId];
} catch (error) {
console.error(error);
return [];
}
},
fetchProductMap() {
2025-09-03 11:55:00 +08:00
listProduct({ pageNum: 1, pageSize: 10000 }).then(res => {
2025-08-28 13:07:28 +08:00
const map = {};
2025-09-03 11:55:00 +08:00
res.rows.forEach(item => {
2025-08-28 13:07:28 +08:00
map[item.productId] = item;
});
2025-09-03 11:55:00 +08:00
console.log(map, res, 'productMap');
2025-08-28 13:07:28 +08:00
this.productMap = map;
})
},
}
})
export default useProductStore;