import HocError from '@/Hoc/HocError'
import React, { useEffect, useMemo } from 'react'
import { useModel } from 'umi'
import TableDataTab from '../../../../components/TableData/indexTab'
import { columns } from './tableConfig'
/**广告投放详细数据 */
function Page() {
    const { state: { dataSource }, getChannelOverview } = 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.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 <>
        <TableDataTab
            isBook
            isQs
            isTableDateArr
            isZj
            isGroupTab={false}
            isAdmin
            isUserId
            isPitcher={true}
            sortArr={sortArr}
            columns={columns}
            ajax={getChannelOverview}
            title='广告投放详细数据'
            dataSource={data}
            scroll={{ x: 1000, y: 600 }}
        />
    </>
}

export default HocError(Page)