import HocError from '@/Hoc/HocError'
import React, { useMemo } from 'react'
import { useModel } from 'umi'
import TableData from '../../components/TableData'
import { columns } from './tableConfig'

/**充值历史（年） */
function Page() {
    const { state: { dataSource }, getRechargeHisYaer } = useModel('useData.useTableData')
    //加工数据
    const data = useMemo(() => {
        if (dataSource) {
            return dataSource?.map((item: any, index: number) => {
                item['id'] = index
                return item
            })
        }
        return []
    }, [dataSource])
    // 获取排序列表 今年以前月份倒序
    const sortArr = useMemo(() => {
        let arr: any[] = []
        columns().map((item: any) => {
            if (typeof item.title === 'string') {
                arr.push({ title: item.title, value: item.dataIndex, key: item.key })
            }
            if (typeof item.title === 'object' && typeof item.title.props.children[0] === 'string') {
                arr.push({ title: item.title, value: item.dataIndex, key: item.key })
            }
        })
        return arr
    }, [columns])
    
    return <>
        <TableData
            isUserId
            // isDownload
            isLoginId
            isShowTotal={false}
            isCostYear
            isSelctAccTags
            isGroupTab={false}
            isOrderMonth
            isLastReverse
            isHideSort
            isPitcherSelf
            isDataSelectPitcher
            isDataSelectPitcher_isDisabled
            isPitcherId
            sortArr={sortArr}
            columns={columns}
            dataSource={data}
            title='充值历史（年）'
            subTitle={<span style={{fontSize: 12, color: 'red'}}>本模块数据只作为运营监控作用，不做财务对账的作用（不考虑公众号更换投手的场景）</span>}
            scroll={{ x: 1000, y: 600 }}
            ajax={getRechargeHisYaer}
        />
    </>
}

export default HocError(Page)