Authored by 于良

对账结算接口修改 review by yewanwan

'use strict';
import Immutable, {List, Record} from 'immutable';
import LoadMoreIndicator from './indicator/LoadMoreIndicator'
import LoadingIndicator from './indicator/LoadingIndicator';
import React, {Component} from 'react';
import moment from 'moment';
... ... @@ -30,9 +30,8 @@ export default class AccountSettlement extends Component {
this.renderRow = this.renderRow.bind(this);
}
renderRow(rowData,sectionId) {
renderRow(rowData, sectionId) {
switch (sectionId) {
case 'SECTION_HEADER':
return (
<View style={styles.headerContainer}>
... ... @@ -86,35 +85,22 @@ export default class AccountSettlement extends Component {
</View>
);
}
return (<Text>Error data source</Text>);
}
render() {
let isFetching = this.props.isFetching;
let loadText = '暂无更多数据';
if (!this.props.reachEnd) {
loadText = isFetching?'正在加载...':'上拉加载更多';
}
let {isFetching, dataBlob} = this.props;
return (
<View>
<View style={styles.container}>
<ListView
style={styles.container}
dataSource={this.dataSource.cloneWithRowsAndSections(this.props.dataBlob.toJS())}
dataSource={this.dataSource.cloneWithRowsAndSections(dataBlob.toJS())}
renderRow={this.renderRow}
onEndReachedThreshold={-50}
onEndReached={this.props.fetchNextPage}
enableEmptySections={true}
renderFooter={()=>{
return <LoadMoreIndicator
hidden={this.props.hideLoadingFooter}
loadingText={loadText}
animating={isFetching}
/>
}}
/>
<LoadingIndicator
isVisible={isFetching}
/>
</View>
);
... ... @@ -159,9 +145,7 @@ const styles = StyleSheet.create({
},
container: {
top: navbarHeight,
flex:1,
height: Dimensions.get('window').height-navbarHeight,
},
headerContainer: {
... ...
... ... @@ -7,10 +7,10 @@ import Immutable, {List, Record} from 'immutable';
import AccountSettlement from '../components/AccountSettlement'
import {
StyleSheet,
View,
Text,
ListView,
StyleSheet,
Dimensions,
Platform
}
from 'react-native';
... ... @@ -48,41 +48,45 @@ export default class AccountSettlementContainer extends Component {
constructor(props) {
super(props);
this.fetchNextPage = this.fetchNextPage.bind(this);
}
componentDidMount() {
this.fetchNextPage();
this.props.actions.nextPageOfDataRequest();
}
fetchNextPage() {
let params = {
page: this.props.actStmt.currentPage+1,
size: 20,
shopId: this.props.home.get('shopId'),
}
this.props.actions.nextPageOfDataRequest(params);
}
render() {
let {actStmt} = this.props;
let dataBlob = {
'SECTION_HEADER':[{title:'累计结算金额(元)',content:`${this.props.actStmt.sum}`}],
'SECTION_SEPORATOR':[{}],
'SECTION_TITLE':[{}],
'SECTION_CONTENT':this.props.actStmt.jsonData,
'SECTION_HEADER': [{title:'累计结算金额(元)',content:`${actStmt.sum}`}],
'SECTION_SEPORATOR': [{}],
'SECTION_TITLE': [{}],
'SECTION_CONTENT': actStmt.list,
};
let mapBlob = Immutable.fromJS(dataBlob);
let end = this.props.actStmt.currentPage>=this.props.actStmt.pageCount;
return (
<AccountSettlement
dataBlob={mapBlob}
fetchNextPage={this.fetchNextPage}
isFetching={this.props.actStmt.isFetching}
hideLoadingFooter={this.props.actStmt.currentPage<1}
reachEnd={end}
/>
<View style={styles.container}>
<AccountSettlement
dataBlob={mapBlob}
isFetching={actStmt.isFetching}
/>
</View>
);
}
}
let {width, height} = Dimensions.get('window');
let navbarHeight = (Platform.OS === 'android') ? 50 : 64;
let styles = StyleSheet.create({
container: {
top: navbarHeight,
height: height - navbarHeight,
},
});
export default connect(mapStateToProps, mapDispatchToProps)(AccountSettlementContainer);
... ...
... ... @@ -40,24 +40,20 @@ export function nextPageOfDataFailure(error) {
* @method nextPageOfDataRequest
* @return {JS Objecrt}
*/
export function nextPageOfDataRequest(params) {
export function nextPageOfDataRequest() {
return (dispatch,getState) => {
const {actStmt} = getState();
if (actStmt.currentPage >= actStmt.pageCount || actStmt.isFetching) {//Last page reached....
return;
}
const {home, actStmt} = getState();
dispatch(requestNextPage());
return new HomeService().accountSettlementData(params)
.then(json => {
dispatch(nextPageOfDataSuccess(json));
})
.catch(error => {
dispatch(nextPageOfDataFailure(error));
})
return new HomeService().accountSettlementData(home.shopId)
.then(json => {
dispatch(nextPageOfDataSuccess(json));
})
.catch(error => {
dispatch(nextPageOfDataFailure(error));
})
};
}
... ...
... ... @@ -5,10 +5,8 @@ import {List, Record} from 'immutable';
let InitialState = Record({
error: null,
isFetching: false,
pageCount: 1,
currentPage:0,
sum:'0.00',
jsonData:List(),
sum: '0.00',
list: List(),
});
export default InitialState;
... ...
... ... @@ -19,27 +19,22 @@ export default function messageReducer(state = initialState, action) {
switch (action.type) {
case ACCOUNT_LIST_REQUEST: {
let nextState = state.set('isFetching', true)
.set('error', null);
.set('error', null);
return nextState;
}
break;
case ACCOUNT_LIST_SUCCESS: {
const {jsonData} = state;
let origin = jsonData.toJS();
let {additionInfo, list} = action.payload;
let data = [...origin, ...(list || [])];
let {totalAmount, list} = action.payload;
let nextState = state.set('isFetching', false)
.set('pageCount', action.payload.totalPage)
.set('currentPage', action.payload.page)
.set('sum', additionInfo.allAmount)
.set('jsonData', Immutable.fromJS(data));
.set('error', null)
.set('sum', totalAmount || '0.00')
.set('list', Immutable.fromJS(list || []));
return nextState;
}
break;
case ACCOUNT_LIST_FAILURE: {
let nextState = state.set('isFetching', false)
.set('error', action.playload);
.set('error', action.playload);
return nextState;
}
break;
... ...
... ... @@ -45,12 +45,12 @@ export default class UserService {
});
}
async accountSettlementData(params) {
async accountSettlementData(shopId) {
return await this.api.get({
url:'',
body: {
method: 'app.shops.accountbalance',
...params
shopId
}
})
.then((json) => {
... ...