Authored by 叶弯弯

库存统计接口调试。reviewed by yuliang。

... ... @@ -3,6 +3,7 @@
import React, {Component} from 'react';
import PlainTextSection from './PlainTextSection';
import Placeholder from './Placeholder';
import LoadMoreIndicator from './indicator/LoadMoreIndicator';
import {
StyleSheet,
... ... @@ -20,45 +21,82 @@ export default class StockStats extends Component {
super (props);
this.ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2,
rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
});
this._renderRow = this._renderRow.bind(this);
}
_renderRow(rowData, sectionID, rowID) {
return (
<TouchableHighlight underlayColor={'white'} onPress={() => {}}>
<View style={styles.row}>
<Image source={{uri: rowData.thumb}} style={styles.thumb}/>
<View style={styles.detail}>
<Text style={styles.brand}>{rowData.brand}</Text>
<Text style={styles.product}>{rowData.product}</Text>
<Text style={styles.brand}>{'厂家编号:' + rowData.vendor + ' sku:' + rowData.sku}</Text>
<Text style={styles.product}>{'进货价:' + rowData.importPrice + ' 库存:' + rowData.stockNum}</Text>
switch (sectionID) {
case 'SECTION_HEADER':
return (
<View style={styles.container}>
<PlainTextSection content={rowData.section2} />
<Placeholder />
</View>
</View>
</TouchableHighlight>
);
);
case 'SECTION_TIME':
return (
<View style={styles.container}>
<View style={styles.dateContainer}>
<Image source={require('../images/date.png')}/>
<Text style={styles.date}>{rowData.section1}</Text>
</View>
<Placeholder />
</View>
);
case 'SECTION_CONTENT':
return (
<TouchableHighlight underlayColor={'white'} onPress={() => {}}>
<View style={styles.row}>
<Image source={{uri: rowData.thumb}} style={styles.thumb}/>
<View style={styles.detail}>
<Text style={styles.brand}>{rowData.brand}</Text>
<Text style={styles.product}>{rowData.product}</Text>
<Text style={styles.brand}>{'厂家编号:' + rowData.vendor + ' sku:' + rowData.sku}</Text>
<Text style={styles.product}>{'进货价:' + rowData.importPrice + ' 库存:' + rowData.stockNum}</Text>
</View>
</View>
</TouchableHighlight>
);
default:
return (
<Text>Error data source</Text>
);
}
}
render() {
let isFetching = this.props.isFetching;
let loadText = '暂无更多数据';
if (!this.props.reachEnd) {
loadText = isFetching ? '正在加载...' : '上拉加载更多';
}
return (
<View style={styles.container}>
<View style={styles.dateContainer}>
<Image source={require('../images/date.png')}/>
<Text style={styles.date}>{this.props.section1}</Text>
</View>
<Placeholder />
<PlainTextSection content={this.props.section2} />
<Placeholder />
<ListView
dataSource={this.ds.cloneWithRows(this.props.section3)}
dataSource={this.ds.cloneWithRowsAndSections(this.props.section.toJS())}
renderRow={this._renderRow}
renderSeparator={(sectionID, rowID) => <View key={`${sectionID}-${rowID}`} style={styles.separator}/>}
onEndReachedThreshold={-10}
onEndReachedThreshold={-50}
onEndReached={this.props.requestData}
enableEmptySections={true} />
enableEmptySections={true}
renderFooter={()=>{
return <LoadMoreIndicator
hidden={this.props.hideLoadingFooter}
loadingText={loadText}
animating={isFetching}
/>
}}
/>
</View>
);
}
... ...
... ... @@ -2,6 +2,7 @@
'use strict';
import React, { Component } from 'react';
import Immutable, {List, Record} from 'immutable';
import StockStats from '../components/StockStats'
... ... @@ -53,11 +54,16 @@ export default class StockStatsContainer extends Component {
}
componentDidMount() {
this.props.actions.requestData();
this._requestData();
}
_requestData() {
this.props.actions.requestData();
let params = {
page: this.props.stockStats.currentPage + 1,
size: 12,
brandId: this.props.home.get('brandId'),
};
this.props.actions.requestData(params);
}
render() {
... ... @@ -74,14 +80,22 @@ export default class StockStatsContainer extends Component {
bottom: `${this.props.stockStats.totalAmount}`,
}
];
let dataBlob = {
'SECTION_TIME': [{section1}],
'SECTION_HEADER': [{section2}],
'SECTION_CONTENT': this.props.stockStats.jsonData,
}
let mapBlob = Immutable.fromJS(dataBlob);
let end = this.props.stockStats.currentPage >= this.props.stockStats.pageCount;
return (
<View style={styles.container}>
<StockStats
section1={section1}
section2={section2}
section3={this.props.stockStats.jsonData.toJS()}
section={mapBlob}
requestData={this._requestData}
isFetching={this.props.stockStats.isFetching}
hideLoadingFooter={this.props.stockStats.currentPage<1}
reachEnd={end}
/>
</View>
);
... ...
... ... @@ -29,19 +29,24 @@ export function failure(error) {
}
}
export function requestData() {
// return dispatch => {
// dispatch(request());
// return new StockStatsService()
// .stockStatsData()
// .then(json => {
// dispatch(success(json));
// })
// .catch(error => {
// dispatch(failure(error));
// })
// };
return success(testStockStatsData);
export function requestData(params) {
return (dispatch, getState) => {
const {stockStats} = getState();
if (stockStats.currentPage >= stockStats.pageCount || stockStats.isFetching) {//Last page reached....
return;
}
dispatch(request());
return new StockStatsService()
.stockStatsData(params)
.then(json => {
dispatch(success(json));
})
.catch(error => {
dispatch(failure(error));
})
};
}
let testStockStatsData = {
... ...
... ... @@ -5,10 +5,11 @@ import {List, Record} from 'immutable';
let InitialState = Record({
error: null,
isFetching: false,
pageCount: 0,
pageCount: 1,
currentPage: 0,
sum: '0',
totalAmount: '0',
jsonData: List([]),
totalAmount: '0.00',
jsonData: List(),
});
export default InitialState;
... ...
... ... @@ -25,13 +25,14 @@ export default function stockStatsReducer(state = initialState, action) {
case STOCK_STATS_SUCCESS: {
const {jsonData} = state;
let origin = jsonData.toJS();
let data = [...origin, ...action.payload.list];
let newPageCount = action.payload.list ? state.pageCount + 1 : state.pageCount;
let {additionInfo, list} = action.payload;
let data = [...origin, ...(list || [])];
let nextState = state.set('isFetching',false)
.set('sum', action.payload.sum)
.set('totalAmount', action.payload.totalAmount)
.set('pageCount', newPageCount)
.set('jsonData', List(data));
.set('sum', additionInfo.storageTotalNum)
.set('totalAmount', additionInfo.storageTotalMoney)
.set('currentPage', action.payload.page)
.set('pageCount', action.payload.totalPage)
.set('jsonData', Immutable.fromJS(data));
return nextState;
}
case STOCK_STATS_FAILURE: {
... ...
... ... @@ -94,9 +94,13 @@ export default class UserService {
})
}
async stockStatsData() {
async stockStatsData(params) {
return await this.api.get({
url: '/'
url: '',
body: {
method: 'app.shops.storagestatistics',
...params,
}
})
.then((json) => {
return json;
... ...