|
|
@ -3,7 +3,7 @@ import moment from 'moment';
|
|
|
|
import * as config from '../config';
|
|
|
|
import * as config from '../config';
|
|
|
|
import * as comm from '../utils/commons';
|
|
|
|
import * as comm from '../utils/commons';
|
|
|
|
import { NavLink } from 'react-router-dom';
|
|
|
|
import { NavLink } from 'react-router-dom';
|
|
|
|
import { groupsMappedByCode } from './../libs/ht';
|
|
|
|
import { groupsMappedByCode, dataFieldAlias } from './../libs/ht';
|
|
|
|
|
|
|
|
|
|
|
|
// 销售数据
|
|
|
|
// 销售数据
|
|
|
|
class SaleStore {
|
|
|
|
class SaleStore {
|
|
|
@ -125,7 +125,9 @@ class SaleStore {
|
|
|
|
fetch(config.HT_HOST + url)
|
|
|
|
fetch(config.HT_HOST + url)
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((json) => {
|
|
|
|
.then((json) => {
|
|
|
|
if (!comm.empty(json.result2) && !comm.empty(date_moment.start_date_cp)) {
|
|
|
|
// if (!comm.empty(json.result2) && !comm.empty(date_moment.start_date_cp)) {
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-constant-condition
|
|
|
|
|
|
|
|
if (false) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (this.active_tab_key === 'All') {
|
|
|
|
if (this.active_tab_key === 'All') {
|
|
|
|
result.columns = [
|
|
|
|
result.columns = [
|
|
|
@ -306,10 +308,12 @@ class SaleStore {
|
|
|
|
];
|
|
|
|
];
|
|
|
|
result.dataSource = json.result1;
|
|
|
|
result.dataSource = json.result1;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const diffDateFlagYes = !comm.isEmpty(date_moment.start_date_cp);
|
|
|
|
// if (this.active_tab_key == "Country")
|
|
|
|
// if (this.active_tab_key == "Country")
|
|
|
|
|
|
|
|
const mergeDiffData = calcDiff({result1: json.result1, result2: json.result2});
|
|
|
|
// 获取类型的项目,去掉重复,作为列名
|
|
|
|
// 获取类型的项目,去掉重复,作为列名
|
|
|
|
const type_name_arr = [];
|
|
|
|
const type_name_arr = [];
|
|
|
|
json.result1.map((item) => {
|
|
|
|
mergeDiffData.map((item) => {
|
|
|
|
type_name_arr[item.SubTypeSN] = { SubTypeSN: item.SubTypeSN, SubTypeName: item.SubTypeName };
|
|
|
|
type_name_arr[item.SubTypeSN] = { SubTypeSN: item.SubTypeSN, SubTypeName: item.SubTypeName };
|
|
|
|
return item;
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -317,14 +321,26 @@ class SaleStore {
|
|
|
|
const type_data = [];
|
|
|
|
const type_data = [];
|
|
|
|
const type_data_arr = [];
|
|
|
|
const type_data_arr = [];
|
|
|
|
|
|
|
|
|
|
|
|
for (const item of json.result1) {
|
|
|
|
for (const item of mergeDiffData) {
|
|
|
|
const op_sn = 'OP_' + item.OPI_SN; // 顾问的SN
|
|
|
|
const op_sn = 'OP_' + item.OPI_SN; // 顾问的SN
|
|
|
|
const items = json.result1.filter((d) => String(d.OPI_SN) === String(item.OPI_SN)); // 筛选出有当前顾问的记录
|
|
|
|
const items = mergeDiffData.filter((d) => String(d.OPI_SN) === String(item.OPI_SN)); // 筛选出有当前顾问的记录
|
|
|
|
const total_data_value = items.length ? items.reduce((a, b) => a + b.COLI_YJLY, 0) : ''; // 记录累加
|
|
|
|
const total_data_value = items.length ? items.reduce((a, b) => a + b.COLI_YJLY, 0) : ''; // 记录累加
|
|
|
|
|
|
|
|
const total_data_value_diff = items.length ? items.reduce((a, b) => a + b.COLI_YJLY2, 0) : ''; // 记录累加
|
|
|
|
if (comm.empty(type_data[op_sn])) {
|
|
|
|
if (comm.empty(type_data[op_sn])) {
|
|
|
|
type_data[op_sn] = [{ key: item.OPI_SN }, { T_name: item.OPI_Name }, { T_total: total_data_value }];
|
|
|
|
type_data[op_sn] = [{ key: item.OPI_SN }, { T_name: item.OPI_Name }, { T_total: total_data_value }, { V_total: total_data_value_diff }];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
type_data[op_sn].push({ ['T_' + item.SubTypeSN]: item.COLI_YJLY });
|
|
|
|
const _diff = comm.objectMapper(comm.pick(item, ['COLI_YJLY_diff', 'COLI_YJLY_vs', 'COLI_YJLY2']), {
|
|
|
|
|
|
|
|
COLI_YJLY2: { key: `v_${item.SubTypeSN}` },
|
|
|
|
|
|
|
|
COLI_YJLY_diff: { key: `diff_${item.SubTypeSN}` },
|
|
|
|
|
|
|
|
COLI_YJLY_vs: { key: `vs_${item.SubTypeSN}` },
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
type_data[op_sn].push({
|
|
|
|
|
|
|
|
['T_' + item.SubTypeSN]: diffDateFlagYes
|
|
|
|
|
|
|
|
? comm.show_vs_tag(_diff[`vs_${item.SubTypeSN}`]+'%', _diff[`diff_${item.SubTypeSN}`], item.COLI_YJLY, _diff[`v_${item.SubTypeSN}`])
|
|
|
|
|
|
|
|
: item.COLI_YJLY,
|
|
|
|
|
|
|
|
..._diff,
|
|
|
|
|
|
|
|
[`TV_${item.SubTypeSN}`]: item.COLI_YJLY,
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Object.values(type_data).map((item) => {
|
|
|
|
Object.values(type_data).map((item) => {
|
|
|
|
type_data_arr.push(
|
|
|
|
type_data_arr.push(
|
|
|
@ -336,18 +352,41 @@ class SaleStore {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
return item;
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const totalDiff = {
|
|
|
|
|
|
|
|
diffVal: type_data_arr.reduce((a, b) => a + b.V_total, 0),
|
|
|
|
|
|
|
|
val: type_data_arr.reduce((a, b) => a + b.T_total, 0),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
totalDiff.diff = (totalDiff.val-totalDiff.diffVal);
|
|
|
|
|
|
|
|
totalDiff.vs = comm.fixTo2Decimals(((totalDiff.val-totalDiff.diffVal)/totalDiff.diffVal)*100)+'%';
|
|
|
|
result.columns.push(
|
|
|
|
result.columns.push(
|
|
|
|
{ title: '顾问', children: [{ title: '', dataIndex: 'T_name', render: (text, record) => <NavLink to={`/sale_sub/${this.active_tab_key}`}>{text}</NavLink> }] },
|
|
|
|
{ title: '顾问', children: [{ title: '', dataIndex: 'T_name', render: (text, record) => <NavLink to={`/sale_sub/${this.active_tab_key}`}>{text}</NavLink> }] },
|
|
|
|
{ title: '合计', children: [{ title: type_data_arr.reduce((a, b) => a + b.T_total, 0), dataIndex: 'T_total' }], sorter: (a, b) => b.T_total - a.T_total }
|
|
|
|
{
|
|
|
|
|
|
|
|
title: '合计',
|
|
|
|
|
|
|
|
children: [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
title: diffDateFlagYes
|
|
|
|
|
|
|
|
? comm.show_vs_tag(totalDiff.vs, totalDiff.diff, totalDiff.val, totalDiff.diffVal)
|
|
|
|
|
|
|
|
: type_data_arr.reduce((a, b) => a + b.T_total, 0),
|
|
|
|
|
|
|
|
dataIndex: 'T_total',
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
sorter: (a, b) => b.T_total - a.T_total,
|
|
|
|
|
|
|
|
}
|
|
|
|
);
|
|
|
|
);
|
|
|
|
Object.values(type_name_arr).map((item, index) => {
|
|
|
|
Object.values(type_name_arr).map((item, index) => {
|
|
|
|
const data_index = 'T_' + item.SubTypeSN;
|
|
|
|
const data_index = 'T_' + item.SubTypeSN;
|
|
|
|
const items = type_data_arr.filter((d) => d[data_index]); // 筛选出有对应类型的记录
|
|
|
|
const items = type_data_arr.filter((d) => d[data_index]); // 筛选出有对应类型的记录
|
|
|
|
const total_data_value = items.length ? items.reduce((a, b) => a + b[data_index], 0) : ''; // 记录累加
|
|
|
|
const total_data_value = items.length ? items.reduce((a, b) => a + b[`TV_${item.SubTypeSN}`], 0) : ''; // 记录累加
|
|
|
|
|
|
|
|
const total_data_value_diff = items.length ? items.reduce((a, b) => a + b[`v_${item.SubTypeSN}`], 0) : 0; // 记录累加
|
|
|
|
|
|
|
|
const columnDiff = {
|
|
|
|
|
|
|
|
val: total_data_value_diff,
|
|
|
|
|
|
|
|
diff: total_data_value - total_data_value_diff,
|
|
|
|
|
|
|
|
vs: comm.fixTo2Decimals(((total_data_value-total_data_value_diff)/total_data_value_diff)*100)+'%',
|
|
|
|
|
|
|
|
};
|
|
|
|
result.columns.push({
|
|
|
|
result.columns.push({
|
|
|
|
title: item.SubTypeName,
|
|
|
|
title: item.SubTypeName,
|
|
|
|
children: [{ title: total_data_value, dataIndex: data_index }],
|
|
|
|
children: [{ title: diffDateFlagYes ? comm.show_vs_tag(columnDiff.vs, columnDiff.diff, total_data_value, total_data_value_diff) : total_data_value, dataIndex: data_index }],
|
|
|
|
sorter: (a, b) => b[data_index] - a[data_index],
|
|
|
|
sorter: (a, b) => b[`TV_${item.SubTypeSN}`] - a[`TV_${item.SubTypeSN}`],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return item;
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -383,7 +422,9 @@ class SaleStore {
|
|
|
|
fetch(config.HT_HOST + url)
|
|
|
|
fetch(config.HT_HOST + url)
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((json) => {
|
|
|
|
.then((json) => {
|
|
|
|
if (!comm.empty(json.result2) && !comm.empty(date_moment.start_date_cp)) {
|
|
|
|
// if (!comm.empty(json.result2) && !comm.empty(date_moment.start_date_cp)) {
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-constant-condition
|
|
|
|
|
|
|
|
if (false) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
result.columns = [
|
|
|
|
result.columns = [
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -450,4 +491,25 @@ class SaleStore {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const calcDiff = ({ result1 , result2 }) => {
|
|
|
|
|
|
|
|
const initialDataWithAllKeys = comm.unique([].concat(result1 , result2).map((ele) => `${ele.OPI_SN}@${ele.SubTypeSN}`)).reduce((r, v) => {
|
|
|
|
|
|
|
|
const [OPI_SN, SubTypeSN] = String(v).split('@');
|
|
|
|
|
|
|
|
r.push({OPI_SN, SubTypeSN, COLI_YJLY: 0, key: `${OPI_SN}@${SubTypeSN}` });
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const initialMapped = initialDataWithAllKeys.reduce((r, v) => ({ ...r, [v.key]: v }), {});
|
|
|
|
|
|
|
|
const result1Mapped = result1.reduce((r, v) => ({ ...r, [`${v.OPI_SN}@${v.SubTypeSN}`]: v }), comm.cloneDeep(initialMapped));
|
|
|
|
|
|
|
|
const result2Mapped = result2.reduce((r, v) => ({ ...r, [`${v.OPI_SN}@${v.SubTypeSN}`]: v }), comm.cloneDeep(initialMapped));
|
|
|
|
|
|
|
|
const afterCalc = initialDataWithAllKeys.map((row) => {
|
|
|
|
|
|
|
|
const diff = {
|
|
|
|
|
|
|
|
COLI_YJLY2: result2Mapped?.[row.key]?.COLI_YJLY || 0,
|
|
|
|
|
|
|
|
COLI_YJLY_vs: result2Mapped?.[row.key]?.COLI_YJLY ? comm.fixTo2Decimals(((result1Mapped[row.key].COLI_YJLY - result2Mapped[row.key].COLI_YJLY) / result2Mapped[row.key].COLI_YJLY) * 100) : 0,
|
|
|
|
|
|
|
|
COLI_YJLY_diff: result1Mapped[row.key].COLI_YJLY - result2Mapped[row.key].COLI_YJLY,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const extField = comm.pick(result2Mapped[row.key], ['OPI_Name', 'SubTypeName', 'groups']);
|
|
|
|
|
|
|
|
return { ...result1Mapped[row.key], ...extField, ...diff };
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return afterCalc;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default SaleStore;
|
|
|
|
export default SaleStore;
|
|
|
|