<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="filterBtnList(btnList, record)" :record="record" class="btn-list-sticky" @click="openComponent" />
      </template>
      <!-- 类型 -->
      <template #buildtype="{ record }">
        <a>{{ getBuyOrSellTypeName(record.buyorsell) }}</a>
      </template>
      <!-- 状态 -->
      <template #orderstatus="{ record }">
        <a>{{ getOrderStatusName(record.orderstatus) }}</a>
      </template>

      <template #ordertime="{ text }">
        <a>{{ formatTime(text) }}</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 { queryTableList, BtnList, defineAsyncComponent, defineComponent } from '@/common/export/commonTable';
import { QueryPerformancePlan, queryWrTradeDetail } from '@/services/go/wrtrade';
import { QueryPerformancePlanReq, WrPerformancePlan } 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 { queryAmountLog } from '@/services/go/TaAccount';
import { QueryAmountLogReq } from '@/services/go/TaAccount/interface';
import { getSelectedAccountId } from '@/services/bus/account';
import { getBuyOrSellTypeName, getOperateTypeEnumItemName, getOperateTypeName, getOrderStatusName } from '@/common/constants/enumsName';
import { formatTime } from '@/common/methods';
import Bus from '@/utils/eventBus/index';
import { expandIcon } from '@/common/setup/table/clolumn';
import { queryTradeOrderDetail } from '@/services/go/ermcp/order';
import { QueryTradeOrderDetailRsp } from '@/services/go/ermcp/order/interface';
import { BtnListType } from '@/common/components/btnList/interface';

export default defineComponent({
  name: enumOrderComponents.commodity_contract_commission,
  components: {
    BtnList,
    commodity_contract_commission_cancel_order: defineAsyncComponent(() => import('./components/cancel/index.vue')),
  },
  setup() {
    // 表格列表数据
    const { loading, tableList, queryTable } = queryTableList<QueryTradeOrderDetailRsp>();
    // 获取列表数据
    const queryTableAction = () => {
      queryTable(queryTradeOrderDetail, {});
    };
    // 表格通用逻辑
    const param: ComposeOrderTableParam = {
      queryFn: queryTableAction,
      tableName: 'table_pcweb_spot_trade_bottom_commodity_contract_commission',
      recordList: getRecordItemTab(),
    };
    function filterBtnList(list: BtnListType[], record: QueryTradeOrderDetailRsp) {
      //委托状态 - 1:委托请求 2:待冻结 3:委托成功 4:委托失败 5:配对成功 6:已撤 7:已成 8:成交失败 9:委托拒绝 1number;
      const arr = [3, 7];
      if (!arr.includes(record.orderstatus)) {
        return list.filter((e) => e.code !== 'commodity_contract_commission_cancel_order');
      } else {
        return list;
      }
    }
    return {
      ...handleComposeOrderTable<WrPerformancePlan>(param),
      loading,
      tableList,
      formatTime,
      expandIcon,
      getBuyOrSellTypeName,
      getOrderStatusName,
      filterBtnList,
    };
  },
});
</script>