Authored by shangjf

首页业务逻辑优化 review by 陈林

  1 +'use strict';
  2 +
  3 +import React from 'react';
  4 +import ReactNative from 'react-native';
  5 +import Immutable, {Map} from 'immutable';
  6 +
  7 +const {
  8 + View,
  9 + Text,
  10 + ListView,
  11 + TouchableOpacity,
  12 + Dimensions,
  13 + StyleSheet,
  14 + Platform,
  15 +} = ReactNative;
  16 +
  17 +
  18 +export default class ChannelSelector extends React.Component {
  19 +
  20 + constructor(props) {
  21 + super (props);
  22 +
  23 + this._renderRow = this._renderRow.bind(this);
  24 + this._renderSeparator = this._renderSeparator.bind(this);
  25 +
  26 + this.dataSource = new ListView.DataSource({
  27 + rowHasChanged: (r1, r2) => r1.id != r2.id,
  28 + });
  29 + }
  30 +
  31 + shouldComponentUpdate(nextProps){
  32 + if (nextProps.onSelectdIndex == this.props.onSelectdIndex) {
  33 + return false;
  34 + } else {
  35 + return true;
  36 + }
  37 + }
  38 +
  39 + _renderRow(rowData, sectionID, rowID) {
  40 + let isRowSelected = false;
  41 + let onSelectdIndex = this.props.onSelectdIndex;
  42 + let dataSource = this.props.dataSource;
  43 + isRowSelected = onSelectdIndex == rowID;
  44 +
  45 + let colorStyle = isRowSelected ? {color: '#444444', fontFamily: 'HelveticaNeue', fontSize: 17} : {color: '#b0b0b0', fontFamily: 'HelveticaNeue', fontSize: 17,};
  46 + let rowWidth = width/dataSource.length;
  47 +
  48 + return (
  49 + <TouchableOpacity activeOpacity={1} onPress={() => {
  50 + if (isRowSelected) {
  51 + return;
  52 + }
  53 + this.props.onClickSort && this.props.onClickSort(rowID);
  54 + }}>
  55 + <View key={'row' + rowID} style={[styles.rowContainer, {width: rowWidth}]}>
  56 + <Text style={[styles.name, colorStyle]}>{rowData}</Text>
  57 + </View>
  58 + </TouchableOpacity>
  59 + );
  60 + }
  61 +
  62 + _renderSeparator(sectionID, rowID, adjacentRowHighlighted) {
  63 + return (
  64 + <View key={'sep' + rowID} style={styles.separator}>
  65 + </View>
  66 + );
  67 + }
  68 +
  69 + render() {
  70 + let {dataSource} = this.props;
  71 + dataSource = dataSource ? dataSource : [];
  72 + return (
  73 + <View style={styles.container}>
  74 + <ListView
  75 + contentContainerStyle={styles.contentContainer}
  76 + enableEmptySections={true}
  77 + dataSource={this.dataSource.cloneWithRows(dataSource)}
  78 + renderRow={this._renderRow}
  79 + renderSeparator={this._renderSeparator}
  80 + scrollEnabled={false}
  81 + scrollsToTop={false}
  82 + />
  83 + </View>
  84 + );
  85 + }
  86 +}
  87 +
  88 +let {width, height} = Dimensions.get('window');
  89 +
  90 +let viewHeight = 44;
  91 +
  92 +
  93 +let styles = StyleSheet.create({
  94 + container: {
  95 + width: width,
  96 + height: viewHeight,
  97 + borderTopColor: 'transparent',
  98 + borderBottomColor: '#e0e0e0',
  99 + borderBottomWidth: 0.5,
  100 + backgroundColor:'white',
  101 + },
  102 + contentContainer: {
  103 + flexDirection: 'row',
  104 + },
  105 + rowContainer: {
  106 + flexDirection: 'row',
  107 + justifyContent: 'center',
  108 + alignItems: 'center',
  109 + height: viewHeight,
  110 + backgroundColor:'white',
  111 + },
  112 + name: {
  113 + color: '#b0b0b0',
  114 + },
  115 + separator: {
  116 + width: 0.5,
  117 + top: 14,
  118 + height: 16,
  119 + backgroundColor: '#e0e0e0',
  120 + },
  121 +});
@@ -16,8 +16,9 @@ import ReactNative, { @@ -16,8 +16,9 @@ import ReactNative, {
16 } from 'react-native'; 16 } from 'react-native';
17 import Immutable, {Map} from 'immutable'; 17 import Immutable, {Map} from 'immutable';
18 import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator'; 18 import LoadMoreIndicator from '../../../common/components/LoadMoreIndicator';
  19 +import YH_SortView from '../../../common/components/YH_SortView';
19 import HeadTitleCell from '../cell/HeadTitleCell'; 20 import HeadTitleCell from '../cell/HeadTitleCell';
20 -import channelTransfer from '../../../common/utils/channelTransfer'; 21 +import floorParser from '../../utils/floorParser';
21 22
22 import Focus from '../floor/Focus'; 23 import Focus from '../floor/Focus';
23 import AppIconList from '../floor/AppIconList'; 24 import AppIconList from '../floor/AppIconList';
@@ -56,6 +57,7 @@ export default class Home extends Component { @@ -56,6 +57,7 @@ export default class Home extends Component {
56 this.trigggePullToRefresh = this.trigggePullToRefresh.bind(this); 57 this.trigggePullToRefresh = this.trigggePullToRefresh.bind(this);
57 this._floorCellRender = this._floorCellRender.bind(this); 58 this._floorCellRender = this._floorCellRender.bind(this);
58 this._currentChannelData = this._currentChannelData.bind(this); 59 this._currentChannelData = this._currentChannelData.bind(this);
  60 + this._renderSectionHeader = this._renderSectionHeader.bind(this);
59 61
60 this.dataSource = new ListView.DataSource({ 62 this.dataSource = new ListView.DataSource({
61 rowHasChanged: (r1, r2) => !Immutable.is(r1, r2), 63 rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
@@ -133,8 +135,19 @@ export default class Home extends Component { @@ -133,8 +135,19 @@ export default class Home extends Component {
133 ); 135 );
134 } 136 }
135 case 'lifeStyleFav': { 137 case 'lifeStyleFav': {
136 - return null;  
137 - } 138 + let paddingLeft = rowID % 2 == 1 ? rowMarginHorizontal*1.5 : rowMarginHorizontal*2;
  139 + let customStyle = {paddingLeft};
  140 + return (
  141 + <View style={[styles.product,]}>
  142 + <ProductListCell
  143 + style={[styles.listContainer, customStyle]}
  144 + key={'row' + rowID}
  145 + rowID={rowID}
  146 + data={rowData}
  147 + onPressProduct={this.props.onPressProductListProduct}
  148 + />
  149 + </View>
  150 + ); }
138 break; 151 break;
139 default: 152 default:
140 { 153 {
@@ -377,8 +390,10 @@ export default class Home extends Component { @@ -377,8 +390,10 @@ export default class Home extends Component {
377 390
378 _renderFooter() { 391 _renderFooter() {
379 let data = this._currentChannelData(); 392 let data = this._currentChannelData();
380 - let {isFetching, endReached, list} = data;  
381 - let isLoadingMore = !endReached && list.size != 0; 393 + let {isFetching, endReached, list, cached} = data;
  394 + let floorList = list.size > 0 ? list.toArray() : cached.get('list').toArray();
  395 + let isLoadingMore = !endReached && floorList.size != 0;
  396 +
382 return ( 397 return (
383 <LoadMoreIndicator 398 <LoadMoreIndicator
384 isVisible={isLoadingMore} 399 isVisible={isLoadingMore}
@@ -388,12 +403,17 @@ export default class Home extends Component { @@ -388,12 +403,17 @@ export default class Home extends Component {
388 } 403 }
389 404
390 _renderSectionHeader(sectionData, sectionID) { 405 _renderSectionHeader(sectionData, sectionID) {
391 - let floor = [];  
392 - if (sectionID == 'floor') {  
393 - floor = sectionData;  
394 - }  
395 if (sectionID == 'lifeStyleFav') { 406 if (sectionID == 'lifeStyleFav') {
396 - 407 + let data = this._currentChannelData();
  408 + let selectIndex = data.selectIndex;
  409 + selectIndex = parseInt(selectIndex);
  410 + return (
  411 + <YH_SortView
  412 + dataSource={['新品到着', '人气单品']}
  413 + onSelectdIndex={selectIndex}
  414 + onClickSort={this.props.onClickSort}
  415 + />
  416 + );
397 }else { 417 }else {
398 return null 418 return null
399 } 419 }
@@ -402,43 +422,8 @@ export default class Home extends Component { @@ -402,43 +422,8 @@ export default class Home extends Component {
402 render() { 422 render() {
403 let channel = this.props.channel; 423 let channel = this.props.channel;
404 let data = this._currentChannelData(); 424 let data = this._currentChannelData();
405 - let {list, cached, isFetching, isFirstLoad, endReached, favorite, bottomBanner, hotList, newList} = data;  
406 - let floorList = list.size > 0 ? list.toArray() : cached.get('list').toArray();  
407 - let dataSource = {};  
408 -  
409 - if (channel == 4) {  
410 - dataSource = {  
411 - floor: floorList,  
412 - lifeStyleFav:{  
413 - hotList,  
414 - newList  
415 - }  
416 - }  
417 - } else {  
418 - let favoriteList = favorite.get('list');  
419 - let bottomBannerList = bottomBanner.get('list');  
420 - if (favoriteList.size == 0) {  
421 - dataSource = {  
422 - floor: floorList,  
423 - }  
424 - }else {  
425 - if (favoriteList.size > 0 && endReached) {  
426 - dataSource = {  
427 - floor: floorList,  
428 - favoriteHeader: ['1'],  
429 - favorite: favoriteList.toArray(),  
430 - bottomBanner: [bottomBannerList],  
431 - footer: ['1']  
432 - }  
433 - }else {  
434 - dataSource = {  
435 - floor: floorList,  
436 - favoriteHeader: ['1'],  
437 - favorite: favoriteList.toArray()  
438 - }  
439 - }  
440 - }  
441 - } 425 + let {isFetching} = data;
  426 + let dataSource = floorParser.homeDataParse(data, channel);
442 427
443 let isPullToRefresh = isFetching; 428 let isPullToRefresh = isFetching;
444 429
@@ -9,7 +9,7 @@ export default keyMirror({ @@ -9,7 +9,7 @@ export default keyMirror({
9 9
10 HOME_RESET_STATE_WHEN_REFRESH: null, 10 HOME_RESET_STATE_WHEN_REFRESH: null,
11 HOME_FLOOR_DATA_HAS_NOT_CHANGE: null, 11 HOME_FLOOR_DATA_HAS_NOT_CHANGE: null,
12 - 12 +
13 LOAD_CHANNEL_CACHED_DATA: null, 13 LOAD_CHANNEL_CACHED_DATA: null,
14 14
15 HOME_FLOOR_REQUEST: null, 15 HOME_FLOOR_REQUEST: null,
@@ -28,6 +28,8 @@ export default keyMirror({ @@ -28,6 +28,8 @@ export default keyMirror({
28 HOME_LIFESTYLE_FAVORITE_SUCCESS: null, 28 HOME_LIFESTYLE_FAVORITE_SUCCESS: null,
29 HOME_LIFESTYLE_FAVORITE_FAILURE: null, 29 HOME_LIFESTYLE_FAVORITE_FAILURE: null,
30 30
  31 + HOME_LIFESTYLE_FAVORITE_SET_INDEX: null,
  32 +
31 HOME_SHOP_INFO_REQUEST: null, 33 HOME_SHOP_INFO_REQUEST: null,
32 HOME_SHOP_INFO_SUCCESS: null, 34 HOME_SHOP_INFO_SUCCESS: null,
33 HOME_SHOP_INFO_FAILURE: null, 35 HOME_SHOP_INFO_FAILURE: null,
@@ -68,6 +68,7 @@ class HomeContainer extends Component { @@ -68,6 +68,7 @@ class HomeContainer extends Component {
68 this.onPressShopRecommendItem = this.onPressShopRecommendItem.bind(this); 68 this.onPressShopRecommendItem = this.onPressShopRecommendItem.bind(this);
69 this.onPressShopFavorite = this.onPressShopFavorite.bind(this); 69 this.onPressShopFavorite = this.onPressShopFavorite.bind(this);
70 this.onPressTitleMore = this.onPressTitleMore.bind(this); 70 this.onPressTitleMore = this.onPressTitleMore.bind(this);
  71 + this.onClickSort = this.onClickSort.bind(this);
71 72
72 this.subscription = NativeAppEventEmitter.addListener( 73 this.subscription = NativeAppEventEmitter.addListener(
73 'ChannelDidChangeEvent', 74 'ChannelDidChangeEvent',
@@ -166,7 +167,7 @@ class HomeContainer extends Component { @@ -166,7 +167,7 @@ class HomeContainer extends Component {
166 } 167 }
167 168
168 onPressShopFavorite(shopId, index) { 169 onPressShopFavorite(shopId, index) {
169 - console.log(shopId) 170 +
170 } 171 }
171 172
172 onPressBrandItem(url, index) { 173 onPressBrandItem(url, index) {
@@ -186,6 +187,10 @@ class HomeContainer extends Component { @@ -186,6 +187,10 @@ class HomeContainer extends Component {
186 this.jumpWithUrl(url); 187 this.jumpWithUrl(url);
187 } 188 }
188 189
  190 + onClickSort(index) {
  191 + this.props.actions.selecLifeStyleProductIndex(index);
  192 + }
  193 +
189 render() { 194 render() {
190 let {app, home} = this.props; 195 let {app, home} = this.props;
191 return ( 196 return (
@@ -216,6 +221,7 @@ class HomeContainer extends Component { @@ -216,6 +221,7 @@ class HomeContainer extends Component {
216 onPressShopRecommendItem={this.onPressShopRecommendItem} 221 onPressShopRecommendItem={this.onPressShopRecommendItem}
217 onPressShopFavorite={this.onPressShopFavorite} 222 onPressShopFavorite={this.onPressShopFavorite}
218 onPressTitleMore={this.onPressTitleMore} 223 onPressTitleMore={this.onPressTitleMore}
  224 + onClickSort={this.onClickSort}
219 /> 225 />
220 </View> 226 </View>
221 ); 227 );
@@ -27,6 +27,8 @@ const { @@ -27,6 +27,8 @@ const {
27 HOME_LIFESTYLE_FAVORITE_SUCCESS, 27 HOME_LIFESTYLE_FAVORITE_SUCCESS,
28 HOME_LIFESTYLE_FAVORITE_FAILURE, 28 HOME_LIFESTYLE_FAVORITE_FAILURE,
29 29
  30 + HOME_LIFESTYLE_FAVORITE_SET_INDEX,
  31 +
30 HOME_SHOP_INFO_REQUEST, 32 HOME_SHOP_INFO_REQUEST,
31 HOME_SHOP_INFO_SUCCESS, 33 HOME_SHOP_INFO_SUCCESS,
32 HOME_SHOP_INFO_FAILURE, 34 HOME_SHOP_INFO_FAILURE,
@@ -156,7 +158,7 @@ export function fetchBoyGirlFavoriteList() { @@ -156,7 +158,7 @@ export function fetchBoyGirlFavoriteList() {
156 158
157 if (currentChannelData.favorite.isFetching 159 if (currentChannelData.favorite.isFetching
158 || currentChannelData.endReached 160 || currentChannelData.endReached
159 - || currentChannelData.list.size == 0) { 161 + || (currentChannelData.list.size == 0 && currentChannelData.cached.get('list').size == 0)) {
160 162
161 return; 163 return;
162 } 164 }
@@ -222,7 +224,7 @@ export function fetchKidsFavoriteList() { @@ -222,7 +224,7 @@ export function fetchKidsFavoriteList() {
222 let {kid} = home; 224 let {kid} = home;
223 if (kid.favorite.isFetching 225 if (kid.favorite.isFetching
224 || kid.endReached 226 || kid.endReached
225 - || kid.list.size == 0) { 227 + || (kid.list.size == 0 && kid.cached.get('list').size == 0)) {
226 228
227 return; 229 return;
228 } 230 }
@@ -236,7 +238,7 @@ export function fetchKidsFavoriteList() { @@ -236,7 +238,7 @@ export function fetchKidsFavoriteList() {
236 .then(json =>{ 238 .then(json =>{
237 let payload = floorParser.parseKidsFavorite(json); 239 let payload = floorParser.parseKidsFavorite(json);
238 if (payload.currentPage > 1) { 240 if (payload.currentPage > 1) {
239 - let oldList = kid.favorite.list.toJS(); 241 + let oldList = kid.favorite.get('list').toJS();
240 let newList = [...oldList, ...payload.list]; 242 let newList = [...oldList, ...payload.list];
241 payload.list = newList; 243 payload.list = newList;
242 } 244 }
@@ -275,8 +277,7 @@ function fetchLifeStyleFavoriteList(fromPage) { @@ -275,8 +277,7 @@ function fetchLifeStyleFavoriteList(fromPage) {
275 let {lifeStyle} = home; 277 let {lifeStyle} = home;
276 if (lifeStyle.isListFetching 278 if (lifeStyle.isListFetching
277 || lifeStyle.endReached 279 || lifeStyle.endReached
278 - || lifeStyle.list.size == 0) {  
279 - 280 + || (lifeStyle.list.size == 0 && lifeStyle.cached.get('list').size == 0)) {
280 return; 281 return;
281 } 282 }
282 283
@@ -308,6 +309,19 @@ function fetchLifeStyleFavoriteList(fromPage) { @@ -308,6 +309,19 @@ function fetchLifeStyleFavoriteList(fromPage) {
308 } 309 }
309 } 310 }
310 311
  312 +export function selecLifeStyleProductIndex(index) {
  313 + return (dispatch) => {
  314 + dispatch(selectLifeStyleIndex(index));
  315 + }
  316 +}
  317 +
  318 +function selectLifeStyleIndex(index) {
  319 + return {
  320 + type: HOME_LIFESTYLE_FAVORITE_SET_INDEX,
  321 + payload: index
  322 + }
  323 +}
  324 +
311 /** 325 /**
312 ** 男女频道底部banner 326 ** 男女频道底部banner
313 **/ 327 **/
@@ -60,6 +60,8 @@ let lifeStyle = new (Record({ @@ -60,6 +60,8 @@ let lifeStyle = new (Record({
60 listError: null, 60 listError: null,
61 hotList: List(), //创意生活频道 人气单品商品列表 61 hotList: List(), //创意生活频道 人气单品商品列表
62 newList: List(), //创意生活频道 新品到着商品列表 62 newList: List(), //创意生活频道 新品到着商品列表
  63 + selectIndex: 0,
  64 +
63 content_code: '', 65 content_code: '',
64 })); 66 }));
65 67
@@ -15,7 +15,7 @@ const { @@ -15,7 +15,7 @@ const {
15 HOME_FAVORITE_REQUEST, 15 HOME_FAVORITE_REQUEST,
16 HOME_FAVORITE_SUCCESS, 16 HOME_FAVORITE_SUCCESS,
17 HOME_FAVORITE_FAILURE, 17 HOME_FAVORITE_FAILURE,
18 - 18 +
19 HOME_KIDS_FAVORITE_REQUEST, 19 HOME_KIDS_FAVORITE_REQUEST,
20 HOME_KIDS_FAVORITE_SUCCESS, 20 HOME_KIDS_FAVORITE_SUCCESS,
21 HOME_KIDS_FAVORITE_FAILURE, 21 HOME_KIDS_FAVORITE_FAILURE,
@@ -24,6 +24,8 @@ const { @@ -24,6 +24,8 @@ const {
24 HOME_LIFESTYLE_FAVORITE_SUCCESS, 24 HOME_LIFESTYLE_FAVORITE_SUCCESS,
25 HOME_LIFESTYLE_FAVORITE_FAILURE, 25 HOME_LIFESTYLE_FAVORITE_FAILURE,
26 26
  27 + HOME_LIFESTYLE_FAVORITE_SET_INDEX,
  28 +
27 HOME_SHOP_INFO_REQUEST, 29 HOME_SHOP_INFO_REQUEST,
28 HOME_SHOP_INFO_SUCCESS, 30 HOME_SHOP_INFO_SUCCESS,
29 HOME_SHOP_INFO_FAILURE, 31 HOME_SHOP_INFO_FAILURE,
@@ -65,11 +67,13 @@ export default function homeReducer(state=initialState, action) { @@ -65,11 +67,13 @@ export default function homeReducer(state=initialState, action) {
65 *** 猜你喜欢列表 67 *** 猜你喜欢列表
66 *****************************/ 68 *****************************/
67 case HOME_FAVORITE_REQUEST: 69 case HOME_FAVORITE_REQUEST:
68 - case HOME_KIDS_FAVORITE_REQUEST:  
69 - case HOME_LIFESTYLE_FAVORITE_REQUEST:{ 70 + case HOME_KIDS_FAVORITE_REQUEST:{
70 let channelStr = action.payload; 71 let channelStr = action.payload;
71 return state.setIn([channelStr, 'favorite', 'isFetching'], true); 72 return state.setIn([channelStr, 'favorite', 'isFetching'], true);
72 } 73 }
  74 + case HOME_LIFESTYLE_FAVORITE_REQUEST:{
  75 + return state.setIn(['lifeStyle', 'isListFetching'], true);
  76 + }
73 case HOME_FAVORITE_SUCCESS: 77 case HOME_FAVORITE_SUCCESS:
74 case HOME_KIDS_FAVORITE_SUCCESS:{ 78 case HOME_KIDS_FAVORITE_SUCCESS:{
75 let {channelStr, json} = action.payload; 79 let {channelStr, json} = action.payload;
@@ -87,22 +91,24 @@ export default function homeReducer(state=initialState, action) { @@ -87,22 +91,24 @@ export default function homeReducer(state=initialState, action) {
87 .setIn([channelStr, 'favorite', 'error'], error); 91 .setIn([channelStr, 'favorite', 'error'], error);
88 } 92 }
89 93
90 - 94 +
91 case HOME_LIFESTYLE_FAVORITE_SUCCESS:{ 95 case HOME_LIFESTYLE_FAVORITE_SUCCESS:{
92 let {channelStr, json} = action.payload; 96 let {channelStr, json} = action.payload;
93 return state.setIn([channelStr, 'hotList'], Immutable.fromJS(json.hotList)) 97 return state.setIn([channelStr, 'hotList'], Immutable.fromJS(json.hotList))
94 .setIn([channelStr, 'newList'], Immutable.fromJS(json.newList)) 98 .setIn([channelStr, 'newList'], Immutable.fromJS(json.newList))
95 - .setIn([channelStr, 'isFetching'], false)  
96 - .setIn([channelStr, 'isFirstLoad'], false) 99 + .setIn([channelStr, 'isListFetching'], false)
97 .setIn([channelStr, 'endReached'], true); 100 .setIn([channelStr, 'endReached'], true);
98 } 101 }
99 - 102 +
100 case HOME_LIFESTYLE_FAVORITE_FAILURE:{ 103 case HOME_LIFESTYLE_FAVORITE_FAILURE:{
101 let {channelStr, error} = action.payload; 104 let {channelStr, error} = action.payload;
102 return state.setIn([channelStr, 'isFetching'], false) 105 return state.setIn([channelStr, 'isFetching'], false)
103 .setIn([channelStr, 'listError'], error); 106 .setIn([channelStr, 'listError'], error);
104 } 107 }
105 - 108 +
  109 + case HOME_LIFESTYLE_FAVORITE_SET_INDEX:{
  110 + return state.setIn(['lifeStyle', 'selectIndex'], action.payload);
  111 + }
106 112
107 /**************************** 113 /****************************
108 *** 底部banner 114 *** 底部banner
@@ -129,7 +135,7 @@ export default function homeReducer(state=initialState, action) { @@ -129,7 +135,7 @@ export default function homeReducer(state=initialState, action) {
129 let channelStr = action.payload; 135 let channelStr = action.payload;
130 return state.setIn([channelStr, 'shop', 'isFetching'], true); 136 return state.setIn([channelStr, 'shop', 'isFetching'], true);
131 } 137 }
132 - 138 +
133 case HOME_SHOP_INFO_SUCCESS:{ 139 case HOME_SHOP_INFO_SUCCESS:{
134 let {channelStr, json} = action.payload; 140 let {channelStr, json} = action.payload;
135 return state.setIn([channelStr, 'shop', 'isFetching'], false) 141 return state.setIn([channelStr, 'shop', 'isFetching'], false)
@@ -150,7 +156,7 @@ export default function homeReducer(state=initialState, action) { @@ -150,7 +156,7 @@ export default function homeReducer(state=initialState, action) {
150 .setIn([channelStr, 'cached', 'md5'], data.md5) 156 .setIn([channelStr, 'cached', 'md5'], data.md5)
151 .setIn([channelStr, 'cached', 'content_code'], data.content_code); 157 .setIn([channelStr, 'cached', 'content_code'], data.content_code);
152 } 158 }
153 - 159 +
154 case HOME_FLOOR_DATA_HAS_NOT_CHANGE:{ 160 case HOME_FLOOR_DATA_HAS_NOT_CHANGE:{
155 let channelStr = action.payload; 161 let channelStr = action.payload;
156 return state.setIn([channelStr, 'isFetching'], false); 162 return state.setIn([channelStr, 'isFetching'], false);
1 'use strict'; 1 'use strict';
2 2
  3 +function homeDataParse(data, channel) {
  4 + let {list, cached, isFetching, isFirstLoad, endReached, favorite, bottomBanner, hotList, newList, selectIndex} = data;
  5 + let floorList = list.size > 0 ? list.toArray() : cached.get('list').toArray();
  6 + let dataSource = {};
  7 + if (channel == '4') {
  8 + let favlist = selectIndex == 0 ? newList : hotList;
  9 + if (endReached) {
  10 + dataSource = {
  11 + floor: floorList,
  12 + lifeStyleFav:favlist.toArray(),
  13 + footer: ['1']
  14 + }
  15 + }else {
  16 + dataSource = {
  17 + floor: floorList,
  18 + }
  19 + }
  20 + } else {
  21 + let favoriteList = favorite.get('list');
  22 + let bottomBannerList = bottomBanner.get('list');
  23 + if (favoriteList.size == 0) {
  24 + dataSource = {
  25 + floor: floorList,
  26 + }
  27 + }else {
  28 + if (favoriteList.size > 0 && endReached) {
  29 + dataSource = {
  30 + floor: floorList,
  31 + favoriteHeader: ['1'],
  32 + favorite: favoriteList.toArray(),
  33 + bottomBanner: [bottomBannerList],
  34 + footer: ['1']
  35 + }
  36 + if (channel == 3) {
  37 + dataSource = {
  38 + floor: floorList,
  39 + favoriteHeader: ['1'],
  40 + favorite: favoriteList.toArray(),
  41 + footer: ['1']
  42 + }
  43 + }
  44 + }else {
  45 + dataSource = {
  46 + floor: floorList,
  47 + favoriteHeader: ['1'],
  48 + favorite: favoriteList.toArray()
  49 + }
  50 + }
  51 + }
  52 + }
  53 +
  54 + return dataSource;
  55 +}
  56 +
3 function channelCacheKey(channelKey) { 57 function channelCacheKey(channelKey) {
4 return 'YH_RNCacheTypeHomeChannel' + channelKey; 58 return 'YH_RNCacheTypeHomeChannel' + channelKey;
5 } 59 }
@@ -75,6 +129,7 @@ function parseShopInfo(json) { @@ -75,6 +129,7 @@ function parseShopInfo(json) {
75 } 129 }
76 130
77 module.exports = { 131 module.exports = {
  132 + homeDataParse,
78 channelCacheKey, 133 channelCacheKey,
79 parseHomeFloor, 134 parseHomeFloor,
80 parseBoyGirlFavorite, 135 parseBoyGirlFavorite,