<template>
    <!-- 仓单贸易 一口价挂牌-->
    <div class="topTableHeight">
        <Filter :enumName="name" @search="search" @buy="buyOpen" />
        <a-table
            :columns="columns"
            :class="['srcollYTable', isBottom ? 'condSecondTabTable' : 'condSecondTabTableNoBottom']"
            :scroll="{ x: '100%', y: isBottom ? 'calc(100vh- 443px)' : 'calc(100vh - 196px)' }"
            :pagination="false"
            :loading="loading"
            :expandedRowKeys="expandedRowKeys"
            :customRow="Rowclick"
            rowKey="key"
            :data-source="tableList"
        ></a-table>
        <!-- 右键 -->
        <contextMenu :contextMenu="contextMenu" @cancel="closeContext" :list="firstBtn"></contextMenu>
        <component
            :is="componentId"
            v-if="componentId"
            :enumName="name"
            :selectedRow="selectedRow"
            @cancel="closeComponent"
        ></component>
    </div>
</template>

<script lang="ts">
import { EnumRouterName } from '@/common/constants/enumRouterName';
import { queryTableList, BtnList, contextMenu, defineAsyncComponent, defineComponent, ModalEnum, ComposeTableParam } from '@/common/export/commonTable';
import { QueryOrderQuoteReq, WrOrderQuote } from '@/services/go/wrtrade/interface';
import { queryOrderQuote } from '@/services/go/wrtrade';
import { handleComposeTable } from '@/views/market/spot_trade/setup';
import Bus from '@/utils/eventBus/index';
import Filter from '../../components/filter/index.vue';
import { getShowBottomValue } from '@/common/config/constrolBottom';

export default defineComponent({
    name: EnumRouterName.warehouse_receipt_trade_price,
    components: {
        contextMenu,
        Filter,
        [ModalEnum.spot_trade_warehouse_detail]: defineAsyncComponent(() => import('../../components/detail/index.vue')),
        [ModalEnum.spot_trade_warehouse_post_buying]: defineAsyncComponent(() => import('../../components/post_buying/index.vue')),
        buyAndSell: defineAsyncComponent(() => import('../../components/buy-sell-market/index.vue')),
        postBuying: defineAsyncComponent(() => import('../../components/post_buying/index.vue')),
    },
    setup() {
        const isBottom = getShowBottomValue();
        // 表格列表数据
        const { loading, tableList, queryTable } = queryTableList<WrOrderQuote>();
        // 获取列表数据
        const queryTableAction = () => {
            const param: QueryOrderQuoteReq = {
                wrpricetype: 1,
                haswr: 1,
            };
            queryTable(queryOrderQuote, param);
        };
        Bus.$on('spotTrade', queryTableAction);
        // 表格通用逻辑
        const param: ComposeTableParam = {
            queryFn: queryTableAction,
            menuType: EnumRouterName.warehouse_receipt_trade_price,
            tableName: 'table_pcweb_spot_trade_warehouse_price',
            tableFilterKey: [],
            isDetail: false,
        };
        const {
            contextMenu,
            openContext,
            closeContext, // 右键
            columns,
            registerColumn,
            updateColumn, // 表头
            expandedRowKeys,
            selectedRow,
            Rowclick, // 表格折腾面板数据与单击、双击事件
            componentId,
            closeComponent, // 控制异步组件
            firstBtn, // 表格按钮
        } = handleComposeTable<WrOrderQuote>(param);
        function search(value: Object) {
            const param: QueryOrderQuoteReq = {
                wrpricetype: 1,
                haswr: 1,
            };
            Object.assign(param, value);
            queryTable(queryOrderQuote, param);
        }
        function buyOpen(value: any, goods: any) {
            componentId.value = 'postBuying';
            selectedRow.value = value;
        }

        return {
            isBottom,
            contextMenu,
            openContext,
            closeContext, // 右键
            columns,
            registerColumn,
            updateColumn, // 表头
            expandedRowKeys,
            selectedRow,
            Rowclick, // 表格折腾面板数据与单击、双击事件
            componentId,
            closeComponent, // 控制异步组件
            firstBtn, // 表格按钮
            name: EnumRouterName.warehouse_receipt_trade_price,
            loading,
            tableList,
            search,
            buyOpen,
        };
    },
});
</script>
<style lang="less">
</style>