Authored by 孙凯

add 触底更新 review by hongmo

... ... @@ -48,6 +48,7 @@ export default class Outlet extends Component {
onPressProduct = {this.props.onPressProduct}
setActivityFliter = {this.props.setActivityFliter}
onPressFilter = {this.props.onPressFilter}
onEndReached = {this.props.onEndReached}
/>
);
})}
... ...
... ... @@ -83,10 +83,13 @@ export default class OutletPageListView extends Component {
return null;
}
let categoryNavigationList = resource.get('categoryNavigationList');
let Navfliter = resource.get('Navfliter')?resource.get('Navfliter'):0;
return (
<ProductFliter
resource={categoryNavigationList}
onPressFilter={this._onPressFilter}
navfliter={Navfliter}
/>
);
}
... ... @@ -154,9 +157,8 @@ export default class OutletPageListView extends Component {
let activityList = resource.get('activityList')?resource.get('activityList').toArray():null;
let activityMore = resource.get('activityMore');
let categoryNavigationList = resource.get('categoryNavigationList')?resource.get('categoryNavigationList').toArray():null;
let fliter = resource.get('value')?resource.get('value'):0;
let productObj = categoryNavigationList?categoryNavigationList[fliter].get('list'):null;
let productList = productObj?productObj.get('product_list'):null;
let fliter = resource.get('Navfliter')?resource.get('Navfliter'):0;
let productList = categoryNavigationList?categoryNavigationList[fliter].get('list'):null;
let error = resource.get('error');
let ptr = resource.get('ptr')==true ? true : false;
let list = list = honeResource?honeResource.get('list'):null;
... ... @@ -186,6 +188,14 @@ export default class OutletPageListView extends Component {
onRefreshData={() => {
this._onRefresh && this._onRefresh(true);
}}
onEndReached={() => {
if (categoryNavigationList && productList && productList.size > 0) {
let {
resource,
} = this.props;
this.props.onEndReached && this.props.onEndReached(resource.get('content_code'),categoryNavigationList?categoryNavigationList[fliter].toJS():null);
}
}}
/>
</View>
);
... ...
... ... @@ -26,7 +26,7 @@ export default class ProductFliter extends React.Component {
rowHasChanged: (r1, r2) => r1.key != r2.key,
});
this.state = {
selectedIndex: 0,
selectedIndex: this.props.navfliter,
};
}
... ... @@ -64,13 +64,17 @@ export default class ProductFliter extends React.Component {
render() {
let {resource} = this.props;
let {resource,navfliter} = this.props;
let res = resource?resource.toJS():null;
if (!res) {
return null;
}
if (this.state.selectedIndex != parseInt(navfliter)) {
this.state.selectedIndex = parseInt(navfliter);
}
return (
<View style={styles.container}>
<ListView
... ...
... ... @@ -44,6 +44,7 @@ class OutletContainer extends Component {
this._onPressProduct = this._onPressProduct.bind(this);
this._onPressFilter = this._onPressFilter.bind(this);
this._getOutletActivityList = this._getOutletActivityList.bind(this);
this._onEndReached = this._onEndReached.bind(this);
this._setActivityFliter = this._setActivityFliter.bind(this);
}
... ... @@ -55,6 +56,13 @@ class OutletContainer extends Component {
}
_onEndReached(content_code,categoryNavigationItem) {
let list = categoryNavigationItem?categoryNavigationItem.list:null;
if (categoryNavigationItem) {
this.props.actions.getProductList(content_code,categoryNavigationItem);
}
}
_getOutletHomeResource(content_code,ptr){
this.props.actions.getOutletHomeResource(content_code,ptr);
}
... ... @@ -93,6 +101,7 @@ class OutletContainer extends Component {
getOutletActivityList = {this._getOutletActivityList}
onPressProduct = {this._onPressProduct}
onPressFilter = {this._onPressFilter}
onEndReached = {this._onEndReached}
/>
);
}
... ...
... ... @@ -158,18 +158,27 @@ export function getProductList(content_code,categoryNavigationItem) {
let {app, outlet} = getState();
let {categoryList} = outlet;
//limit,page,uid,firstProductSkn=''
// if (productList.isFetching || productList.endReached || productList.error) {
// return;
// }
if (!categoryNavigationItem || categoryNavigationItem.isFetching || categoryNavigationItem.endReached || categoryNavigationItem.error) {
return;
}
let page = categoryNavigationItem.currentPage?categoryNavigationItem.currentPage + 1:1;
let pageSize = categoryNavigationItem.pageSize?categoryNavigationItem.pageSize:60;
let param = parseUrlForparam(categoryNavigationItem.url);
let page = 1;//productList.currentPage + 1;
let pageSize = 60;//productList.pageSize;
dispatch(getProductListRequest({'content_code':content_code,'categoryNavigationItem':categoryNavigationItem}));
return new OutletService(app.host).getProductList(pageSize,page,param)
.then(json => {
dispatch(getProductListSuccess({'json':json,'content_code':content_code,'categoryNavigationItem':categoryNavigationItem}));
let payload = parseProductList(json)
payload.endReached = payload.currentPage == payload.pageCount || payload.list.length < pageSize;
if (payload.currentPage > 1) {
let oldList = categoryNavigationItem.list;
let list = [...oldList, ...payload.list];
payload.list = list;
}
dispatch(getProductListSuccess({'json':payload,'content_code':content_code,'categoryNavigationItem':categoryNavigationItem}));
})
.catch(error => {
dispatch(getProductListFailure(content_code,error,categoryNavigationItem));
... ... @@ -183,6 +192,21 @@ function parseUrlForparam(url) {
return param;
}
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 list = json && json.product_list ? json.product_list : [];
return {
list,
currentPage,
pageCount,
total,
};
}
export function getOutletActivityListRequest(content_code) {
return {
type: GET_OUTLET_ACTIVITY_LIST_REQUEST,
... ...
... ... @@ -77,6 +77,7 @@ export default function outletReducer(state=initialState, action) {
item.isFetching = false;
item.error = '';
item.ptr = false;
item.Navfliter = 0;
}
})
return state.setIn(['categoryList', 'list'], Immutable.fromJS(categoryList.list))
... ... @@ -126,8 +127,12 @@ export default function outletReducer(state=initialState, action) {
item.categoryNavigationList.map((item0, i) => {
let categoryName = item0.categoryName;
if (categoryNavigationItem.categoryName == categoryName) {
item0.list = action.payload.json;
item0.list = action.payload.json.list;
item0.isFetching = false;
item0.currentPage = action.payload.json.currentPage;
item0.endReached = action.payload.json.endReached;
item0.pageCount = action.payload.json.pageCount;
item0.total = action.payload.json.total;
}
});
}
... ... @@ -191,7 +196,7 @@ export default function outletReducer(state=initialState, action) {
categoryList.list.map((item, i) => {
let content_code0 = item.content_code;
if (content_code1 == content_code0) {
item.value = action.payload.value;
item.Navfliter = action.payload.value;
}
})
return state.setIn(['categoryList', 'list'], Immutable.fromJS(categoryList.list))
... ...