<template>
  <!-- 期货订单-持仓 -->
  <mtp-table-scroll>
    <template #default="{ scroll }">
      <a-table :columns="getColumns()" class="srcollYTable" :scroll="scroll" :pagination="false" :loading="loading"
        :expandedRowKeys="expandedRowKeys" :customRow="Rowclick" :expandIcon="expandIcon" :expandIconAsCell="false"
        :rowKey="(record, index) => index" :data-source="tradePositionList">
        <!-- 额外的展开行 -->
        <template v-if="auth.length" #expandedRowRender="{ record }">
          <BtnList class="btn-list-sticky" :btnList="auth" :record="record" @click="openComponent" />
        </template>
      </a-table>
    </template>
  </mtp-table-scroll>
  <component :is="componentId" v-if="componentId" :selectedRow="selectedRow" @cancel="closeComponent"></component>
</template>

<script lang="ts">
import MtpTableScroll from '@/common/components/tableScroll/index.vue';
import { defineComponent, defineAsyncComponent, PropType } from 'vue';
import { BtnList } from '@/common/export/commonTable';
import { handleComposeOrderTable } from '@/common/setup/table/compose';
import { ComposeOrderTableParam } from '@/common/setup/table/interface';
import { expandIcon } from '@/common/setup/table/clolumn';
import { getColumns } from './columns';
import { useTradeAccount } from '@/hooks/account'
import { DynamicComponent } from '@/@next/hooks/common/interface'

export default defineComponent({
  props: {
    parentComponent: {
      type: Object as PropType<DynamicComponent>,
      required: true
    }
  },
  components: {
    MtpTableScroll,
    BtnList,
    close: defineAsyncComponent(() => import('@/views/market/futures/compoments/futures-trade/index.vue')),
  },
  setup(props) {
    const { auth } = props.parentComponent;
    const { loading, tradePositionList } = useTradeAccount();

    // 表格通用逻辑
    const param: ComposeOrderTableParam = {
      queryFn: () => { },
    };

    return {
      ...handleComposeOrderTable(param),
      getColumns,
      loading,
      expandIcon,
      tradePositionList,
      auth,
    };
  },
});
</script>
