<template>
    <!-- 套期交易：未关联采购合同-未关联购销计划 -->
    <mtp-table-scroll>
        <template #header>
            <Filter @search="updateColumn"></Filter>
        </template>
        <template #default="{ scroll }">
            <a-table :columns="columns" class="srcollYTable" :pagination="false" :loading="loading"
                :expandedRowKeys="expandedRowKeys" :customRow="Rowclick" :rowKey="(record, index) => index"
                :data-source="tableList" :scroll="scroll">
                <template #expandedRowRender="{ record }">
                    <mtp-table-button class="btn-list-sticky" :buttons="auth" :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="auth"> </contextMenu>
    <component :is="componentId" v-if="componentId" :selectedRow="selectedRow" @cancel="closeComponent"></component>
</template>

<script lang="ts">
import { queryTableList, contextMenu, defineComponent, MtpTableButton, defineAsyncComponent, handleComposeTable } from '@/common/export/commonTable'
import { UnLinkErmcpHedgePlanReq, UnLinkErmcpHedgePlanRsp } from '@/services/go/ermcp/hedgedItem/interface'
import { queryUnLinkErmcpHedgePlan } from '@/services/go/ermcp/hedgedItem'
import { getPlanStatusName } from '@/views/business/plan/setup'
import { getPlanContractType } from '@/views/business/plan/setup'
import { useMenu } from '@/@next/hooks/common'
import { getAreaUserId } from '@/services/bus/user'
import MtpTableScroll from '@/common/components/tableScroll/index.vue'
import Filter from './components/filter/index.vue';

export default defineComponent({
    components: {
        MtpTableScroll,
        Filter,
        MtpTableButton,
        contextMenu,
        detail: defineAsyncComponent(() => import('@/views/business/plan/components/detail/index.vue')), // 详情
        bind: defineAsyncComponent(() => import('./components/bind/index.vue')), // 关联项目
    },
    setup() {
        const { auth } = useMenu();
        const { loading, tableList, queryTable } = queryTableList<UnLinkErmcpHedgePlanRsp>(true, 2); // 表格列表数据

        const queryFn = () => {
            const param: UnLinkErmcpHedgePlanReq = {
                areauserid: getAreaUserId(),
            }
            queryTable(queryUnLinkErmcpHedgePlan, param);
        }

        // 表格通用逻辑
        const composeTable = handleComposeTable<UnLinkErmcpHedgePlanRsp>({
            queryFn,
            tableName: 'table_pcweb_hedgeditem_spot_plan',
        })

        return {
            ...composeTable,
            loading,
            tableList,
            auth,
            getPlanStatusName,
            getPlanContractType,
        }
    }
})
</script>