<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" :record="record" class="btn-list-sticky" @click="openComponent" />
      </template>
      <!-- 挂牌有效期 -->
      <template #validtime="{ text }">
        <span>{{ formatTime(text, 'd') }}</span>
      </template>
      <!-- 挂牌类型 -->
      <template #buyorsell="{ text }">
        <span>{{ text ? '买' : '卖' }}</span>
      </template>
      <!--  委托状态-->
      <!-- <template #wrtradeorderstatus="{ record }">
        <a>{{ getWrTradeOrderStatusName(record.wrtradeorderstatus) }}</a>
      </template> -->
      <!-- 挂牌类型 -->
      <template #wrtradetype="{ record }">
        <a>{{ getWrOrderTypeName(record.buyorsell, record.wrtradetype) }}</a>
      </template>
      <template #applystatus="{ text }">
        <span>{{ getBarmaginApplyStatus(text) }}</span>
      </template>
      <template #applytime="{ text }">
        <span>{{ formatTime(text) }}</span>
      </template>
      <template #marginvalue="{ text }">
        <span>{{ (text * 100).toFixed(2) }}%</span>
      </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, ModalEnum } from '@/common/export/commonTable';
import { queryQueryWrTradeBargainApply, queryWrOrderDetail } from '@/services/go/wrtrade';
import { QueryWrOrderDetailReq, QueryWrTradeBargainApplyQsp, QueryWrTradeBargainApplyReq, 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, getWrTradeOrderStatusName, getBarmaginApplyStatus } from '@/common/constants/enumsName';
import { BtnListType } from '@/common/components/btnList/interface';
import { expandIcon } from '@/common/setup/table/clolumn';
import { getSpotWarrantBargainColumns } from './setup';
import { formatTime } from '@/common/methods';
import { getUserId } from '@/services/bus/user';
import Bus from '@/utils/eventBus';

export default defineComponent({
  name: enumOrderComponents.pre_sale_warehouse_receipt_bargain,
  components: {
    BtnList,
    pre_sale_warehouse_receipt_bargain_detail: defineAsyncComponent(() => import('./components/bargain_detail/index.vue')),
  },
  setup() {
    // 表格列表数据
    const { loading, tableList, queryTable } = queryTableList<QueryWrTradeBargainApplyQsp>();
    // 获取列表数据
    const queryTableAction = () => {
      const param: QueryWrTradeBargainApplyReq = {
        userid: getUserId(),
        haswr: 0,
      };
      queryTable(queryQueryWrTradeBargainApply, param);
    };
    Bus.$on('blocsTrade', () => {
      queryTableAction();
    });
    // 表格通用逻辑
    const param: ComposeOrderTableParam = {
      queryFn: queryTableAction,
      recordList: getRecordItemTab(),
    };
    const {
      contextMenu,
      openContext,
      closeContext, // 右键
      expandedRowKeys,
      selectedRow,
      Rowclick, // 表格折腾面板数据与单击、双击事件
      componentId,
      closeComponent,
      openComponent, // 控制异步组件
      btnList, // 表格按钮
    } = handleComposeOrderTable<QueryWrTradeBargainApplyQsp>(param);

    return {
      contextMenu,
      openContext,
      closeContext, // 右键
      expandedRowKeys,
      selectedRow,
      Rowclick, // 表格折腾面板数据与单击、双击事件
      componentId,
      closeComponent,
      openComponent, // 控制异步组件
      btnList, // 表格按钮
      columns: getSpotWarrantBargainColumns(),
      loading,
      tableList,
      getWrTradeOrderStatusName,
      getWrOrderTypeName,
      expandIcon,
      formatTime,
      getBarmaginApplyStatus,
    };
  },
});
</script>