linkTab.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <hc-sys class="hc-ledger-table-form" navBarUi="white">
  3. <template #navBar>
  4. <hc-nav-back-bar title="关联工序">
  5. <text @click="finishClick">确定</text>
  6. </hc-nav-back-bar>
  7. </template>
  8. <uni-section title="关联工序列表" type="line" class="mt-1px">
  9. <uni-list>
  10. <uni-list-item :title="item.path" v-for="(item, index) in linkIds" >
  11. <template v-slot:footer>
  12. <view>
  13. <uni-tag :inverted="true" @click="clearItem(index)" text="删除" type="error" />
  14. </view>
  15. </template>
  16. </uni-list-item>
  17. </uni-list>
  18. </uni-section>
  19. <!--底部操作栏-->
  20. <HcTabbarBlock :height="85"/>
  21. <hc-tabbars>
  22. <button class="check-btn" type="primary" @click="addLinks">新增关联工序</button>
  23. </hc-tabbars>
  24. <!-- 普通弹窗 -->
  25. <hc-popup ref="popupRef" @confirm="popupConfirm">
  26. <hc-tree ref="hcTreeRef" check strictly :checkKey="treeCheckKey" @load="getLazyLoad"/>
  27. </hc-popup>
  28. </hc-sys>
  29. </template>
  30. <script setup>
  31. import {ref, nextTick, getCurrentInstance} from "vue";
  32. import {onLoad} from '@dcloudio/uni-app'
  33. import {getArrValue, getObjValue} from "js-fast-way";
  34. import wbsApi from '~api/data-fill/wbs';
  35. import mainApi from '~api/ledger/index';
  36. import {useAppStore} from "@/store";
  37. const store = useAppStore()
  38. const instance = getCurrentInstance().proxy
  39. //初始变量
  40. const contractInfo = ref(store.contractInfo);
  41. const projectId = ref(store.projectId);
  42. const contractId = ref(store.contractId);
  43. const itemFormId = ref('');
  44. //页面传参数据
  45. let eventChannel = null;
  46. const getEventChannel = async () => {
  47. await nextTick();
  48. eventChannel = instance.getOpenerEventChannel();
  49. }
  50. onLoad((option) => {
  51. itemFormId.value = option?.id ?? ''
  52. getEventChannel()
  53. querySelectProcessList()
  54. })
  55. //已关联的工序
  56. const linkIds = ref([])
  57. const treeCheckKey = ref([])
  58. //查询已关联的工序
  59. const querySelectProcessList = async () => {
  60. if (itemFormId.value) {
  61. const { data } = await mainApi.queryCurrentLogSelectProcessList({
  62. contractId: contractId.value ?? '',
  63. businessId: itemFormId.value,
  64. })
  65. linkIds.value = getArrValue(data)
  66. } else {
  67. linkIds.value = []
  68. }
  69. }
  70. //删除当前的节点
  71. const clearItem = (index) => {
  72. linkIds.value.splice(index, 1)
  73. }
  74. //新增关联工序
  75. const popupRef = ref(null)
  76. const addLinks = () => {
  77. let ids = linkIds.value, tree_check_key = []
  78. for (let i = 0; i < ids.length; i++) {
  79. const {primaryKeyId} = ids[i]
  80. tree_check_key.push(primaryKeyId ? primaryKeyId + '' : '')
  81. }
  82. treeCheckKey.value = tree_check_key
  83. popupRef.value?.open()
  84. }
  85. //获取树形数据
  86. const hcTreeRef = ref(null)
  87. const getLazyLoad = async (node, resolve) => {
  88. const { contractType } = contractInfo.value
  89. const { id, primaryKeyId, contractIdRelation } = getObjValue(node.data)
  90. const { data } = await wbsApi.queryWbsTreeData({
  91. contractId: contractId.value || '',
  92. contractIdRelation: contractIdRelation ?? '',
  93. primaryKeyId: id ?? '',
  94. parentId: node.level <= 0 ? '' : contractIdRelation ? primaryKeyId : id,
  95. classifyType: node.level <= 0 ? '' : contractType ?? '',
  96. tableOwner: contractType ?? ''
  97. })
  98. resolve(getArrValue(data))
  99. }
  100. //确认选择
  101. const popupConfirm = async () => {
  102. const linkTabIds = []
  103. const { nodes } = await hcTreeRef.value?.getCheckKeys()
  104. for (let i = 0; i < nodes.length; i++) {
  105. let pathArr = [], item = nodes[i]
  106. if (item.level > 1) {
  107. getPathName(item, pathArr)
  108. linkTabIds.push({
  109. path: pathArr.join('/'),
  110. primaryKeyId: item.key,
  111. })
  112. }
  113. }
  114. linkIds.value = linkTabIds
  115. popupRef.value?.close()
  116. }
  117. //获取节点的路径名字
  118. const getPathName = (node, pathArr) => {
  119. if (node.level > 1) {
  120. pathArr.unshift(node.label.replace(/(^\s*)|(\s*$)/g, '')) //去掉头尾空格
  121. getPathName(node.parentNodes, pathArr)
  122. }
  123. }
  124. //确认关联工序
  125. const finishClick = () => {
  126. eventChannel.emit('finish', linkIds.value);
  127. uni.navigateBack()
  128. }
  129. </script>
  130. <style lang="scss" scoped>
  131. page {
  132. height: 100%;
  133. background: #FAFBFE;
  134. }
  135. </style>
  136. <style lang="scss">
  137. </style>