<template>
    <!-- 套期交易-现货成交明细 -->
    <mtp-table-scroll>
        <template #default="{ scroll }">
            <a-table :columns="columns" class="srcollYTable" :pagination="false" :rowKey="(record, index) => index"
                :data-source="tableList" :scroll="scroll">
                <!-- 合同类型 -->
                <template #spottype="{ text }">
                    <span>{{ getSpotTypeName(text) }}</span>
                </template>
            </a-table>
        </template>
    </mtp-table-scroll>
</template>

<script lang="ts">
import { PropType, watch } from 'vue'
import { queryTableList, defineComponent, handleComposeTable } from '@/common/export/commonTable';
import { Ermcp2HedgedItemRsp, ERMCP2HedgedItemSpotDetailRsp } from '@/services/go/ermcp/hedgedItem/interface'
import { queryERMCP2HedgedItemSpotDetail } from '@/services/go/ermcp/hedgedItem'
import { getSpotTypeName } from '@/@next/constants/enum/spotType'
import MtpTableScroll from '@/common/components/tableScroll/index.vue';

export default defineComponent({
    components: {
        MtpTableScroll,
    },
    props: {
        name: String,
        selectedRow: {
            type: Object as PropType<Ermcp2HedgedItemRsp>,
            default: () => ({}),
        },
    },
    setup(props) {
        const { loading, tableList, queryTable } = queryTableList<ERMCP2HedgedItemSpotDetailRsp>(true, 2); // 表格列表数据

        const queryFn = () => {
            const { hedgeditemid } = props.selectedRow;
            if (hedgeditemid) {
                queryTable(queryERMCP2HedgedItemSpotDetail, { hedgeditemid });
            }
        }

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

        watch(() => props.selectedRow, () => queryFn());

        return {
            ...composeTable,
            loading,
            tableList,
            getSpotTypeName,
        }
    }
})
</script>