import { QueryErmcpTradeDetailsRsp } from '@/services/go/ermcp/futures/interface';
import { getChannelBuildName, getBuyOrSellTypeName, getChannelOperateName } from '@/common/constants/enumsName';
import { BuildType } from '@/common/constants/enumCommon';
import { formatTime } from '@/common/methods';

export function getColumns() {
    const columns = [
        {
            title: '合约',
            key: 'goodscode',
            customRender: ({ record }: { record: QueryErmcpTradeDetailsRsp }) => {
                return record.goodscode
            }
        },
        {
            title: '订单类型',
            key: 'channelbuildtype',
            customRender: ({ record }: { record: QueryErmcpTradeDetailsRsp }) => {
                return getBuyOrSellTypeName(record.buyorsell) + getChannelBuildName(record.channelbuildtype)
            }
        },
        {
            title: '成交类型',
            key: 'tradetype',
            customRender: ({ record }: { record: QueryErmcpTradeDetailsRsp }) => {
                return getChannelOperateName(record.tradetype)
            }
        },
        {
            title: '成交数量',
            key: 'tradeqty'
        },
        {
            title: '成交价格',
            key: 'tradeprice',
            customRender: ({ record }: { record: QueryErmcpTradeDetailsRsp }) => {
                return record.tradeprice.toFixed(record.decimalplace)
            }
        },
        {
            title: '手续费',
            key: 'closecharge',
            customRender: ({ record }: { record: QueryErmcpTradeDetailsRsp }) => {
                return record.channelbuildtype === BuildType.open ? record.opencharge.toFixed(2) : record.closecharge.toFixed(2)
            }
        },
        {
            title: '成交时间',
            key: 'tradetime',
            width: 180,
            customRender: ({ record }: { record: QueryErmcpTradeDetailsRsp }) => {
                return formatTime(record.tradetime)
            }
        },
        {
            title: '交易所',
            key: 'exchangefullname',
            width: 120,
            customRender: ({ record }: { record: QueryErmcpTradeDetailsRsp }) => {
                return record.exchangefullname
            }
        },
        {
            title: '订单号',
            key: 'orderid',
            width: 180,
        },
        {
            title: '委托人',
            key: 'orderlogincode'
        },
    ];

    return columns.map(el => {
        return {
            dataIndex: el.key,
            width: 100,
            align: 'center',
            ...el
        }
    })
}