<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="key"
             :data-source="tableList">
      <!-- 额外的展开行 -->
      <template #expandedRowRender="{ record }">
        <BtnList :btnList="filterBtnList(btnList, record)"
                 :record="record"
                 class="btn-list-sticky"
                 @click="openComponent" />
      </template>
      <!--  委托状态-->
      <template #wrtradeorderstatus="{ record }">
        <a>{{ getWrTradeOrderStatusName(record.wrtradeorderstatus) }}</a>
      </template>
      <!-- 挂牌类型 -->
      <template #wrtradetype="{ record }">
        <a>{{ getWrOrderTypeName(record.buyorsell, record.wrtradetype) }}</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, 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, getWrTradeOrderStatusName } from '@/common/constants/enumsName';
import { BtnListType } from '@/common/components/btnList/interface';
import { expandIcon } from '@/common/setup/table/clolumn';

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

<style lang="less">
</style>;
