import HocError from '@/Hoc/HocError'
import React, { useEffect, useMemo } from 'react'
import { useModel } from 'umi'
import TableData from '../../components/TableData'
import { columns } from './tableConfig'
/**公众号用户充值查询 */
function Page() {
    const { state: { dataSource}, getChannelAnalysis, dispatch } = useModel('useData.useTableData')
    useEffect(() => {
        if (window.location.hash?.indexOf('?') !== -1 && window.location.hash?.indexOf('channel') !== -1) {
            let cs = window.location.hash?.split('?')
            let channel = cs[1]?.split('=')[1]
            dispatch({ type: 'channel', params: { channel: decodeURI(channel) } })
        }
    }, [])

    //加工数据
    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.dataIndex })
            }
            if (typeof item.title === 'object' && typeof item.title.props.children[0] === 'string') {
                arr.push({ title: item.title, value: item.dataIndex, key: item.dataIndex })
            }
        })
        return arr
    }, [columns])

    return <>
        <TableData
            isTableDateArr
            isTableDateArrSt
            isZj
            isGroupTab={false}
            isAdmin
            isUserId
            isSelctAcc
            // isSelctAccTags
            sortArr={sortArr}
            columns={columns}
            ajax={getChannelAnalysis}
            title='公众号用户充值查询'
            dataSource={data}
            scroll={{ x: 1000, y: 600 }}
        />
    </>
}

export default HocError(Page)