import type { CurrentUser } from "umi";
import { connect } from "umi";
import React, { useEffect, useRef, useState } from 'react';
import type { ConnectState } from "@/models/connect";
import type { queryObjType } from "@/components/AntvTable";
import AntvTable from "@/components/AntvTable";
import type { S2DataConfig, S2Options } from "@antv/s2";
import { GetProjectSplitSummary, getProjectDetail } from './service'
import ProjectDetail from "@/pages/BussinessProject/detail";
import ProCard from "@ant-design/pro-card";
import { MenuFoldOutlined } from "@ant-design/icons";
import { Button, DatePicker, Drawer, message, Spin, Tree } from "antd";
import useRequest from "@ahooksjs/use-request";
import { getServerpartTree } from "@/services/options";
import moment from "moment";
import { G2, Column } from "@ant-design/charts";
import { ScrollbarPositionType } from "@antv/s2";
import './style.less'
import ShopExpense from "@/pages/reports/ShopExpenses/Index";
import NoData from "@/pages/basicManage/Brand/components/noData";

const TestTable: React.FC<{ currentUser?: CurrentUser }> = (props) => {
    const { currentUser } = props
    const tableRef = useRef()
    const G = G2.getEngine('canvas');
    const [printOut, setPrintOut] = useState<any>(); // 打印数据的内容
    const [tableLoading, setTableLoading] = useState<boolean>(false)// 是否显示加载效果
    const [collapsible, setCollapsible] = useState<boolean>(false)
    const [s2DataConfig, setS2DataConfig] = useState<S2DataConfig>({
        fields: {
            rows: ['SPREGIONTYPE_NAME', 'SERVERPART_NAME', 'SERVERPARTSHOP_NAME', 'MERCHANTS_NAME', 'STARTDATEENDDATE'],
            columns: ['age', 'typeLabel'],
            values: ['count'],
            valueInCols: true,
        },
        meta: [
            {
                field: 'SPREGIONTYPE_NAME',
                name: '隶属',
            },
            {
                field: 'SERVERPART_NAME',
                name: '服务区',
            },
            {
                field: 'SERVERPARTSHOP_NAME',
                name: '门店名称',
            },
            {
                field: 'MERCHANTS_NAME',
                name: '合作单位名称',
            },
            {
                field: 'STARTDATEENDDATE',
                name: '计租期',
            },
            {
                field: 'age',
                name: '经营项目信息'
            },
            {
                field: 'typeLabel',
                name: '年保底租金'
            },
            {
                field: 'count',
                name: '数值',
            },
        ],
        data: []
    })
    const [tableData, setTableData] = useState<any>()// 表格的值
    const [selectedId, setSelectedId] = useState<string>()
    const [serverId, setServerId] = useState<string | null>()// 选中的服务区id
    const [searchTime, setSearchTime] = useState<any>()// 查询的时间
    const [searchName, setSearchName] = useState<string>()// 查询的单位名称
    const [s2Options, setS2Options] = useState<S2Options>({
        height: 550,
        tooltip: {
            showTooltip: true,
            operation: {
                hiddenColumns: true,
            },
            adjustPosition: ((positionInfo: any) => {
                let obj = {
                    x: positionInfo.position.x,
                    y: positionInfo.position.y
                }
                if (positionInfo.event?.target?.cfg?.attrs?.text === "提成收入") {
                    obj = {
                        x: positionInfo.event.clientX - 400,
                        y: positionInfo.event.clientY + 20
                    }
                }
                return obj
            }),
            // @ts-ignore
            content: ((cell, defaultTooltipShowOptions) => {
                return <div style={{ padding: '5px' }}>
                    {/* 名称 */}
                    {
                        cell ?
                            cell.meta.value ?
                                <span>{cell.meta.value}</span> :
                                cell.meta.data ?
                                    <span>{cell.meta.data.typeLabel}: </span> :
                                    cell.meta.colQuery ?
                                        <span>{cell.meta.colQuery.typeLabel}: </span> : '' : ''
                    }
                    {/* 数值 */}
                    {
                        defaultTooltipShowOptions.data.details && defaultTooltipShowOptions.data.details.length > 0 ?
                            <span style={{ marginLeft: '4px' }}> {defaultTooltipShowOptions.data.details[0].value}</span> : ''
                    }
                    {/* 公式  */}
                    {
                        cell ?
                            cell.actionIcons && cell.actionIcons.length > 0 ?
                                cell.meta.label !== '提成收入' ?
                                    <p>
                                        {getFormula(cell.meta.label, searchTime)}
                                    </p> :
                                    <div>
                                        <p>{"1、除税营业提成金额>除税月度累计保底金额："}</p>
                                        <p style={{ marginLeft: '50px' }}>{"除税营业提成金额"}</p>
                                        <p>{"2、除税营业提成金额<=除税月度累计保底金额："}</p>
                                        <p style={{ marginLeft: '50px' }}>{"除税月度累计保底金额"}</p>
                                        <p>{"3、计算公式："}</p>
                                        <p style={{ marginLeft: '50px' }}>{"除税营业提成金额：[营收金额*提成比例/100，保留2位]/（1+营业税率/100），保留2位"}</p>
                                        <p style={{ marginLeft: '50px' }}>{"除税月度累计保底金额：[[保底金额/（1+营业税率/100），保留2位]/总月份数，保留2位]*累计期数，保留2位"}</p>
                                    </div>
                                : '' : ''
                    }
                </div>
            })
        },
        interaction: {
            selectedCellsSpotlight: true,
            hoverHighlight: false,
            scrollbarPosition: ScrollbarPositionType.CANVAS,
        },
        style: {
            layoutWidthType: 'colAdaptive',
            colCfg: {
                hideMeasureColumn: true,
            },
            cellCfg: {
                width: 110,
            },
            rowCfg: {
                width: 110,
            },
        },
        conditions: {
            text: [
                // {
                //     field: 'count',
                //     mapping(value) {
                //         return {
                //             fill: value >= 50 ? '#fff' : '#282b32',
                //         };
                //     },
                // },
            ]
        },
    })
    const [typeList, setTypeList] = useState<any>()// 五个小计的索引位置
    const [listLength, setListLength] = useState<number>(0)// 列表长度
    const [bigSum, setBigSum] = useState<any>()// 总计
    const [pieConfigObj, setPieConfigObj] = useState<any>()//
    const [showDrawer, setShowDrawer] = useState<boolean>(false)// 是否显示抽屉
    const [drawerDetail, setDrawerDetail] = useState<any>()// 抽屜内容的详情
    const [drawerSearchTime, setDrawerSearchTime] = useState<any>()// 抽屉里面的搜索时间
    const { RangePicker } = DatePicker;
    const [getDataColIndex, setGetDataColIndex] = useState<any>()// 点击的行索引
    const [getDataColName, setGetDataColName] = useState<any>()// 点击的行名称
    const [selectDataDetail, setSelectDataDetail] = useState<any>()// 点击单元格的详情信息
    const [showLoading, setShowLoading] = useState<boolean>(false)// 是否显示加载效果
    const [themeCfg, setThemeCfg] = useState<any>({
        theme: {
            dataCell: {
                text: {
                    textAlign: 'right',
                    fontSize: 14,
                    fontFamily: '-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji'
                },
                bolderText: {
                    fontSize: 14,
                }
            },
            colCell: {
                text: {
                    textAlign: 'center',
                    fontSize: 14,
                    fontFamily: '-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji'
                },
                bolderText: {
                    textAlign: 'center',
                    fontSize: 14,
                }
            },
            rowCell: {
                text: {
                    textAlign: 'center',
                    fontSize: 14,
                    fontFamily: '-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji'
                },
                bolderText: {
                    textAlign: 'center',
                    fontSize: 14,
                }
            },
            cornerCell: {
                text: {
                    textAlign: 'center',
                    fontSize: 14,
                    fontFamily: '-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Arial, Noto Sans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji'
                },
                bolderText: {
                    textAlign: 'center',
                    fontSize: 14,
                }
            }
        }
    })
    const [showBrandDetail, setShowBrandDetail] = useState<boolean>(false)
    const [showShopExpenses,setShowShopExpenses] = useState<boolean>(false)// 物业水电费抽屉
    const [currentProject, setCurrentProject] = useState<any>()// 当前选中的项目信息
    const [selectItemShopName, setSelectItemShopName] = useState<any>()// 选择的项目信息
    // 拿到接口数据的方法
    const getLineBoxData = async (field: any, name: string, obj: any, startTime?: any, time?: any) => {
        // 用传入的搜索时间
        const date = new Date(searchTime)
        const y = date.getFullYear()
        // 请求接口的参数
        const req = {
            StatisticsMonth: time ? moment(time).format('YYYYMM') : moment(searchTime).format('YYYYMM'),
            StatisticsStartMonth: startTime ? moment(startTime).format('YYYYMM') : `${y}01`,
            SPRegionTypeId: obj.data.SPREGIONTYPEID,
            ServerpartId: obj.data.SERVERPARTID,
            ServerpartShopId: obj.data.shopId
        }
        // 如果抽屉里面的时间已经有了的话 就不去设置
        // 没有的话 就设置一月份到选中的时间
        if (drawerSearchTime && drawerSearchTime.length > 0) {

        } else {
            // 设置抽屉的初始化时间
            setDrawerSearchTime([moment(`${y}-01`), moment(searchTime)])
        }
        const res = await GetProjectSplitSummary(req)
        const list: any = []
        const typeObj = {
            MINTURNOVER: '年保底租金',
            DUTY_PARAGRAPH: '税率',
            YEAR_INCOME: '年收入',
            MONTH_INCOME: '月收入',
            ACCUMULATED_PERIOD: '累计期数',
            ACCUMULATED_INCOME: '累计应确认收入',
            REVENUE_TOTALAMOUNT: '营业额',
            ROYALTY_TOTALAMOUNT: '分润金额(含税)',
            ROYALTY_TOTALAMOUNT_NoTax: '分润金额',
            GUARANTEERATIO: '提成比例',
            COMMISSION_INCOME: '提成金额(含税)',
            COMMISSION_INCOME_NoTax: '提成金额',
            CONFIRM_TAXCOMINCOME: '累计应确认含税收入',
            CONFIRM_COMINCOME: '累计应确认收入',
            MERCHANT_PAYMENT: '商家缴款',
            LMONTH_TAXCOMINCOME: '累计已确认收入(含税)',
            LMONTH_COMINCOME: '累计已确认收入',

        }
        // 想让全部图例不显示 然后根据点击的单元格信息 来判断哪个图例高亮显示
        const selectObj = {
            '营业额': true,
            '分润金额(含税)': false,
            '分润金额': false,
            '提成比例': false,
            '提成金额(含税)': true,
            '提成金额': false,
            '提成收入': true,
            '累计应确认收入': false,
            '商家缴款': false,
            '累计已确认收入(含税)': false,
            '累计已确认收入': false,
        }
        selectObj[typeObj[field]] = true
        // 画图的数据
          res.List.forEach((item: any) => {
            list.push({
              月份: item.STATISTICS_MONTH,
              value: item.REVENUE_TOTALAMOUNT,
              name: '营业额'
            })
            list.push({
              月份: item.STATISTICS_MONTH,
              value: item.COMMISSION_INCOME,
              name: '提成金额(含税)'
            })
            // list.push({
            //   Date: item.STATISTICS_MONTH,
            //   value:item.COMMISSION_INCOME_NoTax,
            //   category:'提成金额'
            // })
            // list.push({
            //   Date: item.STATISTICS_MONTH,
            //   value:item.ROYALTY_TOTALAMOUNT,
            //   category:'分润金额(含税)'
            // })
            // list.push({
            //   Date: item.STATISTICS_MONTH,
            //   value:item.ROYALTY_TOTALAMOUNT_NoTax,
            //   category:'分润金额'
            // })
            list.push({
              月份: item.STATISTICS_MONTH,
              value: item.CONFIRM_TAXCOMINCOME,
              name: '累计应确认含税收入'
              // 累计应确认含税收入
            })
            // list.push({
            //   Date: item.STATISTICS_MONTH,
            //   value:item.CONFIRM_COMINCOME,
            //   category:'累计应确认收入'
            // })
            list.push({
              月份: item.STATISTICS_MONTH,
                value: item.MERCHANT_PAYMENT,
              name: '商家缴款'
            })
            // list.push({
            //     Date: item.STATISTICS_MONTH,
            //     value:item.CONFIRM_INCOME,
            //     category:'应确认收入'
            // })
            // list.push({
            //   Date: item.STATISTICS_MONTH,
            //   value:item.ADVINCOME_DIFFERENCE,
            //   category:'预收差额'
            // })
          })
        // 使用组件的基本方法
        const pieConfig = {
            width: 400,
            height: 400,
            data: list,
          isGroup: true,
            padding: 'auto',
            xField: '月份',
            yField: 'value',
            seriesField: 'name',
            xAxis: {
                tickCount: 5,
            },
            label:{
              layout: [
                // 柱形图数据标签位置自动调整
                { type: 'interval-adjust-position' },
                // 数据标签防遮挡
                { type: 'interval-hide-overlap' },
                // 数据标签文颜色自动调整
                { type: 'adjust-color' },
              ]
            },
            // legend: {
            //     position: 'bottom',
            //     flipPage: false,
            //     selected: selectObj
            // },
            tooltip: {
                // 处理鼠标移入 显示的数据
                customItems: (originalItems: any) => {
                    if (originalItems && originalItems.length > 0) {
                        originalItems.forEach((item: any) => {
                            item.data.value = fmoney(item.data.value, 2)
                        })
                    }
                    return originalItems
                }
            }
        }
        setPieConfigObj(pieConfig)
        setShowLoading(false)
        // 出现抽屉
        setShowDrawer(true);
    }
    // 格式化数字 保留小数根据第二位形参的方法 直接用
    const fmoney = (s: any, n: any) => {
        /*
         * 参数说明：
         * s：要格式化的数字
         * n：保留几位小数
         * */
        n = n > 0 && n <= 20 ? n : 2;
        let fuhao = ''; // 如果数字小于零则值为-
        if (s < 0) {
            s = Math.abs(s);
            fuhao = '-'
        }
        s = `${parseFloat((`${s}`).replace(/[^\d\.-]/g, "")).toFixed(n)}`;
        const l = s.split(".")[0].split("").reverse();
        const r = s.split(".")[1];
        let t = "";
        for (let i = 0; i < l.length; i++) {
            t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
        }
        if (n === 0) {
            return s
        }
        return `${fuhao + [...t].reverse().join("")}.${r}`;

    }
    // 表格组件的顶部搜索框内容
    const tableQuery: queryObjType[] = [
        {
            type: 'input',
            span: 7,
            label: '合作单位：',
            props: {
                size: 'middle',
                style: { width: '288px' },
                value: searchName,
                placeholder: '请输入合作单位',
                onChange: (e: any) => {
                    setSearchName(e.target.value)
                },
            },
        },
        {
            type: 'datePicker',
            span: 7,
            label: '统计月份：',
            props: {
                onChange: (e: any) => {
                    setSearchTime(e)
                },
                value: searchTime,
                picker: 'month',
            },
        },
    ]
    // 控制导出excel合并单元格的数据
    const mergeArray = [
        { s: { c: 0, r: 0 }, e: { c: 14, r: 0 } },
        { s: { c: 0, r: 1 }, e: { c: 4, r: 1 } },
        { s: { c: 5, r: 1 }, e: { c: 6, r: 1 } },
        { s: { c: 7, r: 1 }, e: { c: 14, r: 1 } },
    ]
    const forMulaList: any = ['年收入','月收入','累计期数','累计应确认收入','营业额',
        '分润金额(含税)','分润金额','提成金额(含税)','提成金额','商家缴款','应确认收入',
        '预收差额','累计已确认收入','本月应确认收入','本月确认收入','年保底租金','累计应确认含税收入','累计已确认收入(含税)','本月应确认收入(含税)']
    // 拿到公式文字的方法
    // 点击表头 显示相对应的文字的方法
    const getFormula = (name: string, time: any) => {
        const month = time ? new Date(time).getMonth() + 1 : 0
        switch (name) {
            case '年收入':
                return '除税年保底租金';
            case '月收入':
                return '除税月保底租金';
            case '累计期数':
                return "【项目本期开始日期的月份】到【当前统计日期的月份】的月份数；项目开始日期在1至10号之间，要加上1个月；在11至20号之间，要加上0.5个月；"
            case '累计应确认收入': // 累计应确认收入
                return '除税月保底租金*累计期数';
            case '营业额':
                return month > 1 ? `1-${month}月累计对客营收` : month > 0 ? `1月累计对客营收` : '';
            case '分润金额(含税)':
                return '按先70%的预售，然后在达到保底后按照提成比例进行预售模式，驿达收到的移动支付交易金额';
            case '分润金额':
                return '扣除税率后的移动支付分润金额';
            case '提成金额(含税)':
                return '营业额*提成比例';
            case '提成金额':
                return '扣除税率后的提成金额';
            // case '提成收入':
            //     return '1、超保底情况:\n对客营收*提成比例 >= 保底租金 提成收入按对客营收*提成比例';
            // case '提成收入(除税)':
            //     return '扣除门店税率后收入';
            case '商家缴款':
                return '商家缴款部分，目前未计入水电费，后续统一计入';
            case '应确认收入':
                return '提成收入(除税)+商家缴款两部分合计，属于累计驿达应确认收入';
            case '预收差额':
                return '分润金额-提成收入，代表驿达总体租金预收盈亏';
            case '累计已确认收入':
                return `${month>1?`1-${month}`:'1'}月的累计提升收入`;
            case '本月应确认收入':
                return '累计应确认收入-累计已确认收入';
            default:
                return ''
        }
    }

    // 请求数据的方法
    const getList = async (type: string, params: any, checkList?: string[]) => {
        // 先判断有没有搜索时间 没有的话 就调用不了方法
        if (searchTime) {
            // 让表单看着有加载效果
            setTableLoading(true)
            let req: any = {}
            // 判断调用的是重置 还是查询
            // 重置传入当前时间的前一个月 查询传入查询的时间
            // 重置清空合作范围搜索框内的值
            if (type === 'reset') {
                setSearchName('')
                setSearchTime(moment().subtract(1, 'month'))
                req = {
                    StatisticsMonth: moment().subtract(1, 'month').format('YYYYMM'),
                    ServerpartId: params.id
                }
            } else if (type === 'query') {
                req = {
                    StatisticsMonth: params.time ? moment(params.time).format('YYYYMM') : moment().subtract(1, 'month').format('YYYYMM'),
                    ServerpartId: params.id
                }
            } else if (type === 'null') {
                // 有可能服务区数据选择了之后 去掉 或者没选择的饿时候就按查询 就直接赋值空
                setS2DataConfig({
                    ...s2DataConfig,
                    data: []
                })
                return
            }
            // 如果有值就显出现加载效果
            if (s2DataConfig.data && s2DataConfig.data.length <= 0) {
                setShowLoading(true)
            }
            // 从接口拿到数据
            const data = await GetProjectSplitSummary(req)
            setTableData(data.List)
            let list: any = []
            // 拿到接口数据之后 如果要搜索名称的话 就的前端这边 模糊查询一下
            // 不是搜索就直接拿值就行
            if (type === 'query') {
                if (params.name) {
                    const smallList: any = []
                    // 前端的模糊搜索 如果合作单位里面填了东西 就模糊查找数组 拿到符合要求的数据
                    data.List.forEach((item: any) => {
                        if (item.MERCHANTS_NAME.indexOf(params.name) !== -1) {
                            smallList.push(item)
                        }
                    })
                    list = smallList
                } else {
                    list = data.List
                }
            } else {
                list = data.List
            }

            const dataList: any = []
            // 这个if里面就是把接口返回的值变成组件表格要的 已经写好 不用改也不用管
            if (list && list.length > 0) {
                // 由于接口数据里面没有返回总计和小计的内容
                // 所以要自己算小计和总计要加入的位置 和 创建他们的初始对象
                // 总计的初始对象
                const listSumAll = {
                    SPREGIONTYPE_NAME: '总计',
                    SERVERPART_NAME: '',
                    SERVERPARTSHOP_NAME: '',
                    MERCHANTS_NAME: '',
                    STARTDATEENDDATE: '',
                    MINTURNOVER: 0,
                    DUTY_PARAGRAPH: 0,
                    GUARANTEERATIO: 0,
                    REVENUE_TOTALAMOUNT: 0,
                    ROYALTY_TOTALAMOUNT: 0,
                    COMMISSION_INCOME: 0,// 提成金额(含税)
                    COMMISSION_INCOME_NoTax: 0,// 提成金额
                    CONFIRM_TAXCOMINCOME: 0,
                    CONFIRM_COMINCOME: 0,
                    MERCHANT_PAYMENT: 0,
                    ROYALTY_TOTALAMOUNT_NoTax: 0,
                    LMONTH_TAXCOMINCOME: 0,// 累计已确认收入(含税)
                    LMONTH_COMINCOME: 0,// 累计已确认收入
                    CMONTH_TAXCOMINCOME: 0,// 本月应确认收入(含税)
                    CMONTH_COMINCOME: 0,// 本月应确认收入
                    YEAR_INCOME: 0,
                    MONTH_INCOME: 0,
                    ACCUMULATED_INCOME: 0
                }
                // 小计要加入的位置(key 为索引，name为管理中心)
                const typeLists: any = []
                // 由于我们最后加了一条数据 所以最后变为canvas的时候 它截取不到最后一行的总计数据
                // 所以加一行占位的 让他能拿到总计
                list.push({ SPREGIONTYPE_NAME: 'last' })
                // 遍历全部数据
                for (let i = 0; i < list.length; i++) {
                    if (list[i] && list[i].SPREGIONTYPE_NAME && list[i + 1] && list[i + 1].SPREGIONTYPE_NAME) {
                        // 判断如果该项的管理中心不等于下一项的管理中心
                        // 说明要在中间插入一项小计 记录下索引位置 放到数组中
                        if (list[i].SPREGIONTYPE_NAME !== list[i + 1].SPREGIONTYPE_NAME) {
                            typeLists.push({ key: i + 1, name: list[i].SPREGIONTYPE_NAME })
                        }
                    }
                }
                setTypeList(typeLists)

                // 将索引列表遍历
                typeLists.forEach((item: any, index: number) => {
                    let dataList: any = []
                    // 拿到每个小计要确认计算的数组 第一个要从0开始 后面要从前一个索引值的位置开始
                    if (index > 0) {
                        dataList = list.slice(typeLists[index - 1].key + index, typeLists[index].key + index)
                    } else {
                        dataList = list.slice(0, typeLists[0].key)
                    }
                    // 创建小计的初始化对象
                    const sum = {
                        SERVERPART_NAME: '',// 服务区名称 但是要作为小计的名称显示
                        MINTURNOVERSUM: 0,// 年保底租金
                        REVENUE_TOTALAMOUNTSUM: 0,// 营业额
                        ROYALTY_TOTALAMOUNTSUM: 0,// 分润金额(含税)
                        ROYALTY_TOTALAMOUNT_NoTaxSUM: 0,// 分润金额
                        YEAR_INCOMESUM: 0,// 年收入
                        MONTH_INCOMESUM: 0,// 月收入
                        ACCUMULATED_INCOMESUM: 0,// 累计应确认收入
                        COMMISSION_INCOMESUM: 0,// 提成金额(含税)
                        COMMISSION_INCOME_NoTaxSUM: 0,// 提成金额
                        CONFIRM_TAXCOMINCOMESUM: 0,// 提成收入
                        CONFIRM_COMINCOMESUM: 0,// 提成收入(除税)
                        MERCHANT_PAYMENTSUM: 0,// 商家缴款
                        LMONTH_TAXCOMINCOMESUM: 0,// 累计已确认收入(含税)
                        LMONTH_COMINCOMESUM: 0,// 累计已确认收入
                        CMONTH_TAXCOMINCOMESUM: 0,// 本月应确认收入(含税)
                        CMONTH_COMINCOMESUM: 0,// 本月应确认收入
                        SPREGIONTYPE_NAME: '',// ****小计
                    }
                    // 当前的dataList就是 这个片区下面的数据集合
                    // 数据的累加  和 总计的累加
                    dataList.forEach((subItem: any)=>{
                        // 年保底租金
                        if (subItem.MINTURNOVER){
                            sum.MINTURNOVERSUM+=subItem.MINTURNOVER
                            listSumAll.MINTURNOVER += subItem.MINTURNOVER?subItem.MINTURNOVER:0
                        }
                        // 营业额
                        if (subItem.REVENUE_TOTALAMOUNT){
                            sum.REVENUE_TOTALAMOUNTSUM+=subItem.REVENUE_TOTALAMOUNT
                            listSumAll.REVENUE_TOTALAMOUNT += subItem.REVENUE_TOTALAMOUNT?subItem.REVENUE_TOTALAMOUNT:0
                        }
                        // 分润金额(含税)
                        if (subItem.ROYALTY_TOTALAMOUNT){
                            sum.ROYALTY_TOTALAMOUNTSUM+=subItem.ROYALTY_TOTALAMOUNT
                            listSumAll.ROYALTY_TOTALAMOUNT += subItem.ROYALTY_TOTALAMOUNT?subItem.ROYALTY_TOTALAMOUNT:0
                        }
                        // 累计应确认含税收入
                        if (subItem.CONFIRM_TAXCOMINCOME){
                            sum.CONFIRM_TAXCOMINCOMESUM+=subItem.CONFIRM_TAXCOMINCOME
                            listSumAll.CONFIRM_TAXCOMINCOME += subItem.CONFIRM_TAXCOMINCOME?subItem.CONFIRM_TAXCOMINCOME:0
                        }
                        // 累计应确认收入
                        if (subItem.CONFIRM_COMINCOME){
                            sum.CONFIRM_COMINCOMESUM+=subItem.CONFIRM_COMINCOME
                            listSumAll.CONFIRM_COMINCOME += subItem.CONFIRM_COMINCOME?subItem.CONFIRM_COMINCOME:0
                        }
                        // 商家缴款
                        if (subItem.MERCHANT_PAYMENT){
                            sum.MERCHANT_PAYMENTSUM+=subItem.MERCHANT_PAYMENT
                            listSumAll.MERCHANT_PAYMENT += subItem.MERCHANT_PAYMENT?subItem.MERCHANT_PAYMENT:0
                        }
                        // 累计已确认收入(含税)
                        if (subItem.LMONTH_TAXCOMINCOME){
                            sum.LMONTH_TAXCOMINCOMESUM+=subItem.LMONTH_TAXCOMINCOME
                            listSumAll.LMONTH_TAXCOMINCOME += subItem.LMONTH_TAXCOMINCOME?subItem.LMONTH_TAXCOMINCOME:0
                        }
                        // 累计已确认收入
                        if (subItem.LMONTH_COMINCOME){
                            sum.LMONTH_COMINCOMESUM+=subItem.LMONTH_COMINCOME
                            listSumAll.LMONTH_COMINCOME += subItem.LMONTH_COMINCOME?subItem.LMONTH_COMINCOME:0
                        }
                        // 本月应确认收入(含税)
                        if (subItem.CMONTH_TAXCOMINCOME){
                            sum.CMONTH_TAXCOMINCOMESUM+=subItem.CMONTH_TAXCOMINCOME
                            listSumAll.CMONTH_TAXCOMINCOME += subItem.CMONTH_TAXCOMINCOME?subItem.CMONTH_TAXCOMINCOME:0
                        }
                        // 本月应确认收入
                        if (subItem.CMONTH_COMINCOME){
                            sum.CMONTH_COMINCOMESUM+=subItem.CMONTH_COMINCOME
                            listSumAll.CMONTH_COMINCOME += subItem.CMONTH_COMINCOME?subItem.CMONTH_COMINCOME:0
                        }
                        if (subItem.ROYALTY_TOTALAMOUNT_NoTax){
                            sum.ROYALTY_TOTALAMOUNT_NoTaxSUM+=subItem.ROYALTY_TOTALAMOUNT_NoTax
                            listSumAll.ROYALTY_TOTALAMOUNT_NoTax += subItem.ROYALTY_TOTALAMOUNT_NoTax?subItem.ROYALTY_TOTALAMOUNT_NoTax:0
                        }
                        if (subItem.YEAR_INCOME){
                            sum.YEAR_INCOMESUM+=subItem.YEAR_INCOME
                            listSumAll.YEAR_INCOME += subItem.YEAR_INCOME?subItem.YEAR_INCOME:0
                        }
                        if (subItem.MONTH_INCOME){
                            sum.MONTH_INCOMESUM+=subItem.MONTH_INCOME
                            listSumAll.MONTH_INCOME += subItem.MONTH_INCOME?subItem.MONTH_INCOME:0
                        }
                        if (subItem.ACCUMULATED_INCOME){
                            sum.ACCUMULATED_INCOMESUM+=subItem.ACCUMULATED_INCOME
                            listSumAll.ACCUMULATED_INCOME += subItem.ACCUMULATED_INCOME?subItem.ACCUMULATED_INCOME:0
                        }
                        if (subItem.COMMISSION_INCOME){
                            sum.COMMISSION_INCOMESUM+=subItem.COMMISSION_INCOME
                            listSumAll.COMMISSION_INCOME += subItem.COMMISSION_INCOME?subItem.COMMISSION_INCOME:0
                        }
                        if (subItem.COMMISSION_INCOME_NoTax){
                            sum.COMMISSION_INCOME_NoTaxSUM+=subItem.COMMISSION_INCOME_NoTax
                            listSumAll.COMMISSION_INCOME_NoTax += subItem.COMMISSION_INCOME_NoTax?subItem.COMMISSION_INCOME_NoTax:0
                        }
                        if (subItem.SPREGIONTYPE_NAME){
                            sum.SPREGIONTYPE_NAME = subItem.SPREGIONTYPE_NAME
                        }

                        if (subItem.SPREGIONTYPE_NAME){
                          sum.SERVERPART_NAME = `小计`
                        }
                    })
                    // 将计算的小计 插入到 之前计算的索引位置
                    if (index===0){
                        list.splice(0,0, sum)
                    }else{
                        list.splice(typeLists[index-1].key,0, sum)
                    }
                })
                // 删除掉刚刚凑数的最后一项
                list.pop()
                // 对总计进行数据格式的处理
                listSumAll.LMONTH_TAXCOMINCOME = Number(listSumAll.LMONTH_TAXCOMINCOME.toFixed(2))
                listSumAll.LMONTH_COMINCOME = Number(listSumAll.LMONTH_COMINCOME.toFixed(2))
                listSumAll.CMONTH_TAXCOMINCOME = Number(listSumAll.CMONTH_TAXCOMINCOME.toFixed(2))
                listSumAll.CMONTH_COMINCOME = Number(listSumAll.CMONTH_COMINCOME.toFixed(2))
                listSumAll.MERCHANT_PAYMENT = Number(listSumAll.MERCHANT_PAYMENT.toFixed(2))
                listSumAll.CONFIRM_COMINCOME = Number(listSumAll.CONFIRM_COMINCOME.toFixed(2))
                listSumAll.CONFIRM_TAXCOMINCOME = Number(listSumAll.CONFIRM_TAXCOMINCOME.toFixed(2))
                listSumAll.ROYALTY_TOTALAMOUNT = Number(listSumAll.ROYALTY_TOTALAMOUNT.toFixed(2))
                listSumAll.ROYALTY_TOTALAMOUNT_NoTax = Number(listSumAll.ROYALTY_TOTALAMOUNT_NoTax.toFixed(2))
                listSumAll.REVENUE_TOTALAMOUNT = Number(listSumAll.REVENUE_TOTALAMOUNT.toFixed(2))
                listSumAll.MINTURNOVER = Number(listSumAll.MINTURNOVER.toFixed(2))
                // 加入到数据的最后一项中
                // list.push(listSumAll)
                list.splice(0, 0, listSumAll)
                const month = new Date(searchTime).getMonth() + 1
                setBigSum([
                    // {label:'年保底租金: ',value:listSumAll.MINTURNOVER?fmoney(listSumAll.MINTURNOVER,2).split('.')[0]:'0.00',smallValue:`.${fmoney(listSumAll.MINTURNOVER, 2).split('.')[1]}`,showSmall:listSumAll.MINTURNOVER && fmoney(listSumAll.MINTURNOVER,2).split('.') && fmoney(listSumAll.MINTURNOVER,2).split('.').length>0},
                    { label: '营业额: ', value: listSumAll.REVENUE_TOTALAMOUNT ? fmoney(listSumAll.REVENUE_TOTALAMOUNT, 2).split('.')[0] : '0.00', smallValue: `.${fmoney(listSumAll.REVENUE_TOTALAMOUNT, 2).split('.')[1]}`, showSmall: listSumAll.REVENUE_TOTALAMOUNT && fmoney(listSumAll.REVENUE_TOTALAMOUNT, 2).split('.') && fmoney(listSumAll.REVENUE_TOTALAMOUNT, 2).split('.').length > 0 },
                    { label: '分润金额(含税): ', value: listSumAll.ROYALTY_TOTALAMOUNT ? fmoney(listSumAll.ROYALTY_TOTALAMOUNT, 2).split('.')[0] : '0.00', smallValue: `.${fmoney(listSumAll.ROYALTY_TOTALAMOUNT, 2).split('.')[1]}`, showSmall: listSumAll.ROYALTY_TOTALAMOUNT && fmoney(listSumAll.ROYALTY_TOTALAMOUNT, 2).split('.') && fmoney(listSumAll.ROYALTY_TOTALAMOUNT, 2).split('.').length > 0 },
                    { label: '除税分润金额: ', value: listSumAll.ROYALTY_TOTALAMOUNT_NoTax ? fmoney(listSumAll.ROYALTY_TOTALAMOUNT_NoTax, 2).split('.')[0] : '0.00', smallValue: `.${fmoney(listSumAll.ROYALTY_TOTALAMOUNT_NoTax, 2).split('.')[1]}`, showSmall: listSumAll.ROYALTY_TOTALAMOUNT_NoTax && fmoney(listSumAll.ROYALTY_TOTALAMOUNT_NoTax, 2).split('.') && fmoney(listSumAll.ROYALTY_TOTALAMOUNT_NoTax, 2).split('.').length > 0 },
                    { label: ': ', value: '', smallValue: '', noShow: true },
                    // {label:'提成收入: ',value:listSumAll.CONFIRM_TAXCOMINCOME?fmoney(listSumAll.CONFIRM_TAXCOMINCOME,2).split('.')[0]:'0.00',smallValue:`.${fmoney(listSumAll.CONFIRM_TAXCOMINCOME, 2).split('.')[1]}`,showSmall:listSumAll.CONFIRM_TAXCOMINCOME && fmoney(listSumAll.CONFIRM_TAXCOMINCOME,2).split('.') && fmoney(listSumAll.CONFIRM_TAXCOMINCOME,2).split('.').length>0},
                    { label: '累计应确认收入: ', value: listSumAll.LMONTH_COMINCOME ? fmoney(listSumAll.LMONTH_COMINCOME, 2).split('.')[0] : '0.00', smallValue: `.${fmoney(listSumAll.LMONTH_COMINCOME, 2).split('.')[1]}`, showSmall: listSumAll.LMONTH_COMINCOME && fmoney(listSumAll.LMONTH_COMINCOME, 2).split('.') && fmoney(listSumAll.LMONTH_COMINCOME, 2).split('.').length > 0 },
                    { label: '商家缴款: ', value: listSumAll.MERCHANT_PAYMENT ? fmoney(listSumAll.MERCHANT_PAYMENT, 2).split('.')[0] : '0.00', smallValue: `.${fmoney(listSumAll.MERCHANT_PAYMENT, 2).split('.')[1]}`, showSmall: listSumAll.MERCHANT_PAYMENT && fmoney(listSumAll.MERCHANT_PAYMENT, 2).split('.') && fmoney(listSumAll.MERCHANT_PAYMENT, 2).split('.').length > 0 },
                    { label: `${month}月应确认收入: `, value: listSumAll.CMONTH_COMINCOME ? fmoney(listSumAll.CMONTH_COMINCOME, 2).split('.')[0] : '0.00', smallValue: `.${fmoney(listSumAll.CMONTH_COMINCOME, 2).split('.')[1]}`, showSmall: listSumAll.CMONTH_COMINCOME && fmoney(listSumAll.CMONTH_COMINCOME, 2).split('.') && fmoney(listSumAll.CMONTH_COMINCOME, 2).split('.').length > 0 },
                    // 本月提成收入 === 应确认收入
                    // {label:`${month}月提成收入: `,value:listSumAll.CONFIRM_INCOME?fmoney(listSumAll.CONFIRM_INCOME,2).split('.')[0]:'0.00',smallValue:`.${fmoney(listSumAll.CONFIRM_INCOME, 2).split('.')[1]}`,showSmall:listSumAll.CONFIRM_INCOME && fmoney(listSumAll.CONFIRM_INCOME,2).split('.') && fmoney(listSumAll.CONFIRM_INCOME,2).split('.').length>0},
                    // {label:'预收差额: ',value:listSumAll.ADVINCOME_DIFFERENCE?fmoney(listSumAll.ADVINCOME_DIFFERENCE,2).split('.')[0]:'0.00',smallValue:`.${fmoney(listSumAll.ADVINCOME_DIFFERENCE, 2).split('.')[1]}`,showSmall:listSumAll.ADVINCOME_DIFFERENCE && fmoney(listSumAll.ADVINCOME_DIFFERENCE,2).split('.') && fmoney(listSumAll.ADVINCOME_DIFFERENCE,2).split('.').length>0}
                ])
                // 添加占位的
                // list.push({SPREGIONTYPE_NAME:''})
                setListLength(list.length)
                // 遍历全部数据 给canvas的表格赋值
                list.forEach((item: any) => {
                    // if (item.STARTDATE) {
                    //     const subItem = JSON.parse(JSON.stringify(item))
                    //     subItem.STARTDATEENDDATE = item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`
                    //     dataList.push(subItem)
                    // }
                    // 用设置里面的选中项判断是否显示该列 且赋值
                    if (checkList?.indexOf('1-1') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '保底租金应确认收入',
                            typeLabel: '年保底租金',
                            count: item.MINTURNOVER ? fmoney(item.MINTURNOVER, 2) : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('1-2') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '保底租金应确认收入',
                            typeLabel: '税率',
                            count: item.DUTY_PARAGRAPH ? `${item.DUTY_PARAGRAPH}%` : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('1-3') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '保底租金应确认收入',
                            typeLabel: '年收入',
                            count: item.YEAR_INCOME ? fmoney(item.YEAR_INCOME, 2) : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('1-4') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '保底租金应确认收入',
                            typeLabel: '月收入',
                            count: item.MONTH_INCOME ? `${fmoney(item.MONTH_INCOME, 2)}` : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('1-5') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '保底租金应确认收入',
                            typeLabel: '累计期数',
                            count: item.ACCUMULATED_PERIOD ? `${item.ACCUMULATED_PERIOD}` : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('1-6') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '保底租金应确认收入',
                            typeLabel: '累计应确认收入',
                            count: item.ACCUMULATED_INCOME ? `${fmoney(item.ACCUMULATED_INCOME, 2)}` : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('2-1') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '浮动提成应确认收入',
                            typeLabel: '营业额',
                            count: item.REVENUE_TOTALAMOUNT ? fmoney(item.REVENUE_TOTALAMOUNT, 2) : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('2-5') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '浮动提成应确认收入',
                            typeLabel: '分润金额(含税)',
                            count: item.ROYALTY_TOTALAMOUNT ? fmoney(item.ROYALTY_TOTALAMOUNT, 2) : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('2-6') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '浮动提成应确认收入',
                            typeLabel: '分润金额',
                            count: item.ROYALTY_TOTALAMOUNT_NoTax ? fmoney(item.ROYALTY_TOTALAMOUNT_NoTax, 2) : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('2-2') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '浮动提成应确认收入',
                            typeLabel: '提成比例',
                            count: item.GUARANTEERATIO ? `${item.GUARANTEERATIO}%` : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('2-3') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '浮动提成应确认收入',
                            typeLabel: '提成金额(含税)',
                            count: item.COMMISSION_INCOME ? `${fmoney(item.COMMISSION_INCOME, 2)}` : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('2-4') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '浮动提成应确认收入',
                            typeLabel: '提成金额',
                            count: item.COMMISSION_INCOME_NoTax ? `${fmoney(item.COMMISSION_INCOME_NoTax, 2)}` : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('3-1') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '本月确认收入',
                            typeLabel: '累计应确认含税收入',
                            count: item.CONFIRM_TAXCOMINCOME ? fmoney(item.CONFIRM_TAXCOMINCOME, 2) : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('3-2') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '本月确认收入',
                            typeLabel: '累计应确认收入',
                            count: item.CONFIRM_COMINCOME ? fmoney(item.CONFIRM_COMINCOME, 2) : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('3-3') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '本月确认收入',
                            typeLabel: '商家缴款',
                            count: item.MERCHANT_PAYMENT ? fmoney(item.MERCHANT_PAYMENT, 2) : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('3-4') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '本月确认收入',
                            typeLabel: '累计已确认收入(含税)',
                            count: item.LMONTH_TAXCOMINCOME ? fmoney(item.LMONTH_TAXCOMINCOME, 2) : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('3-5') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '本月确认收入',
                            typeLabel: '累计已确认收入',
                            count: item.LMONTH_COMINCOME ? fmoney(item.LMONTH_COMINCOME, 2) : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('3-6') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '本月确认收入',
                            typeLabel: '本月应确认收入(含税)',
                            count: item.CMONTH_TAXCOMINCOME ? fmoney(item.CMONTH_TAXCOMINCOME, 2) : '-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('3-7') !== -1) {
                        const obj = {
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: item.SERVERPARTSHOP_NAME,
                            MERCHANTS_NAME: item.MERCHANTS_NAME,
                            shopId: item.SERVERPARTSHOP_ID,
                            SERVERPARTID: item.SERVERPART_ID,
                            SPREGIONTYPEID: item.SPREGIONTYPE_ID,
                            STARTDATEENDDATE: item.ENDDATE ? `${item.STARTDATE}-${item.ENDDATE}` : `${item.STARTDATE}`,
                            age: '本月确认收入',
                            typeLabel: '本月应确认收入',
                            count: item.CMONTH_COMINCOME ? fmoney(item.CMONTH_COMINCOME, 2) : '-'
                        }
                        dataList.push(obj)
                    }


                  // 先判断是不是小计 把小计的内容 赋值
                  if (item.SERVERPART_NAME && item.SERVERPART_NAME.indexOf('小计')!==-1){
                    // 判断权限的 就是是否显示 根据设置里面选中的显示项判断
                    if (checkList?.indexOf('1-1')!==-1){
                      const obj ={
                        SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                        SERVERPART_NAME: item.SERVERPART_NAME,
                        SERVERPARTSHOP_NAME: '',
                        MERCHANTS_NAME: '',
                        STARTDATEENDDATE: '',
                        age: '保底租金应确认收入',
                        typeLabel: '年保底租金',
                        count:item.MINTURNOVERSUM?fmoney(item.MINTURNOVERSUM,2):'-'
                      }
                      dataList.push(obj)
                    }
                    if (checkList?.indexOf('1-3')!==-1){
                      const obj ={
                        SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                        SERVERPART_NAME: item.SERVERPART_NAME,
                        SERVERPARTSHOP_NAME: '',
                        MERCHANTS_NAME: '',
                        STARTDATEENDDATE: '',
                        age: '保底租金应确认收入',
                        typeLabel: '年收入',
                        count:item.YEAR_INCOMESUM?fmoney(item.YEAR_INCOMESUM,2):'-'
                      }
                      dataList.push(obj)
                    }
                    if (checkList?.indexOf('1-4')!==-1){
                        const obj ={
                            SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                            SERVERPART_NAME: item.SERVERPART_NAME,
                            SERVERPARTSHOP_NAME: '',
                            MERCHANTS_NAME: '',
                            STARTDATEENDDATE: '',
                            age: '保底租金应确认收入',
                            typeLabel: '月收入',
                            count:item.MONTH_INCOMESUM?fmoney(item.MONTH_INCOMESUM,2):'-'
                        }
                        dataList.push(obj)
                    }
                    if (checkList?.indexOf('1-6')!==-1){
                      const obj ={
                          SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                          SERVERPART_NAME: item.SERVERPART_NAME,
                          SERVERPARTSHOP_NAME: '',
                          MERCHANTS_NAME: '',
                          STARTDATEENDDATE: '',
                          age: '保底租金应确认收入',
                          typeLabel: '累计应确认收入',
                          count:item.ACCUMULATED_INCOMESUM?fmoney(item.ACCUMULATED_INCOMESUM,2):'-'
                      }
                      dataList.push(obj)
                    }
                    if (checkList?.indexOf('2-1')!==-1){
                          const obj1 ={
                              SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                              SERVERPART_NAME: item.SERVERPART_NAME,
                              SERVERPARTSHOP_NAME: '',
                              MERCHANTS_NAME: '',
                              STARTDATEENDDATE: '',
                              age: '浮动提成应确认收入',
                              typeLabel: '营业额',
                              count:item.REVENUE_TOTALAMOUNTSUM?fmoney(item.REVENUE_TOTALAMOUNTSUM,2):'-'
                          }
                          dataList.push(obj1)
                      }
                    if (checkList?.indexOf('2-5')!==-1){
                      const obj2 ={
                        SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                        SERVERPART_NAME: item.SERVERPART_NAME,
                        SERVERPARTSHOP_NAME: '',
                        MERCHANTS_NAME: '',
                        STARTDATEENDDATE: '',
                        age: '浮动提成应确认收入',
                        typeLabel: '分润金额(含税)',
                        count:item.ROYALTY_TOTALAMOUNTSUM?fmoney(item.ROYALTY_TOTALAMOUNTSUM,2):0
                      }
                      dataList.push(obj2)
                    }
                    if (checkList?.indexOf('2-6')!==-1){
                      const obj2 ={
                        SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                        SERVERPART_NAME: item.SERVERPART_NAME,
                        SERVERPARTSHOP_NAME: '',
                        MERCHANTS_NAME: '',
                        STARTDATEENDDATE: '',
                        age: '浮动提成应确认收入',
                        typeLabel: '分润金额',
                        count:item.ROYALTY_TOTALAMOUNT_NoTaxSUM?fmoney(item.ROYALTY_TOTALAMOUNT_NoTaxSUM,2):'-'
                      }
                      dataList.push(obj2)
                    }
                    if (checkList?.indexOf('2-3')!==-1){
                      const obj ={
                        SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                        SERVERPART_NAME: item.SERVERPART_NAME,
                        SERVERPARTSHOP_NAME: '',
                        MERCHANTS_NAME: '',
                        STARTDATEENDDATE: '',
                        age: '浮动提成应确认收入',
                        typeLabel: '提成金额(含税)',
                        count:item.COMMISSION_INCOMESUM?fmoney(item.COMMISSION_INCOMESUM,2):'-'
                      }
                      dataList.push(obj)
                    }
                    if (checkList?.indexOf('2-4')!==-1){
                          const obj ={
                              SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                              SERVERPART_NAME: item.SERVERPART_NAME,
                              SERVERPARTSHOP_NAME: '',
                              MERCHANTS_NAME: '',
                              STARTDATEENDDATE: '',
                              age: '浮动提成应确认收入',
                              typeLabel: '提成金额',
                              count:item.COMMISSION_INCOME_NoTaxSUM?fmoney(item.COMMISSION_INCOME_NoTaxSUM,2):'-'
                          }
                          dataList.push(obj)
                      }
                    if (checkList?.indexOf('3-1')!==-1){
                          const obj3 ={
                              SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                              SERVERPART_NAME: item.SERVERPART_NAME,
                              SERVERPARTSHOP_NAME: '',
                              MERCHANTS_NAME: '',
                              STARTDATEENDDATE: '',
                              age: '本月确认收入',
                              typeLabel: '累计应确认含税收入',
                              count:item.CONFIRM_TAXCOMINCOMESUM?fmoney(item.CONFIRM_TAXCOMINCOMESUM,2):'-'
                          }
                          dataList.push(obj3)
                      }
                    if (checkList?.indexOf('3-2')!==-1){
                          const obj4 ={
                              SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                              SERVERPART_NAME: item.SERVERPART_NAME,
                              SERVERPARTSHOP_NAME: '',
                              MERCHANTS_NAME: '',
                              STARTDATEENDDATE: '',
                              age: '本月确认收入',
                              typeLabel: '累计应确认收入',
                              count:item.CONFIRM_COMINCOMESUM?fmoney(item.CONFIRM_COMINCOMESUM,2):'-'
                          }
                          dataList.push(obj4)
                      }
                    if (checkList?.indexOf('3-3')!==-1){
                          const obj5 ={
                              SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                              SERVERPART_NAME: item.SERVERPART_NAME,
                              SERVERPARTSHOP_NAME: '',
                              MERCHANTS_NAME: '',
                              STARTDATEENDDATE: '',
                              age: '本月确认收入',
                              typeLabel: '商家缴款',
                              count:item.MERCHANT_PAYMENTSUM?fmoney(item.MERCHANT_PAYMENTSUM,2):'-'
                          }
                          dataList.push(obj5)
                      }
                    if (checkList?.indexOf('3-4')!==-1){
                          const obj6 ={
                              SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                              SERVERPART_NAME: item.SERVERPART_NAME,
                              SERVERPARTSHOP_NAME: '',
                              MERCHANTS_NAME: '',
                              STARTDATEENDDATE: '',
                              age: '本月确认收入',
                              typeLabel: '累计已确认收入(含税)',
                              count:item.LMONTH_TAXCOMINCOMESUM?fmoney(item.LMONTH_TAXCOMINCOMESUM,2):'-'
                          }
                          dataList.push(obj6)
                      }
                    if (checkList?.indexOf('3-5')!==-1){
                          const obj7 ={
                              SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                              SERVERPART_NAME: item.SERVERPART_NAME,
                              SERVERPARTSHOP_NAME: '',
                              MERCHANTS_NAME: '',
                              STARTDATEENDDATE: '',
                              age: '本月确认收入',
                              typeLabel: '累计已确认收入',
                              count:item.LMONTH_COMINCOMESUM?fmoney(item.LMONTH_COMINCOMESUM,2):'-'
                          }
                          dataList.push(obj7)
                      }
                    if (checkList?.indexOf('3-6')!==-1){
                          const obj7 ={
                              SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                              SERVERPART_NAME: item.SERVERPART_NAME,
                              SERVERPARTSHOP_NAME: '',
                              MERCHANTS_NAME: '',
                              STARTDATEENDDATE: '',
                              age: '本月确认收入',
                              typeLabel: '本月应确认收入(含税)',
                              count:item.CMONTH_TAXCOMINCOMESUM?fmoney(item.CMONTH_TAXCOMINCOMESUM,2):'-'
                          }
                          dataList.push(obj7)
                      }
                    if (checkList?.indexOf('3-7')!==-1){
                          const obj7 ={
                              SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                              SERVERPART_NAME: item.SERVERPART_NAME,
                              SERVERPARTSHOP_NAME: '',
                              MERCHANTS_NAME: '',
                              STARTDATEENDDATE: '',
                              age: '本月确认收入',
                              typeLabel: '本月应确认收入',
                              count:item.CMONTH_COMINCOMESUM?fmoney(item.CMONTH_COMINCOMESUM,2):'-'
                          }
                          dataList.push(obj7)
                      }
                  }


                    if (item.SPREGIONTYPE_NAME && item.SPREGIONTYPE_NAME==='总计'){
                        if (checkList?.indexOf('1-1')!==-1){
                            const obj ={
                                SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                                SERVERPART_NAME: '',
                                SERVERPARTSHOP_NAME: '',
                                MERCHANTS_NAME: '',
                                STARTDATEENDDATE: '',
                                age: '保底租金应确认收入',
                                typeLabel: '年保底租金',
                                count:listSumAll.MINTURNOVER?fmoney(listSumAll.MINTURNOVER,2):'-'
                            }
                            dataList.push(obj)
                        }
                        if (checkList?.indexOf('1-3')!==-1){
                            const obj ={
                                SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                                SERVERPART_NAME: '',
                                SERVERPARTSHOP_NAME: '',
                                MERCHANTS_NAME: '',
                                STARTDATEENDDATE: '',
                                age: '保底租金应确认收入',
                                typeLabel: '年收入',
                                count:listSumAll.YEAR_INCOME?fmoney(listSumAll.YEAR_INCOME,2):'-'
                            }
                            dataList.push(obj)
                        }
                        if (checkList?.indexOf('1-4')!==-1){
                            const obj ={
                                SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                                SERVERPART_NAME: '',
                                SERVERPARTSHOP_NAME: '',
                                MERCHANTS_NAME: '',
                                STARTDATEENDDATE: '',
                                age: '保底租金应确认收入',
                                typeLabel: '月收入',
                                count:listSumAll.MONTH_INCOME?fmoney(listSumAll.MONTH_INCOME,2):'-'
                            }
                            dataList.push(obj)
                        }
                        if (checkList?.indexOf('1-6')!==-1){
                            const obj ={
                                SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                                SERVERPART_NAME: '',
                                SERVERPARTSHOP_NAME: '',
                                MERCHANTS_NAME: '',
                                STARTDATEENDDATE: '',
                                age: '保底租金应确认收入',
                                typeLabel: '累计应确认收入',
                                count:listSumAll.ACCUMULATED_INCOME?fmoney(listSumAll.ACCUMULATED_INCOME,2):'-'
                            }
                            dataList.push(obj)
                        }
                        if (checkList?.indexOf('2-1')!==-1){
                            const obj1 ={
                                SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                                SERVERPART_NAME: '',
                                SERVERPARTSHOP_NAME: '',
                                MERCHANTS_NAME: '',
                                STARTDATEENDDATE: '',
                                age: '浮动提成应确认收入',
                                typeLabel: '营业额',
                                count:listSumAll.REVENUE_TOTALAMOUNT?fmoney(listSumAll.REVENUE_TOTALAMOUNT,2):'-'
                            }
                            dataList.push(obj1)
                        }
                        if (checkList?.indexOf('2-5')!==-1){
                        const obj2 ={
                          SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                          SERVERPART_NAME: '',
                          SERVERPARTSHOP_NAME: '',
                          MERCHANTS_NAME: '',
                          STARTDATEENDDATE: '',
                          age: '浮动提成应确认收入',
                          typeLabel: '分润金额(含税)',
                          count:listSumAll.ROYALTY_TOTALAMOUNT?fmoney(listSumAll.ROYALTY_TOTALAMOUNT,2):'0.00'
                        }
                        dataList.push(obj2)
                      }
                        if (checkList?.indexOf('2-6')!==-1){
                        const obj3 ={
                          SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                          SERVERPART_NAME: '',
                          SERVERPARTSHOP_NAME: '',
                          MERCHANTS_NAME: '',
                          STARTDATEENDDATE: '',
                          age: '浮动提成应确认收入',
                          typeLabel: '分润金额',
                          count:listSumAll.ROYALTY_TOTALAMOUNT_NoTax?fmoney(listSumAll.ROYALTY_TOTALAMOUNT_NoTax,2):'-'
                        }
                        dataList.push(obj3)
                      }
                        if (checkList?.indexOf('2-3')!==-1){
                            const obj ={
                                SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                                SERVERPART_NAME: '',
                                SERVERPARTSHOP_NAME: '',
                                MERCHANTS_NAME: '',
                                STARTDATEENDDATE: '',
                                age: '浮动提成应确认收入',
                                typeLabel: '提成金额(含税)',
                                count:listSumAll.COMMISSION_INCOME?fmoney(listSumAll.COMMISSION_INCOME,2):'-'
                            }
                            dataList.push(obj)
                        }
                        if (checkList?.indexOf('2-4')!==-1){
                            const obj ={
                                SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                                SERVERPART_NAME: '',
                                SERVERPARTSHOP_NAME: '',
                                MERCHANTS_NAME: '',
                                STARTDATEENDDATE: '',
                                age: '浮动提成应确认收入',
                                typeLabel: '提成金额',
                                count:listSumAll.COMMISSION_INCOME_NoTax?fmoney(listSumAll.COMMISSION_INCOME_NoTax,2):'-'
                            }
                            dataList.push(obj)
                        }
                        if (checkList?.indexOf('3-1')!==-1){
                            const obj3 ={
                                SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                                SERVERPART_NAME: '',
                                SERVERPARTSHOP_NAME: '',
                                MERCHANTS_NAME: '',
                                STARTDATEENDDATE: '',
                                age: '本月确认收入',
                                typeLabel: '累计应确认含税收入',
                                count:listSumAll.CONFIRM_TAXCOMINCOME?fmoney(listSumAll.CONFIRM_TAXCOMINCOME,2):'-'
                            }
                            dataList.push(obj3)
                        }
                        if (checkList?.indexOf('3-2')!==-1){
                            const obj4 ={
                                SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                                SERVERPART_NAME: '',
                                SERVERPARTSHOP_NAME: '',
                                MERCHANTS_NAME: '',
                                STARTDATEENDDATE: '',
                                age: '本月确认收入',
                                typeLabel: '累计应确认收入',
                                count:listSumAll.CONFIRM_COMINCOME?fmoney(listSumAll.CONFIRM_COMINCOME,2):'-'
                            }
                            dataList.push(obj4)
                        }
                        if (checkList?.indexOf('3-3')!==-1){
                            const obj5 ={
                                SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                                SERVERPART_NAME: '',
                                SERVERPARTSHOP_NAME: '',
                                MERCHANTS_NAME: '',
                                STARTDATEENDDATE: '',
                                age: '本月确认收入',
                                typeLabel: '商家缴款',
                                count:listSumAll.MERCHANT_PAYMENT?fmoney(listSumAll.MERCHANT_PAYMENT,2):'-'
                            }
                            dataList.push(obj5)
                        }
                        if (checkList?.indexOf('3-4')!==-1){
                            const obj6 ={
                                SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                                SERVERPART_NAME: '',
                                SERVERPARTSHOP_NAME: '',
                                MERCHANTS_NAME: '',
                                STARTDATEENDDATE: '',
                                age: '本月确认收入',
                                typeLabel: '累计已确认收入(含税)',
                                count:listSumAll.LMONTH_TAXCOMINCOME?fmoney(listSumAll.LMONTH_TAXCOMINCOME,2):'-'
                            }
                            dataList.push(obj6)
                        }
                        if (checkList?.indexOf('3-5')!==-1){
                            const obj7 ={
                                SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                                SERVERPART_NAME: '',
                                SERVERPARTSHOP_NAME: '',
                                MERCHANTS_NAME: '',
                                STARTDATEENDDATE: '',
                                age: '本月确认收入',
                                typeLabel: '累计已确认收入',
                                count:listSumAll.LMONTH_COMINCOME?fmoney(listSumAll.LMONTH_COMINCOME,2):'-'
                            }
                            dataList.push(obj7)
                        }
                        if (checkList?.indexOf('3-6')!==-1){
                            const obj7 ={
                                SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                                SERVERPART_NAME: '',
                                SERVERPARTSHOP_NAME: '',
                                MERCHANTS_NAME: '',
                                STARTDATEENDDATE: '',
                                age: '本月确认收入',
                                typeLabel: '本月应确认收入(含税)',
                                count:listSumAll.CMONTH_TAXCOMINCOME?fmoney(listSumAll.CMONTH_TAXCOMINCOME,2):'-'
                            }
                            dataList.push(obj7)
                        }
                        if (checkList?.indexOf('3-7')!==-1){
                            const obj7 ={
                                SPREGIONTYPE_NAME: item.SPREGIONTYPE_NAME,
                                SERVERPART_NAME: '',
                                SERVERPARTSHOP_NAME: '',
                                MERCHANTS_NAME: '',
                                STARTDATEENDDATE: '',
                                age: '本月确认收入',
                                typeLabel: '本月应确认收入',
                                count:listSumAll.CMONTH_COMINCOME?fmoney(listSumAll.CMONTH_COMINCOME,2):'-'
                            }
                            dataList.push(obj7)
                        }

                    }
                })
            }
            // 计算完之后 重新赋值
            setS2DataConfig({
                ...s2DataConfig,
                data: dataList
            })
            setShowLoading(false)
            // 关掉加载
            setTableLoading(false)

            setS2Options({
                ...s2Options,
                tooltip: {
                    showTooltip: true,
                    operation: {
                        hiddenColumns: true,
                    },
                    adjustPosition: ((positionInfo: any) => {
                        const obj = {
                            x: positionInfo.position.x,
                            y: positionInfo.position.y
                        }
                        // if (positionInfo.event?.target?.cfg?.attrs?.text === "提成金额") {
                        //     obj = {
                        //         x: positionInfo.event.clientX - 400,
                        //         y: positionInfo.event.clientY + 20
                        //     }
                        // }
                        return obj
                    }),
                    // @ts-ignore
                    content: ((cell, defaultTooltipShowOptions) => {
                        return <div style={{ padding: '5px' }}>
                            {/* 名称 */}
                            {
                                forMulaList.indexOf(cell?.meta?.label)!==-1?'':
                                cell ?
                                    cell.meta.value ?
                                        <span>{cell.meta.value}</span> :
                                        cell.meta.data ?
                                            <span>{cell.meta.data.typeLabel}: </span> :
                                            cell.meta.colQuery ?
                                                <span>{cell.meta.colQuery.typeLabel}: </span> : '' : ''
                            }
                            {/* 数值 */}
                            {
                                defaultTooltipShowOptions.data.details && defaultTooltipShowOptions.data.details.length > 0 ?
                                    <span style={{ marginLeft: '4px' }}> {defaultTooltipShowOptions.data.details[0].value}</span> : ''
                            }
                            {/* 公式  */}
                            {
                                cell ?
                                    cell.actionIcons && cell.actionIcons.length > 0 ?
                                        cell.meta.query.age==='本月确认收入' && cell.meta.label === '累计应确认收入' ?
                                            <div>
                                                <p>{cell.meta.value.length>4?cell.meta.value:''}</p>
                                                <p>{"1、除税营业提成金额>除税月度累计保底金额："}</p>
                                                <p style={{ marginLeft: '50px' }}>{"除税营业提成金额"}</p>
                                                <p>{"2、除税营业提成金额<=除税月度累计保底金额："}</p>
                                                <p style={{ marginLeft: '50px' }}>{"除税月度累计保底金额"}</p>
                                                <p>{"3、计算公式："}</p>
                                                <p style={{ marginLeft: '50px' }}>{"除税营业提成金额：[营收金额*提成比例/100，保留2位]/（1+营业税率/100），保留2位"}</p>
                                                <p style={{ marginLeft: '50px' }}>{"除税月度累计保底金额：[[保底金额/（1+营业税率/100），保留2位]/总月份数，保留2位]*累计期数，保留2位"}</p>
                                            </div>
                                             :
                                            <div>
                                                <p>{cell.meta.value.length>4?cell.meta.value:''}</p>
                                                <p>
                                                    {getFormula(cell.meta.label, searchTime)}
                                                </p>
                                            </div>

                                        : '' : ''
                            }
                        </div>
                    })
                },
            })
        } else {
            message.open({
                type: 'error',
                content: '请先选择时间',
            });
            setS2DataConfig({
                ...s2DataConfig,
                data: []
            })
        }


    }
    // 行头点击方法
    const onRowCellClick = async (params: any) => {
        setShowLoading(true)
        // "MERCHANTS_NAME"
        // "STARTDATEENDDATE"
        let obj: any = {}
        if (params.viewMeta.field === "SERVERPARTSHOP_NAME" || params.viewMeta.field === "MERCHANTS_NAME" || params.viewMeta.field === "STARTDATEENDDATE") {
            if (tableData && tableData.length > 0) {
                tableData.forEach((item: any) => {
                    if (item.SERVERPARTSHOP_NAME === params.viewMeta.query.SERVERPARTSHOP_NAME &&
                        item.SERVERPART_NAME === params.viewMeta.query.SERVERPART_NAME &&
                        item.SPREGIONTYPE_NAME === params.viewMeta.query.SPREGIONTYPE_NAME) {
                        obj = item
                    }
                })
            }
            const req = {
                BusinessProjectId: obj.BUSINESSPROJECT_ID
            }
            const data = await getProjectDetail(req)
            setCurrentProject(data)
            setSelectItemShopName(params.viewMeta.query.SERVERPARTSHOP_NAME)
            if (data) {
                setShowLoading(false)
                setShowBrandDetail(true)
            }
        }
    }
    // 点击表格单元格调用的方法
    const onDataCellClick = async (data: any) => {

        // 先排除点击不会出现抽屉的内容  小计和总计点击也无效 也得排除
        if (data.viewMeta.colQuery.typeLabel === '营业额' && data.viewMeta.data.SERVERPART_NAME !== '小计' && data.viewMeta.data.SPREGIONTYPE_NAME !== '总计'
            || data.viewMeta.colQuery.typeLabel === '提成金额' && data.viewMeta.data.SERVERPART_NAME !== '小计' && data.viewMeta.data.SPREGIONTYPE_NAME !== '总计'
            || data.viewMeta.colQuery.typeLabel === '累计应确认含税收入' && data.viewMeta.data.SERVERPART_NAME !== '小计' && data.viewMeta.data.SPREGIONTYPE_NAME !== '总计'
            ) {
        // || data.viewMeta.colQuery.typeLabel === '商家缴款' && data.viewMeta.data.SERVERPART_NAME !== '小计' && data.viewMeta.data.SPREGIONTYPE_NAME !== '总计'
            setShowLoading(true)
            // 抽屉的详情赋值
            setDrawerDetail(data?.viewMeta?.rowQuery)
            // 根据点击的列 拿到字段名称 显示内容
            // 根据表格的当前内容 列举出字段值 和 字段名称
            const listType: string[] = [
                'MINTURNOVER',// 年保底租金
                'DUTY_PARAGRAPH',// 税率
                'YEAR_INCOME',// 年收入
                'MONTH_INCOME',// 月收入
                'ACCUMULATED_PERIOD',// 累计期数
                'ACCUMULATED_INCOME',// 累计应确认收入
                'REVENUE_TOTALAMOUNT',// 营业额
                'ROYALTY_TOTALAMOUNT',// 分润金额(含税)
                'ROYALTY_TOTALAMOUNT_NoTax',// 分润金额
                'GUARANTEERATIO',// 提成比例
                'COMMISSION_INCOME',// 提成金额(含税)
                'COMMISSION_INCOME_NoTax',// 提成金额
                'CONFIRM_TAXCOMINCOME',// 累计应确认含税收入
                'CONFIRM_COMINCOME',// 累计应确认收入
                'MERCHANT_PAYMENT',// 商家缴款
                'LMONTH_TAXCOMINCOME',// 累计已确认收入(含税)
                'LMONTH_COMINCOME']
            const listName: string[] = [
                '年保底租金',// MINTURNOVER
                '税率',// DUTY_PARAGRAPH
                '年收入',// YEAR_INCOME
                '月收入',// MONTH_INCOME
                '累计期数',// ACCUMULATED_PERIOD
                '累计应确认收入',// ACCUMULATED_INCOME
                '营业额',// REVENUE_TOTALAMOUNT
                '分润金额(含税)',// ROYALTY_TOTALAMOUNT
                '分润金额',// ROYALTY_TOTALAMOUNT_NoTax
                '提成比例',// GUARANTEERATIO
                '提成金额(含税)',// COMMISSION_INCOME
                '提成金额',// COMMISSION_INCOME_NoTax
                '累计应确认含税收入',// CONFIRM_TAXCOMINCOME
                '累计应确认收入', // CONFIRM_COMINCOME
                '商家缴款',// MERCHANT_PAYMENT
                '累计已确认收入(含税)', // LMONTH_TAXCOMINCOME
                '累计已确认收入'// LMONTH_COMINCOME
            ]
            // 拿到点击的当前行 、行代表的名字 和数据
            setGetDataColIndex(listType[data.viewMeta.colIndex])
            setGetDataColName(listName[data.viewMeta.colIndex])
            setSelectDataDetail(data.viewMeta)
            // 全部传入调用方法
            getLineBoxData(listType[data.viewMeta.colIndex], listName[data.viewMeta.colIndex], data.viewMeta)
        }else if (data.viewMeta.colQuery.typeLabel === '商家缴款' && data.viewMeta.data.SERVERPART_NAME !== '小计' && data.viewMeta.data.SPREGIONTYPE_NAME !== '总计'){
            setShowLoading(true)
            let obj: any = {}
            if (tableData && tableData.length > 0) {
                tableData.forEach((item: any) => {
                    if (item.SERVERPARTSHOP_NAME === data.viewMeta.rowQuery.SERVERPARTSHOP_NAME &&
                        item.SERVERPART_NAME === data.viewMeta.rowQuery.SERVERPART_NAME &&
                        item.SPREGIONTYPE_NAME === data.viewMeta.rowQuery.SPREGIONTYPE_NAME) {
                        obj = item
                    }
                })
            }
            const req = {
                BusinessProjectId: obj.BUSINESSPROJECT_ID
            }
            const res = await getProjectDetail(req)
            setCurrentProject(res)
            setSelectItemShopName(data.viewMeta.rowQuery.SERVERPARTSHOP_NAME)
            if (res) {
                setShowLoading(false)
                setShowShopExpenses(true)
            }
        }
    }

    // 请求服务区树列表
    const { loading: treeLoading, data: treeView } = useRequest(async () => {
        return getServerpartTree(currentUser?.ProvinceCode, currentUser?.CityAuthority, true, false, true)
    })

    // 初始化时间  进入页面默认拿到上个月的月份时间
    useEffect(() => {
        // getList()
        setSearchTime(moment().subtract(1, 'month'))
    }, []);

    return (
        <div ref={(el) => {
            // 打印报表
            setPrintOut(el);
        }}>
            <ProCard split="vertical" style={{ height: 'calc(100vh - 130px)', backgroundColor: '#fff' }}>
                <ProCard
                    className="pageTable-leftnav"
                    bodyStyle={{ padding: 0, paddingTop: 20, paddingLeft: 20 }}
                    extra={<MenuFoldOutlined onClick={() => { setCollapsible(!collapsible) }} />}
                    colSpan={!collapsible ? "240px" : "60px"}
                    title={!collapsible ? "请选择服务区" : ""}
                    headerBordered
                    collapsed={collapsible}
                >
                    {treeView && treeView.length > 0 ? <Tree
                        checkable
                        treeData={!treeLoading ? [{
                            label: '全部',
                            value: 0,
                            key: '0-0',
                            children: treeView
                        }] : []}
                        fieldNames={{
                            title: "label",
                            key: "key"
                        }}
                        blockNode
                        defaultExpandedKeys={['0-0']}
                        onCheck={(checkedKeys: React.Key[] | any, info) => {
                            const selectedIds = info.checkedNodes.filter(n => n?.type === 1)
                            setSelectedId(selectedIds.map(n => n?.value)?.toString() || '')
                            let id: string = ''
                            if (checkedKeys && checkedKeys.length > 0) {
                                // 截取服务区id
                                checkedKeys.forEach((item: any) => {
                                    if (item.indexOf('1-') !== -1) {
                                        if (id === '') {
                                            id = item.split('1-')[1]
                                        } else {
                                            id += `,${item.split('1-')[1]}`
                                        }
                                    }
                                })
                                setServerId(id)
                            } else {
                                setServerId(null)
                            }
                            // 取消掉选择点击左侧  右侧列表就直接调用接口拿到数据
                            // actionRef?.current?.reload()
                        }}
                    // switcherIcon={<PlusOutlined />}
                    /> : ''}
                </ProCard>
                <ProCard id='bigAccountMonthly' bodyStyle={{ position: 'relative', height: 'calc(100vh - 145px)', paddingTop: 0, paddingBottom: 0, paddingRight: 0 }}>
                    <div id='accountMonthly' style={{ position: 'absolute', zIndex: -1, top: 0, left: 0 }} />
                    {/* <iframe id={'iframe'} width="500" height="500" src="https://kyfw.12306.cn/otn/leftTicket/init?linktypeid=dc&fs=%E6%9D%AD%E5%B7%9E%E8%A5%BF,HVU&ts=%E6%B7%84%E5%8D%9A,ZBK&date=2023-09-15&flag=N,N,Y"></iframe> */}
                    {/* <Button onClick={()=>{ */}
                    {/* }}>1</Button> */}
                    <div style={{ boxSizing: "border-box", width: '100%', padding: '24px 24px 24px 0',height: '100%' }}>
                        <AntvTable
                            tableConfig={{ ...s2DataConfig }}
                            tableOptions={{ ...s2Options }}
                            tableQuery={tableQuery}
                            tableRef={tableRef}
                            requestObj={{
                                id: serverId,
                                time: searchTime,
                                name: searchName
                            }}
                            themeCfg={themeCfg}
                            showLoading={showLoading}
                            mergeArray={mergeArray}
                            onRowCellClick={onRowCellClick}
                            onDataCellClick={onDataCellClick}
                            tableLoading={tableLoading}
                            handleQuery={getList}
                            typeList={typeList}
                            bigSum={bigSum}
                            listLength={listLength}

                            tableTitle={'场地租赁（分账收银模式）收入确认明细表'}
                        />
                    </div>
                </ProCard>
            </ProCard>

            <Drawer
                width={'60%'}
                visible={showDrawer}
                onClose={() => {
                    // 删除抽屉的图表数据和详情数据
                    setShowDrawer(false);
                    setDrawerDetail(undefined)
                    setPieConfigObj(undefined)
                    setGetDataColIndex(undefined)
                    setGetDataColName(undefined)
                    setSelectDataDetail(undefined)
                    setDrawerSearchTime(undefined)
                }}
                bodyStyle={{ padding: 0 }}
                footer={
                    <div style={{ width: '100%', display: 'flex', justifyContent: 'flex-end' }}>
                        <Button onClick={() => {
                            setShowDrawer(false)
                            setDrawerDetail(undefined)
                            setPieConfigObj(undefined)
                            setGetDataColIndex(undefined)
                            setGetDataColName(undefined)
                            setDrawerSearchTime(undefined)
                            setSelectDataDetail(undefined)
                        }}>取消</Button>
                        {/* <Button type={'primary'}>确定</Button> */}
                    </div>
                }
                closable={false}>
                {
                    showDrawer ?
                        <div className={'drawerContent'}>
                            <div style={{ boxSizing: 'border-box', padding: '30px' }}>
                                <div style={{ width: '100%', position: 'relative' }}>
                                    <p style={{ textAlign: 'center', fontSize: '20px', fontWeight: 600 }}>
                                        {drawerDetail?.SPREGIONTYPE_NAME}
                                        {drawerDetail?.SERVERPART_NAME}
                                        {drawerDetail?.SERVERPARTSHOP_NAME}
                                    </p>
                                    <RangePicker style={{ position: 'absolute', right: 0, top: 0 }} value={drawerSearchTime} format={'YYYY-MM'} picker="month" onChange={(val: any) => {
                                        setDrawerSearchTime([moment(val[0]._d), moment(val[1]._d)])
                                        setPieConfigObj(undefined)
                                        getLineBoxData(getDataColIndex, getDataColName, selectDataDetail, moment(val[0]._d), moment(val[1]._d))
                                    }} />
                                </div>

                                {
                                    pieConfigObj && pieConfigObj.data && pieConfigObj.data.length > 0 && !showLoading?
                                        // <Line {...pieConfigObj}></Line> :
                                      <Column {...pieConfigObj}></Column>:
                                      pieConfigObj && pieConfigObj.data && pieConfigObj.data.length === 0 && !showLoading?
                                        <>
                                          <NoData/>
                                        </>:
                                        <div className={'drawerLoading'}>
                                            <div className={'loadingBox'}>
                                                <Spin />
                                                <span style={{ marginLeft: '5px' }}>数据加载中...</span>
                                            </div>
                                        </div>
                                }
                            </div>
                        </div> : ''
                }
            </Drawer>

            {/*     品牌详情抽屉 */}
            <Drawer
                width={'80%'}
                visible={showBrandDetail}
                onClose={() => {
                    setShowBrandDetail(false)
                }}
                bodyStyle={{ padding: 0 }}
                footer={
                    <div style={{ width: '100%', display: 'flex', justifyContent: 'flex-end' }}>
                        <Button onClick={() => {
                            setShowBrandDetail(false)
                        }}>取消</Button>
                        {/* <Button type={'primary'}>确定</Button> */}
                    </div>
                }
                closable={false}>
                <ProjectDetail {...{
                    id: currentProject?.BUSINESSPROJECT_ID,
                    type: currentProject?.SETTLEMENT_MODES,
                    showTabs: [1, 3, 7, 8, 9, 10, 11],
                    tabActive: "7", isPayment: false,
                    serverShopId: currentProject?.SERVERPARTSHOP_ID,
                    shopName: selectItemShopName,
                    // price: currentProject.PAYABLE_AMOUNT || 0, date: currentProject.ACCOUNT_DATE,
                    editable: false
                }}></ProjectDetail>
            </Drawer>
            {/*     物业水电费抽屉 */}
            <Drawer
                width={'80%'}
                visible={showShopExpenses}
                onClose={() => {
                    setShowShopExpenses(false)
                }}
                bodyStyle={{ padding: 0 }}
                footer={
                    <div style={{ width: '100%', display: 'flex', justifyContent: 'flex-end' }}>
                        <Button onClick={() => {
                            setShowShopExpenses(false)
                        }}>取消</Button>
                        {/* <Button type={'primary'}>确定</Button> */}
                    </div>
                }
                closable={false}>
                {/* ServerpartId={serverpartId.current} */}
                <ShopExpense isComponents={true}  ServerpartId={currentProject?.SERVERPART_IDS}/>
            </Drawer>
        </div>
    )
}
export default connect(({ user }: ConnectState) => ({
    currentUser: user.currentUser
}))(TestTable);
