Authored by 盖剑秋

调接口。 Reviewer: Yu Liang.

... ... @@ -15,13 +15,16 @@ export default class ChartView extends Component {
render() {
let xString = '';
if (this.props.xData.length!==0) {
xString = this.props.xData.reduce((previous, current, index, array) => {
if (index==1) {
previous = `\'` + previous + `\'`;
}
return previous + ','+ `\'` + current+ `\'`;
});
}
let xString = this.props.xData.reduce((previous, current, index, array) => {
if (index==1) {
previous = `\'` + previous + `\'`;
}
return previous + ','+ `\'` + current+ `\'`;
});
// xString = '\'' + xString;
console.log(xString);
... ...
... ... @@ -106,6 +106,8 @@ export default class SaleStatistics extends Component {
let months = ['5.01','5.02','5.03','5.04','5.05','5.06','5.07'];
let data = [100,122,80,110,140,77,151];
console.log(this.props.sevenDays);
console.log(this.props.trendInSevenDays);
return (
<ScrollView contentContainerStyle={{flex: 1}}>
... ... @@ -116,8 +118,8 @@ export default class SaleStatistics extends Component {
<Placeholder />
<ChartView
chartTitle={'近7天交易趋势'}
xData={months}
yData={data}
xData={this.props.sevenDays}
yData={this.props.trendInSevenDays}
/>
{this.state.showPicker ? <CalendarPicker calendarModes={this.calendarModes} selectMode={this.state.selectMode} selected={this.state.selected} onCancel={this.onCancel} onOK={this.onOK}/> : null}
... ...
... ... @@ -29,5 +29,10 @@ module.exports = {
deliveryStats: 'deliveryStats',
requestStats: 'requestStats',
accountSettlement: 'accountSettlement',
},
dateFilterKey: {
date: 1,//天
week: 2,
month: 3,
}
}
... ...
... ... @@ -14,6 +14,9 @@ import {Map} from 'immutable';
import SaleStatistics from '../components/SaleStatistics';
import * as saleStatisticsActions from '../reducers/saleStatistics/saleStatisticsActions';
import moment from 'moment';
import Immutable, {List, Record} from 'immutable';
import config from '../constants/config';
let {
Component,
... ... @@ -56,11 +59,56 @@ class SalestisticsContainer extends Component {
}
componentDidMount() {
this.props.actions.saleStats(111);
let params = {
type: config.dateFilterKey.date,
reqTime: moment().subtract(1,'days').format('YYYYMMDD'),
brandId: this.props.home.get('brandId'),
}
this.props.actions.saleStats(params);
}
onChangeDate(selected) {
this.props.actions.saleStats(111);
let params = {};
switch (selected.selectMode) {
case 'day':
let wrapper = moment(selected.day);
let dateStr = wrapper.format('YYYYMMDD');
params = {
type: config.dateFilterKey.date,
reqTime: dateStr,
brandId: this.props.home.get('brandId'),
}
break;
case 'week':
params = {
type: config.dateFilterKey.week,
beginTime: moment(selected.from).format('YYYYMMDD'),
endTime: moment(selected.to).format('YYYYMMDD'),
brandId: this.props.home.get('brandId'),
}
break;
case 'month':
let monthStr = '';
if (selected.month>9) {
monthStr = `${selected.year}`+`${selected.month}`
} else {
monthStr = `${selected.year}`+'0'+`${selected.month}`
}
params = {
type: config.dateFilterKey.month,
reqTime: monthStr,
brandId: this.props.home.get('brandId'),
}
break;
default:
}
this.props.actions.saleStats(params);
}
render() {
... ... @@ -94,8 +142,8 @@ class SalestisticsContainer extends Component {
<SaleStatistics
section1={section1}
section2={section2}
sevenDays={this.props.saleStats.sevenDays}
trendInSevenDays={this.props.saleStats.trendInSevenDays}
sevenDays={this.props.saleStats.sevenDays.toJS()}
trendInSevenDays={this.props.saleStats.trendInSevenDays.toJS()}
onChangeDate={this.onChangeDate}
/>
</View>
... ...
... ... @@ -18,10 +18,10 @@ const {
} = require('../../constants/actionTypes').default;
export function saleStatsRequest(shopId) {
export function saleStatsRequest(params) {
return {
type: SALE_STATS_REQUEST,
payload: shopId
payload: params
};
}
... ... @@ -39,12 +39,13 @@ export function saleStatsFailure(error) {
};
}
export function saleStats(shopId) {
export function saleStats(params) {
return dispatch => {
dispatch(saleStatsRequest(shopId));
return new HomeService().saleStats(shopId)
dispatch(saleStatsRequest(params));
return new HomeService().saleStats(params)
.then(json => {
console.log(json);
dispatch(saleStatsSuccess(json));
})
.catch(error => {
... ...
... ... @@ -12,6 +12,7 @@
import InitialState from './saleStatisticsInitialState';
import Immutable, {List, Record} from 'immutable';
import moment from 'moment';
const {
... ... @@ -40,22 +41,30 @@ export default function saleStatisticsReducer(state = initialState, action) {
}
case SALE_STATS_SUCCESS: {
console.log(action.payload);
let sevenDays = [];
let trendInSevenDays = [];
for (var i = 0; i < action.payload.list.length; i++) {
let item = action.payload.list[i];
sevenDays.push(item.dateId);
sevenDays.push(moment(item.dateId).format('MM.DD'));
trendInSevenDays.push(item.allNums);
}
console.log(sevenDays);
console.log(trendInSevenDays);
let amountRate = Math.abs(action.payload.additionInfo.allAmountRate)
let countRate = Math.abs(action.payload.additionInfo.allNumberRate);
let nextState = state.set('isFetching', false)
.set('error', null)
.set('goodsAmount', action.payload.addtionInfo.allAmount)
.set('amountRise', action.payload.addtionInfo.allAmountRate>=0)
.set('amountRisePercent', action.payload.addtionInfo.allAmountRate)
.set('goodsCount', action.payload.addtionInfo.allNumber)
.set('countRise', action.payload.addtionInfo.allNumberRate>=0)
.set('countRisePercent', action.payload.addtionInfo.allNumberRate)
.set('goodsAmount', action.payload.additionInfo.allAmount)
.set('amountRise', action.payload.additionInfo.allAmountRate>=0)
.set('amountRisePercent', amountRate)
.set('goodsCount', action.payload.additionInfo.allNumber)
.set('countRise', action.payload.additionInfo.allNumberRate>=0)
.set('countRisePercent', countRate)
.set('sevenDays', Immutable.fromJS(sevenDays))
.set('trendInSevenDays', Immutable.fromJS(trendInSevenDays));
return nextState;
... ...
... ... @@ -57,14 +57,14 @@ export default class UserService {
})
}
async saleStats() {
async saleStats(params) {
console.log(params);
return await this.api.get({
url:'/gateway',
body: {
method: 'app.shops.sales',
shopsId: 6666,
type: 1,
reqTime: 20160525,
...params,
}
})
.then((json) => {
... ...