import QueryForm from "@/components/QueryForm"
import { useAjax } from "@/Hook/useAjax"
import { getOrderListApi, OrderListType } from "@/services/gameData/order"
import React, { useEffect, useState } from "react"
import TableData from "../components/TableData"
import columns12 from "./tableConfig"



const Order: React.FC = () => {

    /***************************/
    const [queryForm, setQueryForm] = useState<OrderListType>({ pageNum: 1, pageSize: 20, sourceSystem: 'ZX_ONE' })
    const getOrderList = useAjax((params) => getOrderListApi(params))
    /***************************/

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

    return <div>

        <TableData
            leftChild={<QueryForm
                initialValues={{ sourceSystem: 'ZX_ONE' }}
                onChange={(data: any) => {
                    const { pitcherId, regStartDay, regEndDay, beginOrderTime, endOrderTime, ...params } = data
                    console.log(params, pitcherId)
                    let newQueryForm = JSON.parse(JSON.stringify(queryForm))
                    newQueryForm.pageNum = 1
                    newQueryForm.zxPitcherId = pitcherId
                    if (regStartDay && regEndDay) {
                        newQueryForm.beginRegTime = regStartDay + ' 00:00:00'
                        newQueryForm.endRegTime = regEndDay + ' 59:59:59'
                    } else {
                        delete newQueryForm.beginRegTime
                        delete newQueryForm.endRegTime
                    }
                    if (beginOrderTime && endOrderTime) {
                        newQueryForm.beginOrderTime = beginOrderTime + ' 00:00:00'
                        newQueryForm.endOrderTime = endOrderTime + ' 59:59:59'
                    } else {
                        delete newQueryForm.beginOrderTime
                        delete newQueryForm.endOrderTime
                    }

                    setQueryForm({ ...newQueryForm, ...params })
                }}
                isSource
                isAccountId
                isAgentId
                isGameId
                isCpOrderId
                isGameUserId
                isMerchantOrderNo
                isOrderGameId
                isOrderId
                isPayStatus
                isOs
                isParentId
                isPayWay
                isGameRoleName
                isGameRoleId
                isUserName
                isSysUserId
                isCreateDay
                isRegDay
            />}
            scroll={{ x: 1000, y: 600 }}
            ajax={getOrderList}
            fixed={{ left: 3, right: 2 }}
            dataSource={getOrderList?.data?.records?.map((item: any, index: number) => ({ ...item, id: item?.orderId?.replace(/\D/g, '') || index }))}
            total={getOrderList?.data?.total}
            page={queryForm.pageNum}
            pageSize={queryForm.pageSize}
            title='订单明细'
            onChange={(props: any) => {
                console.log('props--->', props)
                let { pagination, sortData } = props
                let { current, pageSize } = pagination
                let newQueryForm = JSON.parse(JSON.stringify(queryForm))
                if (sortData && sortData?.order) {
                    newQueryForm['sortType'] = sortData?.order === 'ascend' ? 'asc' : 'desc'
                    newQueryForm['sortFiled'] = sortData?.field
                } else {
                    delete newQueryForm['sortType']
                    delete newQueryForm['sortFiled']
                }
                newQueryForm.pageNum = current
                newQueryForm.pageSize = pageSize
                setQueryForm({ ...newQueryForm })
            }}
            config={columns12()}
            configName={'订单明细'}
        // summary={() => {
        //     let defSelectData = localStorage.getItem(`myAdMonitorConfig1.0.0_订单明细`)
        //     let newDefSelectData: any[] = []
        //     if (defSelectData) {
        //         newDefSelectData = JSON.parse(defSelectData)
        //     } else {
        //         newDefSelectData = columns12()[0]?.data
        //     }
        //     return <Table.Summary fixed={'top'}>
        //         <Table.Summary.Row>
        //             {newDefSelectData?.map((item: { dataIndex: string }, index: number) => {
        //                 if (item.dataIndex === 'amount') {
        //                     return <Table.Summary.Cell index={index} align='center' key={index}><Statistic valueStyle={{ color: 'red', fontWeight: 600 }} value={getOrderList?.data?.totalData?.totalAmount || 0} precision={2}/></Table.Summary.Cell>
        //                 } else if (item.dataIndex === 'realAmount') {
        //                     return <Table.Summary.Cell index={index} align='center' key={index}><Statistic valueStyle={{ color: 'red', fontWeight: 600 }} value={getOrderList?.data?.totalData?.totalRealAmount || 0} precision={2}/></Table.Summary.Cell>
        //                 } else if (index === 0) {
        //                     return <Table.Summary.Cell index={index} align='center' key={index}><span style={{ fontSize: 16, fontWeight: 'bold' }}>汇总</span></Table.Summary.Cell>
        //                 }
        //                 return <Table.Summary.Cell index={index} align='center' key={index}><span>--</span></Table.Summary.Cell>
        //             })}
        //         </Table.Summary.Row>
        //     </Table.Summary>
        // }}
        />
    </div>
}

export default Order