gaoluyang
2026-06-29 27cd042df9aca0383a49f3514bc21958dd890912
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<script lang="ts" setup>
import type { WmsItemCategoryApi } from '#/api/wms/md/item/category';
 
import { computed, onMounted, ref } from 'vue';
 
import { handleTree } from '../../../../../../packages/utils/src';
 
import { TreeSelect } from 'ant-design-vue';
 
import { getItemCategorySimpleList } from '#/api/wms/md/item/category';
 
/** WMS 商品分类选择器 */
defineOptions({ name: 'WmsItemCategorySelect', inheritAttrs: false });
 
const props = withDefaults(
  defineProps<{
    allowClear?: boolean;
    disabled?: boolean;
    modelValue?: number;
    placeholder?: string;
  }>(),
  {
    allowClear: true,
    disabled: false,
    modelValue: undefined,
    placeholder: '请选择商品分类',
  },
);
 
const emit = defineEmits<{
  'update:modelValue': [value: number | undefined];
}>();
 
const categoryTree = ref<WmsItemCategoryApi.ItemCategory[]>([]);
 
const selectValue = computed({
  get: () => props.modelValue,
  set: (value: number | undefined) => {
    emit('update:modelValue', value);
  },
});
 
/** 查询商品分类树 */
async function getCategoryTree() {
  const data = await getItemCategorySimpleList();
  categoryTree.value = handleTree(data, 'id', 'parentId');
}
 
onMounted(() => {
  getCategoryTree();
});
</script>
 
<template>
  <TreeSelect
    v-bind="$attrs"
    v-model:value="selectValue"
    :allow-clear="allowClear"
    :disabled="disabled"
    :field-names="{ children: 'children', label: 'name', value: 'id' }"
    :placeholder="placeholder"
    :tree-data="categoryTree"
    class="w-full"
    tree-default-expand-all
    tree-node-filter-prop="name"
    show-search
  />
</template>