Authored by 孙凯

添加触底更新 review by zhanglixia

@@ -22,6 +22,7 @@ import ProductFliter from './ProductFliter'; @@ -22,6 +22,7 @@ import ProductFliter from './ProductFliter';
22 import SmallPic from './SmallPic'; 22 import SmallPic from './SmallPic';
23 import {getSlicedUrl} from '../../../classify/utils/Utils'; 23 import {getSlicedUrl} from '../../../classify/utils/Utils';
24 import BrandProductListCell from '../../../common/components/ListCell/ProductListCell'; 24 import BrandProductListCell from '../../../common/components/ListCell/ProductListCell';
  25 +import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator';
25 26
26 export default class Home extends Component { 27 export default class Home extends Component {
27 28
@@ -149,22 +150,32 @@ export default class Home extends Component { @@ -149,22 +150,32 @@ export default class Home extends Component {
149 } 150 }
150 151
151 _onEndReached() { 152 _onEndReached() {
152 - 153 + this.props.onEndReached && this.props.onEndReached();
153 } 154 }
154 155
155 _renderFooter() { 156 _renderFooter() {
  157 + // endReached
  158 + let {groupInfo} = this.props.data;
  159 + let info = groupInfo.toJS();
  160 + if (info.list.length > 0) {
  161 + let {endReached,isFetching} = info.list[info.fliter];
  162 + if (endReached) {
  163 + return <View style={styles.placeholder} />;
  164 + } else {
  165 + return <LoadMoreIndicator isVisible={isFetching?true:false} animating={true} text={'正在加载更多的内容...'} />;
  166 + }
  167 + }
156 return null; 168 return null;
157 } 169 }
158 170
159 render() { 171 render() {
160 let {list, ptr, isFetching, endReached,groupInfo} = this.props.data; 172 let {list, ptr, isFetching, endReached,groupInfo} = this.props.data;
161 let isPullToRefresh = ptr && isFetching; 173 let isPullToRefresh = ptr && isFetching;
162 -  
163 let list_product = groupInfo.list.toArray(); 174 let list_product = groupInfo.list.toArray();
164 let fliter = groupInfo.fliter; 175 let fliter = groupInfo.fliter;
165 let data = list_product.length > fliter ?list_product[fliter].toJS():null; 176 let data = list_product.length > fliter ?list_product[fliter].toJS():null;
166 let product = data?data.product:null; 177 let product = data?data.product:null;
167 - let productList = product?product.product_list:[]; 178 + let productList = product?product:[];
168 179
169 let dataSource = { 180 let dataSource = {
170 topHeader: list.toArray(), 181 topHeader: list.toArray(),
@@ -226,4 +237,8 @@ let styles = StyleSheet.create({ @@ -226,4 +237,8 @@ let styles = StyleSheet.create({
226 width: width / 2, 237 width: width / 2,
227 backgroundColor: 'white', 238 backgroundColor: 'white',
228 }, 239 },
  240 + placeholder: {
  241 + width,
  242 + height: 15,
  243 + },
229 }); 244 });
@@ -101,7 +101,7 @@ export default class RecommendContentFive extends React.Component { @@ -101,7 +101,7 @@ export default class RecommendContentFive extends React.Component {
101 renderRow={this.renderRow} 101 renderRow={this.renderRow}
102 renderHeader={this.renderHeader} 102 renderHeader={this.renderHeader}
103 enableEmptySections={true} 103 enableEmptySections={true}
104 - pageSize={Math.ceil(data.length/4)} 104 + initialListSize={list.length}
105 scrollEnabled={false} 105 scrollEnabled={false}
106 scrollsToTop={false} 106 scrollsToTop={false}
107 /> 107 />
@@ -111,7 +111,6 @@ export default class RecommendContentTwo extends React.Component { @@ -111,7 +111,6 @@ export default class RecommendContentTwo extends React.Component {
111 renderRow={this.renderRow} 111 renderRow={this.renderRow}
112 renderHeader={this.renderHeader} 112 renderHeader={this.renderHeader}
113 enableEmptySections={true} 113 enableEmptySections={true}
114 - pageSize={Math.ceil(list.length/3)}  
115 scrollEnabled={false} 114 scrollEnabled={false}
116 scrollsToTop={false} 115 scrollsToTop={false}
117 /> 116 />
@@ -72,6 +72,19 @@ class HomeContainer extends Component { @@ -72,6 +72,19 @@ class HomeContainer extends Component {
72 72
73 _onEndReached() { 73 _onEndReached() {
74 74
  75 + let {home} = this.props;
  76 + let groupInfo = home.get('groupInfo');
  77 + let fliter = groupInfo.get('fliter');
  78 + let list = groupInfo.get('list').toJS();
  79 + let reload = true;
  80 +
  81 + if (list.length > 0 ) {
  82 + let data = list[fliter];
  83 + let product = data.product?data.product:null;
  84 + if (product) {
  85 + this.props.actions.getGlobalProductList(fliter,list[fliter],reload);
  86 + }
  87 + }
75 } 88 }
76 89
77 _onPressFilter(value){ 90 _onPressFilter(value){
@@ -84,9 +84,10 @@ function parseProductList(json) { @@ -84,9 +84,10 @@ function parseProductList(json) {
84 }; 84 };
85 } 85 }
86 86
87 -export function getGlobalProductListRequest() { 87 +export function getGlobalProductListRequest(json) {
88 return { 88 return {
89 type: GET_GLOBAL_PRODUCT_LIST_REQUEST, 89 type: GET_GLOBAL_PRODUCT_LIST_REQUEST,
  90 + payload: json,
90 } 91 }
91 } 92 }
92 93
@@ -103,13 +104,27 @@ export function getGlobalProductListFailure(error) { @@ -103,13 +104,27 @@ export function getGlobalProductListFailure(error) {
103 payload: error 104 payload: error
104 } 105 }
105 } 106 }
106 -export function getGlobalProductList(index,json) { 107 +export function getGlobalProductList(index,json,reload=false) {
107 return (dispatch, getState) => { 108 return (dispatch, getState) => {
108 let {app, home} = getState(); 109 let {app, home} = getState();
109 - let page = 1; 110 +
  111 + if (json.isFetching || json.endReached) {
  112 + return;
  113 + }
  114 +
  115 + let page_0 = json.page?json.page:1;
  116 + let page = reload?parseInt(page_0)+1:parseInt(page_0);
110 let order = json.order; 117 let order = json.order;
111 let sort = json.msort?json.msort:''; 118 let sort = json.msort?json.msort:'';
112 - dispatch(getGlobalProductListRequest()); 119 + console.log(page);
  120 + if (json) {
  121 + json.page = page;
  122 + json.isFetching = true;
  123 + json.filter = index;
  124 + json.endReached = false;
  125 + }
  126 +
  127 + dispatch(getGlobalProductListRequest(json));
113 return new HomeService(app.host).getGlobalProductList(page,order,sort) 128 return new HomeService(app.host).getGlobalProductList(page,order,sort)
114 .then(json => { 129 .then(json => {
115 let data = parseDetailProductList(index,home,json); 130 let data = parseDetailProductList(index,home,json);
@@ -127,13 +142,26 @@ function parseDetailProductList(index,home,json) { @@ -127,13 +142,26 @@ function parseDetailProductList(index,home,json) {
127 let total = json.total; 142 let total = json.total;
128 let product_list = json.product_list; 143 let product_list = json.product_list;
129 let page_total = json.page_total; 144 let page_total = json.page_total;
  145 + let isFetching = false;
  146 + let error = '';
130 let filter = index; 147 let filter = index;
131 - let obj = {page,total,product_list,page_total,filter};  
132 148
133 let list = home.groupInfo.list.toJS(); 149 let list = home.groupInfo.list.toJS();
  150 +
134 for (var i = 0; i < list.length; i++) { 151 for (var i = 0; i < list.length; i++) {
135 if (i == filter) { 152 if (i == filter) {
136 - list[i].product = obj 153 + if (page > 1) {
  154 + let oldList =list[i].product;
  155 + product_list = [...oldList, ...product_list];
  156 + }
  157 + list[i].product = product_list;
  158 + list[i].page = page;
  159 + list[i].isFetching = isFetching;
  160 + list[i].error = error;
  161 + list[i].total = total;
  162 + list[i].page_total = page_total;
  163 + list[i].filter = parseInt(filter);
  164 + list[i].endReached = page == page_total;
137 } 165 }
138 } 166 }
139 return list; 167 return list;
@@ -13,10 +13,7 @@ let InitialState = Record({ @@ -13,10 +13,7 @@ let InitialState = Record({
13 isFetching: false, 13 isFetching: false,
14 error: null, 14 error: null,
15 groupInfo: new (Record({ 15 groupInfo: new (Record({
16 - list: List(),  
17 - page: 0,  
18 - isFetching: false,  
19 - error: null, 16 + list: List(),//isFetching error total_page currentPage
20 fliter: 0, 17 fliter: 0,
21 })), 18 })),
22 }); 19 });
@@ -62,7 +62,20 @@ export default function homeReducer(state=initialState, action) { @@ -62,7 +62,20 @@ export default function homeReducer(state=initialState, action) {
62 break; 62 break;
63 case GET_GLOBAL_PRODUCT_LIST_REQUEST: 63 case GET_GLOBAL_PRODUCT_LIST_REQUEST:
64 { 64 {
  65 + let {
  66 + isFetching,
  67 + page,
  68 + fliter,
  69 + endReached,
  70 + } = action.payload;
65 71
  72 + let list = state.groupInfo.list.toJS();
  73 + list[0].isFetching = isFetching;
  74 + list[0].fliter = fliter;
  75 + list[0].page = page;
  76 + list[0].endReached = endReached;
  77 +
  78 + return state.setIn(['groupInfo', 'list'], Immutable.fromJS(list));
66 } 79 }
67 break; 80 break;
68 case GET_GLOBAL_PRODUCT_LIST_SUCCESS: 81 case GET_GLOBAL_PRODUCT_LIST_SUCCESS:
@@ -73,7 +86,11 @@ export default function homeReducer(state=initialState, action) { @@ -73,7 +86,11 @@ export default function homeReducer(state=initialState, action) {
73 break; 86 break;
74 case GET_GLOBAL_PRODUCT_LIST_FAILURE: 87 case GET_GLOBAL_PRODUCT_LIST_FAILURE:
75 { 88 {
76 - 89 + let list = state.groupInfo.list.toJS();
  90 + list[0].isFetching = false;
  91 + list[0].page = list[0].page - 1;
  92 + list[0].error = error;
  93 + return state.setIn(['groupInfo', 'list'], Immutable.fromJS(list));
77 } 94 }
78 break; 95 break;
79 case SET_FLITER: 96 case SET_FLITER: