import React, { useContext, useState } from 'react'; import { Row, Col, Table, Select, Space, Typography, Progress, Spin, Divider, Button, Switch } from 'antd'; import { stores_Context } from '../config'; import { observer } from 'mobx-react'; import * as comm from '../utils/commons'; import SearchForm from './../components/search/SearchForm'; import { dataFieldAlias, overviewGroup } from '../libs/ht'; import Donut from './../components/Donut'; import LineWithKPI from '../components/LineWithKPI'; import { TableExportBtn } from './../components/Data'; const { Text } = Typography; const overviewGroupKeys = overviewGroup.map(item => item.key); const Sale_KPI = () => { const { sale_store, date_picker_store: searchFormStore } = useContext(stores_Context); const { formValues, siderBroken } = searchFormStore; const { groupType, loading, operator, tableDataSource: dataSource } = sale_store.salesTrade; const yearData = sale_store.salesTrade[groupType].reduce((r, ele) => r.concat(Object.values(ele.mData)), []); const operatorObjects = operator.map((v) => ({ key: v.groupsKey, value: v.groupsKey, label: v.groupsLabel })); const pageRefresh = async (queryData) => { const overviewFlag = queryData.DepartmentList.toLowerCase() === 'all' || overviewGroupKeys.includes(queryData.DepartmentList.toLowerCase()); // queryData.DepartmentList.toLowerCase().includes(','); const _groupType = overviewFlag ? 'overview' : 'dept'; sale_store.setGroupType(_groupType); await sale_store.fetchOperatorTradeData(_groupType, { ...queryData, groupDateType: 'year' }); await sale_store.fetchOperatorTradeData('operator', { ...queryData, groupDateType: 'year' }); sale_store.setPickSales([]); sale_store.setTableDataSource(false); setIfmerge(false); }; const [ifmerge, setIfmerge] = useState(false); const monthCol = new Array(12).fill(1).map((_, index) => { return { title: `${index + 1}月`, dataIndex: `M${index + 1}Percent`, valueType: 'digit', width: '7.5em', render: (_, row) => ( {/* 目标 */}
{dataFieldAlias.SumML.formatter(row.mData[`month_${String(index + 1).padStart(2, '0')}`]?.MLKPIvalue || 0)}
{/* 完成 */}
{dataFieldAlias.SumML.formatter(row.mData[`month_${String(index + 1).padStart(2, '0')}`]?.SumML || 0)}
{row.mData[`month_${String(index + 1).padStart(2, '0')}`]?.MLKPIrates || 0 ? ( `${row.mData[`month_${String(index + 1).padStart(2, '0')}`]?.MLKPIrates || 0}%`} status={ row.mData[`month_${String(index + 1).padStart(2, '0')}`].MLKPIrates < 80 ? 'exception' : row.mData[`month_${String(index + 1).padStart(2, '0')}`].MLKPIrates < 100 ? 'normal' : 'success' } /> ) : ( '-' )}
), }; }); const columns = [ { title: ``, dataIndex: 'groupsLabel', editable: false, width: '7.5em', fixed: 'left', }, { title: '年度', dataIndex: 'yearValue', width: '10em', fixed: 'left', render: (_, row) => (
目标 {dataFieldAlias.SumML.formatter(row.yData?.MLKPIvalue || 0)}
完成 {dataFieldAlias.SumML.formatter(row.yData?.SumML || 0)}
{row.yData?.MLKPIrates || 0 ? ( `${row.yData?.MLKPIrates || 0}%`} status={row.yData.MLKPIrates < 80 ? 'exception' : row.yData.MLKPIrates < 100 ? 'normal' : 'success'} /> ) : ( '-' )}
), }, ...monthCol, ]; const columnsForExport = [ { title: `#`, dataIndex: 'groupsLabel', editable: false, width: '7.5em', fixed: 'left', }, { title: '--', dataIndex: 'rowLabel', width: '10em', fixed: 'left', }, { title: '年度', dataIndex: 'yearML', width: '10em', fixed: 'left', }, ...new Array(12).fill(1).map((_, index) => { return { title: `${index + 1}月`, dataIndex: ['mData', `month_${String(index + 1).padStart(2, '0')}`], // , 'SumML' valueType: 'digit', width: '7.5em', }; }), ]; const dataForExport = dataSource.reduce((r, ele) => { const targetRow = { groupsLabel: ele.groupsLabel, rowLabel: '目标', yearML: ele.yData.MLKPIvalue, mData: Object.values(ele.mData).reduce((rt, et) => ({ ...rt, [`month_${et.dateVal}`]: et.MLKPIvalue }), {}), }; const valRow = { groupsLabel: ele.groupsLabel, rowLabel: '完成', yearML: ele.yData.SumML, mData: Object.values(ele.mData).reduce((rt, et) => ({ ...rt, [`month_${et.dateVal}`]: et.SumML }), {}) }; const processRow = { groupsLabel: ele.groupsLabel, rowLabel: '进度(%)', yearML: ele.yData.MLKPIrates, mData: Object.values(ele.mData).reduce((rt, et) => ({ ...rt, [`month_${et.dateVal}`]: et.MLKPIrates }), {}), }; r.push(targetRow, valRow, processRow); return r; }, []); const lineConfig = { appendPadding: 10, xField: 'groupDateVal', yField: 'SumML', seriesField: 'groupsLabel', isGroup: true, smooth: false, meta: comm.cloneDeep(dataFieldAlias), }; return (
{ sale_store.setSearchValues(obj, form); pageRefresh(obj); }} />

年度业绩组成和走势

({ ...row, SumML: row.yearML }))} />

顾问业绩走势

{dataSource.length > 0 && ( { sale_store.setTableDataSource(e); setIfmerge(e); }} /> )} ); }; export default observer(Sale_KPI);