fix: 销售>业绩数据: 对比数据显示

feature/2.0-sales-trade
Lei OT 2 years ago
parent 921106af1d
commit c6e4471a35

@ -142,7 +142,7 @@ export const KPIObjects = [
{
key: 'guestgrouptype',
value: 'guestgrouptype',
label: '成员关系',
label: '客群类别',
data: [
{ key: '146001', value: '146001', label: '夫妻' },
{ key: '146002', value: '146002', label: '家庭' },

@ -3,7 +3,7 @@ import moment from 'moment';
import * as config from '../config';
import * as comm from '../utils/commons';
import { NavLink } from 'react-router-dom';
import { groupsMappedByCode } from './../libs/ht';
import { groupsMappedByCode, dataFieldAlias } from './../libs/ht';
// 销售数据
class SaleStore {
@ -125,7 +125,9 @@ class SaleStore {
fetch(config.HT_HOST + url)
.then((response) => response.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 {
if (this.active_tab_key === 'All') {
result.columns = [
@ -300,10 +302,12 @@ class SaleStore {
];
result.dataSource = json.result1;
} else {
const diffDateFlagYes = !comm.isEmpty(date_moment.start_date_cp);
// if (this.active_tab_key == "Country")
const mergeDiffData = calcDiff({result1: json.result1, result2: json.result2});
// 获取类型的项目,去掉重复,作为列名
const type_name_arr = [];
json.result1.map((item) => {
mergeDiffData.map((item) => {
type_name_arr[item.SubTypeSN] = { SubTypeSN: item.SubTypeSN, SubTypeName: item.SubTypeName };
return item;
});
@ -311,14 +315,26 @@ class SaleStore {
const type_data = [];
const type_data_arr = [];
for (const item of json.result1) {
for (const item of mergeDiffData) {
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_diff = items.length ? items.reduce((a, b) => a + b.COLI_YJLY2, 0) : ''; // 记录累加
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) => {
type_data_arr.push(
@ -330,18 +346,41 @@ class SaleStore {
);
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(
{ 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) => {
const data_index = 'T_' + item.SubTypeSN;
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({
title: item.SubTypeName,
children: [{ title: total_data_value, dataIndex: data_index }],
sorter: (a, b) => b[data_index] - a[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[`TV_${item.SubTypeSN}`] - a[`TV_${item.SubTypeSN}`],
});
return item;
});
@ -377,7 +416,9 @@ class SaleStore {
fetch(config.HT_HOST + url)
.then((response) => response.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 {
result.columns = [
{
@ -439,4 +480,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;

@ -75,7 +75,10 @@ const Sale = () => {
average_value = Math.round(config_data.data.reduce((a, b) => a + b.PriceTime, 0) / config_data.data.length);
break;
default:
config_data.data = [];
// config_data.data = [];
config_data.data = type_data.dataSource;
config_data.xField = 'T_name';
config_data.yField = 'T_total';
break;
}
return {

Loading…
Cancel
Save