<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="tableList">
        <!-- 额外的展开行 -->
        <template v-if="auth.length" #expandedRowRender="{ record }">
          <BtnList :btnList="handleBtnList(auth, record)" :record="record" class="btn-list-sticky" @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 { defineComponent, PropType } from 'vue';
import MtpTableScroll from '@/common/components/tableScroll/index.vue';
import { queryTableList, BtnList } from '@/common/export/commonTable';
import { handleComposeOrderTable } from '@/common/setup/table/compose';
import { ComposeOrderTableParam } from '@/common/setup/table/interface';
import { BtnListType } from '@/common/components/btnList/interface';
import { expandIcon } from '@/common/setup/table/clolumn';
import { queryErmcpOrderDetails } from '@/services/go/ermcp/futures';
import { QueryErmcpOrderDetailsRsp } from '@/services/go/ermcp/futures/interface';
import { getColumns } from './columns';
import { cancel } from './setup';
import { DynamicComponent } from '@/@next/hooks/common/interface'

export default defineComponent({
  props: {
    parentComponent: {
      type: Object as PropType<DynamicComponent>,
      required: true
    }
  },
  components: {
    MtpTableScroll,
    BtnList,
    cancel,
  },
  setup(props) {
    const { auth } = props.parentComponent;
    // 表格列表数据
    const { loading, tableList, queryTable } = queryTableList<QueryErmcpOrderDetailsRsp>();

    // 处理根据状态显示对应按钮
    const handleBtnList = (btnList: BtnListType[], item: QueryErmcpOrderDetailsRsp) => {
      if ([1, 4, 5].includes(item.channelinnerorderstatus)) {
        return btnList;
      }
      return btnList.filter((e) => e.code !== 'cancel');
    };

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

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