import { useAjax } from "@/Hook/useAjax"
import { getBigRApi, GetBigRProps } from "@/services/gsData"
import React, { useEffect, useState } from "react"
import columns12 from "./tableConfig"
import TablePro from "@/pages/gameDataStatistics/components/TablePro"
import QueryFormGS from "@/components/QueryForm/indexGs"
import moment from "moment"

/**
 * 大R每日充值比
 * @returns 
 */
const BidREveryday: React.FC = () => {

    /****************************************/
    const [queryForm, setQueryForm] = useState<GetBigRProps>({
        pageNum: 1,
        pageSize: 30,
        sourceSystem: 'ZX_ONE',
        roleSource: 2,
        dtBegin: moment().format('YYYY-MM-DD'),
        dtEnd: moment().format('YYYY-MM-DD')
    })
    const getBigR = useAjax((params) => getBigRApi(params))
    /****************************************/

    useEffect(() => {
        getBigR.run(queryForm)
    }, [queryForm])

    return <div>
        <TablePro
            leftChild={<QueryFormGS
                initialValues={{ sourceSystem: 'ZX_ONE', roleSource: 2, rechargeDay: [moment(), moment()] }}
                isSource
                isGsId
                rechargeDay={{ placeholder: ['充值统计开始日期', '充值统计结束日期'] }}
                isCreateRoleDay={{}}
                isServeDay={{}}
                isRemoveGame
                isRemoveGameForSystem
                isParentId
                isSuperParentGameId
                isGameRoleName
                isServerIds
                isRoleSource
                isServeStatus
                onChange={(data: any) => {
                    console.log(data)
                    const { rechargeDay, gsId, parentId, createRoleDay, serveDay, superParentGameId, serverIds, ...params } = data
                    let newQueryForm = JSON.parse(JSON.stringify(queryForm))
                    newQueryForm.pageNum = 1
                    newQueryForm.gsIdList = gsId
                    newQueryForm.parentGameId = parentId
                    newQueryForm.superGameId = superParentGameId
                    newQueryForm.serverIdList = serverIds
                    if (rechargeDay && rechargeDay?.length === 2) {
                        newQueryForm['dtBegin'] = moment(rechargeDay[0]).format('YYYY-MM-DD')
                        newQueryForm['dtEnd'] = moment(rechargeDay[1]).format('YYYY-MM-DD')
                    } else {
                        delete newQueryForm['dtBegin']
                        delete newQueryForm['dtEnd']
                    }
                    if (createRoleDay && createRoleDay?.length === 2) {
                        newQueryForm['roleCreateDayBegin'] = moment(createRoleDay[0]).format('YYYY-MM-DD')
                        newQueryForm['roleCreateDayEnd'] = moment(createRoleDay[1]).format('YYYY-MM-DD')
                    } else {
                        delete newQueryForm['roleCreateDayBegin']
                        delete newQueryForm['roleCreateDayEnd']
                    }
                    if (serveDay && serveDay?.length === 2) {
                        newQueryForm['serveDayBegin'] = moment(serveDay[0]).format('YYYY-MM-DD')
                        newQueryForm['serveDayEnd'] = moment(serveDay[1]).format('YYYY-MM-DD')
                    } else {
                        delete newQueryForm['serveDayBegin']
                        delete newQueryForm['serveDayEnd']
                    }
                    setQueryForm({ ...newQueryForm, ...params })
                }}
            />}
            config={columns12()}
            configName={'大R每日充值比'}
            fixed={{ left: 4, right: 0 }}
            scroll={{ x: 1000, y: 620 }}
            title='大R每日充值比'
            loading={getBigR.loading}
            ajax={getBigR}
            page={getBigR?.data?.current || 1}
            pageSize={getBigR?.data?.size || 20}
            total={getBigR?.data?.total || 0}
            dataSource={getBigR?.data?.records?.map((item: any, index: number) => ({ ...item, id: Number(queryForm.pageNum.toString() + (index + '')) }))}
            onChange={(pagination: any, _: any, sortData: any) => {
                let { current, pageSize } = pagination
                let newQueryForm = JSON.parse(JSON.stringify(queryForm))
                if (sortData && sortData?.order) {
                    newQueryForm['sortAsc'] = sortData?.order === 'ascend' ? true : false
                    newQueryForm['sortFiled'] = sortData?.field
                } else {
                    delete newQueryForm['sortAsc']
                    delete newQueryForm['sortFiled']
                }
                newQueryForm.pageNum = current || newQueryForm.pageNum
                newQueryForm.pageSize = pageSize || newQueryForm.pageSize
                setQueryForm({ ...newQueryForm })
            }}
        />
    </div>
}

export default BidREveryday