Authored by 孙凯

添加 奥莱 频道切换 review by zhanglixia

@@ -34,9 +34,12 @@ export default class Outlet extends Component { @@ -34,9 +34,12 @@ export default class Outlet extends Component {
34 34
35 let list = categoryList.get('list').toArray(); 35 let list = categoryList.get('list').toArray();
36 let isFetching = categoryList.get('isFetching'); 36 let isFetching = categoryList.get('isFetching');
  37 + let initialPage = categoryList.get('initialPage');
  38 +
37 return ( 39 return (
38 <View style={styles.container}> 40 <View style={styles.container}>
39 {!isFetching?<ScrollableTabView 41 {!isFetching?<ScrollableTabView
  42 + initialPage={initialPage}
40 renderTabBar={() => <OutletSrollableBar />} 43 renderTabBar={() => <OutletSrollableBar />}
41 > 44 >
42 {list.map((item, i) => { 45 {list.map((item, i) => {
@@ -5,6 +5,7 @@ export default keyMirror({ @@ -5,6 +5,7 @@ export default keyMirror({
5 SET_PLATFORM: null, 5 SET_PLATFORM: null,
6 SET_HOST: null, 6 SET_HOST: null,
7 SET_CHANNEL: null, 7 SET_CHANNEL: null,
  8 + SET_YH_CHANNEL: null,
8 SET_SERVICE_HOST: null, 9 SET_SERVICE_HOST: null,
9 SET_CATEGORYID: null, 10 SET_CATEGORYID: null,
10 HIDE_TOAST: null, 11 HIDE_TOAST: null,
@@ -49,6 +49,13 @@ class OutletContainer extends Component { @@ -49,6 +49,13 @@ class OutletContainer extends Component {
49 this._setActivityFliter = this._setActivityFliter.bind(this); 49 this._setActivityFliter = this._setActivityFliter.bind(this);
50 this._showToast = this._showToast.bind(this); 50 this._showToast = this._showToast.bind(this);
51 this._hideToastMessage = this._hideToastMessage.bind(this); 51 this._hideToastMessage = this._hideToastMessage.bind(this);
  52 + this._onSelectChannel = this._onSelectChannel.bind(this);
  53 + this.subscription = NativeAppEventEmitter.addListener(
  54 + 'ChannelDidChangeEvent',
  55 + (reminder) => {
  56 + this._onSelectChannel(reminder.channel);
  57 + }
  58 + );
52 } 59 }
53 60
54 componentDidMount() { 61 componentDidMount() {
@@ -56,7 +63,11 @@ class OutletContainer extends Component { @@ -56,7 +63,11 @@ class OutletContainer extends Component {
56 } 63 }
57 64
58 componentWillUnmount() { 65 componentWillUnmount() {
  66 + this.subscription && this.subscription.remove();
  67 + }
59 68
  69 + _onSelectChannel(channel){
  70 + this.props.actions.setChannel(channel);
60 } 71 }
61 72
62 _onEndReached(content_code,categoryNavigationItem) { 73 _onEndReached(content_code,categoryNavigationItem) {
@@ -9,7 +9,7 @@ const { @@ -9,7 +9,7 @@ const {
9 SET_PLATFORM, 9 SET_PLATFORM,
10 10
11 SET_ACTIVITY_FLITER, 11 SET_ACTIVITY_FLITER,
12 - 12 + SET_YH_CHANNEL,
13 SET_FLITER, 13 SET_FLITER,
14 SHOW_TOAST, 14 SHOW_TOAST,
15 HIDE_TOAST, 15 HIDE_TOAST,
@@ -38,6 +38,13 @@ export function onPressCoupon() { @@ -38,6 +38,13 @@ export function onPressCoupon() {
38 }; 38 };
39 } 39 }
40 40
  41 +export function setChannel(channel) {
  42 + return {
  43 + type: SET_YH_CHANNEL,
  44 + payload: channel
  45 + };
  46 +}
  47 +
41 export function getCategoryRequest() { 48 export function getCategoryRequest() {
42 return { 49 return {
43 type: GET_CATEGORY_REQUEST, 50 type: GET_CATEGORY_REQUEST,
@@ -62,10 +69,11 @@ export function getCategory() { @@ -62,10 +69,11 @@ export function getCategory() {
62 return (dispatch, getState) => { 69 return (dispatch, getState) => {
63 let {app, outlet} = getState(); 70 let {app, outlet} = getState();
64 let parent_id = app.categoryId; 71 let parent_id = app.categoryId;
  72 + let channel = outlet.channel;
65 dispatch(getCategoryRequest()); 73 dispatch(getCategoryRequest());
66 return new OutletService(app.serviceHost).getCategory(parent_id) 74 return new OutletService(app.serviceHost).getCategory(parent_id)
67 .then(json => { 75 .then(json => {
68 - let params = parseListFromCategory(json); 76 + let params = parseListFromCategory(channel,json);
69 dispatch(getCategorySuccess(params)); 77 dispatch(getCategorySuccess(params));
70 }) 78 })
71 .catch(error => { 79 .catch(error => {
@@ -74,8 +82,8 @@ export function getCategory() { @@ -74,8 +82,8 @@ export function getCategory() {
74 }; 82 };
75 } 83 }
76 84
77 -function parseListFromCategory(json) {  
78 - 85 +function parseListFromCategory(channel,json) {
  86 + let initialPage = 0;
79 json.map((item, i) => { 87 json.map((item, i) => {
80 let url = item.sort_url; 88 let url = item.sort_url;
81 let content_code = GetQueryString(url,'content_code'); 89 let content_code = GetQueryString(url,'content_code');
@@ -87,8 +95,15 @@ function parseListFromCategory(json) { @@ -87,8 +95,15 @@ function parseListFromCategory(json) {
87 item.content_code = content_code; 95 item.content_code = content_code;
88 item.type = type?type:0; 96 item.type = type?type:0;
89 item.yh_channel=yh_channel?yh_channel:0; 97 item.yh_channel=yh_channel?yh_channel:0;
  98 + if (yh_channel == channel) {
  99 + initialPage = i;
  100 + }
90 }) 101 })
91 - return json; 102 +
  103 + return {
  104 + json,
  105 + initialPage,
  106 + };
92 } 107 }
93 108
94 export function getOutletHomeResourceRequest(content_code) { 109 export function getOutletHomeResourceRequest(content_code) {
@@ -7,10 +7,12 @@ let InitialState = Record({ @@ -7,10 +7,12 @@ let InitialState = Record({
7 categoryList: new (Record({ 7 categoryList: new (Record({
8 isFetching: false, 8 isFetching: false,
9 error: null, 9 error: null,
  10 + initialPage: 0,
10 list: List(), 11 list: List(),
11 })), 12 })),
12 isShowToast: false, 13 isShowToast: false,
13 toastMessage: '', 14 toastMessage: '',
  15 + channel: 1, // 1 - boy, 2 - girl, 3 - kid, 4 - lifestyle, 5 - yoho
14 }); 16 });
15 17
16 export default InitialState; 18 export default InitialState;
@@ -8,6 +8,7 @@ const { @@ -8,6 +8,7 @@ const {
8 SET_FLITER, 8 SET_FLITER,
9 SHOW_TOAST, 9 SHOW_TOAST,
10 HIDE_TOAST, 10 HIDE_TOAST,
  11 + SET_YH_CHANNEL,
11 GET_CATEGORY_REQUEST, 12 GET_CATEGORY_REQUEST,
12 GET_CATEGORY_SUCCESS, 13 GET_CATEGORY_SUCCESS,
13 GET_CATEGORY_FAILURE, 14 GET_CATEGORY_FAILURE,
@@ -30,13 +31,16 @@ const initialState = new InitialState; @@ -30,13 +31,16 @@ const initialState = new InitialState;
30 31
31 export default function outletReducer(state=initialState, action) { 32 export default function outletReducer(state=initialState, action) {
32 switch(action.type) { 33 switch(action.type) {
33 - 34 + case SET_YH_CHANNEL: {
  35 + return state.set('channel', action.payload);
  36 + }
34 case GET_CATEGORY_REQUEST: { 37 case GET_CATEGORY_REQUEST: {
35 return state.setIn(['categoryList', 'isFetching'], true); 38 return state.setIn(['categoryList', 'isFetching'], true);
36 } 39 }
37 case GET_CATEGORY_SUCCESS: { 40 case GET_CATEGORY_SUCCESS: {
38 - return state.setIn(['categoryList', 'list'], Immutable.fromJS(action.payload))  
39 - .setIn(['categoryList', 'isFetching'], false); 41 + return state.setIn(['categoryList', 'list'], Immutable.fromJS(action.payload.json))
  42 + .setIn(['categoryList', 'isFetching'], false)
  43 + .setIn(['categoryList', 'initialPage'], action.payload.initialPage);
40 } 44 }
41 case GET_CATEGORY_FAILURE: { 45 case GET_CATEGORY_FAILURE: {
42 return state.setIn(['categoryList', 'isFetching'], false) 46 return state.setIn(['categoryList', 'isFetching'], false)