Authored by 盖剑秋

调接口。 Reviewer: Yu Liang.

@@ -15,13 +15,16 @@ export default class ChartView extends Component { @@ -15,13 +15,16 @@ export default class ChartView extends Component {
15 15
16 render() { 16 render() {
17 17
18 -  
19 - let xString = this.props.xData.reduce((previous, current, index, array) => { 18 + let xString = '';
  19 + if (this.props.xData.length!==0) {
  20 + xString = this.props.xData.reduce((previous, current, index, array) => {
20 if (index==1) { 21 if (index==1) {
21 previous = `\'` + previous + `\'`; 22 previous = `\'` + previous + `\'`;
22 } 23 }
23 return previous + ','+ `\'` + current+ `\'`; 24 return previous + ','+ `\'` + current+ `\'`;
24 }); 25 });
  26 + }
  27 +
25 // xString = '\'' + xString; 28 // xString = '\'' + xString;
26 29
27 console.log(xString); 30 console.log(xString);
@@ -106,6 +106,8 @@ export default class SaleStatistics extends Component { @@ -106,6 +106,8 @@ export default class SaleStatistics extends Component {
106 let months = ['5.01','5.02','5.03','5.04','5.05','5.06','5.07']; 106 let months = ['5.01','5.02','5.03','5.04','5.05','5.06','5.07'];
107 let data = [100,122,80,110,140,77,151]; 107 let data = [100,122,80,110,140,77,151];
108 108
  109 + console.log(this.props.sevenDays);
  110 + console.log(this.props.trendInSevenDays);
109 111
110 return ( 112 return (
111 <ScrollView contentContainerStyle={{flex: 1}}> 113 <ScrollView contentContainerStyle={{flex: 1}}>
@@ -116,8 +118,8 @@ export default class SaleStatistics extends Component { @@ -116,8 +118,8 @@ export default class SaleStatistics extends Component {
116 <Placeholder /> 118 <Placeholder />
117 <ChartView 119 <ChartView
118 chartTitle={'近7天交易趋势'} 120 chartTitle={'近7天交易趋势'}
119 - xData={months}  
120 - yData={data} 121 + xData={this.props.sevenDays}
  122 + yData={this.props.trendInSevenDays}
121 /> 123 />
122 124
123 {this.state.showPicker ? <CalendarPicker calendarModes={this.calendarModes} selectMode={this.state.selectMode} selected={this.state.selected} onCancel={this.onCancel} onOK={this.onOK}/> : null} 125 {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 = { @@ -29,5 +29,10 @@ module.exports = {
29 deliveryStats: 'deliveryStats', 29 deliveryStats: 'deliveryStats',
30 requestStats: 'requestStats', 30 requestStats: 'requestStats',
31 accountSettlement: 'accountSettlement', 31 accountSettlement: 'accountSettlement',
  32 + },
  33 + dateFilterKey: {
  34 + date: 1,//天
  35 + week: 2,
  36 + month: 3,
32 } 37 }
33 } 38 }
@@ -14,6 +14,9 @@ import {Map} from 'immutable'; @@ -14,6 +14,9 @@ import {Map} from 'immutable';
14 import SaleStatistics from '../components/SaleStatistics'; 14 import SaleStatistics from '../components/SaleStatistics';
15 15
16 import * as saleStatisticsActions from '../reducers/saleStatistics/saleStatisticsActions'; 16 import * as saleStatisticsActions from '../reducers/saleStatistics/saleStatisticsActions';
  17 +import moment from 'moment';
  18 +import Immutable, {List, Record} from 'immutable';
  19 +import config from '../constants/config';
17 20
18 let { 21 let {
19 Component, 22 Component,
@@ -56,11 +59,56 @@ class SalestisticsContainer extends Component { @@ -56,11 +59,56 @@ class SalestisticsContainer extends Component {
56 } 59 }
57 60
58 componentDidMount() { 61 componentDidMount() {
59 - this.props.actions.saleStats(111); 62 + let params = {
  63 + type: config.dateFilterKey.date,
  64 + reqTime: moment().subtract(1,'days').format('YYYYMMDD'),
  65 + brandId: this.props.home.get('brandId'),
  66 + }
  67 + this.props.actions.saleStats(params);
60 } 68 }
61 69
62 onChangeDate(selected) { 70 onChangeDate(selected) {
63 - this.props.actions.saleStats(111); 71 +
  72 + let params = {};
  73 + switch (selected.selectMode) {
  74 + case 'day':
  75 +
  76 + let wrapper = moment(selected.day);
  77 + let dateStr = wrapper.format('YYYYMMDD');
  78 + params = {
  79 + type: config.dateFilterKey.date,
  80 + reqTime: dateStr,
  81 + brandId: this.props.home.get('brandId'),
  82 + }
  83 +
  84 + break;
  85 + case 'week':
  86 + params = {
  87 + type: config.dateFilterKey.week,
  88 + beginTime: moment(selected.from).format('YYYYMMDD'),
  89 + endTime: moment(selected.to).format('YYYYMMDD'),
  90 + brandId: this.props.home.get('brandId'),
  91 + }
  92 + break;
  93 + case 'month':
  94 +
  95 + let monthStr = '';
  96 + if (selected.month>9) {
  97 + monthStr = `${selected.year}`+`${selected.month}`
  98 + } else {
  99 + monthStr = `${selected.year}`+'0'+`${selected.month}`
  100 + }
  101 + params = {
  102 + type: config.dateFilterKey.month,
  103 + reqTime: monthStr,
  104 + brandId: this.props.home.get('brandId'),
  105 + }
  106 + break;
  107 + default:
  108 +
  109 + }
  110 +
  111 + this.props.actions.saleStats(params);
64 } 112 }
65 113
66 render() { 114 render() {
@@ -94,8 +142,8 @@ class SalestisticsContainer extends Component { @@ -94,8 +142,8 @@ class SalestisticsContainer extends Component {
94 <SaleStatistics 142 <SaleStatistics
95 section1={section1} 143 section1={section1}
96 section2={section2} 144 section2={section2}
97 - sevenDays={this.props.saleStats.sevenDays}  
98 - trendInSevenDays={this.props.saleStats.trendInSevenDays} 145 + sevenDays={this.props.saleStats.sevenDays.toJS()}
  146 + trendInSevenDays={this.props.saleStats.trendInSevenDays.toJS()}
99 onChangeDate={this.onChangeDate} 147 onChangeDate={this.onChangeDate}
100 /> 148 />
101 </View> 149 </View>
@@ -18,10 +18,10 @@ const { @@ -18,10 +18,10 @@ const {
18 18
19 } = require('../../constants/actionTypes').default; 19 } = require('../../constants/actionTypes').default;
20 20
21 -export function saleStatsRequest(shopId) { 21 +export function saleStatsRequest(params) {
22 return { 22 return {
23 type: SALE_STATS_REQUEST, 23 type: SALE_STATS_REQUEST,
24 - payload: shopId 24 + payload: params
25 }; 25 };
26 } 26 }
27 27
@@ -39,12 +39,13 @@ export function saleStatsFailure(error) { @@ -39,12 +39,13 @@ export function saleStatsFailure(error) {
39 }; 39 };
40 } 40 }
41 41
42 -export function saleStats(shopId) { 42 +export function saleStats(params) {
43 43
44 return dispatch => { 44 return dispatch => {
45 - dispatch(saleStatsRequest(shopId));  
46 - return new HomeService().saleStats(shopId) 45 + dispatch(saleStatsRequest(params));
  46 + return new HomeService().saleStats(params)
47 .then(json => { 47 .then(json => {
  48 + console.log(json);
48 dispatch(saleStatsSuccess(json)); 49 dispatch(saleStatsSuccess(json));
49 }) 50 })
50 .catch(error => { 51 .catch(error => {
@@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
12 import InitialState from './saleStatisticsInitialState'; 12 import InitialState from './saleStatisticsInitialState';
13 13
14 import Immutable, {List, Record} from 'immutable'; 14 import Immutable, {List, Record} from 'immutable';
  15 +import moment from 'moment';
15 16
16 const { 17 const {
17 18
@@ -40,22 +41,30 @@ export default function saleStatisticsReducer(state = initialState, action) { @@ -40,22 +41,30 @@ export default function saleStatisticsReducer(state = initialState, action) {
40 } 41 }
41 42
42 case SALE_STATS_SUCCESS: { 43 case SALE_STATS_SUCCESS: {
  44 +
  45 + console.log(action.payload);
  46 +
43 let sevenDays = []; 47 let sevenDays = [];
44 let trendInSevenDays = []; 48 let trendInSevenDays = [];
45 for (var i = 0; i < action.payload.list.length; i++) { 49 for (var i = 0; i < action.payload.list.length; i++) {
46 let item = action.payload.list[i]; 50 let item = action.payload.list[i];
47 - sevenDays.push(item.dateId); 51 + sevenDays.push(moment(item.dateId).format('MM.DD'));
48 trendInSevenDays.push(item.allNums); 52 trendInSevenDays.push(item.allNums);
49 } 53 }
  54 + console.log(sevenDays);
  55 + console.log(trendInSevenDays);
  56 +
  57 + let amountRate = Math.abs(action.payload.additionInfo.allAmountRate)
  58 + let countRate = Math.abs(action.payload.additionInfo.allNumberRate);
50 59
51 let nextState = state.set('isFetching', false) 60 let nextState = state.set('isFetching', false)
52 .set('error', null) 61 .set('error', null)
53 - .set('goodsAmount', action.payload.addtionInfo.allAmount)  
54 - .set('amountRise', action.payload.addtionInfo.allAmountRate>=0)  
55 - .set('amountRisePercent', action.payload.addtionInfo.allAmountRate)  
56 - .set('goodsCount', action.payload.addtionInfo.allNumber)  
57 - .set('countRise', action.payload.addtionInfo.allNumberRate>=0)  
58 - .set('countRisePercent', action.payload.addtionInfo.allNumberRate) 62 + .set('goodsAmount', action.payload.additionInfo.allAmount)
  63 + .set('amountRise', action.payload.additionInfo.allAmountRate>=0)
  64 + .set('amountRisePercent', amountRate)
  65 + .set('goodsCount', action.payload.additionInfo.allNumber)
  66 + .set('countRise', action.payload.additionInfo.allNumberRate>=0)
  67 + .set('countRisePercent', countRate)
59 .set('sevenDays', Immutable.fromJS(sevenDays)) 68 .set('sevenDays', Immutable.fromJS(sevenDays))
60 .set('trendInSevenDays', Immutable.fromJS(trendInSevenDays)); 69 .set('trendInSevenDays', Immutable.fromJS(trendInSevenDays));
61 return nextState; 70 return nextState;
@@ -57,14 +57,14 @@ export default class UserService { @@ -57,14 +57,14 @@ export default class UserService {
57 }) 57 })
58 } 58 }
59 59
60 - async saleStats() { 60 + async saleStats(params) {
  61 + console.log(params);
  62 +
61 return await this.api.get({ 63 return await this.api.get({
62 url:'/gateway', 64 url:'/gateway',
63 body: { 65 body: {
64 method: 'app.shops.sales', 66 method: 'app.shops.sales',
65 - shopsId: 6666,  
66 - type: 1,  
67 - reqTime: 20160525, 67 + ...params,
68 } 68 }
69 }) 69 })
70 .then((json) => { 70 .then((json) => {