|
|
|
import { makeAutoObservable, runInAction } from "mobx";
|
|
|
|
import moment from "moment";
|
|
|
|
import * as config from "../config";
|
|
|
|
import * as comm from "../utils/commons";
|
|
|
|
|
|
|
|
//销售数据
|
|
|
|
class SaleStore {
|
|
|
|
constructor(rootStore) {
|
|
|
|
this.rootStore = rootStore;
|
|
|
|
makeAutoObservable(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
loading = false;
|
|
|
|
loading_table = false;
|
|
|
|
active_tab_key = "All"; //当前选择的标签
|
|
|
|
group_select_mode = false;
|
|
|
|
date_type = "applyDate";
|
|
|
|
groups = ["1,2,28,7"];
|
|
|
|
ml_data = []; //毛利数据
|
|
|
|
type_data = []; //类型的数据
|
|
|
|
date_title = "date_title"; //日期段,只用于显示,防止日期选择控件的变化导致页面刷新
|
|
|
|
|
|
|
|
//选择事业部
|
|
|
|
group_handleChange(value) {
|
|
|
|
this.groups = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//切换标签页
|
|
|
|
onChange_Tabs(active_key) {
|
|
|
|
this.active_tab_key = active_key;
|
|
|
|
//this.getOrderCountByType_sub(ordertype, ordertype_sub, this.active_tab_key_sub);
|
|
|
|
}
|
|
|
|
|
|
|
|
//下单日期或者出发日期
|
|
|
|
onChange_datetype(e) {
|
|
|
|
this.date_type = e.target.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取业绩信息
|
|
|
|
get_department_order_ml(date_moment) {
|
|
|
|
let result = [];
|
|
|
|
const date1_start = date_moment.start_date.format(config.DATE_FORMAT);
|
|
|
|
const date1_end = date_moment.end_date.format(config.DATE_FORMAT);
|
|
|
|
const date2_start = comm.empty(date_moment.start_date_cp) ? "" : date_moment.start_date_cp.format(config.DATE_FORMAT);
|
|
|
|
const date2_end = comm.empty(date_moment.end_date_cp) ? "" : date_moment.end_date_cp.format(config.DATE_FORMAT);
|
|
|
|
this.loading = true;
|
|
|
|
this.date_title = `${date1_start}~${date1_end}`;
|
|
|
|
let url = "/service-web/QueryData/GetDepartmentOrderML";
|
|
|
|
url += `?DepartmentList=${this.groups.toString()}&DateType=${this.date_type}`;
|
|
|
|
url += `&Date1=${date1_start}&Date2=${date1_end}%2023:59:59`;
|
|
|
|
if (date2_start && date2_end) {
|
|
|
|
url += `&OldDate1=${date2_start}&OldDate2=${date2_end}%2023:59:59`;
|
|
|
|
this.date_title += ` ${date2_start}~${date2_end}`;
|
|
|
|
}
|
|
|
|
fetch(config.HT_HOST + url)
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(json => {
|
|
|
|
result.push(...json.result1);
|
|
|
|
if (!comm.empty(json.result2) && !comm.empty(date_moment.start_date_cp)) {
|
|
|
|
let diff_days = date_moment.start_date.diff(date_moment.start_date_cp, "days");
|
|
|
|
for (let item of json.result2) {
|
|
|
|
result.push({
|
|
|
|
COLI_Date: moment(item.COLI_Date).add(diff_days, "days").format(config.DATE_FORMAT),
|
|
|
|
COLI_YJLY: item.COLI_YJLY,
|
|
|
|
groups: item.groups,
|
|
|
|
key: item.key,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
runInAction(() => {
|
|
|
|
this.ml_data = result;
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.loading = false;
|
|
|
|
console.log("fetch data failed", error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
//按类型获取业绩
|
|
|
|
get_department_order_ml_by_type(date_moment) {
|
|
|
|
let result = { dataSource: [], columns: [] };
|
|
|
|
const date1_start = date_moment.start_date.format(config.DATE_FORMAT);
|
|
|
|
const date1_end = date_moment.end_date.format(config.DATE_FORMAT);
|
|
|
|
const date2_start = comm.empty(date_moment.start_date_cp) ? "" : date_moment.start_date_cp.format(config.DATE_FORMAT);
|
|
|
|
const date2_end = comm.empty(date_moment.end_date_cp) ? "" : date_moment.end_date_cp.format(config.DATE_FORMAT);
|
|
|
|
this.loading_table = true;
|
|
|
|
this.date_title = `${date1_start}~${date1_end}`;
|
|
|
|
let url = "/service-web/QueryData/GetDepartmentOrderMLByType";
|
|
|
|
url += `?DepartmentList=${this.groups.toString()}&DateType=${this.date_type}&OrderType=${this.active_tab_key}`;
|
|
|
|
url += `&Date1=${date1_start}&Date2=${date1_end}%2023:59:59`;
|
|
|
|
if (date2_start && date2_end) {
|
|
|
|
url += `&OldDate1=${date2_start}&OldDate2=${date2_end}%2023:59:59`;
|
|
|
|
this.date_title += ` ${date2_start}~${date2_end}`;
|
|
|
|
}
|
|
|
|
fetch(config.HT_HOST + url)
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(json => {
|
|
|
|
if (!comm.empty(json.result2) && !comm.empty(date_moment.start_date_cp)) {
|
|
|
|
} else {
|
|
|
|
let opi_arr = []; //顾问列表
|
|
|
|
let row_title = ""; //行标题
|
|
|
|
let new_data_arr = []; //行列转换后的数组
|
|
|
|
Object.keys(json.result1[0]).map((col, col_i) => {
|
|
|
|
switch (col) {
|
|
|
|
case "OPI_Name":
|
|
|
|
opi_arr = [
|
|
|
|
{ name: "", index: "c0" },
|
|
|
|
...Object.values(json.result1).map((row, row_i) => {
|
|
|
|
return { name: Object.values(row)[col_i], index: "c" + ++row_i };
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
case "COLI_OrderCount":
|
|
|
|
row_title = "订单数";
|
|
|
|
break;
|
|
|
|
case "COLI_ML":
|
|
|
|
row_title = "毛利";
|
|
|
|
break;
|
|
|
|
case "COLI_CJCount":
|
|
|
|
row_title = "成团数";
|
|
|
|
break;
|
|
|
|
case "COLI_CJrate":
|
|
|
|
row_title = "成行率";
|
|
|
|
break;
|
|
|
|
case "COLI_Cycle":
|
|
|
|
row_title = "成行周期";
|
|
|
|
break;
|
|
|
|
case "COLI_SingleML":
|
|
|
|
row_title = "单团毛利";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
new_data_arr.push(
|
|
|
|
Object.assign(
|
|
|
|
{ key: col_i },
|
|
|
|
{ c0: row_title },
|
|
|
|
...Object.values(json.result1).map((row, row_i) => {
|
|
|
|
return { ["c" + ++row_i]: Object.values(row)[col_i] };
|
|
|
|
})
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
for (let item of opi_arr) {
|
|
|
|
result.columns.push({
|
|
|
|
title: item.name,
|
|
|
|
dataIndex: item.index,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
result.dataSource = new_data_arr;
|
|
|
|
}
|
|
|
|
runInAction(() => {
|
|
|
|
this.type_data = result;
|
|
|
|
this.loading_table = false;
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.loading_table = false;
|
|
|
|
console.log("fetch data failed", error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SaleStore;
|