<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="auth" :record="record" class="btn-list-sticky" @click="openComponent" />
        </template>
        <!-- 成交金额 -->
        <template #amount="{ record }">
          <a>{{ (record.tradeqty * record.tradeprice).toFixed(2) }}</a>
        </template>
        <!-- 挂牌类型 -->
        <template #wrtradetype="{ record }">
          <a>{{ getWrOrderTypeName(record.buyorsell, record.wrtradetype) }}</a>
        </template>
      </a-table>
    </template>
  </mtp-table-scroll>
  <component :is="componentId" v-if="componentId" :tableName="tableName" :selectedRow="selectedRow"
    @cancel="closeComponent"></component>
</template>

<script lang="ts">
import { PropType } from 'vue';
import { queryTableList, BtnList, defineAsyncComponent, defineComponent } from '@/common/export/commonTable';
import { queryWrTradeDetail } from '@/services/go/wrtrade';
import { QueryWrSpecialMatchOrderReq, WrSpecialMatchOrder } 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 { getWrOrderTypeName } from '@/common/constants/enumsName';
import { TableKey } from '@/common/methods/table/interface';
import MtpTableScroll from '@/common/components/tableScroll/index.vue';
import { DynamicComponent } from '@/@next/hooks/common/interface'

export default defineComponent({
  props: {
    parentComponent: {
      type: Object as PropType<DynamicComponent>,
      required: true
    }
  },
  components: {
    BtnList,
    MtpTableScroll,
    detail: defineAsyncComponent(() => import('./components/detail/index.vue')),
  },
  setup(props) {
    const { auth } = props.parentComponent;
    const tableName: keyof TableKey = 'table_pcweb_spot_trade_bottom_spot_warrant_deal';
    // 表格列表数据
    const { loading, tableList, queryTable } = queryTableList<WrSpecialMatchOrder>();

    // 获取列表数据
    const queryTableAction = () => {
      const param: QueryWrSpecialMatchOrderReq = {
        haswr: 1,
      };
      queryTable(queryWrTradeDetail, param);
    };

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

    //仓单贸易类型 - 1:挂牌 2:摘牌 3:提货卖(文化中国) 4:提货买(文化中国)
    function getType(type: number) {
      let result = '--';
      switch (type) {
        case 1:
          result = '挂牌';
          break;
        case 2:
          result = '摘牌';
          break;
        case 3:
          result = '提货卖';
          break;
        case 4:
          result = '提货买';
          break;
      }
      return result;
    }

    return {
      ...handleComposeOrderTable<WrSpecialMatchOrder>(param),
      loading,
      tableName,
      tableList,
      auth,
      expandIcon,
      getWrOrderTypeName,
    }
  }
})
</script>
