diff --git a/src/charts/Customer_care_regular.jsx b/src/charts/Customer_care_regular.jsx index 75e7ec6..f5acfd8 100644 --- a/src/charts/Customer_care_regular.jsx +++ b/src/charts/Customer_care_regular.jsx @@ -27,13 +27,23 @@ const Customer_care_regular = () => { fieldProps: { DepartmentList: { show_all: false, mode: 'multiple' }, WebCode: { show_all: false, mode: 'multiple' }, - dates: { hide_vs: true }, + years: { hide_vs: true }, }, }} - onSubmit={(_err, obj, form, str) => { + onSubmit={async (_err, obj, form, str) => { customer_store.setSearchValues(obj, form, 'regular_data'); - customer_store.regular_customer_order(); - customer_store.regular_customer_order(true); + regular_data.data_compare=[]; + regular_data.isRenderCount=0; + if (obj.DateDiff1 && obj.DateDiff2){ + await customer_store.regular_customer_order(); + customer_store.regular_customer_order(false,true); + customer_store.regular_customer_order(true,false,true); + customer_store.regular_customer_order(true,true,true); + } + else{ + customer_store.regular_customer_order(); + customer_store.regular_customer_order(true); + } }} /> @@ -81,7 +91,7 @@ const Customer_care_regular = () => { title: '成行率', dataIndex: 'SUCRate', key: 'SUCRate', - render: (text, record) => {Math.round(text * 100)}%, + render: (text) => typeof text === 'number'?{Math.round(text * 100)}%:text, }, { title: '毛利', diff --git a/src/stores/CustomerStore.js b/src/stores/CustomerStore.js index fbda875..3da2c68 100644 --- a/src/stores/CustomerStore.js +++ b/src/stores/CustomerStore.js @@ -2,7 +2,7 @@ import {makeAutoObservable, runInAction} from "mobx"; import { fetchJSON } from '../utils/request'; import * as config from "../config"; import { groupsMappedByKey, sitesMappedByCode, pivotBy } from './../libs/ht'; -import { sortBy } from "../utils/commons"; +import { sortBy, show_vs_tag, formatPercent } from "../utils/commons"; import moment from 'moment'; /** @@ -101,7 +101,7 @@ class CustomerStore { // 老客户 beign - regular_customer_order(get_detail = false) { + regular_customer_order(get_detail = false, isCompare = false, isRender=false) { let pivotByOrder = 'SumOrder'; let pivotByDate = 'applyDate'; this.regular_data.loading = true; @@ -120,55 +120,131 @@ class CustomerStore { pivotByOrder = 'ConfirmOrder'; pivotByDate = 'startDate'; } - url += '&ApplydateStart=' + date_picker_store.start_date.format(config.DATE_FORMAT) + '&ApplydateEnd=' + date_picker_store.end_date.format(config.SMALL_DATETIME_FORMAT); - url += '&EntrancedateStart=' + date_picker_store.start_date.format(config.DATE_FORMAT) + '&EntrancedateEnd=' + date_picker_store.end_date.format(config.SMALL_DATETIME_FORMAT); - url += '&ConfirmdateStart=' + date_picker_store.start_date.format(config.DATE_FORMAT) + '&ConfirmdateEnd=' + date_picker_store.end_date.format(config.SMALL_DATETIME_FORMAT); + if (isCompare){ + url += '&ApplydateStart=' + date_picker_store.start_date_cp.format(config.DATE_FORMAT) + '&ApplydateEnd=' + date_picker_store.end_date_cp.format(config.SMALL_DATETIME_FORMAT); + url += '&EntrancedateStart=' + date_picker_store.start_date_cp.format(config.DATE_FORMAT) + '&EntrancedateEnd=' + date_picker_store.end_date_cp.format(config.SMALL_DATETIME_FORMAT); + url += '&ConfirmdateStart=' + date_picker_store.start_date_cp.format(config.DATE_FORMAT) + '&ConfirmdateEnd=' + date_picker_store.end_date_cp.format(config.SMALL_DATETIME_FORMAT); + } + else{ + url += '&ApplydateStart=' + date_picker_store.start_date.format(config.DATE_FORMAT) + '&ApplydateEnd=' + date_picker_store.end_date.format(config.SMALL_DATETIME_FORMAT); + url += '&EntrancedateStart=' + date_picker_store.start_date.format(config.DATE_FORMAT) + '&EntrancedateEnd=' + date_picker_store.end_date.format(config.SMALL_DATETIME_FORMAT); + url += '&ConfirmdateStart=' + date_picker_store.start_date.format(config.DATE_FORMAT) + '&ConfirmdateEnd=' + date_picker_store.end_date.format(config.SMALL_DATETIME_FORMAT); + } if (get_detail) { url += '&IsDetail=1'; } else { url += '&IsDetail=0'; } url += `&IncludeTickets=${this.regular_data.include_tickets}`; - + return new Promise((resolve, reject) => { fetch(config.HT_HOST + url) .then((response) => response.json()) .then((json) => { runInAction(() => { if (get_detail) { - this.regular_data.detail_loading = false; - this.regular_data.data_detail = json; - const dump_l = (json || []).filter(ele => ele.COLI_IsOld !== '' && ele.COLI_IsCusCommend !== '').length; - this.regular_data.total_data_tips = dump_l > 0 ? `包含 ${dump_l} 条同时勾选的数据` : ''; - /** 使用明细数据画图 */ - const data_detail = (json || []).map((ele) => ({ - ...ele, - key: ele.COLI_ID, - orderState: ele.OrderState, - applyDate: moment(ele.COLI_ApplyDate).format('YYYY-MM-DD'), - startDate: ele.COLI_OrderStartDate, - confirmDate: moment(ele.COLI_ConfirmDate).format('YYYY-MM-DD'), - })); - const { data: IsOldData, } = pivotBy(data_detail.filter(ele => ele.COLI_IsOld === '是'), [['COLI_IsOld', ], [], pivotByDate]); - const { data: isCusCommendData, } = pivotBy(data_detail.filter(ele => ele.COLI_IsCusCommend === '是'), [['COLI_IsCusCommend', ], [], pivotByDate]); - // console.log('IsOldData====', IsOldData, '\nisCusCommend', isCusCommendData); - // 合并成两个系列 - const seriesData = [].concat(IsOldData.map(ele => ({...ele, _ylabel: '老客户'})), isCusCommendData.map(ele => ({...ele, _ylabel: '老客户推荐'})),).sort(sortBy(pivotByDate)); - // console.log('seriesData====', seriesData); - - this.regular_data.pivotData = seriesData; // { IsOldData, isCusCommendData, }; - this.regular_data.pivotY = pivotByOrder; - this.regular_data.pivotX = pivotByDate; - + if (!isCompare){ + this.regular_data.data_detail = json; + } + if (this.regular_data.data_compare.length===0){ + this.regular_data.data_compare = json; + } + else{ + const fistCompareDetail = this.regular_data.data_compare; + json.push(...fistCompareDetail); + } + if (isRender){ + if (this.regular_data.isRenderCount===0){ + this.regular_data.isRenderCount=1; + } + else{ + this.regular_data.detail_loading = false; + const dump_l = (json || []).filter(ele => ele.COLI_IsOld !== '' && ele.COLI_IsCusCommend !== '').length; + this.regular_data.total_data_tips = dump_l > 0 ? `包含 ${dump_l} 条同时勾选的数据` : ''; + /** 使用明细数据画图 */ + const data_detail = (json || []).map((ele) => ({ + ...ele, + key: ele.COLI_ID, + orderState: ele.OrderState, + applyDate: moment(ele.COLI_ApplyDate).format('YYYY-MM-DD'), + startDate: ele.COLI_OrderStartDate, + confirmDate: moment(ele.COLI_ConfirmDate).format('YYYY-MM-DD'), + })); + const { data: IsOldData, } = pivotBy(data_detail.filter(ele => ele.COLI_IsOld === '是'), [['COLI_IsOld', ], [], pivotByDate]); + const { data: isCusCommendData, } = pivotBy(data_detail.filter(ele => ele.COLI_IsCusCommend === '是'), [['COLI_IsCusCommend', ], [], pivotByDate]); + // console.log('IsOldData====', IsOldData, '\nisCusCommend', isCusCommendData); + // 合并成两个系列 + const seriesData = [].concat(IsOldData.map(ele => ({...ele, _ylabel: '老客户'})), isCusCommendData.map(ele => ({...ele, _ylabel: '老客户推荐'})),).sort(sortBy(pivotByDate)); + // console.log('seriesData====', seriesData); + + this.regular_data.pivotData = seriesData; // { IsOldData, isCusCommendData, }; + this.regular_data.pivotY = pivotByOrder; + this.regular_data.pivotX = pivotByDate; + } + } + else{ + this.regular_data.detail_loading = false; + const dump_l = (json || []).filter(ele => ele.COLI_IsOld !== '' && ele.COLI_IsCusCommend !== '').length; + this.regular_data.total_data_tips = dump_l > 0 ? `包含 ${dump_l} 条同时勾选的数据` : ''; + /** 使用明细数据画图 */ + const data_detail = (json || []).map((ele) => ({ + ...ele, + key: ele.COLI_ID, + orderState: ele.OrderState, + applyDate: moment(ele.COLI_ApplyDate).format('YYYY-MM-DD'), + startDate: ele.COLI_OrderStartDate, + confirmDate: moment(ele.COLI_ConfirmDate).format('YYYY-MM-DD'), + })); + const { data: IsOldData, } = pivotBy(data_detail.filter(ele => ele.COLI_IsOld === '是'), [['COLI_IsOld', ], [], pivotByDate]); + const { data: isCusCommendData, } = pivotBy(data_detail.filter(ele => ele.COLI_IsCusCommend === '是'), [['COLI_IsCusCommend', ], [], pivotByDate]); + // console.log('IsOldData====', IsOldData, '\nisCusCommend', isCusCommendData); + // 合并成两个系列 + const seriesData = [].concat(IsOldData.map(ele => ({...ele, _ylabel: '老客户'})), isCusCommendData.map(ele => ({...ele, _ylabel: '老客户推荐'})),).sort(sortBy(pivotByDate)); + // console.log('seriesData====', seriesData); + + this.regular_data.pivotData = seriesData; // { IsOldData, isCusCommendData, }; + this.regular_data.pivotY = pivotByOrder; + this.regular_data.pivotX = pivotByDate; + } + + } else { - this.regular_data.data = json; + if (isCompare){ + const result = []; + const firstCompareData = this.regular_data.data; + for (const item1 of firstCompareData) { + for (const item2 of json) { + if (item1.ItemName === item2.ItemName) { + result.push({ + ItemName: item1.ItemName, + OrderNum: show_vs_tag(formatPercent((item1.OrderNum-item2.OrderNum)/(item2.OrderNum===0?1:item2.OrderNum)), + item1.OrderNum-item2.OrderNum,item1.OrderNum,item2.OrderNum), + SUCOrderNum: show_vs_tag(formatPercent((item1.SUCOrderNum-item2.SUCOrderNum)/(item2.SUCOrderNum===0?1:item2.SUCOrderNum)), + item1.SUCOrderNum-item2.SUCOrderNum,item1.SUCOrderNum,item2.SUCOrderNum), + SUCRate: show_vs_tag(formatPercent((item1.SUCRate-item2.SUCRate)/(item2.SUCRate===0?1:item2.SUCRate)), + formatPercent(item1.SUCRate-item2.SUCRate),formatPercent(item1.SUCRate),formatPercent(item2.SUCRate)), + ML: show_vs_tag(formatPercent((item1.ML-item2.ML)/(item2.ML===0?1:item2.ML)), + (item1.ML-item2.ML).toFixed(2),item1.ML,item2.ML), + PersonNum: show_vs_tag(formatPercent((item1.PersonNum-item2.PersonNum)/(item2.PersonNum===0?1:item2.PersonNum)), + item1.PersonNum-item2.PersonNum,item1.PersonNum,item2.PersonNum), + }); + } + } + }; + this.regular_data.data = result; + } + else{ + this.regular_data.data = json; + } } this.regular_data.loading = false; + resolve(); }); }) .catch((error) => { this.regular_data.loading = false; console.log('fetch data failed', error); }); + }); } handleChange_webcode_regular = (value) => { @@ -192,6 +268,8 @@ class CustomerStore { detail_loading: false, data: [], data_detail: [], + data_compare: [], + isRenderCount:0, total_data_tips: '', webcode: 'ALL', site_select_mode: 'multiple',// 站点是否多选