index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <hc-sys navBarUi="hc-bg-white">
  3. <template #navBar>
  4. <hc-nav-back-bar ui="hc-bg-white" title="资料填报"/>
  5. </template>
  6. <view class="hc-search-bar">
  7. <uni-search-bar radius="5" bgColor="#f5f5f5" placeholder="搜索" cancelButton="none" @input="searchInput" @confirm="searchConfirm"/>
  8. </view>
  9. <view class="hc-page-body">
  10. <scroll-view scroll-y class="hc-page-menu">
  11. <template v-for="item in menuData">
  12. <view class="hc-page-menu-item"
  13. :class="item.primaryKeyId === menuItem.primaryKeyId ? 'cur': ''"
  14. @click="menuItemClick(item)"
  15. >{{ item.title }}
  16. </view>
  17. </template>
  18. </scroll-view>
  19. <scroll-view scroll-y class="hc-page-data">
  20. <template v-for="(item, index) in pageNode">
  21. <view class="hc-page-data-item"
  22. :class="item.primaryKeyId === pageItem.primaryKeyId ? 'cur': ''"
  23. @click="pageItemClick(item, index)"
  24. >{{ item.title }}
  25. </view>
  26. </template>
  27. </scroll-view>
  28. </view>
  29. </hc-sys>
  30. </template>
  31. <script setup>
  32. import {ref, onMounted} from "vue";
  33. import {useAppStore} from "@/store";
  34. import wbsApi from '~api/data-fill/wbs';
  35. import {getObjValue, getArrValue, deepClone} from "js-fast-way"
  36. import {setStorage, delStorage} from "@/utils/storage";
  37. const store = useAppStore()
  38. //初始变量
  39. const contractInfo = ref(store.contractInfo);
  40. const projectId = ref(store.projectId);
  41. const contractId = ref(store.contractId);
  42. //渲染完成
  43. onMounted(() => {
  44. delStorage('dataFill')
  45. getLoadNode()
  46. })
  47. let menuData = ref([]);
  48. let menuItem = ref({});
  49. //获取数据
  50. const getLoadNode = async () => {
  51. uni.showLoading({title: '获取数据中...', mask: true});
  52. //获取根节点的数据
  53. const {error, code, data} = await wbsApi.queryWbsTreeData({
  54. contractId: contractId.value || '',
  55. contractIdRelation: '',
  56. primaryKeyId: '',
  57. parentId: '',
  58. classifyType: '',
  59. tableOwner: contractInfo.value?.contractType ?? ''
  60. })
  61. //处理根节点的数据
  62. const nodeData = getArrValue(data)
  63. if (!error && code === 200 && nodeData.length > 0) {
  64. const {contractIdRelation, primaryKeyId, id} = getObjValue(nodeData[0])
  65. const {item, list} = await getChildNodeData({
  66. contractIdRelation: contractIdRelation ?? '',
  67. primaryKeyId: id,
  68. parentId: contractIdRelation ? primaryKeyId : id
  69. })
  70. menuItem.value = item
  71. menuData.value = list
  72. await menuItemClick(item)
  73. uni.hideLoading();
  74. } else {
  75. menuItem.value = {}
  76. menuData.value = []
  77. uni.hideLoading();
  78. }
  79. }
  80. //左侧菜单被点击
  81. const pageNodes = ref([])
  82. const pageNode = ref([])
  83. const pageItem = ref({})
  84. const menuItemClick = async (item) => {
  85. pageNodes.value = []
  86. pageNode.value = []
  87. menuItem.value = item
  88. const {contractIdRelation, primaryKeyId, id} = item
  89. const {list} = await getChildNodeData({
  90. contractIdRelation: contractIdRelation ?? '',
  91. primaryKeyId: id,
  92. parentId: contractIdRelation ? primaryKeyId : id
  93. })
  94. pageNodes.value = list
  95. pageNode.value = list
  96. }
  97. //右侧菜单被点击
  98. const pageItemClick = (item, index) => {
  99. setStorage('dataFill', {
  100. title: menuItem.value.title,
  101. node: pageNode.value,
  102. index: index,
  103. })
  104. uni.navigateTo({
  105. url: '/pages/data-fill/treeData'
  106. });
  107. }
  108. //获取子节点的数据
  109. const getChildNodeData = async (obj) => {
  110. const {error, code, data} = await wbsApi.queryWbsTreeData({
  111. ...obj,
  112. contractId: contractId.value || '',
  113. classifyType: contractInfo.value?.contractType ?? '',
  114. tableOwner: contractInfo.value?.contractType ?? ''
  115. })
  116. //处理二级节点的数据
  117. const nodeData = getArrValue(data)
  118. if (!error && code === 200 && nodeData.length > 0) {
  119. return {
  120. item: getObjValue(nodeData[0]),
  121. list: nodeData
  122. }
  123. } else {
  124. return {item: {}, list: []}
  125. }
  126. }
  127. //搜索
  128. const searchInput = (value) => {
  129. querySearch(value)
  130. }
  131. const searchConfirm = ({value}) => {
  132. querySearch(value)
  133. }
  134. const querySearch = (value) => {
  135. const pageNodeRes = deepClone(pageNodes.value)
  136. const results = value ? pageNodeRes.filter(createFilter(value)) : pageNodeRes
  137. pageNode.value = deepClone(results)
  138. }
  139. const createFilter = (value) => {
  140. return (item) => {
  141. return (item.title.toLowerCase().indexOf(value.toLowerCase()) >= 0)
  142. }
  143. }
  144. </script>
  145. <style lang="scss" scoped>
  146. page {
  147. background: #FAFBFE;
  148. }
  149. </style>
  150. <style lang="scss" scoped>
  151. @import "@/style/data-fill/index.scoped.scss";
  152. </style>