|
|
import * as Types from './types';
|
|
|
import {first, get, flatten} from 'lodash';
|
|
|
|
|
|
export default {
|
|
|
async fetchProduct({commit}, {productId, page = 1, refresh = false, onlyProduct = false}) {
|
|
|
async fetchProduct({commit}, {productId, page = 1, refresh = false}) {
|
|
|
commit(Types.FETCH_ORDER_PRODUCT_REQUEST);
|
|
|
|
|
|
const result = await this.$api.get('/api/ufo/seller/entryGoodsSizeList', {
|
|
|
productId,
|
|
|
page
|
|
|
});
|
|
|
let result;
|
|
|
|
|
|
if (refresh) {
|
|
|
const results = await Promise.all(Array.from(new Array(page)).map((v, i) => {
|
|
|
return this.$api.get('/api/ufo/seller/entryGoodsSizeList', {
|
|
|
productId,
|
|
|
page: i + 1
|
|
|
});
|
|
|
}));
|
|
|
|
|
|
result = {
|
|
|
code: 200,
|
|
|
data: {
|
|
|
productInfo: get(first(results), 'data.productInfo'),
|
|
|
data: flatten(results.map(r => get(r, 'data.data')))
|
|
|
}
|
|
|
};
|
|
|
} else {
|
|
|
result = await this.$api.get('/api/ufo/seller/entryGoodsSizeList', {
|
|
|
productId,
|
|
|
page
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (result && result.code === 200) {
|
|
|
commit(Types.FETCH_ORDER_PRODUCT_SUCCESS, {
|
|
|
order: result.data,
|
|
|
refresh,
|
|
|
onlyProduct
|
|
|
});
|
|
|
} else {
|
|
|
commit(Types.FETCH_ORDER_PRODUCT_FAILD);
|
...
|
...
|
|