wbs-tree.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <hc-new-drawer v-model="isShow" is-close to-id="hc-project-list">
  3. <div class="hc-project-wbs-tree flex">
  4. <div class="header hc-flex">
  5. <div class="name flex-1">{{ typeLable }} - {{ projectInfo.projectName }}</div>
  6. <div class="hc-flex">
  7. <el-button hc-btn type="success">数据同步</el-button>
  8. <el-button hc-btn type="primary">表单设置</el-button>
  9. <el-button hc-btn type="danger">节点参数</el-button>
  10. <el-button hc-btn color="#626aef">独立表单库</el-button>
  11. <el-button hc-btn type="warning">归档文件时间</el-button>
  12. </div>
  13. </div>
  14. <div class="body">
  15. <hc-body split padding="8px">
  16. <template #left>
  17. <hc-new-card v-loading="isTreeLoading" title="工程节点信息" scrollbar class="is-tree">
  18. <template #search>
  19. <hc-search-input v-model="searchTree.queryValue" @search="searchTreeClick">
  20. <template #prepend>
  21. <el-select v-model="searchTree.type" placeholder="类型" class="w-[75px]">
  22. <el-option label="节点" value="1" />
  23. <el-option label="表名" value="2" />
  24. </el-select>
  25. </template>
  26. </hc-search-input>
  27. </template>
  28. <hc-data-tree
  29. v-if="isSearchTree" :h-props="treeProps" :datas="treeLoadData" tree-key="id" :auto-expand-keys="treeExpandKeys"
  30. :menus="treeMenus" @menu-tap="treeMenuClick" @node-tap="treeNodeClick"
  31. />
  32. <hc-lazy-tree
  33. v-else :h-props="treeProps" tree-key="id" :auto-expand-keys="treeExpandKeys"
  34. :menus="treeMenus" @load="treeLoadNode" @menu-tap="treeMenuClick" @node-tap="treeNodeClick"
  35. />
  36. </hc-new-card>
  37. </template>
  38. <div :id="`hc_body_top_${uuid}`" class="body-top">
  39. <hc-body padding="0px">
  40. <hc-new-card title="节点信息">
  41. <hc-table is-new :column="nodeTableColumn" :datas="nodeTableData">
  42. <template #nodeType="{ row }">{{ getDictionaryName(nodeTypelist, row.nodeType, true) }}</template>
  43. </hc-table>
  44. </hc-new-card>
  45. </hc-body>
  46. </div>
  47. <div :id="`hc_body_content_${uuid}`" class="body-content">
  48. <hc-body padding="0px">
  49. <hc-new-card title="当前项目信息表">
  50. 当前项目信息表
  51. </hc-new-card>
  52. </hc-body>
  53. </div>
  54. </hc-body>
  55. </div>
  56. </div>
  57. </hc-new-drawer>
  58. </template>
  59. <script setup>
  60. import { ref, watch } from 'vue'
  61. import { useAppStore } from '~src/store'
  62. import { delMessage, getStore, setStore } from 'hc-vue3-ui'
  63. import { getArrValue, getObjValue, getRandom, isNullES } from 'js-fast-way'
  64. import { getDictionaryData, setSplit } from '~uti/tools'
  65. import mainApi from '~api/project/project'
  66. import wbsTreeApi from '~api/wbs/tree'
  67. import wbsPrivateApi from '~api/wbs/private'
  68. const props = defineProps({
  69. type: {
  70. type: [String, Number],
  71. default: '1',
  72. },
  73. info: {
  74. type: Object,
  75. default: () => ({}),
  76. },
  77. })
  78. //事件
  79. const emit = defineEmits(['change', 'close'])
  80. //双向绑定
  81. // eslint-disable-next-line no-undef
  82. const isShow = defineModel('modelValue', {
  83. default: false,
  84. })
  85. const store = useAppStore()
  86. //监听数据
  87. const isType = ref(props.type)
  88. const projectInfo = ref(props.info)
  89. watch(() => [
  90. props.type,
  91. props.info,
  92. ], ([type, info]) => {
  93. isType.value = type
  94. projectInfo.value = info
  95. }, { deep: true })
  96. //监听显示
  97. watch(isShow, (val) => {
  98. if (val) {
  99. getProjectData()
  100. setSplitRef()
  101. } else {
  102. projectInfo.value = {}
  103. isType.value = ''
  104. emit('close')
  105. }
  106. })
  107. //初始化设置拖动分割线
  108. const uuid = getRandom(4)
  109. const setSplitRef = () => {
  110. setSplit(['#hc_body_top_' + uuid, '#hc_body_content_' + uuid], {
  111. direction: 'vertical',
  112. sizes: [25, 75],
  113. snapOffset: 0,
  114. })
  115. }
  116. //获取项目信息
  117. const typeLable = ref('')
  118. const wbsId = ref('')
  119. const getProjectData = () => {
  120. const type = isType.value ?? 1
  121. const wbsArr = ['WBS树管理', '实验划分', '计量管理', '日志树管理', '征拆划分']
  122. typeLable.value = wbsArr[Number(type) - 1]
  123. const wbsIds = [
  124. 'referenceWbsTemplateId', 'referenceWbsTemplateIdTrial',
  125. 'referenceWbsTemplateIdMeter', 'referenceLogWbsTemplateId',
  126. 'referenceWbsTemplateIdLar',
  127. ]
  128. wbsId.value = projectInfo.value[wbsIds[Number(type) - 1]]
  129. console.log('info: ', projectInfo.value)
  130. getNodeTypelist(Number(type) - 1)
  131. }
  132. //获取节点类型
  133. const nodeTypelist = ref([])
  134. const getNodeTypelist = async (type) => {
  135. const types = ['wbs_node_type', 'trial_node_type', 'meter_node_type', 'wbs_node_type', 'lar_node_type']
  136. const data = await getDictionaryData(types[type])
  137. nodeTypelist.value = getArrValue(data)
  138. }
  139. //获取字典里的数据
  140. const getDictionaryName = (arr, id, name) => {
  141. const item = arr.find((item) => item.value === id)
  142. return name ? item?.label : getObjValue(item)
  143. }
  144. //树节点搜索
  145. const isSearchTree = ref(false)
  146. const isTreeLoading = ref(false)
  147. const searchTree = ref({ queryValue: '', type: '1' })
  148. const searchTreeClick = () => {
  149. const { queryValue } = searchTree.value
  150. isSearchTree.value = !isNullES(queryValue)
  151. getTreeLoadData()
  152. }
  153. //获取搜索树的数据
  154. const treeLoadData = ref([])
  155. const getTreeLoadData = async () => {
  156. isTreeLoading.value = true
  157. const { data } = await wbsTreeApi.getQueryValueByType({
  158. ...searchTree.value,
  159. wbsId: wbsId.value,
  160. projectId: projectInfo.value.id,
  161. })
  162. treeLoadData.value = getArrValue(data)
  163. isTreeLoading.value = false
  164. }
  165. //树属性
  166. const treeExpandKeys = ref(getStore('project-wbs-tree-expand-keys') || [])
  167. const treeProps = {
  168. children: 'children',
  169. label: 'title',
  170. isLeaf: ({ hasChildren, isExistForm, majorDataType, nodeType }) => {
  171. let tag = false
  172. if (!hasChildren) {
  173. tag = true
  174. }
  175. if (isExistForm === 1) {
  176. tag = true
  177. }
  178. if (nodeType >= 6 && nodeType <= 13) {
  179. tag = true
  180. }
  181. //中间交工。开工报告、质量评定)
  182. if (majorDataType >= 1 && majorDataType <= 3) {
  183. tag = true
  184. }
  185. return tag
  186. },
  187. }
  188. //树的右键菜单
  189. const treeMenus = [
  190. { icon: 'draft', label: '编辑节点', key: 'edit' },
  191. { icon: 'refresh', label: '同步新增元素表单', key: 'sync1' },
  192. { icon: 'loop-left', label: '同步元素表单排序到合同段', key: 'sync3' },
  193. { icon: 'loop-right', label: '同步节点基础信息及表单URL', key: 'sync2' },
  194. { icon: 'sort-asc', label: '调整排序', key: 'sort' },
  195. { icon: 'delete-bin', label: '删除节点', key: 'del' },
  196. ]
  197. //菜单被点击
  198. const treeMenuClick = ({ key, node, data, keys }) => {
  199. }
  200. //懒加载树
  201. const treeLoadNode = async ({ item, level }, resolve) => {
  202. let pid = level !== 0 ? item.id : 0
  203. const { data } = await wbsPrivateApi.getLazytree({
  204. wbsId: wbsId.value,
  205. parentId: pid,
  206. tenantId: store.tenantId,
  207. projectId: projectInfo.value.id,
  208. wbsType: isType.value,
  209. })
  210. resolve(getArrValue(data))
  211. }
  212. //节点信息
  213. const nodeTableColumn = ref([
  214. { key: 'nodeName', name: '当前节点' },
  215. { key: 'nodeType', name: '节点类型' },
  216. { key: 'parentName', name: '上级节点' },
  217. ])
  218. const nodeTableData = ref([])
  219. //节点被点击
  220. const treeItem = ref({})
  221. const treeNodeClick = ({ node, data, keys }) => {
  222. //获取父节点名称
  223. let parentName = ''
  224. if (node?.parent?.data) {
  225. parentName = node.parent.data.title ?? ''
  226. }
  227. data.parentName = parentName
  228. //设置相关数据
  229. treeItem.value = getObjValue(data)
  230. setStore('project-wbs-tree-expand-keys', keys)
  231. treeExpandKeys.value = getArrValue(keys)
  232. //获取节点详情
  233. getTreeDetail(data.id, parentName)
  234. }
  235. //获取节点详情
  236. const treeInfo = ref({})
  237. const getTreeDetail = async (id, parentName) => {
  238. const { data } = await wbsPrivateApi.detail({
  239. id,
  240. wbsId: wbsId.value,
  241. projectId: projectInfo.value.id,
  242. })
  243. const res = getObjValue(data)
  244. res.parentName = parentName
  245. treeInfo.value = res
  246. nodeTableData.value = [res]
  247. }
  248. </script>
  249. <style scoped lang="scss">
  250. .hc-project-wbs-tree {
  251. position: relative;
  252. background: #ececec;
  253. border-radius: 4px;
  254. height: 100%;
  255. flex-direction: column;
  256. overflow: hidden;
  257. .header {
  258. color: white;
  259. background: #54565A;
  260. padding: 10px 14px;
  261. flex-shrink: 0;
  262. .name {
  263. white-space:nowrap;
  264. overflow:hidden;
  265. text-overflow:ellipsis;
  266. }
  267. }
  268. .body {
  269. flex: 1;
  270. flex-basis: auto;
  271. position: relative;
  272. }
  273. }
  274. </style>
  275. <style lang="scss">
  276. .hc-project-wbs-tree .body .hc-page-split-content {
  277. position: relative;
  278. .body-top {
  279. position: relative;
  280. height: 166px;
  281. }
  282. .body-content {
  283. position: relative;
  284. height: calc(100% - 166px);
  285. }
  286. }
  287. </style>