对账结算接口修改 review by yewanwan
Showing
6 changed files
with
58 additions
and
81 deletions
1 | 'use strict'; | 1 | 'use strict'; |
2 | import Immutable, {List, Record} from 'immutable'; | 2 | import Immutable, {List, Record} from 'immutable'; |
3 | -import LoadMoreIndicator from './indicator/LoadMoreIndicator' | 3 | +import LoadingIndicator from './indicator/LoadingIndicator'; |
4 | import React, {Component} from 'react'; | 4 | import React, {Component} from 'react'; |
5 | import moment from 'moment'; | 5 | import moment from 'moment'; |
6 | 6 | ||
@@ -30,9 +30,8 @@ export default class AccountSettlement extends Component { | @@ -30,9 +30,8 @@ export default class AccountSettlement extends Component { | ||
30 | this.renderRow = this.renderRow.bind(this); | 30 | this.renderRow = this.renderRow.bind(this); |
31 | } | 31 | } |
32 | 32 | ||
33 | - renderRow(rowData,sectionId) { | 33 | + renderRow(rowData, sectionId) { |
34 | switch (sectionId) { | 34 | switch (sectionId) { |
35 | - | ||
36 | case 'SECTION_HEADER': | 35 | case 'SECTION_HEADER': |
37 | return ( | 36 | return ( |
38 | <View style={styles.headerContainer}> | 37 | <View style={styles.headerContainer}> |
@@ -86,35 +85,22 @@ export default class AccountSettlement extends Component { | @@ -86,35 +85,22 @@ export default class AccountSettlement extends Component { | ||
86 | </View> | 85 | </View> |
87 | ); | 86 | ); |
88 | } | 87 | } |
89 | - | ||
90 | - return (<Text>Error data source</Text>); | ||
91 | } | 88 | } |
92 | 89 | ||
93 | render() { | 90 | render() { |
94 | 91 | ||
95 | - let isFetching = this.props.isFetching; | ||
96 | - | ||
97 | - let loadText = '暂无更多数据'; | ||
98 | - if (!this.props.reachEnd) { | ||
99 | - loadText = isFetching?'正在加载...':'上拉加载更多'; | ||
100 | - } | 92 | + let {isFetching, dataBlob} = this.props; |
101 | 93 | ||
102 | return ( | 94 | return ( |
103 | - <View> | 95 | + <View style={styles.container}> |
104 | <ListView | 96 | <ListView |
105 | - style={styles.container} | ||
106 | - dataSource={this.dataSource.cloneWithRowsAndSections(this.props.dataBlob.toJS())} | 97 | + dataSource={this.dataSource.cloneWithRowsAndSections(dataBlob.toJS())} |
107 | renderRow={this.renderRow} | 98 | renderRow={this.renderRow} |
108 | - onEndReachedThreshold={-50} | ||
109 | - onEndReached={this.props.fetchNextPage} | ||
110 | enableEmptySections={true} | 99 | enableEmptySections={true} |
111 | - renderFooter={()=>{ | ||
112 | - return <LoadMoreIndicator | ||
113 | - hidden={this.props.hideLoadingFooter} | ||
114 | - loadingText={loadText} | ||
115 | - animating={isFetching} | ||
116 | - /> | ||
117 | - }} | 100 | + /> |
101 | + | ||
102 | + <LoadingIndicator | ||
103 | + isVisible={isFetching} | ||
118 | /> | 104 | /> |
119 | </View> | 105 | </View> |
120 | ); | 106 | ); |
@@ -159,9 +145,7 @@ const styles = StyleSheet.create({ | @@ -159,9 +145,7 @@ const styles = StyleSheet.create({ | ||
159 | }, | 145 | }, |
160 | 146 | ||
161 | container: { | 147 | container: { |
162 | - top: navbarHeight, | ||
163 | flex:1, | 148 | flex:1, |
164 | - height: Dimensions.get('window').height-navbarHeight, | ||
165 | }, | 149 | }, |
166 | 150 | ||
167 | headerContainer: { | 151 | headerContainer: { |
@@ -7,10 +7,10 @@ import Immutable, {List, Record} from 'immutable'; | @@ -7,10 +7,10 @@ import Immutable, {List, Record} from 'immutable'; | ||
7 | import AccountSettlement from '../components/AccountSettlement' | 7 | import AccountSettlement from '../components/AccountSettlement' |
8 | 8 | ||
9 | import { | 9 | import { |
10 | - StyleSheet, | ||
11 | View, | 10 | View, |
12 | - Text, | ||
13 | - ListView, | 11 | + StyleSheet, |
12 | + Dimensions, | ||
13 | + Platform | ||
14 | } | 14 | } |
15 | from 'react-native'; | 15 | from 'react-native'; |
16 | 16 | ||
@@ -48,41 +48,45 @@ export default class AccountSettlementContainer extends Component { | @@ -48,41 +48,45 @@ export default class AccountSettlementContainer extends Component { | ||
48 | 48 | ||
49 | constructor(props) { | 49 | constructor(props) { |
50 | super(props); | 50 | super(props); |
51 | - this.fetchNextPage = this.fetchNextPage.bind(this); | 51 | + |
52 | } | 52 | } |
53 | 53 | ||
54 | componentDidMount() { | 54 | componentDidMount() { |
55 | - this.fetchNextPage(); | 55 | + this.props.actions.nextPageOfDataRequest(); |
56 | } | 56 | } |
57 | 57 | ||
58 | - fetchNextPage() { | ||
59 | - let params = { | ||
60 | - page: this.props.actStmt.currentPage+1, | ||
61 | - size: 20, | ||
62 | - shopId: this.props.home.get('shopId'), | ||
63 | - } | ||
64 | - this.props.actions.nextPageOfDataRequest(params); | ||
65 | - } | ||
66 | render() { | 58 | render() { |
59 | + let {actStmt} = this.props; | ||
60 | + | ||
67 | let dataBlob = { | 61 | let dataBlob = { |
68 | - 'SECTION_HEADER':[{title:'累计结算金额(元)',content:`${this.props.actStmt.sum}`}], | ||
69 | - 'SECTION_SEPORATOR':[{}], | ||
70 | - 'SECTION_TITLE':[{}], | ||
71 | - 'SECTION_CONTENT':this.props.actStmt.jsonData, | 62 | + 'SECTION_HEADER': [{title:'累计结算金额(元)',content:`${actStmt.sum}`}], |
63 | + 'SECTION_SEPORATOR': [{}], | ||
64 | + 'SECTION_TITLE': [{}], | ||
65 | + 'SECTION_CONTENT': actStmt.list, | ||
72 | }; | 66 | }; |
67 | + | ||
73 | let mapBlob = Immutable.fromJS(dataBlob); | 68 | let mapBlob = Immutable.fromJS(dataBlob); |
74 | - let end = this.props.actStmt.currentPage>=this.props.actStmt.pageCount; | ||
75 | 69 | ||
76 | return ( | 70 | return ( |
77 | - <AccountSettlement | ||
78 | - dataBlob={mapBlob} | ||
79 | - fetchNextPage={this.fetchNextPage} | ||
80 | - isFetching={this.props.actStmt.isFetching} | ||
81 | - hideLoadingFooter={this.props.actStmt.currentPage<1} | ||
82 | - reachEnd={end} | ||
83 | - /> | ||
84 | - | 71 | + <View style={styles.container}> |
72 | + <AccountSettlement | ||
73 | + dataBlob={mapBlob} | ||
74 | + isFetching={actStmt.isFetching} | ||
75 | + /> | ||
76 | + </View> | ||
85 | ); | 77 | ); |
86 | } | 78 | } |
87 | } | 79 | } |
80 | + | ||
81 | +let {width, height} = Dimensions.get('window'); | ||
82 | +let navbarHeight = (Platform.OS === 'android') ? 50 : 64; | ||
83 | + | ||
84 | +let styles = StyleSheet.create({ | ||
85 | + container: { | ||
86 | + top: navbarHeight, | ||
87 | + height: height - navbarHeight, | ||
88 | + }, | ||
89 | + | ||
90 | +}); | ||
91 | + | ||
88 | export default connect(mapStateToProps, mapDispatchToProps)(AccountSettlementContainer); | 92 | export default connect(mapStateToProps, mapDispatchToProps)(AccountSettlementContainer); |
@@ -40,24 +40,20 @@ export function nextPageOfDataFailure(error) { | @@ -40,24 +40,20 @@ export function nextPageOfDataFailure(error) { | ||
40 | * @method nextPageOfDataRequest | 40 | * @method nextPageOfDataRequest |
41 | * @return {JS Objecrt} | 41 | * @return {JS Objecrt} |
42 | */ | 42 | */ |
43 | -export function nextPageOfDataRequest(params) { | 43 | +export function nextPageOfDataRequest() { |
44 | 44 | ||
45 | return (dispatch,getState) => { | 45 | return (dispatch,getState) => { |
46 | - const {actStmt} = getState(); | ||
47 | - | ||
48 | - if (actStmt.currentPage >= actStmt.pageCount || actStmt.isFetching) {//Last page reached.... | ||
49 | - return; | ||
50 | - } | 46 | + const {home, actStmt} = getState(); |
51 | 47 | ||
52 | dispatch(requestNextPage()); | 48 | dispatch(requestNextPage()); |
53 | 49 | ||
54 | - return new HomeService().accountSettlementData(params) | ||
55 | - .then(json => { | ||
56 | - dispatch(nextPageOfDataSuccess(json)); | ||
57 | - }) | ||
58 | - .catch(error => { | ||
59 | - dispatch(nextPageOfDataFailure(error)); | ||
60 | - }) | 50 | + return new HomeService().accountSettlementData(home.shopId) |
51 | + .then(json => { | ||
52 | + dispatch(nextPageOfDataSuccess(json)); | ||
53 | + }) | ||
54 | + .catch(error => { | ||
55 | + dispatch(nextPageOfDataFailure(error)); | ||
56 | + }) | ||
61 | }; | 57 | }; |
62 | 58 | ||
63 | } | 59 | } |
@@ -5,10 +5,8 @@ import {List, Record} from 'immutable'; | @@ -5,10 +5,8 @@ import {List, Record} from 'immutable'; | ||
5 | let InitialState = Record({ | 5 | let InitialState = Record({ |
6 | error: null, | 6 | error: null, |
7 | isFetching: false, | 7 | isFetching: false, |
8 | - pageCount: 1, | ||
9 | - currentPage:0, | ||
10 | - sum:'0.00', | ||
11 | - jsonData:List(), | 8 | + sum: '0.00', |
9 | + list: List(), | ||
12 | }); | 10 | }); |
13 | 11 | ||
14 | export default InitialState; | 12 | export default InitialState; |
@@ -19,27 +19,22 @@ export default function messageReducer(state = initialState, action) { | @@ -19,27 +19,22 @@ export default function messageReducer(state = initialState, action) { | ||
19 | switch (action.type) { | 19 | switch (action.type) { |
20 | case ACCOUNT_LIST_REQUEST: { | 20 | case ACCOUNT_LIST_REQUEST: { |
21 | let nextState = state.set('isFetching', true) | 21 | let nextState = state.set('isFetching', true) |
22 | - .set('error', null); | 22 | + .set('error', null); |
23 | return nextState; | 23 | return nextState; |
24 | } | 24 | } |
25 | break; | 25 | break; |
26 | case ACCOUNT_LIST_SUCCESS: { | 26 | case ACCOUNT_LIST_SUCCESS: { |
27 | - const {jsonData} = state; | ||
28 | - let origin = jsonData.toJS(); | ||
29 | - let {additionInfo, list} = action.payload; | ||
30 | - let data = [...origin, ...(list || [])]; | ||
31 | - | 27 | + let {totalAmount, list} = action.payload; |
32 | let nextState = state.set('isFetching', false) | 28 | let nextState = state.set('isFetching', false) |
33 | - .set('pageCount', action.payload.totalPage) | ||
34 | - .set('currentPage', action.payload.page) | ||
35 | - .set('sum', additionInfo.allAmount) | ||
36 | - .set('jsonData', Immutable.fromJS(data)); | 29 | + .set('error', null) |
30 | + .set('sum', totalAmount || '0.00') | ||
31 | + .set('list', Immutable.fromJS(list || [])); | ||
37 | return nextState; | 32 | return nextState; |
38 | } | 33 | } |
39 | break; | 34 | break; |
40 | case ACCOUNT_LIST_FAILURE: { | 35 | case ACCOUNT_LIST_FAILURE: { |
41 | let nextState = state.set('isFetching', false) | 36 | let nextState = state.set('isFetching', false) |
42 | - .set('error', action.playload); | 37 | + .set('error', action.playload); |
43 | return nextState; | 38 | return nextState; |
44 | } | 39 | } |
45 | break; | 40 | break; |
@@ -45,12 +45,12 @@ export default class UserService { | @@ -45,12 +45,12 @@ export default class UserService { | ||
45 | }); | 45 | }); |
46 | } | 46 | } |
47 | 47 | ||
48 | - async accountSettlementData(params) { | 48 | + async accountSettlementData(shopId) { |
49 | return await this.api.get({ | 49 | return await this.api.get({ |
50 | url:'', | 50 | url:'', |
51 | body: { | 51 | body: { |
52 | method: 'app.shops.accountbalance', | 52 | method: 'app.shops.accountbalance', |
53 | - ...params | 53 | + shopId |
54 | } | 54 | } |
55 | }) | 55 | }) |
56 | .then((json) => { | 56 | .then((json) => { |
-
Please register or login to post a comment