treeData.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <hc-sys navBarUi="hc-bg-white">
  3. <template #navBar>
  4. <hc-nav-back-bar ui="hc-bg-white" :title="fillInfo.title"/>
  5. </template>
  6. <view class="hc-search-bar">
  7. <uni-search-bar radius="5" bgColor="#f5f5f5" placeholder="搜索" cancelButton="none" @confirm="searchConfirm"/>
  8. </view>
  9. <view class="hc-page-body">
  10. <scroll-view scroll-y class="scroll-h-auto">
  11. <template v-for="(item, index) in nodeData">
  12. <view class="fold-tree-node" :class="primaryId === item.primaryKeyId?'current':''">
  13. <view class="flex flex-items-center node-title"
  14. :class="item.notExsitChild?'blue':''"
  15. @click="getLoadItemNode(item, index)">
  16. <view class="flex flex-items-center icon">
  17. <template v-if="!item.notExsitChild">
  18. <text class="i-ri-arrow-up-s-fill" v-if="primaryId === item.primaryKeyId"/>
  19. <text class="i-ri-arrow-down-s-fill" v-else/>
  20. </template>
  21. </view>
  22. <view class="content">{{item.title}}</view>
  23. </view>
  24. <view class="node-child" v-if="primaryId === item.primaryKeyId">
  25. <template v-for="(items, indexs) in item.childData">
  26. <view class="flex flex-items-center node-title"
  27. :class="items.notExsitChild?'blue':''"
  28. @click="getLoadItemNode(items, indexs, index)"
  29. >
  30. <view class="flex flex-items-center icon">
  31. <text class="i-ri-arrow-down-s-fill" v-if="!items.notExsitChild"/>
  32. </view>
  33. <view class="content">{{items.title}}</view>
  34. </view>
  35. </template>
  36. </view>
  37. </view>
  38. </template>
  39. </scroll-view>
  40. </view>
  41. </hc-sys>
  42. </template>
  43. <script setup>
  44. import {ref, onMounted} from "vue";
  45. import {useAppStore} from "@/store";
  46. import wbsApi from '~api/data-fill/wbs';
  47. import {getStorage} from "@/utils/storage";
  48. import {deepClone, getArrValue, getObjVal} from "js-fast-way"
  49. const store = useAppStore()
  50. //初始变量
  51. const contractInfo = ref(store.contractInfo);
  52. const projectId = ref(store.projectId);
  53. const contractId = ref(store.contractId);
  54. const fillInfo = getStorage('dataFill')
  55. //渲染完成
  56. onMounted(() => {
  57. setTreeNodeData()
  58. })
  59. //数据变量
  60. const nodeData = ref([]); // 当前展示节点
  61. const primaryId = ref(''); // 当前节点索引
  62. const parentData = ref([]); // 父级节点数据
  63. const parentIndex = ref(-1); // 父级节点索引
  64. //处理数据
  65. const setTreeNodeData = async () => {
  66. uni.showLoading({title: '获取数据中...', mask: true});
  67. const node = getArrValue(fillInfo.node)
  68. const index = fillInfo?.index ?? -1
  69. if (node.length > 0) {
  70. for (let i = 0; i < node.length; i++) {
  71. node[i].level = 1
  72. }
  73. }
  74. nodeData.value = node
  75. await getLoadItemNode(nodeData.value[index], index)
  76. uni.hideLoading();
  77. }
  78. //获取数据
  79. const getLoadItemNode = async (item, index, pindex = -1) => {
  80. if (!getObjVal(item)) {
  81. return false
  82. }
  83. //处理数据
  84. const {contractIdRelation, primaryKeyId, id} = item
  85. if (primaryId.value === item.primaryKeyId) {
  86. //返回上级
  87. if (item.level > 1) {
  88. const parent_index = parentIndex.value
  89. const parent_data = getArrValue(parentData.value)
  90. const info = parent_data[parent_index]
  91. primaryId.value = info?.primaryKeyId ?? ''
  92. if (info.childData <= 0) {
  93. const res = await queryWbsTreeData({
  94. primaryKeyId: id,
  95. contractIdRelation: contractIdRelation ?? '',
  96. parentId: contractIdRelation ? primaryKeyId : id,
  97. })
  98. //增加层级
  99. for (let i = 0; i < res.length; i++) {
  100. res[i].level = item.level - 1
  101. }
  102. info.childData = res
  103. }
  104. nodeData.value = deepClone(parent_data)
  105. } else {
  106. uni.navigateBack()
  107. }
  108. } else if (!item.notExsitChild) {
  109. //获取子级
  110. primaryId.value = primaryKeyId ?? ''
  111. const res = await queryWbsTreeData({
  112. primaryKeyId: id,
  113. contractIdRelation: contractIdRelation ?? '',
  114. parentId: contractIdRelation ? primaryKeyId : id,
  115. })
  116. //增加层级
  117. for (let i = 0; i < res.length; i++) {
  118. res[i].level = item.level + 1
  119. }
  120. item.childData = res
  121. //获取相关数据
  122. if (pindex > -1) {
  123. parentIndex.value = pindex
  124. parentData.value = deepClone(nodeData.value)
  125. nodeData.value = deepClone(nodeData.value[pindex].childData)
  126. }
  127. } else if (item.notExsitChild) {
  128. //最后一级被点击
  129. uni.navigateTo({
  130. url: '/pages/data-fill/dataTable?node=' + encodeURIComponent(JSON.stringify({
  131. id: item.id,
  132. title: item.title,
  133. primaryKeyId: item.primaryKeyId,
  134. contractIdRelation: item.contractIdRelation,
  135. }))
  136. });
  137. }
  138. }
  139. //获取节点数据
  140. const queryWbsTreeData = async (obj, level) => {
  141. const { data } = await wbsApi.queryWbsTreeData({
  142. ...obj,
  143. contractId: contractId.value || '',
  144. classifyType: contractInfo.value?.contractType ?? '',
  145. tableOwner: contractInfo.value?.contractType ?? ''
  146. })
  147. return getArrValue(data)
  148. }
  149. //搜索
  150. const searchConfirm = ({value}) => {
  151. }
  152. </script>
  153. <style lang="scss" scoped>
  154. @import "@/style/data-fill/index.scoped.scss";
  155. </style>