divisionDialog.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. <!-- 节点划分 -->
  2. <template>
  3. <hc-new-dialog v-model="linkModal" is-table widths="1200px" @close="closeModal">
  4. <template #header>
  5. <div class="flex justify-between">
  6. <div class="text-lg">节点划分</div>
  7. <div class="mr-8 w-100 flex">
  8. <el-input
  9. v-model="searchTreeVal"
  10. clearable
  11. block
  12. placeholder="请输入名称关键词检索"
  13. @keyup="searchTreeKeyUp"
  14. @clear="searchTreeClick"
  15. >
  16. <template #suffix>
  17. <HcIcon
  18. name="search-2"
  19. ui="text-xl iscusor"
  20. @click="searchTreeClick"
  21. />
  22. </template>
  23. </el-input>
  24. <el-button type="primary" class="ml-2" @click="searchTreeClick">搜索</el-button>
  25. </div>
  26. </div>
  27. </template>
  28. <div class="link-data-box">
  29. <div class="link-data-left">
  30. <div class="relative h-full flex">
  31. <div v-loading="treeLoading" class="hc_tree_card_border relative w-full">
  32. <hc-body scrollbar padding="0px">
  33. <HcLazyTree
  34. ref="leftTree"
  35. show-checkbox
  36. is-type
  37. check-strictly
  38. :h-props="leftTreeProps"
  39. :is-color="false"
  40. :accordion="false"
  41. :auto-expand-keys="treeAutoExpandKeys"
  42. @check="leftTreeNodeCheckChange"
  43. @load="treeLoadNode"
  44. @node-loading="treeNodeLoading"
  45. />
  46. </hc-body>
  47. </div>
  48. </div>
  49. </div>
  50. <div class="link-data-icon">
  51. <HcIcon type="primary" name="links" style="font-size: 22px;" />
  52. </div>
  53. <div class="link-data-right">
  54. <div class="relative h-full flex">
  55. <div v-loading="treeLoadingData" class="hc_tree_card_border relative w-full">
  56. <hc-body scrollbar padding="0px">
  57. <HcLazyTree
  58. v-if="!isSearchTree"
  59. ref="rightTree"
  60. v-model:loading="isLoading"
  61. tree-key="id"
  62. show-checkbox
  63. is-type
  64. :is-color="false"
  65. :default-checked-keys="defaultCheckedKeys"
  66. :is-auto-check="true"
  67. :accordion="false"
  68. :h-props="treeProps"
  69. @check="addTreeNodeCheckChange"
  70. @load="rightTreeLoadNode"
  71. @node-tap="rightElTreeClick"
  72. >
  73. <template #name="{ node, data }">
  74. <div class="custom-tree-node">
  75. <div class="label" @dblclick="ElTreeDblClick(data)">
  76. <el-input v-if="data.isInputName" v-model="data.title" size="small" @blur="ElTreeBtnClick(data)" @keyup="keyUpEvent($event, data)">
  77. <template #append>
  78. <el-button plain size="small" type="primary" @click="ElTreeBtnClick(data)">
  79. <HcIcon name="check" />
  80. </el-button>
  81. </template>
  82. </el-input>
  83. <span v-else>{{ data.title }}</span>
  84. </div>
  85. </div>
  86. </template>
  87. </HcLazyTree>
  88. <HcDataTree
  89. v-if="isSearchTree"
  90. :datas="searchTreeData"
  91. show-checkbox
  92. is-type
  93. :auto-expand-keys="treeAutoExpandKeys"
  94. default-expand-all
  95. />
  96. </hc-body>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <template #footer>
  102. <div class="dialog-footer">
  103. <el-button hc-btn style="border: 1px solid var(--el-button-border-color);" @click="closeModal">
  104. <HcIcon name="close" />
  105. <span>取消</span>
  106. </el-button>
  107. <el-button hc-btn type="primary" :loading="sureLoading" :disabled="isLoading" @click="sureClick(1)">
  108. <HcIcon name="check" />
  109. <span>关联并退出</span>
  110. </el-button>
  111. <el-button hc-btn type="primary" :loading="sureLoading" :disabled="isLoading" @click="sureClick(2)">
  112. <HcIcon name="check" />
  113. <span>关联并继续</span>
  114. </el-button>
  115. </div>
  116. </template>
  117. </hc-new-dialog>
  118. </template>
  119. <script setup>
  120. import { nextTick, ref, watch } from 'vue'
  121. import { getArrValue, getObjValue } from 'js-fast-way'
  122. import { useAppStore } from '~src/store'
  123. import samplingApi from '~api/tentative/material/sampling'
  124. import queryApi from '~api/data-fill/query'
  125. import wbsApi from '~api/data-fill/wbs'
  126. import { getStoreValue } from '~uti/storage'
  127. const props = defineProps({
  128. linkModal: {
  129. type: Boolean,
  130. default: false,
  131. },
  132. classifyType:{
  133. type: String,
  134. default: '1',
  135. },
  136. treeItemInfo:{
  137. type: Object,
  138. default: () => ({}),
  139. },
  140. firstTree: {
  141. type: Object,
  142. default: () => ({}),
  143. },
  144. autoExpandKeys: {
  145. type: Array,
  146. default: () => [],
  147. },
  148. })
  149. //事件
  150. const emit = defineEmits(['close', 'save'])
  151. const useAppState = useAppStore()
  152. const contractId = ref(useAppState.getContractId)
  153. const projectId = ref(useAppState.getProjectId)
  154. const treeItemInfo = ref(props.treeItemInfo)
  155. const classifyType = ref(props.classifyType)
  156. const firstTree = ref(props.firstTree)
  157. const treeAutoExpandKeys = ref(props.autoExpandKeys)
  158. const linkModal = defineModel('modelValue', {
  159. default: false,
  160. })
  161. const closeModal = ()=>{
  162. linkModal.value = false
  163. leftPid.value = ''
  164. allSelectedList.value = []
  165. halfSelectedList.value = []
  166. emit('close')
  167. }
  168. //获取两棵树的数据
  169. const treeLoading = ref(true)
  170. const treeNodeLoading = () => {
  171. treeLoading.value = false
  172. }
  173. const rightTree = ref(null)
  174. const treeProps = ref({
  175. label: 'title',
  176. children: 'children',
  177. isLeaf: (data) => !data.hasChildren,
  178. // disabled: (data) => {
  179. // // 当节点类型为6时才能选择
  180. // return data.nodeType !== 6
  181. // },
  182. })
  183. const leftTreeProps = ref({
  184. label: 'title',
  185. children: 'children',
  186. isLeaf: (data) =>!data.hasChildren,
  187. disabled: (data) => {
  188. // 当节点类型为6时不能能选择
  189. return data.nodeType === 6
  190. },
  191. })
  192. //监听
  193. const isLoading = ref(false)
  194. watch(isLoading, (newVal) => {
  195. console.log('加载状态变化:', newVal)
  196. })
  197. watch(() => [
  198. props.linkModal,
  199. props.classifyType,
  200. props.treeItemInfo,
  201. props.firstTree,
  202. props.autoExpandKeys,
  203. ], ([link, type, treeItemIn, first, keys]) => {
  204. linkModal.value = link
  205. classifyType.value = type
  206. treeItemInfo.value = treeItemIn
  207. firstTree.value = first
  208. treeAutoExpandKeys.value = keys
  209. console.log(keys, 'keys')
  210. }, { immediate: true })
  211. //选中的节点
  212. const defaultCheckedKeys = ref([])
  213. const allSelectedList = ref([])
  214. const halfSelectedList = ref([])
  215. const addTreeNodeCheckChange = async (_, { checkedNodes, checkedKeys, halfCheckedNodes, halfCheckedKeys }) => {
  216. await nextTick()
  217. //全选数据
  218. const keys = checkedNodes || []
  219. console.log('key22222222s', keys)
  220. const NodesArr = keys
  221. .filter(node => node.nodeType === 6)
  222. .map(node => ({
  223. nodeName: node.title,
  224. primaryKeyId: node.primaryKeyId,
  225. }))
  226. // 更新选中状态
  227. defaultCheckedKeys.value = checkedNodes.map(node => node.id)
  228. console.log( defaultCheckedKeys.value, ' defaultCheckedKeys.value')
  229. allSelectedList.value = NodesArr
  230. //半选数据
  231. const halfNodes = halfCheckedNodes || []
  232. const halfArr = halfNodes
  233. .filter(node => node.nodeType === 6)
  234. .map(node => ({
  235. nodeName: node.title,
  236. primaryKeyId: node.primaryKeyId,
  237. }))
  238. halfSelectedList.value = halfArr
  239. }
  240. const sureLoading = ref(false)
  241. const sureClick = async (type) => {
  242. await nextTick() // 等待下一个 DOM
  243. const keys = allSelectedList.value || []
  244. console.log('keys', keys)
  245. if (keys.length <= 0 || leftPid.value.length <= 0) {
  246. window?.$message?.warning('请先选择节点')
  247. return
  248. } else {
  249. //发起请求
  250. sureLoading.value = true
  251. const { error, code, msg } = await wbsApi.saveContractTreeNode({
  252. projectId: projectId.value,
  253. contractId: contractId.value,
  254. saveType: 4, //节点划分,多对多
  255. allSelectedList: allSelectedList.value,
  256. halfSelectedList: halfSelectedList.value,
  257. currentNodePrimaryKeyId: leftPid.value,
  258. isImportTree: 1,
  259. templateType:useAppState.contractInfo?.templateType,
  260. })
  261. //判断状态
  262. sureLoading.value = false
  263. if (!error && code === 200) {
  264. window?.$message?.success(msg)
  265. // type=1时关闭弹窗,type=2时保持打开
  266. if (type === 1) {
  267. closeModal()
  268. emit('save')
  269. } else {
  270. allSelectedList.value = []
  271. halfSelectedList.value = []
  272. leftPid.value = ''
  273. leftTree.value?.treeRef.setCheckedKeys([])
  274. rightTree.value?.treeRef.setCheckedKeys([])
  275. }
  276. }
  277. }
  278. }
  279. const leftTree = ref(null)
  280. const treeLoadNode = async ({ node, item, level }, resolve) => {
  281. let contractIdRelation = '',
  282. parentId = '',
  283. primaryKeyId = ''
  284. if (level !== 0) {
  285. const nodeData = getObjValue(item)
  286. contractIdRelation = nodeData?.contractIdRelation || ''
  287. parentId = contractIdRelation ? nodeData?.primaryKeyId : nodeData?.id
  288. primaryKeyId = nodeData?.id || ''
  289. }
  290. //获取数据
  291. const { data } = await queryApi.queryWbsTreeData({
  292. contractId: contractId.value || '',
  293. contractIdRelation,
  294. primaryKeyId,
  295. parentId,
  296. classifyType: classifyType.value,
  297. tableOwner: classifyType.value,
  298. dataTime:new Date(),
  299. })
  300. resolve(getArrValue(data))
  301. treeLoading.value = false
  302. }
  303. const leftPid = ref('')
  304. const leftTreeNodeCheckChange = (_, { checkedNodes }) => {
  305. if (checkedNodes && checkedNodes.length > 0) {
  306. // 获取所有选中节点的 primaryKeyId 并用逗号拼接
  307. leftPid.value = checkedNodes.map(node => node.primaryKeyId).filter(Boolean).join(',')
  308. } else {
  309. leftPid.value = ''
  310. }
  311. }
  312. //更改节点名称
  313. const ElTreeDblClick = (item) => {
  314. item.isInputName = true
  315. }
  316. //回车
  317. const keyUpEvent = (e, item) => {
  318. if (e.key === 'Enter') {
  319. ElTreeBtnClick(item)
  320. }
  321. }
  322. //更改节点名称完成
  323. const ElTreeBtnClick = (item) => {
  324. if (!item?.title) {
  325. window?.$message?.warning('节点名称不能为空')
  326. } else {
  327. item.isInputName = false
  328. // ElTreeCheckedKeys()
  329. }
  330. }
  331. const rightTreeLoadNode = async ({ node, item, level }, resolve) => {
  332. let parentId = '0'
  333. if (level !== 0) {
  334. parentId = item?.id
  335. }
  336. //获取数据
  337. const { data } = await samplingApi.queryLazyTree({
  338. wbsId: firstTree.value?.wbsId,
  339. tenantId: getStoreValue('tenantId') || '',
  340. projectId: projectId.value,
  341. parentId,
  342. wbsType: firstTree.value.wbsType,
  343. type:1,
  344. })
  345. resolve(getArrValue(data))
  346. // 确保在数据加载完成后,重新设置选中状态
  347. await nextTick()
  348. if (defaultCheckedKeys.value.length > 0) {
  349. rightTree.value?.treeRef.setCheckedKeys(defaultCheckedKeys.value)
  350. }
  351. }
  352. const rightObj = ref(null)
  353. const rightElTreeClick = ({ data }) => {
  354. rightObj.value = data
  355. }
  356. //搜索右边的节点树
  357. const searchTreeVal = ref('')
  358. const searchTreeData = ref([])
  359. const isSearchTree = ref(false)
  360. //回车
  361. const treeLoadingData = ref(false)
  362. const getSearchTreeData = async () => {
  363. treeLoadingData.value = true
  364. const { error, code, data } = await wbsApi.getQueryValueByType({
  365. contractId: contractId.value,
  366. queryValue: searchTreeVal.value,
  367. projectId:projectId.value,
  368. type:1,
  369. wbsId:firstTree.value?.wbsId,
  370. })
  371. //判断状态
  372. if (!error && code === 200) {
  373. let treedata = getArrValue(data)
  374. searchTreeData.value = treedata
  375. treeLoadingData.value = false
  376. } else {
  377. treeLoadingData.value = false
  378. searchTreeData.value = []
  379. }
  380. }
  381. const searchTreeKeyUp = (e) => {
  382. if (e.key === 'Enter') {
  383. searchTreeClick()
  384. }
  385. }
  386. const searchTreeClick = async () => {
  387. if (searchTreeVal.value) {
  388. isSearchTree.value = true
  389. //treeLoading.value = true
  390. getSearchTreeData().then()
  391. } else {
  392. isSearchTree.value = false
  393. }
  394. }
  395. </script>
  396. <style lang='scss' scoped>
  397. .title-box{
  398. position: relative;
  399. display: flex;
  400. // padding: 40px;
  401. font-weight: 400;
  402. font-size: 18px;
  403. width: 100%;
  404. margin-bottom: 10px;
  405. margin-top: 10px;
  406. .title-box-left{
  407. width: 50%;
  408. text-align: center;
  409. }
  410. .title-box-right{
  411. width: 50%;
  412. text-align: center;
  413. }
  414. }
  415. .link-data-box{
  416. position: relative;
  417. display: flex;
  418. height: calc(100% - 45px);
  419. align-items: center;
  420. // border: 1px solid rgb(187, 187, 187);
  421. padding: 0px 40px 0px 40px;
  422. .link-data-left{
  423. width: 50%;
  424. position: relative;
  425. height: 100%;
  426. background: #ffffff;
  427. border: 1px solid #273044;
  428. }
  429. .link-data-icon{
  430. display: inline-block;
  431. vertical-align: middle;
  432. padding: 0 16px;
  433. }
  434. .link-data-right{
  435. width: 50%;
  436. position: relative;
  437. height: 100%;
  438. background: #ffffff;
  439. border: 1px solid #273044;
  440. }
  441. }
  442. </style>
  443. <style lang="scss">
  444. .link-data-right .el-tree.hc-tree-node-v2 .data-custom-tree-node .label, .hc-tree-node .data-custom-tree-node .label{
  445. display: flex;
  446. }
  447. </style>