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

export function getColumns() {
    const columns = [
        {
            title: '委托时间',
            key: 'ordertime',
            width: 180,
            customRender: ({ record }: { record: QueryErmcpOrderDetailsRsp }) => {
                return formatTime(record.ordertime)
            }
        },
        {
            title: '合约',
            key: 'goodscode',
            width: 150,
            customRender: ({ record }: { record: QueryErmcpOrderDetailsRsp }) => {
                return `${record.goodsname}/${record.goodscode}`
            }
        },
        {
            title: '订单类型',
            key: 'channelbuildtype',
            customRender: ({ record }: { record: QueryErmcpOrderDetailsRsp }) => {
                return getBuyOrSellTypeName(record.buyorsell) + getChannelBuildName(record.channelbuildtype)
            }
        },
        {
            title: '委托类型',
            key: 'channeloperatetype',
            customRender: ({ record }: { record: QueryErmcpOrderDetailsRsp }) => {
                return getChannelOperateName(record.channeloperatetype)
            }
        },
        {
            title: '委托数量',
            key: 'orderqty'
        },
        {
            title: '成交数量',
            key: 'tradeqty'
        },
        {
            title: '委托价',
            key: 'orderprice',
            customRender: ({ record }: { record: QueryErmcpOrderDetailsRsp }) => {
                return record.orderprice.toFixed(record.decimalplace)
            }
        },
        {
            title: '冻结保证金',
            key: 'openfreezemargin',
            width: 120,
            customRender: ({ text }: { text: number }) => text.toFixed(2)
        },
        {
            title: '订单状态',
            key: 'channelinnerorderstatus',
            customRender: ({ record }: { record: QueryErmcpOrderDetailsRsp }) => {
                return getChannelInnerOrderStatusName(record.channelinnerorderstatus)
            }
        },
        {
            title: '订单号',
            key: 'orderid',
            width: 180,
        },
        {
            title: '委托人',
            key: 'orderlogincode'
        },
        {
            title: '撤单人',
            key: 'cancellogincode'
        },
    ];

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