Authored by 孙凯

添加触底更新 review by zhanglixia

... ... @@ -22,6 +22,7 @@ import ProductFliter from './ProductFliter';
import SmallPic from './SmallPic';
import {getSlicedUrl} from '../../../classify/utils/Utils';
import BrandProductListCell from '../../../common/components/ListCell/ProductListCell';
import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator';
export default class Home extends Component {
... ... @@ -149,22 +150,32 @@ export default class Home extends Component {
}
_onEndReached() {
this.props.onEndReached && this.props.onEndReached();
}
_renderFooter() {
// endReached
let {groupInfo} = this.props.data;
let info = groupInfo.toJS();
if (info.list.length > 0) {
let {endReached,isFetching} = info.list[info.fliter];
if (endReached) {
return <View style={styles.placeholder} />;
} else {
return <LoadMoreIndicator isVisible={isFetching?true:false} animating={true} text={'正在加载更多的内容...'} />;
}
}
return null;
}
render() {
let {list, ptr, isFetching, endReached,groupInfo} = this.props.data;
let isPullToRefresh = ptr && isFetching;
let list_product = groupInfo.list.toArray();
let fliter = groupInfo.fliter;
let data = list_product.length > fliter ?list_product[fliter].toJS():null;
let product = data?data.product:null;
let productList = product?product.product_list:[];
let productList = product?product:[];
let dataSource = {
topHeader: list.toArray(),
... ... @@ -226,4 +237,8 @@ let styles = StyleSheet.create({
width: width / 2,
backgroundColor: 'white',
},
placeholder: {
width,
height: 15,
},
});
... ...
... ... @@ -101,7 +101,7 @@ export default class RecommendContentFive extends React.Component {
renderRow={this.renderRow}
renderHeader={this.renderHeader}
enableEmptySections={true}
pageSize={Math.ceil(data.length/4)}
initialListSize={list.length}
scrollEnabled={false}
scrollsToTop={false}
/>
... ...
... ... @@ -111,7 +111,6 @@ export default class RecommendContentTwo extends React.Component {
renderRow={this.renderRow}
renderHeader={this.renderHeader}
enableEmptySections={true}
pageSize={Math.ceil(list.length/3)}
scrollEnabled={false}
scrollsToTop={false}
/>
... ...
... ... @@ -72,6 +72,19 @@ class HomeContainer extends Component {
_onEndReached() {
let {home} = this.props;
let groupInfo = home.get('groupInfo');
let fliter = groupInfo.get('fliter');
let list = groupInfo.get('list').toJS();
let reload = true;
if (list.length > 0 ) {
let data = list[fliter];
let product = data.product?data.product:null;
if (product) {
this.props.actions.getGlobalProductList(fliter,list[fliter],reload);
}
}
}
_onPressFilter(value){
... ...
... ... @@ -84,9 +84,10 @@ function parseProductList(json) {
};
}
export function getGlobalProductListRequest() {
export function getGlobalProductListRequest(json) {
return {
type: GET_GLOBAL_PRODUCT_LIST_REQUEST,
payload: json,
}
}
... ... @@ -103,13 +104,27 @@ export function getGlobalProductListFailure(error) {
payload: error
}
}
export function getGlobalProductList(index,json) {
export function getGlobalProductList(index,json,reload=false) {
return (dispatch, getState) => {
let {app, home} = getState();
let page = 1;
if (json.isFetching || json.endReached) {
return;
}
let page_0 = json.page?json.page:1;
let page = reload?parseInt(page_0)+1:parseInt(page_0);
let order = json.order;
let sort = json.msort?json.msort:'';
dispatch(getGlobalProductListRequest());
console.log(page);
if (json) {
json.page = page;
json.isFetching = true;
json.filter = index;
json.endReached = false;
}
dispatch(getGlobalProductListRequest(json));
return new HomeService(app.host).getGlobalProductList(page,order,sort)
.then(json => {
let data = parseDetailProductList(index,home,json);
... ... @@ -127,13 +142,26 @@ function parseDetailProductList(index,home,json) {
let total = json.total;
let product_list = json.product_list;
let page_total = json.page_total;
let isFetching = false;
let error = '';
let filter = index;
let obj = {page,total,product_list,page_total,filter};
let list = home.groupInfo.list.toJS();
for (var i = 0; i < list.length; i++) {
if (i == filter) {
list[i].product = obj
if (page > 1) {
let oldList =list[i].product;
product_list = [...oldList, ...product_list];
}
list[i].product = product_list;
list[i].page = page;
list[i].isFetching = isFetching;
list[i].error = error;
list[i].total = total;
list[i].page_total = page_total;
list[i].filter = parseInt(filter);
list[i].endReached = page == page_total;
}
}
return list;
... ...
... ... @@ -13,10 +13,7 @@ let InitialState = Record({
isFetching: false,
error: null,
groupInfo: new (Record({
list: List(),
page: 0,
isFetching: false,
error: null,
list: List(),//isFetching error total_page currentPage
fliter: 0,
})),
});
... ...
... ... @@ -62,7 +62,20 @@ export default function homeReducer(state=initialState, action) {
break;
case GET_GLOBAL_PRODUCT_LIST_REQUEST:
{
let {
isFetching,
page,
fliter,
endReached,
} = action.payload;
let list = state.groupInfo.list.toJS();
list[0].isFetching = isFetching;
list[0].fliter = fliter;
list[0].page = page;
list[0].endReached = endReached;
return state.setIn(['groupInfo', 'list'], Immutable.fromJS(list));
}
break;
case GET_GLOBAL_PRODUCT_LIST_SUCCESS:
... ... @@ -73,7 +86,11 @@ export default function homeReducer(state=initialState, action) {
break;
case GET_GLOBAL_PRODUCT_LIST_FAILURE:
{
let list = state.groupInfo.list.toJS();
list[0].isFetching = false;
list[0].page = list[0].page - 1;
list[0].error = error;
return state.setIn(['groupInfo', 'list'], Immutable.fromJS(list));
}
break;
case SET_FLITER:
... ...