import { useState, useRef, useMemo } from 'react' import BasicTable from '@/components/Table' import { DatePicker, Table, Typography } from 'antd' import { querySoftwareUsageList } from '@/services/statistic' import consts from '@/consts' import dayjs from 'dayjs' import { Pie } from '@ant-design/charts' import OptionSelect from '../../components/OptionSelect' const { Text } = Typography const colLabelValToZH = { giftsCount: '赠送', lendCount: '借出', salesCount: '销售' } const Usage = () => { const tRef = useRef(null) const [state, setState] = useState({ params: { optionType: 'staff', dataIds: [], startMonth: [dayjs(new Date()), dayjs(new Date())] } }) const pieData = useMemo(() => { if (!state.chart || !state.sum) return {} const leftKeys = Object.keys(state.chart) const pieLeft = [] leftKeys.forEach(item => { const v = state.chart[item] pieLeft.push({ label: item === 'unused' ? '未使用' : '已使用', value: v }) }) const rightKeys = Object.keys(state.sum) const pieRight = [] rightKeys.forEach(item => { const v = state.sum[item] if (!['receiveCount', 'createCount'].includes(item)) { pieRight.push({ label: colLabelValToZH[item], value: v }) } }) return { pieLeft, pieRight } }, [state.chart]) const columns = [ { title: '名称', dataIndex: 'name', key: 'name', width: 100, fixed: 'left', align: 'center' }, { title: '未使用', children: [ { title: '生成', key: 'create', dataIndex: 'create', align: 'center' }, { title: '接收', key: 'receive', dataIndex: 'receive', align: 'center' } ] }, { title: '已使用', children: [ { title: '借出', key: 'lend', dataIndex: 'lend', align: 'center' }, { title: '销售', key: 'sales', dataIndex: 'sales', align: 'center' }, { title: '赠送', key: 'gifts', dataIndex: 'gifts', align: 'center' } ] } ] const leftConfig = { appendPadding: 10, data: pieData.pieLeft, angleField: 'value', colorField: 'label', radius: 0.9, color: ['#40B7E6', '#79CE67'], interactions: [{ type: 'element-active' }] } const rightConfig = { appendPadding: 10, data: pieData.pieRight, angleField: 'value', colorField: 'label', radius: 0.9, color: ['#40B7E6', '#79CE67', '#FBD743'], interactions: [{ type: 'element-active' }] } const optionChange = (type, ids) => setState({ ...state, params: { ...state.params, optionType: type, dataIds: ids } }) return (