<template>
  <!-- 成交 -->
  <section>
    <a-table :columns="columns" class="srcollYTable expandLeftTable" :scroll="{ x: '100%', y: '190px' }" :pagination="false" :loading="loading" :expandedRowKeys="expandedRowKeys" :customRow="Rowclick" :expandIcon="expandIcon" :expandIconAsCell="false" :rowKey="(record,index)=>index" :data-source="tableList">
      <!-- 额外的展开行 -->
      <template #expandedRowRender="{ record }">
        <BtnList :btnList="btnList" class="btn-list-sticky" :record="record" @click="openComponent" />
      </template>
      <!-- 成交金额 -->
      <template #amount="{ record }">
        <a>{{ record.tradeqty * record.tradeprice }}</a>
      </template>
      <!-- 挂牌类型 -->
      <template #wrtradetype="{ record }">
        <a>{{ getWrOrderTypeName(record.buyorsell, record.wrtradetype) }}</a>
      </template>
    </a-table>
    <component :is="componentId" v-if="componentId" :tableName="tableName" :selectedRow="selectedRow" @cancel="closeComponent"></component>
  </section>
</template>

<script lang="ts">
import { enumOrderComponents } from '@/common/constants/enumOrderComponents';
import { queryTableList, BtnList, defineAsyncComponent, defineComponent } from '@/common/export/commonTable';
import { queryWrTradeDetail } from '@/services/go/wrtrade';
import { QueryWrSpecialMatchOrderReq, WrSpecialMatchOrder } from '@/services/go/wrtrade/interface';
import { getRecordItemTab } from '@/common/setup/order/orderData';
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';

export default defineComponent({
  name: enumOrderComponents.pre_sale_warehouse_receipt_deal,
  components: {
    BtnList,
    pre_sale_warehouse_receipt_deal_detail: defineAsyncComponent(() => import('./components/pre_sale_warehouse_receipt_deal_detail/index.vue')),
  },
  setup() {
    const tableName: keyof TableKey = 'table_pcweb_spot_trade_bottom_pre_sale_make_deal';
    // 表格列表数据
    const { loading, tableList, queryTable } = queryTableList<WrSpecialMatchOrder>();
    // 获取列表数据
    const queryTableAction = () => {
      const param: QueryWrSpecialMatchOrderReq = {
        haswr: 0,
      };
      queryTable(queryWrTradeDetail, param);
    };
    // 表格通用逻辑
    const param: ComposeOrderTableParam = {
      tableName,
      queryFn: queryTableAction,
      recordList: getRecordItemTab(),
    };
    return {
      ...handleComposeOrderTable<WrSpecialMatchOrder>(param),
      loading,
      tableName,
      tableList,
      expandIcon,
      getWrOrderTypeName,
    };
  },
});
</script>