Authored by 叶弯弯

完成请退统计模块。reviewed by shixiang。

... ... @@ -43,6 +43,7 @@ import accountSettlementInitialState from './reducers/accountSettlement/accountS
import saleStatisticsInitialState from './reducers/saleStatistics/saleStatisticsInitialState';
import stockStatsInitialState from './reducers/stockStats/stockStatsInitialState';
import deliveryStatsInitialState from './reducers/deliveryStats/deliveryStatsInitialState';
import requestStatsInitialState from './reducers/requestStats/requestStatsInitialState';
import App from './containers/App';
... ... @@ -60,6 +61,7 @@ import StockStatsContainer from './containers/StockStatsContainer'
import SaleStatisticsContainer from './containers/SaleStatisticsContainer'
import DeliveryStatsContainer from './containers/DeliveryStatsContainer'
import MessageDetailContainer from './containers/MessageDetailContainer'
import RequestStatsContainer from './containers/RequestStatsContainer'
import NavBar from './components/NavBar';
import TabIcon from './containers/TabIcon';
... ... @@ -84,6 +86,7 @@ function getInitialState() {
saleStats: (new saleStatisticsInitialState()),
stockStats: (new stockStatsInitialState()),
deliveryStats: (new deliveryStatsInitialState()),
requestStats: (new requestStatsInitialState()),
};
return _initState;
}
... ... @@ -194,6 +197,17 @@ export default function native(platform) {
/>
<Scene
key='RequestStats'
component={RequestStatsContainer}
title='请退统计'
hideNavBar={false}
initial={false}
navBar={NavBar}
titleStyle={styles.navTitle}
type='push'
/>
<Scene
key='StockStats'
component={StockStatsContainer}
title='库存统计'
... ...
'use strict';
import React from 'react-native';
import Immutable, {List, Record} from 'immutable';
let {
Component,
... ... @@ -34,7 +34,7 @@ export default class FixedHeaderList extends Component {
this._renderRow = this._renderRow.bind(this);
this._renderHeader = this._renderHeader.bind(this);
this.ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.ds = new ListView.DataSource({rowHasChanged: (r1, r2) => !Immutable.is(r1, r2)});
// this.dataSource = ds.cloneWithRows(this.props.content);
this.headers = [];
... ... @@ -46,7 +46,7 @@ export default class FixedHeaderList extends Component {
}
}
_renderRow(rowData, sectionID, rowID) {
_renderRow(rowData, sectionID, rowID) { // refactor later
return (
<TouchableHighlight onPress={() => {}} underlayColor={'white'} >
<View style={styles.row}>
... ... @@ -54,8 +54,8 @@ export default class FixedHeaderList extends Component {
<Text style={styles.blackText}>{rowData.id}</Text>
<Text style={styles.blackText}>{rowData.date}</Text>
</View>
<Text style={styles.redText}>{rowData.deliveryNum}</Text>
<Text style={styles.redText}>{rowData.deliveryAmount}</Text>
<Text style={styles.redText}>{rowData.num}</Text>
<Text style={styles.redText}>{rowData.amount}</Text>
</View>
</TouchableHighlight>
);
... ...
'use strict';
import React, {Component} from 'react';
import PlainTextSection from './PlainTextSection';
import Placeholder from './Placeholder';
import DatePicker from './DatePicker';
import FixedHeaderList from './FixedHeaderList';
import {
StyleSheet,
View,
} from 'react-native';
export default class RequestStats extends Component {
constructor(props) {
super (props);
}
render() {
return (
<View style={styles.container}>
<DatePicker currentStartDate={this.props.currentStartDate}
currentEndDate={this.props.currentEndDate}
maxDate={this.props.maxDate}
newDatePicked={this.props.newDatePicked}/>
<Placeholder />
<PlainTextSection content={this.props.section2} />
<Placeholder />
<FixedHeaderList content={this.props.content}
header={this.props.header}/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
... ...
... ... @@ -74,6 +74,12 @@ export default keyMirror({
CHOOSE_DELIVERY_START_DATE: null,
CHOOSE_DELIVERY_END_DATE: null,
REQUEST_STATS_REQUEST: null,
REQUEST_STATS_SUCCESS: null,
REQUEST_STATS_FAILURE: null,
CHOOSE_REQUEST_START_DATE: null,
CHOOSE_REQUEST_END_DATE: null,
/*
GET_PROFILE_REQUEST: null,
GET_PROFILE_SUCCESS: null,
... ...
'use strict';
import React, { Component } from 'react';
import RequestStats from '../components/RequestStats'
import {
StyleSheet,
View,
Text,
ListView,
Dimensions,
Platform,
} from 'react-native';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {Map} from 'immutable';
import * as requestStatsActions from '../reducers/requestStats/requestStatsActions';
import {getLastDay} from '../utils/dateTool';
const actions = [
requestStatsActions,
];
function mapStateToProps(state) {
return {
...state
}
};
function mapDispatchToProps(dispatch) {
const creators = Map()
.merge(...actions)
.filter(value => typeof value === 'function')
.toObject();
return {
actions: bindActionCreators(creators, dispatch),
dispatch
};
}
export default class RequestStatsContainer extends Component {
constructor(props) {
super(props);
this._requestData = this._requestData.bind(this);
}
componentDidMount() {
this.props.actions.requestData();
}
_requestData() {
this.props.actions.requestData();
}
render() {
let section2 = [
{
top: '退货出库总数量',
bottom: `${this.props.requestStats.sum}`,
},
{
top: '退货出库总金额(元)',
bottom: `${this.props.requestStats.totalAmount}`,
}
];
let header = [
'单号/时间', '请退出库数量', '请退出库总金额(元)'
];
return (
<View style={styles.container}>
<RequestStats
currentStartDate={this.props.requestStats.startDay}
currentEndDate={this.props.requestStats.endDay}
maxDate={getLastDay()}
newDatePicked={this.props.actions.newDatePicked}
section2={section2}
content={this.props.requestStats.jsonData.toJS()}
header={header}
/>
</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)(RequestStatsContainer);
... ...
... ... @@ -64,56 +64,56 @@ export function requestData() {
}
let testStockStatsData = {
sum: '100',
totalAmount: '100000.00',
sum: '111',
totalAmount: '99999.00',
list: [
{
id: '1111',
date: '2016-05-06',
deliveryNum: '222222',
deliveryAmount: '1111.00',
num: '222222',
amount: '1111.00',
},
{
id: '1111',
date: '2016-05-06',
deliveryNum: '222222',
deliveryAmount: '1111.00',
num: '222222',
amount: '1111.00',
},
{
id: '1111',
date: '2016-05-06',
deliveryNum: '222222',
deliveryAmount: '1111.00',
num: '222222',
amount: '1111.00',
},
{
id: '1111',
date: '2016-05-06',
deliveryNum: '222222',
deliveryAmount: '1111.00',
num: '222222',
amount: '1111.00',
},
{
id: '1111',
date: '2016-05-06',
deliveryNum: '222222',
deliveryAmount: '1111.00',
num: '222222',
amount: '1111.00',
},
{
id: '1111',
date: '2016-05-06',
deliveryNum: '222222',
deliveryAmount: '1111.00',
num: '222222',
amount: '1111.00',
},
{
id: '1111',
date: '2016-05-06',
deliveryNum: '222222',
deliveryAmount: '1111.00',
num: '222222',
amount: '1111.00',
},
{
id: '0000',
date: '2016-05-06',
deliveryNum: '222222',
deliveryAmount: '1111.00',
num: '222222',
amount: '1111.00',
},
]
}
... ...
... ... @@ -11,7 +11,7 @@ let InitialState = Record({
endDay: getLastDay(),
sum: '0',
totalAmount: '0',
jsonData: List([]),
jsonData: List(),
});
export default InitialState;
... ...
... ... @@ -19,6 +19,7 @@ import stockStats from './stockStats/stockStatsReducer';
import actStmt from './accountSettlement/accountSettlementReducer';
import saleStats from './saleStatistics/saleStatisticsReducer';
import deliveryStats from './deliveryStats/deliveryStatsReducer';
import requestStats from './requestStats/requestStatsReducer';
import { combineReducers } from 'redux';
... ... @@ -38,6 +39,7 @@ const rootReducer = combineReducers({
stockStats,
saleStats,
deliveryStats,
requestStats,
});
export default rootReducer;
... ...
'use strict';
import Request from '../../services/Request';
import RequestStatsService from '../../services/HomeService';
const {
REQUEST_STATS_REQUEST,
REQUEST_STATS_SUCCESS,
REQUEST_STATS_FAILURE,
CHOOSE_REQUEST_START_DATE,
CHOOSE_REQUEST_END_DATE,
} = require('../../constants/actionTypes').default;
export function chooseStartDate(startDay) {
return {
type: CHOOSE_REQUEST_START_DATE,
payload: startDay,
}
}
export function chooseEndDate(endDay) {
return {
type: CHOOSE_REQUEST_END_DATE,
payload: endDay,
}
}
export function newDatePicked(pickedDate, ifStartDate) {
return ifStartDate ? chooseStartDate(pickedDate) : chooseEndDate(pickedDate);
}
export function request() {
return {
type: REQUEST_STATS_REQUEST,
}
}
export function success(json) {
return {
type: REQUEST_STATS_SUCCESS,
payload: json,
}
}
export function failure(error) {
return {
type: REQUEST_STATS_FAILURE,
payload: error,
}
}
export function requestData() {
// return dispatch => {
// dispatch(request());
// return new RequestStatsService()
// .requestStatsData()
// .then(json => {
// dispatch(success(json));
// })
// .catch(error => {
// dispatch(failure(error));
// })
// };
return success(testStockStatsData);
}
let testStockStatsData = {
sum: '100',
totalAmount: '100000.00',
list: [
{
id: '1234',
date: '2016-05-06',
num: '222222',
amount: '1111.00',
},
{
id: '1111',
date: '2016-05-06',
num: '222222',
amount: '1111.00',
},
{
id: '1111',
date: '2016-05-06',
num: '222222',
amount: '1111.00',
},
{
id: '1111',
date: '2016-05-06',
num: '222222',
amount: '1111.00',
},
{
id: '1111',
date: '2016-05-06',
num: '222222',
amount: '1111.00',
},
{
id: '1111',
date: '2016-05-06',
num: '222222',
amount: '1111.00',
},
{
id: '1111',
date: '2016-05-06',
num: '222222',
amount: '1111.00',
},
{
id: '0000',
date: '2016-05-06',
num: '222222',
amount: '1111.00',
},
]
}
... ...
'use strict';
import {List, Record} from 'immutable';
import {getLastDay} from '../../utils/dateTool';
let InitialState = Record({
error: null,
isFetching: false,
pageCount: 0,
startDay: getLastDay(),
endDay: getLastDay(),
sum: '0',
totalAmount: '0',
jsonData: List(),
});
export default InitialState;
... ...
'use strict';
import RequestStatsInitialState from './requestStatsInitialState'
import Immutable, {List, Record} from 'immutable';
const {
REQUEST_STATS_REQUEST,
REQUEST_STATS_SUCCESS,
REQUEST_STATS_FAILURE,
CHOOSE_REQUEST_START_DATE,
CHOOSE_REQUEST_END_DATE,
} = require('../../constants/actionTypes').default;
const initialState = new RequestStatsInitialState;
export default function requestStatsReducer(state = initialState, action) {
if (!(state instanceof RequestStatsInitialState)) return initialState.merge(state);
switch (action.type) {
case REQUEST_STATS_REQUEST: {
let nextState = state.set('isFetching', true).set('error', null);
return nextState;
}
case REQUEST_STATS_SUCCESS: {
// const {jsonData} = state;
// let origin = jsonData.toJS();
let data = [...action.payload.list];
// let newPageCount = action.payload.list ? state.pageCount + 1 : state.pageCount;
let nextState = state.set('isFetching',false)
.set('sum', action.payload.sum)
.set('totalAmount', action.payload.totalAmount)
.set('jsonData', List(data));
// .set('pageCount', newPageCount)
return nextState;
}
case REQUEST_STATS_FAILURE: {
let nextState = state.set('isFetching', false)
.set('error', action.playload);
return nextState;
}
case CHOOSE_REQUEST_START_DATE: {
let nextState = state.set('startDay', action.payload);
return nextState;
}
case CHOOSE_REQUEST_END_DATE: {
let nextState = state.set('endDay', action.payload);
return nextState;
}
}
return state;
}
... ...
... ... @@ -75,6 +75,21 @@ export default class UserService {
throw(error);
})
}
async requestStatsData() {
return await this.api.get({
url: '/',
body: {
}
})
.then((json) => {
return json;
})
.catch((error) => {
throw(error);
})
}
}
... ...