<template>
    <!-- 提货 -->
    <section>
        <a-table
            :columns="columns"
            class="srcollYTable expandLeftTable"
            :scroll="{ x: '100%', y: '190px' }"
            :pagination="false"
            :loading="loading"
            :expandedRowKeys="expandedRowKeys"
            :customRow="Rowclick"
            :expandIcon="expandIcon"
            :expandIconAsCell="false"
            rowKey="key"
            :data-source="tableList"
        >
            <!-- 额外的展开行 -->
            <template #expandedRowRender="{ record }">
                <BtnList
                    :btnList="handleBtnList(btnList, record)"
                    :record="record"
                    class="btn-list-sticky"
                    @click="openComponent"
                />
            </template>

            <!-- applytype 类型-->
            <template #applytype="{ record }">
                <span>{{ getPickUpStatusName(record.applytype) }}</span>
            </template>

            <!-- applystatus 状态 -->
            <template #applystatus="{ record }">
                <span>{{ getPickUpTypeName(record.applystatus) }}</span>
            </template>
        </a-table>
        <component
            :is="componentId"
            v-if="componentId"
            :selectedRow="selectedRow"
            @cancel="closeComponent"
        ></component>
    </section>
</template>

<script lang="ts">
import { enumOrderComponents } from '@/common/constants/enumOrderComponents';
import { queryTableList, BtnList, defineAsyncComponent, defineComponent, ModalEnum } from '@/common/export/commonTable';
import { queryWrOutInApply } from '@/services/go/wrtrade';
import { WrOutInApply } from '@/services/go/wrtrade/interface';
import { getRecordItemTab } from '@/common/setup/order/orderData';
import { handleComposeOrderTable } from '@/common/setup/table/compose';
import { ComposeOrderTableParam } from '@/common/setup/table/interface';
import { expandIcon } from '@/common/setup/table/clolumn';
import { BtnListType } from '@/common/components/btnList/interface';
import { getPickUpStatusName, getPickUpTypeName } from '@/common/constants/enumsName';

export default defineComponent({
    name: enumOrderComponents.spot_warrant_in_and_out_warehouse,
    components: {
        BtnList,
        [ModalEnum.spot_warrant_in_and_out_warehouse_sure_pick_up]: defineAsyncComponent(() => import('./components/pick_up/index.vue')),
        [ModalEnum.spot_warrant_in_and_out_warehouse_revoke]: defineAsyncComponent(() => import('./components/cancel/index.vue')),
    },
    setup() {
        // 表格列表数据
        const { loading, tableList, queryTable } = queryTableList<WrOutInApply>();
        // 获取列表数据
        const queryTableAction = () => {
            queryTable(queryWrOutInApply);
        };
        // 表格通用逻辑
        const param: ComposeOrderTableParam = {
            queryFn: queryTableAction,
            tableName: 'table_pcweb_spot_trade_bottom_spot_warrant_pick_up',
            recordList: getRecordItemTab(),
        };
        function handleBtnList(btnList: BtnListType[], item: WrOutInApply) {
            const { applystatus, applytype } = item;
            if (applystatus === 0 && applytype === 4) {
                return btnList.filter((e) => e.code === ModalEnum.spot_warrant_in_and_out_warehouse_sure_pick_up);
            } else if (applystatus === 1 && applytype === 2) {
                return btnList.filter((e) => e.code === ModalEnum.spot_warrant_in_and_out_warehouse_revoke);
            } else {
                return [];
            }
        }
        return {
            ...handleComposeOrderTable<WrOutInApply>(param),
            loading,
            tableList,
            expandIcon,
            handleBtnList,
            getPickUpStatusName,
            getPickUpTypeName,
        };
    },
});
</script>

<style lang="less">
</style>;
