treeData.vue 6.4 KB

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