<template>
  <!-- 计划: 执行中-->
  <mtp-table-scroll>
    <template #header>
      <Filter @search="updateColumn"></Filter>
    </template>
    <template #default="{ scroll }">
      <a-table :columns="columns" class="srcollYTable" :scroll="scroll" :pagination="false" :loading="loading" :expandedRowKeys="expandedRowKeys" :customRow="Rowclick" :rowKey="(record,index)=>index" :data-source="tableList">
        <!-- 额外的展开行 -->
        <template #expandedRowRender="{ record }">
          <mtp-table-button class="btn-list-sticky" :buttons="buttons" :record="record" @click="openComponent" />
        </template>
        <template #contracttype="{ text }">
          <a>{{ getPlanContractType(text) }}</a>
        </template>
        <template #hedgeplanstatus="{ text }">
          <a>{{ getPlanStatusName(text) }}</a>
        </template>
      </a-table>
    </template>
  </mtp-table-scroll>
  <!-- 右键 -->
  <contextMenu :contextMenu="contextMenu" @cancel="closeContext" :list="buttons"> </contextMenu>
  <component :is="componentId" v-if="componentId" :selectedRow="selectedRow" @cancel="closeComponent"> </component>
</template>

<script lang="ts">
import MtpTableScroll from '@/common/components/tableScroll/index.vue';
import { queryTableList, MtpTableButton, contextMenu, defineAsyncComponent, defineComponent, handleComposeTable, ComposeTableParam } from '@/common/export/commonTable';
import { Filter } from '../../components';
import { getPlanContractType, getPlanStatusName } from '@/views/business/plan/setup';
import { Ermcp3HedgePlan } from '@/services/go/ermcp/plan/interface';
import { QueryHedgePlan } from '@/services/go/ermcp/plan';
import { EnumRouterName } from '@/common/constants/enumRouterName';
import { getTableButton } from '@/common/setup/table/button';

export default defineComponent({
  name: EnumRouterName.plan_running,
  components: {
    MtpTableScroll,
    contextMenu,
    MtpTableButton,
    Filter,
    trade: defineAsyncComponent(() => import('@/views/market/futures/compoments/futures-trade/index.vue')), // 套保交易
    detail: defineAsyncComponent(() => import('../../components/detail/index.vue')),
  },
  setup() {
    // 权限按钮
    const buttons = getTableButton();
    // 表格列表数据
    const { loading, tableList, queryTable } = queryTableList<Ermcp3HedgePlan>();

    // 获取列表数据
    const queryTableAction = () => queryTable(QueryHedgePlan, '2');

    // 表格通用逻辑
    const param: ComposeTableParam = {
      queryFn: queryTableAction,
      tableName: 'table_pcweb_hedging_plan',
    };

    return {
      ...handleComposeTable<Ermcp3HedgePlan>(param),
      loading,
      tableList,
      getPlanStatusName,
      getPlanContractType,
      queryTable,
      buttons,
    };
  },
});
</script>