test-copy.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div>
  3. <el-alert v-if="CopyModalType === '1'" :closable="false" title="复跨节点复制: 把当前表格已形成的数据复制到其他工程部位的相同表格里面" type="warning" />
  4. <el-alert v-else :closable="false" title="本节点复制:在当前节点内复制本表及数据" type="warning" />
  5. <div v-if="CopyModalType === '1'" class="copy-node-many-box">
  6. <div class="copy-node-many-tree">
  7. <el-scrollbar>
  8. <HcLazyTree
  9. ref="copywbstree" is-type
  10. :auto-expand-keys="treeautokeys"
  11. @load="treeLoadNode"
  12. @node-loading="ElTreeNodeLoading"
  13. @node-tap="wbsElTreeClick"
  14. />
  15. <!-- WbsTree
  16. :treeKey="wbstreeKey"
  17. :classifyType="classify"
  18. :contractId="contractId"
  19. :projectId="projectId"
  20. @nodeLoading="ElTreeNodeLoading"
  21. @nodeTap="wbsElTreeClick"
  22. ref="copywbstree"
  23. :autoExpandKeys="treeautokeys"
  24. / -->
  25. </el-scrollbar>
  26. </div>
  27. <div class="copy-node-many-table">
  28. <el-scrollbar v-loading="tableLoading">
  29. <el-table :data="copyModalTable" border>
  30. <el-table-column label="表格名称" prop="fullName" />
  31. <el-table-column align="center" label="操作" prop="action" width="120">
  32. <template #default="{ row }">
  33. <el-checkbox v-model="row.isCheck" size="large" @change="copyModalTableCheck(row)" />
  34. </template>
  35. </el-table-column>
  36. </el-table>
  37. </el-scrollbar>
  38. </div>
  39. </div>
  40. </div>
  41. </template>
  42. <script setup>
  43. import { nextTick, onMounted, ref, watch } from 'vue'
  44. import { getArrValue, getObjValue, setPosInsert } from 'js-fast-way'
  45. import queryApi from '~api/data-fill/query'
  46. import wbsApi from '~api/data-fill/wbs'
  47. const props = defineProps({
  48. projectId: [String, Number],
  49. contractId: [String, Number],
  50. classify:[String, Number],
  51. tree_AutoExpandKeys:[Array],
  52. treenodeDataInfo:[Object], //外层选中的树
  53. copyItems:[Object], //复制本表的数据
  54. CopyModalType:[String, Number],
  55. })
  56. //参数变量
  57. const projectId = ref(props.projectId)
  58. const contractId = ref(props.contractId)
  59. const classify = ref(props.classify)
  60. const tree_AutoExpandKeys = ref(props.tree_AutoExpandKeys)
  61. const treenodeDataInfo = ref(props.treenodeDataInfo)
  62. const copyItems = ref(props.copyItems)
  63. const CopyModalType = ref(props.CopyModalType)
  64. const copyModalTable = ref([])
  65. const tableLoading = ref(false)
  66. const treeLoading = ref(false)
  67. const copywbstree = ref(null)
  68. //监听
  69. watch(() => [
  70. props.projectId,
  71. props.contractId,
  72. props.CopyModalType,
  73. ], ([pid, cid, CopyModaltype]) => {
  74. projectId.value = pid
  75. contractId.value = cid
  76. CopyModalType.value = CopyModaltype
  77. })
  78. //树加载完成
  79. const ElTreeNodeLoading = () => {
  80. treeLoading.value = false
  81. console.log(tree_AutoExpandKeys.value, 'tree_AutoExpandKeys')
  82. }
  83. const wbstreeKey = ref(Math.random())
  84. const nodeItemInfo = ref({})
  85. const nodeDataInfo = ref({})
  86. //懒加载的数据
  87. const treeLoadNode = async ({ node, item, level }, resolve) => {
  88. let contractIdRelation = '', parentId = '', primaryKeyId = ''
  89. if (level !== 0) {
  90. const nodeData = getObjValue(item)
  91. contractIdRelation = nodeData?.contractIdRelation || ''
  92. parentId = contractIdRelation ? nodeData?.primaryKeyId : nodeData?.id
  93. primaryKeyId = nodeData?.id || ''
  94. }
  95. //获取数据
  96. const { data } = await queryApi.queryWbsTreeData({
  97. contractId: contractId.value || '',
  98. contractIdRelation,
  99. primaryKeyId,
  100. parentId,
  101. classifyType: classify.value,
  102. dataTime:new Date(),
  103. })
  104. resolve(getArrValue(data))
  105. }
  106. //树被点击
  107. const wbsElTreeClick = ({ node, data, keys }) => {
  108. nodeItemInfo.value = node
  109. nodeDataInfo.value = data
  110. searchTabledata()
  111. }
  112. const searchTabledata = async () => {
  113. copyModalTable.value = []
  114. const info = nodeDataInfo.value
  115. tableLoading.value = true
  116. const { error, code, data } = await wbsApi.searchNodeAllTable({
  117. projectId: projectId.value,
  118. contractId: contractId.value,
  119. primaryKeyId: info['primaryKeyId'],
  120. type: classify.value,
  121. })
  122. //处理数据
  123. tableLoading.value = false
  124. if (!error && code === 200) {
  125. copyModalTable.value = getArrValue(data)
  126. } else {
  127. copyModalTable.value = []
  128. }
  129. }
  130. //勾选复制本表
  131. const copyModalTableCheck = async (item) => {
  132. console.log('复制本表', item)
  133. }
  134. const treeautokeys = ref([])
  135. </script>
  136. <style>
  137. .mtop5{
  138. margin-top: 5px;
  139. }
  140. </style>