import { BtnListType } from '@/common/components/btnList/interface';
import { BuyOrSell } from '@/common/constants/enumCommon';
import { QueryOrderQuoteMyqQsp } from '@/services/go/wrtrade/interface';


export function handleColumns() {
    const columns = [
        { title: '品种', key: 'deliverygoodsname', align: 'center', width: 140 },
        { title: '商品', key: 'wrtypename', align: 'center', width: 400 },
        { title: '仓库', key: 'warehousename', align: 'center', width: 200 },
        { title: '价格', key: 'fixedprice', align: 'center', width: 120 },
        { title: '议价', key: 'canbargain', align: 'center', width: 80 },
        { title: '数量', key: 'orderqty', align: 'center', width: 120 },
        { title: '整单', key: 'canpart', align: 'center', width: 80 },
        { title: '挂牌有效期', key: 'validtime', align: 'center', width: 120 },
        { title: '履约保证金', key: 'marginvalue', align: 'center', width: 120 },
        { title: '履约模板', key: 'templatename', align: 'center', width: 140 },
        { title: '挂牌方', key: 'username', align: 'center', width: 100 },
    ];
    function getBuyOrSellColumns(type: BuyOrSell) {
        const title = type === BuyOrSell.buy ? '买' : '卖'
        const result = [
            { title, dataIndex: 'index', key: 'index', width: 80, align: 'center' },
            ...columns
        ]
        return result.map(el => {
            const slots = { customRender: el.key };
            return { ...el, slots, dataIndex: el.key };
        })
    }
    return { getBuyOrSellColumns }
}

export function filterBtn(btnList: BtnListType[], selectedRow: QueryOrderQuoteMyqQsp) {
    let result = btnList.filter(e => e.code !== 'warehouse_receipt_trade_blocs_post_buying')
    if (selectedRow) {
        result = selectedRow.canbargain ? result : result.filter(e => e.code !== 'warehouse_receipt_trade_blocs_bargain_delisting')
    }
    return result
}
