<template>
  <!-- 计划: 执行中-->
  <div class="plan_running"
       :loading="loading">
    <Filter @search="updateColumn">
      <BtnList :btnList="firstBtn"
               @click="openComponent" />
    </Filter>
    <a-table :columns="columns"
             class="srcollYTable"
             :scroll="{ x: '100%', y: 'calc(100vh - 163px)' }"
             :pagination="false"
             :loading="loading"
             :expandedRowKeys="expandedRowKeys"
             :customRow="Rowclick"
             rowKey="key"
             :data-source="tableList">
      <!-- 额外的展开行 -->
      <template #expandedRowRender="{ record }">
        <BtnList :btnList="secondBtn"
                 :record="record"
                 class="btn-list-sticky"
                 @click="openComponent" />
      </template>
      <template #contracttype="{ text }">
        <a>{{ getPlanContractType(text) }}</a>
      </template>
      <template #hedgeplanstatus="{ text }">
        <a>{{ getPlanStatusName(text) }}</a>
      </template>
    </a-table>
    <!-- 右键 -->
    <contextMenu :contextMenu="contextMenu"
                 @cancel="closeContext"
                 :list="secondBtn">
    </contextMenu>
    <component :is="componentId"
               v-if="componentId"
               :selectedRow="selectedRow"
               @cancel="closeComponent">
    </component>
  </div>
</template>

<script lang="ts">
import { queryTableList, BtnList, contextMenu, defineAsyncComponent, defineComponent, ModalEnum, 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';

const Detail = defineAsyncComponent(() => import('../../components/detail/index.vue'));

export default defineComponent({
    name: EnumRouterName.plan_running,
    components: {
        contextMenu,
        BtnList,
        Filter,
        [ModalEnum.detail]: Detail,
    },
    setup() {
        // 表格列表数据
        const { loading, tableList, queryTable } = queryTableList<Ermcp3HedgePlan>();
        // 获取列表数据
        const queryTableAction = () => queryTable(QueryHedgePlan, '2');
        // 表格通用逻辑
        const param: ComposeTableParam = {
            queryFn: queryTableAction,
            menuType: EnumRouterName.plan_running,
            tableName: 'table_pcweb_hedging_plan',
            tableFilterKey: ['contracttype', 'hedgeplanno', 'deliverygoodsname'],
            isDetail: true,
        };
        return {
            ...handleComposeTable<Ermcp3HedgePlan>(param),
            loading,
            tableList,
            getPlanStatusName,
            getPlanContractType,
            queryTable,
        };
    },
});
</script>

<style lang="less">
.plan_running {
}
</style>;
