You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dashboard/src/stores/OrdersStore.js

159 lines
7.0 KiB
JavaScript

3 years ago
import {makeAutoObservable} from "mobx"
import * as config from "../config";
import moment from "moment";
3 years ago
class OrdersStore {
3 years ago
constructor(rootStore) {
this.rootStore = rootStore;
makeAutoObservable(this);
}
loading = false;
3 years ago
webcode = 'CHT';
active_tab_key = 'Form';//当前切换的标签页
3 years ago
orderCountData = [];//订单统计数据源
orderCountData_Form = {dataSource: [], columns: []};//表单类型统计数据源
orderCountData_Product = [];//表单类型统计数据源
orderCountData_Country = [];//表单类型统计数据源
orderCountData_line = [];//表单类型统计数据源
3 years ago
handleChange_webcode = (value) => {
this.webcode = value;
};
//格式化一下数据
//映射时间做时间段对比的时候需要把对比时间段映射到开始时间上才能在同一个x轴显示
//比如2022-10-01~2022-10-30 vs 2021-10-01~2021-10-30 则需要在2021年的时间段加365天的时间映射成2022起始时间段
//相差的天数用a.diff(b, 'days')计算
format_data_source(data_source, start_date, end_date) {
let result = [];
let diff_days = start_date.diff(end_date, 'days');
for (let item of data_source.ordercount1) {
result.push({
'xField': item.ApplyDate,
'yField': item.orderCount,
'seriesField': item.groups
})
}
for (let item of data_source.ordercount2) {
result.push({
'xField': moment(item.ApplyDate).add(diff_days, 'days').format(config.DATE_FORMAT),
'yField': item.orderCount,
'seriesField': item.groups
})
}
return result;
}
//网站订单数量
3 years ago
getOrderCount() {
this.loading = true;
const date_picker_store = this.rootStore.date_picker_store;
3 years ago
let url = '/service-web/QueryData/GetOrderCount'//?WebCode=cht&COLI_ApplyDate1=2022-08-01&COLI_ApplyDate2=2022-08-31&COLI_ApplyDateold1=2021-08-01&COLI_ApplyDateold2=2021-08-31';
url += '?WebCode=' + this.webcode + '&COLI_ApplyDate1=' + date_picker_store.start_date.format(config.DATE_FORMAT) + '&COLI_ApplyDate2=' + date_picker_store.end_date.format(config.DATE_FORMAT) + '%2023:59:59';
if (date_picker_store.start_date_cp && date_picker_store.end_date_cp) {
url += '&COLI_ApplyDateold1=' + date_picker_store.start_date_cp.format(config.DATE_FORMAT) + '&COLI_ApplyDateold2=' + date_picker_store.end_date_cp.format(config.DATE_FORMAT) + '%2023:59:59';
}
fetch(config.HT_HOST + url)
.then((response) => response.json())
.then((json) => {
this.orderCountData = this.format_data_source(json, date_picker_store.start_date, date_picker_store.start_date_cp);
this.loading = false;
})
.catch((error) => {
this.loading = false;
console.log('fetch data failed', error);
});
}
//网站订单类型
getOrderCountByType(order_type) {
const date_picker_store = this.rootStore.date_picker_store;
let url = '/service-web/QueryData/GetOrderCountByType'
url += '?WebCode=' + this.webcode + '&OrderType=' + order_type;
url += '&COLI_ApplyDate1=' + date_picker_store.start_date.format(config.DATE_FORMAT) + '&COLI_ApplyDate2=' + date_picker_store.end_date.format(config.DATE_FORMAT) + '%2023:59:59';
if (date_picker_store.start_date_cp && date_picker_store.end_date_cp) {
url += '&COLI_ApplyDateold1=' + date_picker_store.start_date_cp.format(config.DATE_FORMAT) + '&COLI_ApplyDateold2=' + date_picker_store.end_date_cp.format(config.DATE_FORMAT) + '%2023:59:59';
}
3 years ago
fetch(config.HT_HOST + url)
.then((response) => response.json())
.then((json) => {
let ordercountTotal1 = json.ordercountTotal1;
let ordercountTotal2 = json.ordercountTotal2;
if (ordercountTotal2) {
console.log('ok');
}
switch (order_type) {
case 'Form':
let data = [];
let columns =
[
{
title: '来源类型',
children: [{title: '', dataIndex: 'OrderType'}]
},
{
title: '数量',
children: [{title: ordercountTotal1.OrderCount, dataIndex: 'OrderCount'}],
sorter: (a, b) => b.OrderCount - a.OrderCount,
},
{
title: '成交数',
children: [{title: ordercountTotal1.CJCount, dataIndex: 'CJCount'}],
sorter: (a, b) => b.CJCount - a.CJCount,
},
{
title: '成交人数',
children: [{title: ordercountTotal1.CJPersonNum, dataIndex: 'CJPersonNum'}],
sorter: (a, b) => b.CJPersonNum - a.CJPersonNum,
},
{
title: '成交率',
children: [{title: ordercountTotal1.CJrate, dataIndex: 'CJrate'}],
sorter: (a, b) => parseInt(b.CJrate) - parseInt(a.CJrate),
},
{
title: '成交毛利(预计)',
children: [{title: ordercountTotal1.YJLY, dataIndex: 'YJLY'}],
sorter: (a, b) => b.YJLY - a.YJLY,
},
{
title: '单个订单价值',
children: [{title: ordercountTotal1.Ordervalue, dataIndex: 'Ordervalue'}],
sorter: (a, b) => b.Ordervalue - a.Ordervalue,
},
];
data.push(...json.ordercount1, ...json.ordercount2);
this.orderCountData_Form.dataSource = data;
this.orderCountData_Form.columns = columns;
// this.orderCountData_Form = [...json.ordercountTotal1,...json.ordercountTotal2];
console.log(data);
break;
}
3 years ago
})
.catch((error) => {
console.log('fetch data failed', error);
});
}
//切换标签页
onChange_Tabs(active_key) {
this.active_tab_key = active_key;
this.getOrderCountByType(this.active_tab_key);
}
3 years ago
}
3 years ago
3 years ago
export default OrdersStore;