<template>
    <view v-if="list.length">
        <slot :list="list"></slot>
    </view>
    <view v-else class="pd2-40-24 d-flex flex-cln j-c a-c f-s-24 c-999">
        <view>该库房暂未设置货位，仅可直接选到库房；</view>
        <view>如由需要，可前往<span class="c-primary">仓储-库房管理</span>里进行设置 </view>
    </view>
</template>
<script setup lang="ts">
import { useClientRequest } from '@/utils/request';
const props = defineProps({
    warehouseId: {
        type: String,
        default: ''
    },
    expandeds: {
        type: Object,
        default: () => ({})
    },
    warehouseName: {
        type: String,
        default: ''
    }
});
const emit = defineEmits(['changeIdNameMap']);
// 获取货位列表
const idNameMap: { [key: string]: { shelvesName: string, warehouseName: string, warehouseId?: string, shelfId?: string } } = {};
const list = ref<any[]>([]);
const queryWarehouseShelves = async () => {
    const params = {
        warehouseId: props.warehouseId
    };
    const res = await useClientRequest.get<any>('/plt-api/app/shelves/page', params);
    if (!res || res.code !== 200) return;
    list.value = res.rows || [];
    // 构建id名称映射
    list.value.forEach((item: any) => {
        idNameMap[props.warehouseId + '-' + item.id] = {
            shelvesName: item.shelvesName,
            warehouseName: props.warehouseName,
            warehouseId: props.warehouseId,
            shelfId: item.id
        };
    });
    emit('changeIdNameMap', idNameMap);
};
// 判断是不是第一次展开
let firstExpand = true;
watch(() => props.expandeds[props.warehouseId], (val) => {
    if (val && firstExpand) {
        queryWarehouseShelves();
        firstExpand = false;
    }
}, { immediate: true });
</script>