|
|
@@ -13,7 +13,7 @@
|
|
|
:data="deviceCategoryTree"
|
|
|
:props="defaultProps"
|
|
|
check-strictly
|
|
|
- :default-expanded-keys="firstLevelKeys"
|
|
|
+ :default-expanded-keys="deviceCategoryExpandedKeys"
|
|
|
placeholder="请选择设备分类"
|
|
|
value-key="id"
|
|
|
filterable
|
|
|
@@ -71,7 +71,7 @@
|
|
|
</template>
|
|
|
<script lang="ts" setup>
|
|
|
import {DICT_TYPE, getIntDictOptions, getStrDictOptions} from '@/utils/dict'
|
|
|
-import { defaultProps, handleTree } from '@/utils/tree'
|
|
|
+import { defaultProps, findPath, handleTree } from '@/utils/tree'
|
|
|
import * as BomApi from '@/api/pms/bom'
|
|
|
import { CommonStatusEnum } from '@/utils/constants'
|
|
|
import { useTreeStore } from '@/store/modules/treeStore';
|
|
|
@@ -111,7 +111,7 @@ const formRules = reactive<FormRules>({
|
|
|
const formRef = ref() // 表单 Ref
|
|
|
const bomTree = ref() // BOM 树形结构
|
|
|
const deviceCategoryTree = ref<Tree[]>([]) // 设备分类树
|
|
|
-const firstLevelKeys = ref([])
|
|
|
+const deviceCategoryExpandedKeys = ref<Array<number | string>>([])
|
|
|
|
|
|
const queryParams = reactive({
|
|
|
pageNo: 1,
|
|
|
@@ -149,6 +149,8 @@ const open = async (type: string, id?: number, parentId?: number, deviceCategory
|
|
|
formLoading.value = true
|
|
|
try {
|
|
|
formData.value = await BomApi.getBom(id)
|
|
|
+ selfDeviceCategoryId.value = formData.value.deviceCategoryId
|
|
|
+ deviceCategoryExpandedKeys.value = getDeviceCategoryExpandedKeys(formData.value.deviceCategoryId)
|
|
|
} finally {
|
|
|
formLoading.value = false
|
|
|
}
|
|
|
@@ -163,6 +165,7 @@ const handleDeviceCategoryTreeNodeClick = async (row: { [key: string]: any }) =>
|
|
|
emit('node-click', row)
|
|
|
// 清空设备分类bom树的选择,重新查询筛选bom树
|
|
|
selfDeviceCategoryId.value = row.id
|
|
|
+ deviceCategoryExpandedKeys.value = getDeviceCategoryExpandedKeys(row.id)
|
|
|
await getTree()
|
|
|
}
|
|
|
|
|
|
@@ -216,6 +219,20 @@ const getDeviceCategoryTree = async () => {
|
|
|
let device: Tree = { id: 0, name: '顶级设备分类', children: [] }
|
|
|
device.children = handleTree(res)
|
|
|
deviceCategoryTree.value.push(device)
|
|
|
+ deviceCategoryExpandedKeys.value = getDeviceCategoryExpandedKeys(selfDeviceCategoryId.value)
|
|
|
+}
|
|
|
+
|
|
|
+const getDeviceCategoryExpandedKeys = (deviceCategoryId?: number | string | null) => {
|
|
|
+ if (deviceCategoryId === undefined || deviceCategoryId === null) {
|
|
|
+ return deviceCategoryTree.value.map((node) => node.id)
|
|
|
+ }
|
|
|
+
|
|
|
+ const path = findPath<Tree>(deviceCategoryTree.value, (node) => node.id === deviceCategoryId)
|
|
|
+ if (Array.isArray(path)) {
|
|
|
+ return path.map((node) => node.id)
|
|
|
+ }
|
|
|
+
|
|
|
+ return deviceCategoryTree.value.map((node) => node.id)
|
|
|
}
|
|
|
|
|
|
/** 获得 Bom 树 */
|
|
|
@@ -226,7 +243,6 @@ const getTree = async () => {
|
|
|
let bom: Tree = { id: 0, name: '顶级Bom', children: [] }
|
|
|
bom.children = handleTree(data)
|
|
|
bomTree.value.push(bom)
|
|
|
- firstLevelKeys.value = bomTree.value.map(node => node.id);
|
|
|
}
|
|
|
|
|
|
/** 初始化 **/
|