Authored by 王海元

接口增加分页 --review by 孙凯

... ... @@ -65,8 +65,13 @@ export default function native(platform) {
<WithdrawalRecordContainer/>
</Provider>
);
} else {
return (
<Provider store={store}>
<AllianceContainer/>
</Provider>
);
}
return null;
}
});
... ...
... ... @@ -129,7 +129,7 @@ export default class OrderIncome extends Component {
render() {
let {orderList} = this.props;
let orderLists = orderList.order_list ? orderList.order_list.toArray() : [];
let orderLists = orderList.list ? orderList.list.toArray() : [];
return (
<View style={styles.container}>
<ListView
... ... @@ -141,7 +141,12 @@ export default class OrderIncome extends Component {
enableEmptySections={true}
dataSource={this.dataSource.cloneWithRows(orderLists)}
renderRow={this._renderRow}
renderHeader={this._renderHeader}/>
renderHeader={this._renderHeader}
onEndReached={() => {
if (orderLists.size !== 0) {
this.props.onEndReached && this.props.onEndReached();
}
}}/>
</View>
);
}
... ...
... ... @@ -36,7 +36,7 @@ export default class WithdrawalRecord extends Component {
let {
settlementRecordList,
} = this.props;
let recordList = settlementRecordList.settlementRecord_list ? settlementRecordList.settlementRecord_list.toArray() : [];
let recordList = settlementRecordList.list ? settlementRecordList.list.toArray() : [];
return (
<View style={styles.container}>
<ListView
... ... @@ -47,7 +47,12 @@ export default class WithdrawalRecord extends Component {
contentContainerStyle={styles.contentContainer}
enableEmptySections={true}
dataSource={this.dataSource.cloneWithRows(recordList)}
renderRow={this._renderRow}/>
renderRow={this._renderRow}
onEndReached={() => {
if (recordList.size !== 0) {
this.props.onEndReached && this.props.onEndReached();
}
}}/>
</View>
);
}
... ...
... ... @@ -35,20 +35,35 @@ function mapDispatchToProps(dispatch) {
class OrderIncomeContainer extends Component {
constructor(props) {
super(props);
this.state = {
orderType: 1,
orderStatus: 0,
};
this._onPressTab = this._onPressTab.bind(this);
this._onEndReached = this._onEndReached.bind(this);
}
componentDidMount() {
this.props.actions.getOrderList(1, 0);
this.props.actions.getOrderList(this.state.orderType, this.state.orderStatus, true);
}
componentWillUnmount() {
}
_onEndReached() {
this.props.actions.getOrderList(this.state.orderType, this.state.orderStatus, false);
}
_onPressTab(orderType, orderStatus) {
alert(orderType + "\n" + orderStatus);
this.props.actions.getOrderList(orderType, orderStatus);
this.state.orderType = orderType;
this.state.orderStatus = orderStatus;
this.setState({
orderType :this.state.orderType,
orderStatus :this.state.orderStatus
});
this.props.actions.getOrderList(this.state.orderType, this.state.orderStatus, true);
}
render() {
... ... @@ -60,6 +75,7 @@ class OrderIncomeContainer extends Component {
<OrderIncome
orderList={orderList}
onPressTab={this._onPressTab}
onEndReached={this._onEndReached}
/>
</View>
)
... ...
... ... @@ -36,7 +36,7 @@ function mapDispatchToProps(dispatch) {
class WithdrawalRecordContainer extends Component {
constructor(props) {
super(props);
this._onEndReached = this._onEndReached.bind(this);
}
componentDidMount() {
... ... @@ -47,13 +47,19 @@ class WithdrawalRecordContainer extends Component {
}
_onEndReached() {
this.props.actions.getSettlementRecord();
}
render() {
let {settlementRecordList} = this.props.alliance;
let isFetching = settlementRecordList.isFetching;
return (
<View style={styles.container}>
<LoadingIndicator isVisible={isFetching}/>
<WithdrawalRecord settlementRecordList={settlementRecordList}/>
<WithdrawalRecord
settlementRecordList={settlementRecordList}
onEndReached={this._onEndReached}/>
</View>
)
}
... ...
... ... @@ -321,12 +321,35 @@ export function getOderDetail(orderCode) {
export function getSettlementRecord() {
return (dispatch, getState) => {
let {app} = getState();
let {app, alliance} = getState();
let list = alliance.settlementRecordList;
/**
* page: 0, //当前页面
* page_size: 20, //每页显示的数量
* total: 0, //总共多少条
* totalPage: 0, //总共多少页
* endReached: false, //到达底部
*/
if (list.isFetching || list.endReached || list.error || (!list.endReached && list.totalPage === 1)) {
return;
}
let page = list.page + 1;
let pageSize = list.page_size;
let fetchSettlementRecord = (uid) => {
dispatch(settlementRecordRequest());
return new AllianceService(app.host).fetchSettlementRecord(uid, 1, 20)
return new AllianceService(app.host).fetchSettlementRecord(uid, page, pageSize)
.then(json => {
dispatch(settlementRecordSuccess(json));
let payload = json;
payload.endReached = (payload.page === payload.totalPage) && (payload.totalPage !== 1);
if (payload.page > 1) {
let oldList = list.list.toJS();
let newList = [...oldList, ...payload.list];
payload.list = newList;
}
dispatch(settlementRecordSuccess(payload));
})
.catch(error => {
dispatch(settlementRecordFailure(error));
... ... @@ -345,14 +368,37 @@ export function getSettlementRecord() {
};
}
export function getOrderList(orderType, orderStatus) {
export function getOrderList(orderType, orderStatus, isChanged) {
return (dispatch, getState) => {
let {app} = getState();
let {app, alliance} = getState();
let list = alliance.orderList;
/**
* page: 0, //当前页面
* page_size: 20, //每页显示的数量
* total: 0, //总共多少条
* totalPage: 0, //总共多少页
* endReached: false, //到达底部
*/
if (!isChanged && (list.isFetching || list.endReached || list.error || (!list.endReached && list.totalPage === 1))) {
return;
}
let page = isChanged ? 1 : list.page + 1;
let pageSize = list.page_size;
let fetchOrderList = (uid) => {
dispatch(orderListRequest());
return new AllianceService(app.host).fetchOrderList(uid, orderType, orderStatus, 1, 20)
return new AllianceService(app.host).fetchOrderList(uid, orderType, orderStatus, page, pageSize)
.then(json => {
dispatch(orderListSuccess(json));
let payload = json;
payload.endReached = (payload.page === payload.totalPage) && (payload.totalPage !== 1);
if (payload.page > 1) {
let oldList = list.list.toJS();
let newList = [...oldList, ...payload.list];
payload.list = newList;
}
dispatch(orderListSuccess(payload));
})
.catch(error => {
dispatch(orderListFailure(error));
... ... @@ -383,10 +429,6 @@ export function getTop100List() {
* page_total: 0, //总共多少页
* endReached: false, //到达底部
*/
console.log(list.page);
console.log(list.product_list);
console.log(list.product_list.toJS());
console.log('herer');
if (list.isFetching || list.endReached || list.error || (!list.endReached && list.page_total === 1)) {
return;
}
... ... @@ -399,7 +441,7 @@ export function getTop100List() {
return new AllianceService(app.host).fetchTop100List(uid, page, pageSize)
.then(json => {
let payload = json;
payload.endReached = (payload.page === payload.page_total) && (payload.pageCount !== 1);
payload.endReached = (payload.page === payload.page_total) && (payload.page_total !== 1);
if (payload.page > 1) {
let oldList = list.product_list.toJS();
let newList = [...oldList, ...payload.product_list];
... ...
... ... @@ -37,22 +37,32 @@ let InitialState = Record({
})),
orderList: new (Record({
isFetching: true,
isFetching: false,
error: null,
order_list: List(),
page: 0, //当前页面
page_size: 20, //每页显示的数量
total: 0, //总共多少条
totalPage: 0, //总共多少页
endReached: false, //到达底部
list: List(),
})),
settlementRecordList: new (Record({
isFetching: true,
isFetching: false,
error: null,
settlementRecord_list: List(),
page: 0, //当前页面
page_size: 20, //每页显示的数量
total: 0, //总共多少条
totalPage: 0, //总共多少页
endReached: false, //到达底部
list: List(),
})),
topList: new (Record({
isFetching: false,
error: null,
page: 0, //当前页面
page_size: 6, //每页显示的数量
page_size: 20, //每页显示的数量
total: 0, //总共多少条
page_total: 0, //总共多少页
endReached: false, //到达底部
... ...
... ... @@ -148,8 +148,17 @@ export default function couponReducer(state = initialState, action) {
}
case SETTLEMENT_RECORD_SUCCESS: {
let {
page,
totalPage,
endReached,
list,
} = action.payload;
return state.setIn(['settlementRecordList', 'isFetching'], false)
.setIn(['settlementRecordList', 'settlementRecord_list'], Immutable.fromJS(action.payload))
.setIn(['settlementRecordList', 'page'], page)
.setIn(['settlementRecordList', 'totalPage'], totalPage)
.setIn(['settlementRecordList', 'endReached'], endReached)
.setIn(['settlementRecordList', 'list'], Immutable.fromJS(list))
.setIn(['settlementRecordList', 'error'], null);
}
... ... @@ -165,8 +174,17 @@ export default function couponReducer(state = initialState, action) {
}
case ORDER_LIST_SUCCESS: {
let {
page,
totalPage,
endReached,
list,
} = action.payload;
return state.setIn(['orderList', 'isFetching'], false)
.setIn(['orderList', 'order_list'], Immutable.fromJS(action.payload))
.setIn(['orderList', 'page'], page)
.setIn(['orderList', 'totalPage'], totalPage)
.setIn(['orderList', 'endReached'], endReached)
.setIn(['orderList', 'list'], Immutable.fromJS(list))
.setIn(['orderList', 'error'], null);
}
... ...