<template>
  <!-- 计划: 未提交-->
  <div class="plan-uncommitted"
       :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="handleBtnList(secondBtn, record)"
                 :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 { BtnListType } from '@/common/components/btnList/interface';
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'));
const Add = defineAsyncComponent(() => import('../../components/add/index.vue'));
const Delete = defineAsyncComponent(() => import('../../components/delete/index.vue'));
const Modfiy = defineAsyncComponent(() => import('../../components/modify/index.vue'));

export default defineComponent({
    name: EnumRouterName.plan_uncommitted,
    components: {
        contextMenu,
        BtnList,
        Filter,
        [ModalEnum.detail]: Detail,
        [ModalEnum.plan_btn_add]: Add,
        [ModalEnum.plan_uncommitted_delete]: Delete,
        [ModalEnum.plan_uncommitted_modify]: Modfiy,
    },
    setup() {
        // 表格列表数据
        const { loading, tableList, queryTable } = queryTableList<Ermcp3HedgePlan>();
        // 获取列表数据
        const queryTableAction = () => queryTable(QueryHedgePlan, '0,4,6');
        // 表格通用逻辑
        const param: ComposeTableParam = {
            queryFn: queryTableAction,
            menuType: EnumRouterName.plan_uncommitted,
            tableName: 'table_pcweb_hedging_plan',
            tableFilterKey: ['contracttype', 'hedgeplanno', 'deliverygoodsname'],
            isDetail: true,
        };

        function handleBtnList(btnList: BtnListType[], item: Ermcp3HedgePlan) {
            if (item.hedgeplanstatus === 4) {
                // 审核拒绝
                return btnList.filter((e) => e.lable !== '修改');
            } else {
                return btnList.filter((e) => e.lable !== '重新提交');
            }
        }

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

<style lang="less">
.plan-uncommitted {
}
</style>;
