<template>
    <!-- 套期交易-期货成交关联-内部未关联成交单查询 -->
    <mtp-table-scroll>
        <template #header>
            <Filter @search="updateColumn">
                <mtp-table-button class="btn-list-sticky" :buttons="headerButtons" @click="openComponent" />
            </Filter>
        </template>
        <template #default="{ scroll }">
            <a-table :columns="columns" class="srcollYTable" :pagination="false" :loading="loading"
                :expandedRowKeys="expandedRowKeys" :customRow="Rowclick" :rowKey="(record, index) => index"
                :data-source="tableList" :scroll="scroll">
                <template #expandedRowRender="{ record }">
                    <mtp-table-button class="btn-list-sticky" :buttons="tableButtons" :record="record"
                        @click="openComponent" />
                </template>
                <!-- 套期主体 -->
                <template #accountname="{ record }">
                    <span>{{ record.accountname }}/{{ record.accountid }}</span>
                </template>
                <!-- 买卖方向 -->
                <template #buyorsell="{ text }">
                    <span>{{ getBuyOrSellName(text) }}</span>
                </template>
                <!-- 合约代码 -->
                <template #goodscode="{ record }">
                    <span>{{ record.goodscode }}/{{ record.goodsname }}</span>
                </template>
            </a-table>
        </template>
    </mtp-table-scroll>
    <component :is="componentId" v-if="componentId" v-bind="{ selectedRow }" @cancel="closeComponent"></component>
</template>

<script lang="ts">
import { queryTableList, MtpTableButton, defineComponent, defineAsyncComponent, handleComposeTable } from '@/common/export/commonTable'
import { InternalUncorrelatedTradeDetailReq, InternalUncorrelatedTradeDetailRsp } from '@/services/go/ermcp/hedgedItem/interface'
import { queryInternalUncorrelatedTradeDetail } from '@/services/go/ermcp/hedgedItem'
import { getBuyOrSellName } from '@/common/constants/enumsName'
import { useMenu } from '@/@next/hooks/common'
import { getUserId } from '@/services/bus/user';
import MtpTableScroll from '@/common/components/tableScroll/index.vue'
import Filter from '../components/filter/index.vue'

export default defineComponent({
    components: {
        MtpTableButton,
        MtpTableScroll,
        Filter,
        add: defineAsyncComponent(() => import('./components/add/index.vue')), // 补单关联
        bind: defineAsyncComponent(() => import('./components/bind/index.vue')), // 关联
    },
    setup() {
        const { authFilter } = useMenu();
        const { loading, tableList, queryTable } = queryTableList<InternalUncorrelatedTradeDetailRsp>(true, 2); // 表格列表数据

        const headerButtons = authFilter(['add']);
        const tableButtons = authFilter(['add'], true);

        const queryFn = () => {
            const param: InternalUncorrelatedTradeDetailReq = {
                userid: getUserId()
            }
            queryTable(queryInternalUncorrelatedTradeDetail, param);
        }

        // 表格通用逻辑
        const composeTable = handleComposeTable<InternalUncorrelatedTradeDetailRsp>({
            queryFn,
            tableName: 'table_pcweb_hedgeditem_futures_in',
        })

        return {
            ...composeTable,
            headerButtons,
            tableButtons,
            loading,
            tableList,
            getBuyOrSellName,
        }
    }
})
</script>