treeData.vue 6.0 KB

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