<template>
  <!-- 仓单预售 挂单 -->
  <a-table :columns="tableColumns" 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="filterBtnList(btnList, record)" class="btn-list-sticky" :record="record" @click="openComponent" />
    </template>
    <!--  委托状态-->
    <template #wrtradeorderstatus="{ record }">
      <a>{{ getOrderStatusName(record.wrtradeorderstatus) }}</a>
    </template>
    <!-- 挂牌类型 -->
    <template #wrtradetype="{ record }">
      <a>{{ getWrOrderTypeName(record.buyorsell, record.wrtradetype) }}</a>
    </template>
    <!-- 挂牌方式 -->
    <template #wrpricetype="{ record }">
      <span>{{ getWrPriceType(record) }}</span>
    </template>
    <!-- 价格/基差 -->
    <template #futushow="{ record }">
      <span>{{ showPriceOrMove(record) }}</span>
    </template>
  </a-table>
  <component :is="componentId" v-if="componentId" :selectedRow="selectedRow" :isMy="false" @cancel="closeComponent"></component>
</template>

<script lang="ts">
import { enumOrderComponents } from '@/common/constants/enumOrderComponents';
import { queryTableList, BtnList, defineAsyncComponent, defineComponent, ModalEnum } from '@/common/export/commonTable';
import { queryWrOrderDetail } from '@/services/go/wrtrade';
import { QueryWrOrderDetailReq, WrOrderDetail } 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 { getWrOrderTypeName, getOrderStatusName } from '@/common/constants/enumsName';
import { BtnListType } from '@/common/components/btnList/interface';
import { expandIcon } from '@/common/setup/table/clolumn';
import Bus from '@/utils/eventBus';
import { useOrderWarrant } from '@/views/order/setup';

export default defineComponent({
  name: enumOrderComponents.pre_sale_warehouse_receipt_pending_order,
  components: {
    BtnList,
    [ModalEnum.pre_sale_warehouse_receipt_pending_order_cancel_order]: defineAsyncComponent(() => import('./components/cancle/index.vue')),
    detail: defineAsyncComponent(() => import('./components/detail/index.vue')),
    pre_sale_warehouse_receipt_pending_order_bargain_order: defineAsyncComponent(() => import('@/views/order/spot_warran/components/spot_warrant_bargain/components/detail/index.vue')),
  },
  setup() {
    // 表格列表数据
    const { loading, tableList, queryTable } = queryTableList<WrOrderDetail>();
    // 获取列表数据
    const queryTableAction = () => {
      const param: QueryWrOrderDetailReq = {
        haswr: 0,
      };
      queryTable(queryWrOrderDetail, param);
    };
    Bus.$on('blocsTrade', () => {
      queryTableAction();
    });
    const { tableColumns, getWrPriceType, isShowBarginBtn, showPriceOrMove } = useOrderWarrant(0);
    // 表格通用逻辑
    const param: ComposeOrderTableParam = {
      queryFn: queryTableAction,
      recordList: getRecordItemTab(),
    };
    function filterBtnList(list: BtnListType[], record: WrOrderDetail) {
      if (!isShowBarginBtn(record)) {
        list = list.filter((e) => e.code !== 'spot_warrant_pending_order_bargain_order');
      }
      //委托状态 - 1:委托请求 2:待冻结 3:委托成功 4:委托失败 5:配对成功 6:已撤 7:已成 8:成交失败 9:委托拒绝 1number;
      const arr = [3, 7];
      if (!arr.includes(record.wrtradeorderstatus)) {
        return list.filter((e) => e.code !== ModalEnum.pre_sale_warehouse_receipt_pending_order_cancel_order);
      } else {
        return list;
      }
    }
    return {
      ...handleComposeOrderTable<WrOrderDetail>(param),
      filterBtnList,
      loading,
      tableList,
      expandIcon,
      getOrderStatusName,
      getWrOrderTypeName,
      tableColumns,
      getWrPriceType,
      showPriceOrMove,
    };
  },
});
</script>
