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(value) { this.date_type = 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 { if (this.active_tab_key == "All") { result.columns = [ { title: "", children: [ { title: "", dataIndex: "OPI_Name", }, ], }, { title: "毛利", children: [{ title: "毛利合计", dataIndex: "COLI_ML" }], sorter: (a, b) => parseInt(b.COLI_ML.replace(/,/g, "")) - parseInt(a.COLI_ML.replace(/,/g, "")), }, { title: "成行率", children: [{ title: "平均成行率", dataIndex: "COLI_CJrate" }], sorter: (a, b) => parseInt(b.COLI_CJrate) - parseInt(a.COLI_CJrate), }, { title: "成团数", children: [{ title: "成团数合计", dataIndex: "COLI_CJCount" }], sorter: (a, b) => b.COLI_CJCount - a.COLI_CJCount, }, { title: "订单数", children: [{ title: "订单数合计", dataIndex: "COLI_OrderCount" }], sorter: (a, b) => b.COLI_OrderCount - a.COLI_OrderCount, }, { title: "单团毛利", children: [{ title: "平均单团毛利", dataIndex: "COLI_SingleML" }], sorter: (a, b) => parseInt(b.COLI_SingleML.replace(/,/g, "")) - parseInt(a.COLI_SingleML.replace(/,/g, "")), }, { title: "成团周期", children: [{ title: "平均成团周期", dataIndex: "COLI_Cycle" }], sorter: (a, b) => b.COLI_Cycle - a.COLI_Cycle, }, ]; result.dataSource = json.result1; } else if (this.active_tab_key == "Country") { //获取类型的项目,去掉重复,作为列名 let type_name_arr = []; json.result1.map(item => { type_name_arr[item.SubTypeSN] = { SubTypeSN: item.SubTypeSN, SubTypeName: item.SubTypeName }; }); let type_data = []; let type_data_arr = []; for (let item of json.result1) { if (comm.empty(type_data["OP_" + item.OPI_SN])) { type_data["OP_" + item.OPI_SN] = [{ key: item.OPI_SN }, { T_name: item.OPI_Name }, { T_total: item.OPI_TotalYJLY }]; } type_data["OP_" + item.OPI_SN].push({ ["T_" + item.SubTypeSN]: item.COLI_YJLY }); } Object.values(type_data).map(item => { type_data_arr.push( Object.assign( ...item.map(it => { return it; }) ) ); }); result.columns.push({ title: "顾问", dataIndex: "T_name" }, { title: "合计", dataIndex: "T_total" }); type_name_arr.map((item, index) => { result.columns.push({ title: item.SubTypeName, dataIndex: "T_" + item.SubTypeSN, }); }); result.dataSource = type_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;