Authored by 于良

增加店铺页面底部商品列表数据获取 review by 石祥

... ... @@ -22,4 +22,8 @@ export default keyMirror({
HOT_PRODUCT_REQUEST: null,
HOT_PRODUCT_SUCCESS: null,
HOT_PRODUCT_FAILURE: null,
PRODUCT_LIST_REQUEST: null,
PRODUCT_LIST_SUCCESS: null,
PRODUCT_LIST_FAILURE: null,
});
... ...
... ... @@ -51,6 +51,7 @@ class BrandStoreContainer extends Component {
this.props.actions.getShopInfo();
this.props.actions.getShopCouponList();
this.props.actions.getShopResources();
this.props.actions.getProductList();
}
componentWillUnmount() {
... ...
... ... @@ -32,6 +32,9 @@ const {
HOT_PRODUCT_SUCCESS,
HOT_PRODUCT_FAILURE,
PRODUCT_LIST_REQUEST,
PRODUCT_LIST_SUCCESS,
PRODUCT_LIST_FAILURE,
} = require('../../constants/actionTypes').default;
export function onPressBrandItem() {
... ... @@ -288,7 +291,10 @@ export function getHotProduct() {
dispatch(hotProductRequest());
return new BrandStoreService().searchProductBySkn(productSkn)
.then(json => {
let payload = json;
_.forEach(json.product_list, (value, key) => {
json.product_list[key].is_soon_sold_out = 'N';
});
let payload = json.product_list;
dispatch(hotProductSuccess(payload));
})
.catch(error => {
... ... @@ -296,3 +302,81 @@ export function getHotProduct() {
});
};
}
export function productListRequest() {
return {
type: PRODUCT_LIST_REQUEST,
};
}
export function productListSuccess(json) {
return {
type: PRODUCT_LIST_SUCCESS,
payload: json
}
}
export function productListFailure(error) {
return {
type: PRODUCT_LIST_FAILURE,
payload: error
}
}
/*
* 底部产品列表
*/
export function getProductList(reload=false) {
return (dispatch, getState) => {
let {app, brandStore} = getState();
let {shopId, productList} = brandStore;
if (reload) {
} else {
if (productList.isFetching || productList.endReached || productList.error) {
return;
}
}
let order = productList.order;
let page = productList.currentPage + 1;
let pageSize = productList.pageSize;
let channel = 1;
dispatch(productListRequest());
return new BrandStoreService().productList(shopId, channel, order, page, pageSize)
.then(json => {
let payload = parseProductList(json);
payload.endReached = payload.currentPage == payload.pageCount;
if (payload.currentPage > 1) {
let oldList = productList.list.toJS();
let list = [...oldList, ...payload.list];
payload.list = list;
}
dispatch(productListSuccess(payload));
})
.catch(error => {
dispatch(productListFailure(error));
});
};
}
function parseProductList(json) {
let currentPage = json && json.page ? json.page : 1;
let pageCount = json && json.page_total ? json.page_total : 0;
let total = json && json.total ? json.total : 0;
let filter = json && json.filter ? json.filter : {};
let list = json && json.product_list ? json.product_list : [];
return {
list,
filter,
currentPage,
pageCount,
total,
};
}
... ...
... ... @@ -47,6 +47,19 @@ let InitialState = Record({
error: null,
list: List(),
})),
productList: new (Record({
isFetching: false,
error: null,
list: List(),
filter: null,
order: 's_t_asc',
currentPage: 0,
pageCount: 0,
pageSize: 6,//60,
total: 0,
endReached: false,
sourceType: 0, // 0 - 默认,1 - 购,全球2 - 奥莱
})),
isCollection: false,
hasBuy : false,
... ...
... ... @@ -29,6 +29,10 @@ const {
HOT_PRODUCT_REQUEST,
HOT_PRODUCT_SUCCESS,
HOT_PRODUCT_FAILURE,
PRODUCT_LIST_REQUEST,
PRODUCT_LIST_SUCCESS,
PRODUCT_LIST_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
... ... @@ -168,6 +172,39 @@ export default function brandStoreReducer(state=initialState, action) {
return state.setIn(['resource', 'hotProducts_APP'], newHotProducts);
}
case PRODUCT_LIST_REQUEST: {
return state.setIn(['productList', 'isFetching'], true)
.setIn(['productList', 'error'], null);
}
case PRODUCT_LIST_SUCCESS: {
let {
list,
filter,
currentPage,
pageCount,
total,
endReached,
} = action.payload;
let newState = state.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'error'], null)
.setIn(['productList', 'list'], Immutable.fromJS(list))
.setIn(['productList', 'currentPage'], currentPage)
.setIn(['productList', 'pageCount'], pageCount)
.setIn(['productList', 'total'], total)
.setIn(['productList', 'endReached'], endReached);
if (currentPage == 1) {
newState = newState.setIn(['productList', 'filter'], Immutable.fromJS(filter));
}
return newState;
}
case PRODUCT_LIST_FAILURE: {
return state.setIn(['productList', 'isFetching'], false)
.setIn(['productList', 'error'], action.payload);
}
}
return state;
... ...
... ... @@ -75,4 +75,27 @@ export default class BrandStoreService {
});
}
async productList(shop_id, yh_channel=1, order='s_t_asc', page=1, limit=60, v=7) {
return await this.api.get({
url: '',
body: {
method: 'app.search.li',
shop_id,
yh_channel,
order,
status: 1,
sales: 'Y',
stocknumber: 1,
attribute_not: 2,
v,
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
});
}
}
... ...