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

<script lang="ts">
import { PropType } from 'vue';
import { queryTableList, BtnList, defineAsyncComponent, defineComponent } from '@/common/export/commonTable';
import { queryWrPosition } from '@/services/go/wrtrade';
import { QueryWrPositionReq, WrPosition } from '@/services/go/wrtrade/interface';
import { handleComposeOrderTable } from '@/common/setup/table/compose';
import { ComposeOrderTableParam } from '@/common/setup/table/interface';
import { expandIcon } from '@/common/setup/table/clolumn';
import { DynamicComponent } from '@/@next/hooks/common/interface'
import MtpTableScroll from '@/common/components/tableScroll/index.vue';

export default defineComponent({
  props: {
    parentComponent: {
      type: Object as PropType<DynamicComponent>,
      required: true
    }
  },
  components: {
    BtnList,
    MtpTableScroll,
    listed: defineAsyncComponent(() => import('./components/listed/index.vue')), // 挂牌
  },
  setup(props) {
    const { buttons } = props.parentComponent;
    // 表格列表数据
    const { loading, tableList, queryTable } = queryTableList<WrPosition>();

    // 获取列表数据
    const queryTableAction = () => {
      const param: QueryWrPositionReq = {
        haswr: 0,
        querytype: 2,
      };
      queryTable(queryWrPosition, param);
    };

    // 表格通用逻辑
    const param: ComposeOrderTableParam = {
      queryFn: queryTableAction,
      tableName: 'table_pcweb_spot_trade_bottom_pre_sale_order_summary',
    };

    return {
      ...handleComposeOrderTable<WrPosition>(param),
      loading,
      tableList,
      buttons,
      expandIcon,
    };
  },
});
</script>