import React, { useContext } from 'react'; import { Row, Col, Tabs, Table, Divider, Spin } from 'antd'; import { ContainerOutlined, UserSwitchOutlined } from '@ant-design/icons'; import { stores_Context } from '../config'; import { Column, Pie } from '@ant-design/charts'; import { observer } from 'mobx-react'; import * as comm from '../utils/commons'; import { utils, writeFileXLSX } from 'xlsx'; import SearchForm from './../components/search/SearchForm'; const Sale = () => { const { sale_store, date_picker_store } = useContext(stores_Context); //const ml_data = sale_store.ml_data; // 毛利数据 const type_data = comm.empty(sale_store.type_data) ? { dataSource: [], columns: [] } : sale_store.type_data; // 毛利数据 const column_config_create = (tab_name) => { let average_value = 0; //平均线的值 let config_data = []; switch (tab_name) { case 'All': config_data.data = type_data.dataSource; config_data.xField = 'OPI_Name'; config_data.yField = 'COLI_ML2'; average_value = Math.round(config_data.data.reduce((a, b) => a + b.COLI_ML2, 0) / config_data.data.length); break; case 'ResponseRateWhatsApp': config_data.data = type_data.dataSource; config_data.xField = 'OPI_Name'; config_data.yField = 'COLI_ConfirmTimeAVG'; average_value = Math.round(config_data.data.reduce((a, b) => a + b.COLI_ConfirmTimeAVG, 0) / config_data.data.length); break; case 'ResponseRateByWL': config_data.data = type_data.dataSource; config_data.xField = 'OPI_Name'; config_data.yField = 'PriceTime'; 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 = type_data.dataSource; config_data.xField = 'T_name'; config_data.yField = 'T_total'; break; } return { ...config_data, ...{ //seriesField: "OPI_Name",//分组 label: { position: 'top', }, xAxis: { label: { autoHide: false, autoRotate: true, }, }, // legend: { // itemValue: { // formatter: (text, item) => { // const items = ml_data.filter(d => d.groups === item.value); // 按分组筛选 // return items.length ? items.reduce((a, b) => a + b.COLI_ML, 0) : ""; // 计算总数 // }, // }, // }, // tooltip: { // customContent: (title, items) => { // const data = items[0].data || {};console.log(data); // return `
${title}
wwwwwww
`; // }, // title: (title, datum) => { // return title; // + " " + comm.getWeek(datum.COLI_Date); // 显示周几 // }, // },}; annotations: average_value ? [ { type: 'text', position: ['start', average_value], content: average_value, offsetX: -15, style: { fill: '#F4664A', textBaseline: 'bottom', }, }, { type: 'line', start: [-10, average_value], end: ['max', average_value], style: { stroke: '#F4664A', lineDash: [2, 2], }, }, ] : [], }, }; }; const column_config = column_config_create(sale_store.active_tab_key); // 直方图,先隐藏 // const format_data_for_treemap=(data=[])=>{ // const children_array= data.map(item => ({...item, name: item.OPI_Name,value:item.COLI_ML2})); // return { // name: 'root', // children:children_array, // }; // }; // const treemap_config={ // data:format_data_for_treemap(type_data.dataSource), // colorField: 'OPI_Name', // }; //格式化数据,饼图只支持数字模式 const format_data_for_pie = (data = []) => { return data.map((item) => ({ ...item, COLI_ML_number: comm.price_to_number(item.COLI_ML) })); }; const pie_config = { appendPadding: 10, data: format_data_for_pie(type_data.dataSource), angleField: 'COLI_ML_number', colorField: 'OPI_Name', radius: 0.8, label: { type: 'outer', content: '{name} {value} \n {percentage}', }, legend: false, // 不显示图例 interactions: [ { type: 'element-selected', }, { type: 'element-active', }, ], }; const tab_items = [ { key: 'All', label: ( 总览 ), }, { key: 'ResponseRateWhatsApp', label: ( 回复率 ), }, { key: 'ResponseRateByWL', label: ( 沟通数据 ), }, { key: 'Country', label: ( 国籍 ), }, { key: 'Product', label: ( 产品类型 ), }, { key: 'TravelMotivation', label: ( 出行目的 ), }, { key: 'GuestGroupType', label: ( 成员关系 ), }, ]; return (
{ sale_store.setSearchValues(obj, form); sale_store.get_department_order_ml_by_type(date_picker_store); }} /> {/* */} { sale_store.onChange_Tabs(active_key); sale_store.get_department_order_ml_by_type(date_picker_store); }} items={tab_items} > record.key} loading={sale_store.loading_table} pagination={false} scroll={{ x: '100%' }} /> { const wb = utils.table_to_book(document.getElementById('table_to_xlsx_sale').getElementsByTagName('table')[0]); writeFileXLSX(wb, 'sale.xlsx'); }} > 导出excel {sale_store.active_tab_key === 'All' ? : ''} {/* */} ); }; export default observer(Sale);