Authored by 叶弯弯

消息列表接口调试。reviewed by shixiang。

@@ -24,6 +24,9 @@ export default keyMirror({ @@ -24,6 +24,9 @@ export default keyMirror({
24 PWD_MODIFY_SUBMIT:null, 24 PWD_MODIFY_SUBMIT:null,
25 25
26 MESSAGE_DETAIL:null, 26 MESSAGE_DETAIL:null,
  27 + REQUEST_MSG_LIST: null,
  28 + REQUEST_MSG_LIST_SUCCESS: null,
  29 + REQUEST_MSG_LIST_FAILURE: null,
27 30
28 LOGIN_REQUEST: null, 31 LOGIN_REQUEST: null,
29 LOGIN_SUCCESS: null, 32 LOGIN_SUCCESS: null,
@@ -49,56 +49,16 @@ class MessageContainer extends Component { @@ -49,56 +49,16 @@ class MessageContainer extends Component {
49 constructor(props) { 49 constructor(props) {
50 super(props); 50 super(props);
51 this.pressRow = this.pressRow.bind(this); 51 this.pressRow = this.pressRow.bind(this);
52 - this.messageItems = [  
53 - {  
54 - type:'1',  
55 - title: '公告 商家端APP上线',  
56 - time: '2016-03-26',  
57 - content: 'xxxxxxx',  
58 - },  
59 - {  
60 - type:'2',  
61 - title: '变价通知 昨日已有234件商品价格发生变化',  
62 - time: '2016-03-26',  
63 - content: 'xxxxxx',  
64 - },  
65 - {  
66 - type:'3',  
67 - title: '到货入库 有800件商品到货了',  
68 - time: '2016-03-26',  
69 - content: 'xxxxxsssssssssssssssssssssssffsssgsggsgsgsgsgsgsgsgsgsgsggsgsgssshahshshshshshshshshhshshshshshshshshshshshshshhshshshshsh',  
70 - },  
71 - {  
72 - type:'4',  
73 - title: '对账结算 新的结算订单生成',  
74 - time: '2016-03-26',  
75 - content: 'xxxxxx',  
76 - },  
77 - {  
78 - type:'4',  
79 - title: '对账结算 新的结算订单生成',  
80 - time: '2016-03-26',  
81 - content: 'xxxxxx',  
82 - },  
83 - {  
84 - type:'4',  
85 - title: '对账结算 新的结算订单生成',  
86 - time: '2016-03-26',  
87 - content: 'xxxxxx',  
88 - },  
89 - {  
90 - type:'4',  
91 - title: '对账结算 新的结算订单生成',  
92 - time: '2016-03-26',  
93 - content: 'xxxxxx',  
94 - },  
95 - ]; 52 + }
  53 +
  54 + componentDidMount() {
  55 + this.props.actions.getMsgList(this.props.home.brandId);
96 } 56 }
97 57
98 pressRow(rowID){ 58 pressRow(rowID){
99 - this.props.actions.checkMessageDetail(this.messageItems[rowID]); 59 + this.props.actions.checkMessageDetail(this.props.message.messageList.toJS()[rowID]);
100 } 60 }
101 - 61 +
102 render() { 62 render() {
103 return ( 63 return (
104 <View style={styles.container}> 64 <View style={styles.container}>
@@ -107,7 +67,7 @@ class MessageContainer extends Component { @@ -107,7 +67,7 @@ class MessageContainer extends Component {
107 barStyle={'light-content'} 67 barStyle={'light-content'}
108 /> 68 />
109 <Message 69 <Message
110 - items={this.messageItems} 70 + items={this.props.message.messageList.toJS()}
111 onPressItem={this.pressRow} 71 onPressItem={this.pressRow}
112 /> 72 />
113 </View> 73 </View>
@@ -7,11 +7,13 @@ @@ -7,11 +7,13 @@
7 'use strict'; 7 'use strict';
8 8
9 import {Actions} from 'react-native-router-flux'; 9 import {Actions} from 'react-native-router-flux';
10 -import AppAuthToken from '../../services/AppAuthToken';  
11 -import UserService from '../../services/UserService'; 10 +import MessageService from '../../services/MessageService';
12 11
13 const { 12 const {
14 MESSAGE_DETAIL, 13 MESSAGE_DETAIL,
  14 + REQUEST_MSG_LIST,
  15 + REQUEST_MSG_LIST_SUCCESS,
  16 + REQUEST_MSG_LIST_FAILURE,
15 } = require('../../constants/actionTypes').default; 17 } = require('../../constants/actionTypes').default;
16 18
17 export function checkMessageDetail(item) { 19 export function checkMessageDetail(item) {
@@ -20,4 +22,38 @@ export function checkMessageDetail(item) { @@ -20,4 +22,38 @@ export function checkMessageDetail(item) {
20 type: MESSAGE_DETAIL, 22 type: MESSAGE_DETAIL,
21 payload: item, 23 payload: item,
22 }; 24 };
23 -}  
  25 +}
  26 +
  27 +export function requestMsgList(shopsId) {
  28 + return {
  29 + type: REQUEST_MSG_LIST,
  30 + payload: shopsId,
  31 + }
  32 +}
  33 +
  34 +export function requestMsgListSuccess(json) {
  35 + return {
  36 + type: REQUEST_MSG_LIST_SUCCESS,
  37 + payload: json,
  38 + }
  39 +}
  40 +
  41 +export function requestMsgListFailure(error) {
  42 + return {
  43 + type: REQUEST_MSG_LIST_FAILURE,
  44 + payload: error,
  45 + }
  46 +}
  47 +
  48 +export function getMsgList(shopsId) {
  49 + return dispatch => {
  50 + dispatch(requestMsgList(shopsId));
  51 + return new MessageService().getMsgList(shopsId)
  52 + .then(json => {
  53 + dispatch(requestMsgListSuccess(json));
  54 + })
  55 + .catch(error => {
  56 + dispatch(requestMsgListFailure(error));
  57 + });
  58 + };
  59 +}
1 /** 1 /**
2 * # guideInitialState.js 2 * # guideInitialState.js
3 - * 3 + *
4 * 4 *
5 */ 5 */
6 'use strict'; 6 'use strict';
7 /** 7 /**
8 * ## Import immutable record 8 * ## Import immutable record
9 */ 9 */
10 -import {Record} from 'immutable'; 10 +import {Record, List} from 'immutable';
11 11
12 /** 12 /**
13 * ## InitialState 13 * ## InitialState
14 - * 14 + *
15 * The fields we're concerned with 15 * The fields we're concerned with
16 */ 16 */
17 let InitialState = Record({ 17 let InitialState = Record({
  18 + isFetching: false,
  19 + error: null,
18 messageDetail: new (Record({ 20 messageDetail: new (Record({
19 title: '', 21 title: '',
20 content: '', 22 content: '',
21 time: '', 23 time: '',
22 })), 24 })),
  25 + messageList: List(),
23 }); 26 });
24 27
25 export default InitialState; 28 export default InitialState;
@@ -10,12 +10,15 @@ @@ -10,12 +10,15 @@
10 * InitialState 10 * InitialState
11 */ 11 */
12 import InitialState from './messageInitialState'; 12 import InitialState from './messageInitialState';
13 - 13 +import Immutable, {List, Record} from 'immutable';
14 14
15 15
16 const initialState = new InitialState; 16 const initialState = new InitialState;
17 const { 17 const {
18 MESSAGE_DETAIL, 18 MESSAGE_DETAIL,
  19 + REQUEST_MSG_LIST,
  20 + REQUEST_MSG_LIST_SUCCESS,
  21 + REQUEST_MSG_LIST_FAILURE,
19 } = require('../../constants/actionTypes').default; 22 } = require('../../constants/actionTypes').default;
20 /** 23 /**
21 * ## guideReducer function 24 * ## guideReducer function
@@ -29,9 +32,24 @@ export default function messageReducer(state = initialState, action) { @@ -29,9 +32,24 @@ export default function messageReducer(state = initialState, action) {
29 case MESSAGE_DETAIL:{ 32 case MESSAGE_DETAIL:{
30 let nextState = state.setIn(['messageDetail', 'title'], action.payload.title) 33 let nextState = state.setIn(['messageDetail', 'title'], action.payload.title)
31 .setIn(['messageDetail', 'content'], action.payload.content) 34 .setIn(['messageDetail', 'content'], action.payload.content)
32 - .setIn(['messageDetail', 'time'], action.payload.time); 35 + .setIn(['messageDetail', 'time'], action.payload.createTime);
33 return nextState; 36 return nextState;
34 } 37 }
  38 + case REQUEST_MSG_LIST: {
  39 + let nextState = state.set('isFetching', true)
  40 + .set('error', null);
  41 + return nextState;
  42 + }
  43 + case REQUEST_MSG_LIST_SUCCESS: {
  44 + let nextState = state.set('isFetching', false)
  45 + .set('error', null)
  46 + .set('messageList', Immutable.fromJS(action.payload.list));
  47 + return nextState;
  48 + }
  49 + case REQUEST_MSG_LIST_FAILURE: {
  50 + return state.set('isFetching', false)
  51 + .set('error', action.payload);
  52 + }
35 53
36 } 54 }
37 55
  1 +'use strict';
  2 +
  3 +import Request from './Request';
  4 +
  5 +export default class MessageService {
  6 +
  7 + constructor () {
  8 + this.api = new Request();
  9 + }
  10 +
  11 + async getMsgList(shopsId) {
  12 + return this.api.get({
  13 + url: '/gateway',
  14 + body: {
  15 + shopsId: shopsId,
  16 + method: 'app.shopInbox.getList',
  17 + debug: 'XYZ',
  18 + }
  19 + })
  20 + .then(json => {
  21 + return json;
  22 + })
  23 + .catch(error => {
  24 + throw error;
  25 + });
  26 + }
  27 +}