66 lines
1.5 KiB
JavaScript
66 lines
1.5 KiB
JavaScript
import { listCategory } from '@/api/wms/category';
|
|
import { listProduct } from '@/api/wms/product';
|
|
import { listRawMaterial } from '@/api/wms/rawMaterial';
|
|
|
|
const state = {
|
|
categoryList: [],
|
|
productMap: {},
|
|
rawMaterialMap: {}
|
|
};
|
|
|
|
const mutations = {
|
|
SET_CATEGORY_LIST(state, list) {
|
|
state.categoryList = list;
|
|
},
|
|
SET_PRODUCT_MAP(state, map) {
|
|
state.productMap = map;
|
|
},
|
|
SET_RAW_MATERIAL_MAP(state, map) {
|
|
state.rawMaterialMap = map;
|
|
}
|
|
};
|
|
|
|
const actions = {
|
|
getCategoryList({ state, commit }) {
|
|
if (state.categoryList.length > 0) {
|
|
return Promise.resolve(state.categoryList);
|
|
}
|
|
return listCategory().then(res => {
|
|
commit('SET_CATEGORY_LIST', res.rows || []);
|
|
return res.rows || [];
|
|
});
|
|
},
|
|
getProductMap({ state, commit }) {
|
|
if (Object.keys(state.productMap).length > 0) {
|
|
return Promise.resolve(state.productMap);
|
|
}
|
|
return listProduct().then(res => {
|
|
const map = {};
|
|
res.rows.forEach(item => {
|
|
map[item.productId] = item;
|
|
});
|
|
commit('SET_PRODUCT_MAP', map);
|
|
return map;
|
|
});
|
|
},
|
|
getRawMaterialMap({ state, commit }) {
|
|
if (Object.keys(state.rawMaterialMap).length > 0) {
|
|
return Promise.resolve(state.rawMaterialMap);
|
|
}
|
|
return listRawMaterial().then(res => {
|
|
const map = {};
|
|
res.rows.forEach(item => {
|
|
map[item.rawMaterialId] = item;
|
|
});
|
|
commit('SET_RAW_MATERIAL_MAP', map);
|
|
return map;
|
|
});
|
|
}
|
|
};
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state,
|
|
mutations,
|
|
actions
|
|
};
|