<template>
    <!-- 套期交易-已完成 -->
    <mtp-table-scroll>
        <template #header>
            <Filter @search="updateColumn" />
        </template>
        <template #default="{ scroll }">
            <a-table :columns="columns" class="srcollYTable" :pagination="false" :loading="loading"
                :rowClassName="rowClassName" :expandedRowKeys="expandedRowKeys" :customRow="Rowclick"
                :rowKey="(record, index) => index" :data-source="tableList" :scroll="scroll">
                <!-- 套期类型 -->
                <template #hedgedtype="{ text }">
                    <span>{{ getHedgedTypeName(text) }}</span>
                </template>
                <!-- 套期状态 -->
                <template #hedgeditemstatus="{ text }">
                    <span>{{ getHedgedItemStatusName(text) }}</span>
                </template>
            </a-table>
        </template>
    </mtp-table-scroll>
    <mtp-tab-component class="table-detail" :options="{ selectedRow }" />
</template>

<script lang="ts">
import { queryTableList, MtpTableButton, defineComponent, handleComposeTable } from '@/common/export/commonTable'
import { HedgedItemStatus } from '@/@next/constants/enum/hedgedItemStatus'
import { getHedgedTypeName } from '@/@next/constants/enum/hedgedType'
import { getHedgedItemStatusName } from '@/@next/constants/enum/hedgedItemStatus'
import { Ermcp2HedgedItemReq, Ermcp2HedgedItemRsp } from '@/services/go/ermcp/hedgedItem/interface'
import { queryErmcp2HedgedItem } from '@/services/go/ermcp/hedgedItem'
import { getUserId } from '@/services/bus/user'
import MtpTableScroll from '@/common/components/tableScroll/index.vue'
import MtpTabComponent from '@/@next/components/base/tab-component/index.vue'
import Filter from '../components/filter/index.vue'

export default defineComponent({
    components: {
        MtpTabComponent,
        MtpTableButton,
        MtpTableScroll,
        Filter
    },
    setup() {
        const { loading, tableList, queryTable } = queryTableList<Ermcp2HedgedItemRsp>(true, 2); // 表格列表数据

        const queryFn = () => {
            const param: Ermcp2HedgedItemReq = {
                userid: getUserId(),
                hedgeditemstatus: HedgedItemStatus.Finish,
            }
            queryTable(queryErmcp2HedgedItem, param).then((res) => {
                if (res.length) {
                    composeTable.selectedRow.value = res[0];
                }
            })
        }

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

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