feat: 数据列切换

feature/2.0-sales-trade
Lei OT 2 years ago
parent 851ad244ce
commit b797a2d93a

@ -0,0 +1,23 @@
import { observer } from 'mobx-react';
import { Radio, Select } from 'antd';
import { dataFieldOptions } from './../libs/ht';
export default observer((props) => {
const { visible, dataRaw, dataMapper, fieldMapper, onChange, ...extProps } = props;
const handleChange = (value) => {
console.log('handleChange', value);
if (typeof onChange === 'function') {
onChange(value);
}
};
const defaultVal = dataFieldOptions[0].value;
const Component = () =>
dataFieldOptions.length < 5 ? (
<Radio.Group options={dataFieldOptions} optionType="button" onChange={(e) => handleChange(e.target.value)} defaultValue={defaultVal} {...extProps} />
) : (
<Select showSearch options={dataFieldOptions} onChange={handleChange} defaultValue={defaultVal} {...extProps} />
);
return <>{visible !== false ? <Component /> : null}</>;
});

@ -65,3 +65,26 @@ export const dateTypes = [
{ key: 'ConfirmDate', label: '确认日期' },
{ key: 'startDate', label: '走团日期' },
];
/**
* 结果字段
*/
export const dataFieldOptions = [
{ label: '毛利', value: 'SumML', formatter: (v) => `${v / 1000} K` },
{ label: '订单数', value: 'OrderCount', formatter: (v) => v },
{ label: '成交数', value: 'CJCount', formatter: (v) => v },
// { label: '成交人数', value: 'CJPersonNum', formatter: (v) => v },
{ label: '成交率', value: 'CJrate', formatter: (v) => v },
// todo: more...
];
/**
* 结果字段alias
*/
export const dataFieldAlias = dataFieldOptions.reduce(
(a, c) => ({
...a,
[c.value]: { alias: c.label, formatter: (v) => c.formatter(v) },
[`${c.value}KPI`]: { alias: `${c.label}目标`, formatter: (v) => c.formatter(v) },
}),
{}
);

Loading…
Cancel
Save