gaoluyang
2 天以前 b64a0deae5b5d33f9e20671a68936b27f0b9b00b
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<script lang="ts" setup>
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesDvMachineryTypeApi } from '#/api/mes/dv/machinery/type';
 
import { ref } from 'vue';
 
import { CommonStatusEnum } from '@vben/constants';
import { handleTree } from '@vben/utils';
 
import { Card, Input } from 'ant-design-vue';
 
import { useVbenVxeGrid } from '#/adapter/vxe-table';
import { getMachineryTypeList } from '#/api/mes/dv/machinery/type';
 
const emit = defineEmits<{
  nodeClick: [row?: MesDvMachineryTypeApi.MachineryType];
}>();
const selectedId = ref<number>(); // 选中设备类型编号
const searchKeyword = ref(''); // 设备类型搜索关键字
 
const [Grid, gridApi] = useVbenVxeGrid({
  gridOptions: {
    autoResize: true,
    border: false,
    columns: [{ field: 'name', title: '类型名称', treeNode: true }],
    height: 'auto',
    pagerConfig: {
      enabled: false,
    },
    proxyConfig: {
      ajax: {
        query: async () =>
          handleTree(
            await getMachineryTypeList({
              name: searchKeyword.value || undefined,
              status: CommonStatusEnum.ENABLE,
            }),
          ),
      },
    },
    rowConfig: {
      isCurrent: true,
      isHover: true,
      keyField: 'id',
    },
    showHeader: false,
    toolbarConfig: {
      enabled: false,
    },
    treeConfig: { parentField: 'parentId', rowField: 'id', transform: true },
  } as VxeTableGridOptions<MesDvMachineryTypeApi.MachineryType>,
  gridEvents: {
    cellClick: ({ row }: { row: MesDvMachineryTypeApi.MachineryType }) => {
      if (selectedId.value === row.id) {
        selectedId.value = undefined;
        gridApi.grid.clearCurrentRow();
        emit('nodeClick', undefined);
        return;
      }
      selectedId.value = row.id;
      emit('nodeClick', row);
    },
  },
});
 
/** 重置选中状态 */
function reset() {
  selectedId.value = undefined;
  searchKeyword.value = '';
  gridApi.grid.clearCurrentRow();
  emit('nodeClick', undefined);
  gridApi.query();
}
 
/** 搜索设备类型 */
function handleSearch() {
  gridApi.query();
}
 
defineExpose({ reset });
</script>
 
<template>
  <Card class="h-full" size="small" title="设备类型">
    <Input
      v-model:value="searchKeyword"
      allow-clear
      class="mb-3"
      placeholder="搜索设备类型"
      @change="handleSearch"
    />
    <Grid class="h-full" />
  </Card>
</template>