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.
321 lines
14 KiB
JavaScript
321 lines
14 KiB
JavaScript
import {makeAutoObservable, runInAction} from "mobx";
|
|
import { fetchJSON } from '../utils/request';
|
|
import * as config from "../config";
|
|
import { groupsMappedByKey, sitesMappedByCode, pivotBy } from './../libs/ht';
|
|
|
|
/**
|
|
* 用于透视的数据
|
|
*/
|
|
const getDetailData = async (param) => {
|
|
const json = await fetchJSON('/service-Analyse2/GetTradeApartDetail', param);
|
|
return json.errcode === 0 ? json.result : [];
|
|
};
|
|
|
|
class CustomerStore {
|
|
|
|
constructor(rootStore) {
|
|
this.rootStore = rootStore;
|
|
makeAutoObservable(this);
|
|
}
|
|
|
|
|
|
// 潜力客户 beign
|
|
potential_customer_order(get_detail = false) {
|
|
this.potential_data.loading = true;
|
|
const date_picker_store = this.rootStore.date_picker_store;
|
|
let url = '/service-tourdesign/PotentialCusOrder';
|
|
url += '?Website=' + this.potential_data.webcode.toString() + '&DEI_SNList=' + this.potential_data.groups.toString();
|
|
if (String(this.potential_data.date_type).toLowerCase() === 'applydate') {
|
|
url += '&ApplydateCheck=1&EntrancedateCheck=0&ConfirmDateCheck=0';
|
|
} else if(String(this.potential_data.date_type).toLowerCase() === 'confirmdate'){
|
|
url += '&ApplydateCheck=0&EntrancedateCheck=0&ConfirmDateCheck=1';
|
|
}else {
|
|
url += '&ApplydateCheck=0&EntrancedateCheck=1&ConfirmDateCheck=0';
|
|
}
|
|
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';
|
|
}
|
|
fetch(config.HT_HOST + url)
|
|
.then((response) => response.json())
|
|
.then((json) => {
|
|
runInAction(() => {
|
|
if (get_detail) {
|
|
this.potential_data.data_detail = json;
|
|
} else {
|
|
this.potential_data.data = json;
|
|
}
|
|
this.potential_data.loading = false;
|
|
});
|
|
})
|
|
.catch((error) => {
|
|
this.potential_data.loading = false;
|
|
console.log('fetch data failed', error);
|
|
});
|
|
}
|
|
|
|
handleChange_webcode = (value) => {
|
|
this.potential_data.webcode = value;
|
|
};
|
|
|
|
handleChange_group_select(value) {
|
|
this.potential_data.groups = value;
|
|
};
|
|
|
|
onChange_datetype(e) {
|
|
this.potential_data.date_type = e.target.value;
|
|
};
|
|
|
|
onChange_show_detail_table() {
|
|
this.potential_data.show_detail_table = !this.potential_data.show_detail_table;
|
|
}
|
|
|
|
potential_data = {
|
|
loading: false,
|
|
data: [],
|
|
data_detail: [],
|
|
webcode: 'GHKYZG',
|
|
site_select_mode: 'multiple',// 站点是否多选
|
|
group_select_mode: 'multiple',// 是否多选分组
|
|
groups: ['1', '2', '7'],
|
|
date_type: 'applyDate',
|
|
group_handleChange: this.handleChange_group_select.bind(this),
|
|
onChange_datetype: this.onChange_datetype.bind(this),
|
|
potential_customer_order: this.potential_customer_order.bind(this),
|
|
onChange_show_detail_table: this.onChange_show_detail_table.bind(this),
|
|
handleChange_webcode: this.handleChange_webcode.bind(this),
|
|
|
|
searchValues: {
|
|
DepartmentList: ['1', '2', '7'].map(kk => groupsMappedByKey[kk]),
|
|
WebCode: ['GHKYZG'].map(kk => sitesMappedByCode[kk]),
|
|
DateType: { key: 'applyDate', label: '提交日期'},
|
|
},
|
|
};
|
|
// 潜力客户 end
|
|
|
|
|
|
// 老客户 beign
|
|
regular_customer_order(get_detail = false) {
|
|
this.regular_data.loading = true;
|
|
const date_picker_store = this.rootStore.date_picker_store;
|
|
let url = '/service-tourdesign/RegularCusOrder';
|
|
url += '?Website=' + this.regular_data.webcode.toString() + '&DEI_SNList=' + this.regular_data.groups.toString();
|
|
if (String(this.regular_data.date_type).toLowerCase() === 'applydate') {
|
|
url += '&ApplydateCheck=1&EntrancedateCheck=0&ConfirmDateCheck=0';
|
|
} else if(String(this.regular_data.date_type).toLowerCase() === 'confirmdate'){
|
|
url += '&ApplydateCheck=0&EntrancedateCheck=0&ConfirmDateCheck=1';
|
|
}else {
|
|
url += '&ApplydateCheck=0&EntrancedateCheck=1&ConfirmDateCheck=0';
|
|
}
|
|
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';
|
|
}
|
|
fetch(config.HT_HOST + url)
|
|
.then((response) => response.json())
|
|
.then((json) => {
|
|
runInAction(() => {
|
|
if (get_detail) {
|
|
this.regular_data.data_detail = json;
|
|
} else {
|
|
this.regular_data.data = json;
|
|
}
|
|
this.regular_data.loading = false;
|
|
});
|
|
})
|
|
.catch((error) => {
|
|
this.regular_data.loading = false;
|
|
console.log('fetch data failed', error);
|
|
});
|
|
}
|
|
|
|
handleChange_webcode_regular = (value) => {
|
|
this.regular_data.webcode = value;
|
|
};
|
|
|
|
handleChange_group_select_regular(value) {
|
|
this.regular_data.groups = value;
|
|
};
|
|
|
|
onChange_datetype_regular(e) {
|
|
this.regular_data.date_type = e.target.value;
|
|
};
|
|
|
|
onChange_show_detail_table_regular() {
|
|
this.regular_data.show_detail_table = !this.regular_data.show_detail_table;
|
|
}
|
|
|
|
regular_data = {
|
|
loading: false,
|
|
data: [],
|
|
data_detail: [],
|
|
webcode: 'ALL',
|
|
site_select_mode: 'multiple',// 站点是否多选
|
|
group_select_mode: 'multiple',// 是否多选分组
|
|
groups: ['1', '2', '28', '7'],
|
|
date_type: 'applyDate',
|
|
group_handleChange: this.handleChange_group_select_regular.bind(this),
|
|
onChange_datetype: this.onChange_datetype_regular.bind(this),
|
|
regular_customer_order: this.regular_customer_order.bind(this),
|
|
onChange_show_detail_table: this.onChange_show_detail_table_regular.bind(this),
|
|
handleChange_webcode: this.handleChange_webcode_regular.bind(this),
|
|
|
|
searchValues: {
|
|
DepartmentList: ['1', '2', '28', '7'].map(kk => groupsMappedByKey[kk]),
|
|
WebCode: undefined, // ['ALL'].map(kk => sitesMappedByCode[kk]),
|
|
DateType: { key: 'applyDate', label: '提交日期'},
|
|
},
|
|
};
|
|
// 老客户 end
|
|
|
|
|
|
// 在华客人 beign
|
|
inchina_customer_order(get_detail = false) {
|
|
this.inchina_data.loading = true;
|
|
const date_picker_store = this.rootStore.date_picker_store;
|
|
let url = '/service-tourdesign/RegularCusInChinaOrder';
|
|
url += '?Website=' + this.inchina_data.webcode.toString() + '&DEI_SNList=' + this.inchina_data.groups.toString();
|
|
if (String(this.inchina_data.date_type).toLowerCase() === 'applydate') {
|
|
url += '&ApplydateCheck=1&EntrancedateCheck=0&ConfirmDateCheck=0';
|
|
} else if(String(this.inchina_data.date_type).toLowerCase() === 'confirmdate'){
|
|
url += '&ApplydateCheck=0&EntrancedateCheck=0&ConfirmDateCheck=1';
|
|
}else {
|
|
url += '&ApplydateCheck=0&EntrancedateCheck=1&ConfirmDateCheck=0';
|
|
}
|
|
if (get_detail) {
|
|
url += '&IsDetail=1';
|
|
} else {
|
|
url += '&IsDetail=0';
|
|
}
|
|
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);
|
|
fetch(config.HT_HOST + url)
|
|
.then((response) => response.json())
|
|
.then((json) => {
|
|
runInAction(() => {
|
|
if (get_detail) {
|
|
this.inchina_data.data_detail = json;
|
|
} else {
|
|
this.inchina_data.data = json;
|
|
}
|
|
this.inchina_data.loading = false;
|
|
});
|
|
})
|
|
.catch((error) => {
|
|
this.inchina_data.loading = false;
|
|
console.log('fetch data failed', error);
|
|
});
|
|
}
|
|
|
|
handleChange_webcode_inchina = (value) => {
|
|
this.inchina_data.webcode = value;
|
|
};
|
|
|
|
handleChange_group_select_inchina(value) {
|
|
this.inchina_data.groups = value;
|
|
};
|
|
|
|
onChange_datetype_inchina(e) {
|
|
this.inchina_data.date_type = e.target.value;
|
|
};
|
|
|
|
onChange_show_detail_table_inchina() {
|
|
this.inchina_data.show_detail_table = !this.inchina_data.show_detail_table;
|
|
}
|
|
|
|
inchina_data = {
|
|
loading: false,
|
|
data: [],
|
|
data_detail: [],
|
|
webcode: 'ALL',
|
|
site_select_mode: 'multiple',// 站点是否多选
|
|
group_select_mode: 'multiple',// 是否多选分组
|
|
groups: ['1', '2', '28', '7'],
|
|
date_type: 'applyDate',
|
|
group_handleChange: this.handleChange_group_select_inchina.bind(this),
|
|
onChange_datetype: this.onChange_datetype_inchina.bind(this),
|
|
inchina_customer_order: this.inchina_customer_order.bind(this),
|
|
onChange_show_detail_table: this.onChange_show_detail_table_inchina.bind(this),
|
|
handleChange_webcode: this.handleChange_webcode_inchina.bind(this),
|
|
|
|
searchValues: {
|
|
DepartmentList: ['1', '2', '28', '7'].map(kk => groupsMappedByKey[kk]),
|
|
WebCode: undefined, // ['ALL'].map(kk => sitesMappedByCode[kk]),
|
|
DateType: { key: 'applyDate', label: '提交日期'},
|
|
},
|
|
};
|
|
// 在华客人 end
|
|
|
|
sales_regular_data = {
|
|
loading: false,
|
|
data: [],
|
|
mergedData: [],
|
|
rawData: [],
|
|
searchValues: {
|
|
DepartmentList: ['1', '2', '28', '7'].map(kk => groupsMappedByKey[kk]),
|
|
WebCode: undefined, // ['ALL'].map(kk => sitesMappedByCode[kk]),
|
|
DateType: { key: 'applyDate', label: '提交日期'},
|
|
},
|
|
};
|
|
|
|
get_sales_regular_data = async (param) => {
|
|
this.sales_regular_data.loading = true;
|
|
const rawData = await getDetailData({...param, IncludeTickets: 1});
|
|
const filterHasOld = rawData.filter(ele => (ele.IsOld === '1' || ele.isCusCommend === '1')).map(e => ({...e, operatorNameB: e.operatorName.replace(/\([^)]*\)/gi, '').toLowerCase()}));
|
|
|
|
const { data: hasOldData, } = pivotBy(filterHasOld, [['hasOld', 'operatorName'], [], []]);
|
|
const { data: IsOldData, } = pivotBy(filterHasOld.filter(ele => ele.IsOld === '1'), [['operatorName', 'IsOld_txt', ], [], []]);
|
|
const { data: isCusCommendData, } = pivotBy(filterHasOld.filter(ele => ele.isCusCommend === '1'), [['operatorName', 'isCusCommend_txt', ], [], []]);
|
|
// console.log('IsOldData====', IsOldData, '\nisCusCommend', isCusCommendData);
|
|
// console.log('data====', rawData, '\ncolumnValues', columnValues, '\nsummaryRows', summaryRows, '\nsummaryColumns', summaryColumns, '\nsummaryMix', summaryMix, '\nhasOld',filterHasOld);
|
|
const mergeDataBySales = hasOldData.map((ele) => ({
|
|
...ele,
|
|
children: [].concat(
|
|
IsOldData.filter((ele1) => ele1.operatorName === ele.operatorName).map(o => ({...o, operatorName: o.IsOld_txt, key: o.rowLabel})),
|
|
isCusCommendData.filter((ele2) => ele2.operatorName === ele.operatorName).map(o => ({...o, operatorName: o.isCusCommend_txt, key: o.rowLabel}))
|
|
),
|
|
}));
|
|
|
|
// 合并顾问的账户
|
|
const { data: hasOldDataSales, } = pivotBy(filterHasOld, [['hasOld', 'operatorNameB'], [], []]);
|
|
const { data: IsOldDataSales, } = pivotBy(filterHasOld.filter(ele => ele.IsOld === '1'), [['operatorNameB', 'IsOld_txt', ], [], []]);
|
|
const { data: isCusCommendDataSales, } = pivotBy(filterHasOld.filter(ele => ele.isCusCommend === '1'), [['operatorNameB', 'isCusCommend_txt', ], [], []]);
|
|
const mergeDataBySalesAccount = hasOldDataSales.map((ele) => ({
|
|
...ele,
|
|
operatorName: ele.operatorNameB,
|
|
children: [].concat(
|
|
IsOldDataSales.filter((ele1) => ele1.operatorNameB === ele.operatorNameB).map(o => ({...o, operatorName: o.IsOld_txt, key: o.rowLabel})),
|
|
isCusCommendDataSales.filter((ele2) => ele2.operatorNameB === ele.operatorNameB).map(o => ({...o, operatorName: o.isCusCommend_txt, key: o.rowLabel}))
|
|
),
|
|
}));
|
|
// console.log('IsOldDataSales====', IsOldDataSales, '\nisCusCommendDataSales', isCusCommendDataSales);
|
|
// console.log('mergeDataBySalesAccount====', mergeDataBySalesAccount);
|
|
|
|
this.sales_regular_data.loading = false;
|
|
this.sales_regular_data.data = mergeDataBySales;
|
|
this.sales_regular_data.mergedData = mergeDataBySalesAccount;
|
|
this.sales_regular_data.rawData = filterHasOld;
|
|
};
|
|
|
|
setSearchValues(obj, values, target) {
|
|
this[target].groups = obj.DepartmentList;
|
|
this[target].webcode = obj.WebCode;
|
|
this[target].include_tickets = obj.IncludeTickets;
|
|
this[target].date_type = obj.DateType;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
export default CustomerStore;
|
|
|