<template>
    <!-- 统计报表-套期项目报表 -->
    <mtp-table-scroll>
        <template #header>
            <Filter @update="search" @search="updateColumn"></Filter>
        </template>
        <template #default="{ scroll }">
            <a-table :columns="columns" class="srcollYTable" :pagination="false" :expandedRowKeys="expandedRowKeys"
                :customRow="Rowclick" :rowKey="(record, index) => index" :data-source="tableList" :scroll="scroll">
                <!-- 套期类型 -->
                <template #hedgedtype="{ text }">
                    <span>{{ getHedgedTypeName(text) }}</span>
                </template>
                <!-- 套期状态 -->
                <template #hedgeditemstatus="{ text }">
                    <span>{{ getHedgedItemStatusName(text) }}</span>
                </template>
            </a-table>
        </template>
    </mtp-table-scroll>
</template>

<script lang="ts">
import { ref } from 'vue';
import { queryTableList, defineComponent, handleComposeTable } from '@/common/export/commonTable'
import { Ermcp8HedgeditemReportReq, Ermcp8HedgeditemReportRsp } from '@/services/go/ermcp/report/interface'
import { queryErmcp8HedgeditemReport } from '@/services/go/ermcp/report'
import { getHedgedTypeName } from '@/@next/constants/enum/hedgedType'
import { getHedgedItemStatusName } from '@/@next/constants/enum/hedgedItemStatus'
import { getUserId } from '@/services/bus/user'
import { TypeAndTime } from '@/views/report/interface'
import { handleInitTypeAndTime } from '@/views/report/setup'
import MtpTableScroll from '@/common/components/tableScroll/index.vue'
import Filter from '../../components/filterTable/index.vue';

export default defineComponent({
    components: {
        MtpTableScroll,
        Filter
    },
    setup() {
        const { loading, tableList, queryTable } = queryTableList<Ermcp8HedgeditemReportRsp>(true, 2); // 表格列表数据
        const cycletime = ref('');
        const cycletype = ref(0);
        const chaceSearchValue = ref<TypeAndTime>();

        const search = (value: TypeAndTime) => {
            cycletype.value = value.cycletype;
            cycletime.value = value.cycletime;
            chaceSearchValue.value = value;

            queryTable(queryErmcp8HedgeditemReport, Object.assign(value, { userid: getUserId() }));
        }

        const queryFn = () => {
            const { getInitTime, getInitType } = handleInitTypeAndTime();
            const param: Ermcp8HedgeditemReportReq = {
                userid: getUserId(),
                cycletype: getInitType(),
                cycletime: getInitTime()
            }
            queryTable(queryErmcp8HedgeditemReport, param);
        }

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

        return {
            ...composeTable,
            loading,
            tableList,
            search,
            getHedgedTypeName,
            getHedgedItemStatusName,
        }
    }
})
</script>