Files
GEAR-OA/gear-ui3/src/store/modules/product.js
2025-09-03 11:55:00 +08:00

42 lines
986 B
JavaScript

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() {
listProduct({ pageNum: 1, pageSize: 10000 }).then(res => {
const map = {};
res.rows.forEach(item => {
map[item.productId] = item;
});
console.log(map, res, 'productMap');
this.productMap = map;
})
},
}
})
export default useProductStore;