<template>
    <!-- 现货贸易 - 买卖大厅 - 买报价牌 -->
    <a-table
        :columns="handleColumn(columns)"
        :class="['sellHallTable', isBottom ? '' : 'sellHallTableHigh', tableList.length ? '' : 'noDataTable']"
        :scroll="{ x: '100%', y: isBottom ? 'calc(100vh- 378px)' : 'calc(100vh - 135px)' }"
        :pagination="false"
        :loading="loading"
        :expandedRowKeys="expandedRowKeys"
        :customRow="Rowclick"
        :expandIcon="expandIcon"
        :expandIconAsCell="false"
        rowKey="key"
        :data-source="tableList"
    >
        <!-- 额外的展开行 -->
        <template #expandedRowRender="{ record }">
            <BtnList :btnList="btnListData" :record="record" @click="openComponent" />
        </template>
        <template #username="{text, record }">
            <span>{{record.userid + " " }}{{text}}</span>
        </template>
        <template #fixedprice="{record }">
            <span>{{record.useorderpricerid }}</span>
        </template>
    </a-table>
    <component
        :is="componentId"
        v-if="componentId"
        :selectedRow="selectedRow"
        :parantSelectedRow="parantSelectedRow"
        :buyOrSell="BuyOrSell.sell"
        @cancel="closeComponent"
    ></component>
</template>

<script lang="ts">
import { BtnList, defineComponent, queryTableList } from '@/common/export/commonTable';
import { _closeModal } from '@/common/setup/modal/modal';
import { queryWrTradeOrderDetail } from '@/services/go/wrtrade';
import { WrOrderQuote, WrOrderQuoteDetail, WrTradeOrderDetailReq } from '@/services/go/wrtrade/interface';
import { defineAsyncComponent, PropType } from 'vue';
import { BtnListType } from '@/common/components/btnList/interface';
import { BuyOrSell } from '@/common/constants/enumCommon';
import { expandIcon } from '@/common/setup/table/clolumn';
import { ColumnType } from '@/common/methods/table/interface';
import { getShowBottomValue } from '@/common/config/constrolBottom';
import { TableParam } from '@/common/setup/table/interface';
import { handleTableEventAndData } from '@/common/setup/table/compose';
import { QueryDeliveryRelationRsp } from '@/services/go/delivery/interface';

export default defineComponent({
    emits: ['cancel', 'openComponent'],
    name: 'warehouse_receipt_trade_price_delisting_sell',
    props: {
        parantSelectedRow: {
            type: Object as PropType<QueryDeliveryRelationRsp>,
            default: {},
        },
    },
    components: {
        BtnList,
        Delisting: defineAsyncComponent(() => import('../delisting/index.vue')),
    },
    setup(props, context) {
        const isBottom = getShowBottomValue();
        console.log(isBottom.value, 'isBottom');
        // 表格列表数据
        const { loading, tableList, queryTable } = queryTableList<WrOrderQuoteDetail>();
        const columnsList = [
            { title: '序号', key: 'index', width: 60 },
            { title: '销售方', key: 'username' },
            { title: '买量', key: 'orderqty' },

            { title: '买价', key: 'orderprice' },
        ];
        const btnListData: BtnListType[] = [{ lable: '摘牌', code: 'Delisting', className: 'operBtn' }];
        // 获取列表数据
        const queryTableAction = () => {
            const param: WrTradeOrderDetailReq = {
                buyorsell: 1,
                goodsid: props.parantSelectedRow.goodsid,
            };
            queryTable(queryWrTradeOrderDetail, param);
        };
        // 表格通用逻辑
        const param: TableParam = {
            columnsList,
            queryFn: queryTableAction,
        };
        function handleColumn(columns: ColumnType[]) {
            columns.forEach((item) => {
                columns.forEach((item) => {
                    if (item.dataIndex == 'username') {
                        delete item.width;
                    }
                });
            });
            return columns;
        }
        return {
            isBottom,
            ...handleTableEventAndData(param),
            queryTableAction,
            loading,
            tableList,
            BuyOrSell,
            expandIcon,
            handleColumn,
            btnListData,
        };
    },
});
</script>
<style lang="less">
.buy-sell-market {
    .btnDeafault.ant-btn {
        height: 28px;
        line-height: 28px;
    }
}
</style>