<template>
  <!-- 库存查询: 当前库存-->
  <div class="inventory_current"
       :loading="loading">
    <Filter @search="updateColumn">
    </Filter>
    <a-table :columns="columns"
             class="topTable"
             :pagination="false"
             rowKey="key"
             :expandedRowKeys="expandedRowKeys"
             :customRow="Rowclick"
             :data-source="tableList">
    </a-table>
    <!-- 明细 -->
    <Description v-if="visible"
                 @close="closeDrawer"
                 @changeTab="changeTab"
                 :tabList="tabList">
      <a-table :columns="columnsDetail"
               class="topTable"
               :pagination="false"
               rowKey="key"
               :data-source="detailTableList"
               :scroll="{ x: '100%', y: 'calc(100vh - 163px)' }">
        <!-- 类型 -->
        <!-- <template #logtype="{ record }">
          <span>{{ getLogType(record.logtype) }}</span>
        </template> -->
      </a-table>
    </Description>
  </div>
</template>

<script lang="ts">
import { defineComponent, initData, getTableColumns, getTableEvent, getBtnList, contextMenu, BtnList, _getBtnList } from '@/common/export/table';
import Filter from '../../components/filterTable/index.vue';
import Add from '../../components/add/index.vue';

import { getBizTypeName, getContractStatusName, getContractTypeName, getPriceTypeName } from '@/common/constants/enumsName';
import { Ermcp3AreaStock, queryTableList } from './setup';
import Description from '@/common/components/description/index.vue';
import { ComposeTableDetailParam } from '@/common/setup/table/interface';
import { EnumRouterName } from '@/common/constants/enumRouterName';
import { handleComposeTable_detail } from '@/common/setup/table/compose';
import { TabList } from '@/common/components/description/interface';
import { watchEffect } from 'vue';

export default defineComponent({
    name: 'inventory_current',
    components: {
        Filter,
        contextMenu,
        Add,
        BtnList,
    },
    setup() {
        // // 表头数据
        // const { columns, registerColumn, updateColumn } = getTableColumns();
        // // 表格事件
        // const { expandedRowKeys, selectedRow, Rowclick } = getTableEvent<Ermcp3AreaStock>({});
        // // 表格操作按钮列表
        // const [firstBtn, secondBtn] = _getBtnList('inventory_current', false).value;

        // 表格列表数据
        const { loading, tableList, queryTable } = queryTableList();
        const param: ComposeTableDetailParam = {
            queryFn: queryTable, // 查询表格数据
            tableName: 'table_pcweb_current_inventory', // 表头key
            tableFilterKey: ['deliverygoodsid', 'wrstandardid', 'spotgoodsbrandid', 'warehouseinfoid'], // 表格过滤字段
            menuType: EnumRouterName.exposure_realtime, // 当前tab页对应的code
        };

        const {
            visible,
            closeDrawer, // 控制 drawer 组件是否显示
            columns,
            updateColumn, //  表头数据
            columnsDetail,
            registerColumnDetail,
            detailTableList, // 明细表头数据
            expandedRowKeys,
            selectedRow,
            Rowclick, // 表格事件
            tabList,
        } = handleComposeTable_detail<Ermcp3AreaStock>(param);

        // 切换明细
        function changeTab(index: number, current: TabList) {
            const { code, lable } = current;
            let fn = null;
            // if (code === 'exposure_realtime_spot_details') {
            //     // 现货明细信息
            //     // 注册表头
            //     registerColumnDetail('table_pcweb_exposure_detail', []);
            //     fn = QueryActualExposureDetail;

            //     queryResultLoadingAndInfo(fn, loading, { middlegoodsid: selectedRow.value?.MiddleGoodsID }).then((res) => {
            //         detailTableList.value = res;
            //     });
            // } else if (code === 'exposure_realtime_futures_details') {
            //     // 期货明细
            //     // 注册表头
            //     registerColumnDetail('table_pcweb_exposure_futures_detail', []);
            //     fn = QueryAutualExposurePosition;
            //     queryResultLoadingAndInfo(fn, loading, { middleGoodsId: selectedRow.value?.MiddleGoodsID }).then((res) => {
            //         detailTableList.value = res;
            //     });
            // } else {
            //     console.error(`${lable}没有配置对应的code: ${code},`);
            //     return;
            // }
        }
        watchEffect(() => {
            if (visible.value) {
                if (tabList.value.length) {
                    changeTab(0, tabList.value[0]);
                }
            }
        });
        // initData(() => {
        //     // 获取列表数据
        //     queryTable();
        //     // 注册表头信息 过滤
        //     registerColumn('table_pcweb_current_inventory', ['deliverygoodsid', 'wrstandardid', 'spotgoodsbrandid', 'warehouseinfoid']);
        // });
        return {
            loading,
            tableList,
            visible,
            closeDrawer,
            columns,
            updateColumn,
            columnsDetail,
            detailTableList,
            expandedRowKeys,
            selectedRow,
            Rowclick,
            tabList,
            changeTab,
            queryTable,
            getBizTypeName,
            getPriceTypeName,
            getContractStatusName,
            getContractTypeName,
        };
    },
});
</script>

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