<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 #ordertype="{ text }">
                    <span>{{ getOrderTypeName(text) }}</span>
                </template>
                <!-- 方向 -->
                <template #buyorsell="{ text }">
                    <span>{{ getBuyOrSellName(text) }}</span>
                </template>
            </a-table>
        </template>
    </mtp-table-scroll>
</template>

<script lang="ts">
import { PropType, watch } from 'vue'
import { getOrderTypeName } from '@/@next/constants/enum/orderType'
import { getBuyOrSellName } from '@/common/constants/enumsName'
import { queryTableList, defineComponent, handleComposeTable } from '@/common/export/commonTable';
import { Ermcp2AreaExposureRsp, PatradeLinkDetailReq, PatradeLinkDetailRsp } from '@/services/go/ermcp/hedgedItem/interface'
import { queryPatradeLinkDetail } from '@/services/go/ermcp/hedgedItem'
import { getUserId } from '@/services/bus/user'
import MtpTableScroll from '@/common/components/tableScroll/index.vue'

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

        const queryFn = () => {
            const { middlegoodsid } = props.selectedRow;
            if (middlegoodsid) {
                const param: PatradeLinkDetailReq = {
                    userid: getUserId(),
                    middlegoodsid
                }
                queryTable(queryPatradeLinkDetail, param);
            }
        }

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

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

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