<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 v-if="btnList.length" #expandedRowRender="{ record }">
        <BtnList :btnList="btnList" :record="record" class="btn-list-sticky" @click="openComponent" />
      </template>
      <!-- 类型 -->
      <template #buyorsell="{ text }">
        <span>{{ getBuyOrSellTypeName(text) }}</span>
      </template>
      <!-- 状态 -->
      <template #orderstatus="{ record }">
        <a>{{ getOrderStatusName(record.orderstatus) }}</a>
      </template>
      <template #createtime="{ record }">
        <a>{{ formatTime(record.createtime) }}</a>
      </template>
    </a-table>
    <component :is="componentId" v-if="componentId" :selectedRow="selectedRow" @cancel="closeComponent"></component>
  </section>
</template>

<script lang="ts">
import { enumOrderComponents } from '@/common/constants/enumOrderComponents';
import { getBuildTypeName, getBuyOrSellTypeName, getOrderStatusName } from '@/common/constants/enumsName';
import { BtnList, defineComponent, queryTableList } from '@/common/export/commonTable';
import { formatTime } from '@/common/methods';
import { getRecordItemTab } from '@/common/setup/order/orderData';
import { expandIcon } from '@/common/setup/table/clolumn';
import { handleComposeOrderTable } from '@/common/setup/table/compose';
import { ComposeOrderTableParam } from '@/common/setup/table/interface';
import { queryTradeDetail } from '@/services/go/ermcp/order';
import { QueryTradeDetailRsp } from '@/services/go/ermcp/order/interface';

export default defineComponent({
  name: enumOrderComponents.commodity_contract_make_deal,
  components: {
    BtnList,
  },
  setup() {
    // 表格列表数据
    const { loading, tableList, queryTable } = queryTableList<QueryTradeDetailRsp>();
    // 获取列表数据
    const queryTableAction = () => {
      queryTable(queryTradeDetail, {});
    };
    // 表格通用逻辑
    const param: ComposeOrderTableParam = {
      queryFn: queryTableAction,
      tableName: 'table_pcweb_spot_trade_bottom_commodity_contract_make_deal',
      recordList: getRecordItemTab(),
    };
    return {
      ...handleComposeOrderTable<QueryTradeDetailRsp>(param),
      loading,
      tableList,
      formatTime,
      expandIcon,
      getBuildTypeName,
      getOrderStatusName,
      getBuyOrSellTypeName,
    };
  },
});
</script>