wbs-tree.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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-dropdown trigger="click">
  8. <el-button hc-btn type="success">
  9. <span>数据同步</span>
  10. <hc-icon name="arrow-down-s" />
  11. </el-button>
  12. <template #dropdown>
  13. <el-dropdown-menu>
  14. <template v-for="item in dataSyncMenu" :key="item.key">
  15. <el-dropdown-item @click="dataSyncMenuClick(item)">{{ item.name }}</el-dropdown-item>
  16. </template>
  17. </el-dropdown-menu>
  18. </template>
  19. </el-dropdown>
  20. <el-button v-if="isFormSet" class="ml-3" hc-btn type="primary" @click="setIsFormSetValue">表单设置</el-button>
  21. <el-button v-else class="ml-3" hc-btn type="primary" @click="setIsFormSetValue">元素设置</el-button>
  22. <el-button hc-btn type="danger">节点参数</el-button>
  23. <el-button hc-btn color="#626aef">独立表单库</el-button>
  24. <el-button hc-btn type="warning">归档文件时间</el-button>
  25. </div>
  26. </div>
  27. <div class="body">
  28. <hc-body split padding="8px">
  29. <template #left>
  30. <hc-new-card v-loading="isTreeLoading" title="工程节点信息" scrollbar class="is-tree">
  31. <template #search>
  32. <hc-search-input v-model="searchTree.queryValue" @search="searchTreeClick">
  33. <template #prepend>
  34. <el-select v-model="searchTree.type" placeholder="类型" class="w-[75px]">
  35. <el-option label="节点" value="1" />
  36. <el-option label="表名" value="2" />
  37. </el-select>
  38. </template>
  39. </hc-search-input>
  40. </template>
  41. <hc-data-tree
  42. v-if="isSearchTree" :h-props="treeProps" :datas="treeLoadData" tree-key="id" :auto-expand-keys="treeExpandKeys"
  43. :menus="treeMenus" @menu-tap="treeMenuClick" @node-tap="treeNodeClick"
  44. />
  45. <hc-lazy-tree
  46. v-else :h-props="treeProps" tree-key="id" :auto-expand-keys="treeExpandKeys"
  47. :menus="treeMenus" @load="treeLoadNode" @menu-tap="treeMenuClick" @node-tap="treeNodeClick"
  48. />
  49. </hc-new-card>
  50. </template>
  51. <template v-if="isFormSet">
  52. <div class="body-top">
  53. <hc-new-card title="节点信息">
  54. <hc-table is-new :is-index="false" :column="nodeTableColumn" :datas="nodeTableData">
  55. <template #nodeType="{ row }">{{ getDictionaryName(nodeTypelist, row.nodeType, true) }}</template>
  56. </hc-table>
  57. </hc-new-card>
  58. </div>
  59. <div class="body-content">
  60. <hc-new-card title="当前项目信息表">
  61. <template #extra>
  62. <el-button hc-btn type="primary" :disabled="infoTableData.length <= 0">编辑</el-button>
  63. <el-button hc-btn type="success" :disabled="infoTableData.length <= 0">排序</el-button>
  64. </template>
  65. <hc-table v-loading="infoTableLoading" is-new :is-index="false" :column="infoTableColumn" :datas="infoTableData">
  66. <template #tableType="{ row }">{{ getDictionaryName(tableTypelist, row.tableType, true) }}</template>
  67. <template #tableOwner="{ row }">{{ getDictionaryName(ownerTypeList, row.tableOwner, true) }}</template>
  68. <template #action="{ row }">
  69. <el-link type="primary">预览</el-link>
  70. <el-link v-if="row.status === 1" type="warning">隐藏表单</el-link>
  71. <el-link v-if="row.status === 0" type="success">取消隐藏</el-link>
  72. <el-link v-del-com:[delInfoTableRow]="row" type="danger">删除</el-link>
  73. </template>
  74. </hc-table>
  75. </hc-new-card>
  76. </div>
  77. </template>
  78. <template v-else>
  79. <hc-new-card>
  80. <hc-table v-loading="infoTableLoading" is-new :is-index="false" :column="infoTableColumn1" :datas="infoTableData">
  81. <template #tableType="{ row }">{{ getDictionaryName(tableTypelist, row.tableType, true) }}</template>
  82. <template #isLinkTable="{ row }">{{ row.isLinkTable === 2 ? '是' : '否' }}</template>
  83. <template #tableOwner="{ row }">{{ getDictionaryName(ownerTypeList, row.tableOwner, true) }}</template>
  84. <template #action="{ row }">
  85. <el-link type="success">关联清表</el-link>
  86. <el-link type="primary" :disabled="row.excelId === -1 || isNullES(row.excelId)">编辑元素</el-link>
  87. <el-link type="warning" :disabled="row.excelId === -1 || isNullES(row.excelId)">调整表单</el-link>
  88. <el-link type="primary">编辑元素公式</el-link>
  89. <el-link type="warning">表单同步</el-link>
  90. <el-link v-del-com:[delInfoTableRow]="row" type="danger">删除表单</el-link>
  91. </template>
  92. </hc-table>
  93. </hc-new-card>
  94. </template>
  95. </hc-body>
  96. </div>
  97. </div>
  98. </hc-new-drawer>
  99. </template>
  100. <script setup>
  101. import { ref, watch } from 'vue'
  102. import { useAppStore } from '~src/store'
  103. import { getStore, setStore } from 'hc-vue3-ui'
  104. import { getArrValue, getObjValue, isNullES } from 'js-fast-way'
  105. import { getDictionaryData } from '~uti/tools'
  106. import mainApi from '~api/project/project'
  107. import wbsTreeApi from '~api/wbs/tree'
  108. import wbsPrivateApi from '~api/wbs/private'
  109. const props = defineProps({
  110. type: {
  111. type: [String, Number],
  112. default: '1',
  113. },
  114. info: {
  115. type: Object,
  116. default: () => ({}),
  117. },
  118. })
  119. //事件
  120. const emit = defineEmits(['change', 'close'])
  121. //双向绑定
  122. // eslint-disable-next-line no-undef
  123. const isShow = defineModel('modelValue', {
  124. default: false,
  125. })
  126. const store = useAppStore()
  127. //监听数据
  128. const isType = ref(props.type)
  129. const projectInfo = ref(props.info)
  130. watch(() => [
  131. props.type,
  132. props.info,
  133. ], ([type, info]) => {
  134. isType.value = type
  135. projectInfo.value = info
  136. }, { deep: true })
  137. //监听显示
  138. watch(isShow, (val) => {
  139. if (val) {
  140. getProjectData()
  141. } else {
  142. projectInfo.value = {}
  143. isType.value = ''
  144. emit('close')
  145. }
  146. })
  147. //获取项目信息
  148. const typeLable = ref('')
  149. const wbsId = ref('')
  150. const getProjectData = () => {
  151. const type = isType.value ?? 1
  152. const wbsArr = ['WBS树管理', '实验划分', '计量管理', '日志树管理', '征拆划分']
  153. typeLable.value = wbsArr[Number(type) - 1]
  154. const wbsIds = [
  155. 'referenceWbsTemplateId', 'referenceWbsTemplateIdTrial',
  156. 'referenceWbsTemplateIdMeter', 'referenceLogWbsTemplateId',
  157. 'referenceWbsTemplateIdLar',
  158. ]
  159. wbsId.value = projectInfo.value[wbsIds[Number(type) - 1]]
  160. console.log('info: ', projectInfo.value)
  161. getNodeTypelist(Number(type) - 1)
  162. getTableTypelist(Number(type) - 1)
  163. getDataTypelist()
  164. getOwnerTypelist()
  165. getMajorDataTypeList()
  166. }
  167. //获取节点类型
  168. const nodeTypelist = ref([])
  169. const getNodeTypelist = async (type) => {
  170. //计量管理,征拆划分,实验划分,WBS树管理,日志树管理
  171. const types = ['wbs_node_type', 'trial_node_type', 'meter_node_type', 'wbs_node_type', 'lar_node_type']
  172. const data = await getDictionaryData(types[type])
  173. nodeTypelist.value = getArrValue(data)
  174. }
  175. //获取表单类型
  176. const tableTypelist = ref([])
  177. const getTableTypelist = async (type) => {
  178. //计量管理,征拆划分,实验划分,WBS树管理,日志树管理
  179. const types = ['table_type', 'trial_table_type', 'table_type', 'table_type', 'table_type']
  180. const data = await getDictionaryData(types[type])
  181. tableTypelist.value = getArrValue(data)
  182. }
  183. //获取数据类型
  184. const dataTypeList = ref([])
  185. const getDataTypelist = async () => {
  186. const data = await getDictionaryData('data_type')
  187. dataTypeList.value = getArrValue(data)
  188. }
  189. //获取业主类型
  190. const ownerTypeList = ref([])
  191. const getOwnerTypelist = async () => {
  192. const data = await getDictionaryData('owner_type')
  193. ownerTypeList.value = getArrValue(data)
  194. }
  195. //获取类型字典
  196. const majorDataTypeList = ref([])
  197. const getMajorDataTypeList = async () => {
  198. const data = await getDictionaryData('major_data_type')
  199. majorDataTypeList.value = getArrValue(data)
  200. }
  201. //获取字典里的数据
  202. const getDictionaryName = (arr, id, name) => {
  203. if (isNullES(id)) return name ? '' : {}
  204. const item = arr.find((item) => item.value === Number(id))
  205. return name ? item?.label : getObjValue(item)
  206. }
  207. //树节点搜索
  208. const isSearchTree = ref(false)
  209. const isTreeLoading = ref(false)
  210. const searchTree = ref({ queryValue: '', type: '1' })
  211. const searchTreeClick = () => {
  212. const { queryValue } = searchTree.value
  213. isSearchTree.value = !isNullES(queryValue)
  214. getTreeLoadData()
  215. }
  216. //获取搜索树的数据
  217. const treeLoadData = ref([])
  218. const getTreeLoadData = async () => {
  219. isTreeLoading.value = true
  220. const { data } = await wbsTreeApi.getQueryValueByType({
  221. ...searchTree.value,
  222. wbsId: wbsId.value,
  223. projectId: projectInfo.value.id,
  224. })
  225. treeLoadData.value = getArrValue(data)
  226. isTreeLoading.value = false
  227. }
  228. //树属性
  229. const treeExpandKeys = ref(getStore('project-wbs-tree-expand-keys') || [])
  230. const treeProps = {
  231. children: 'children',
  232. label: 'title',
  233. isLeaf: ({ hasChildren, isExistForm, majorDataType, nodeType }) => {
  234. let tag = false
  235. if (!hasChildren) {
  236. tag = true
  237. }
  238. if (isExistForm === 1) {
  239. tag = true
  240. }
  241. if (nodeType >= 6 && nodeType <= 13) {
  242. tag = true
  243. }
  244. //中间交工。开工报告、质量评定)
  245. if (majorDataType >= 1 && majorDataType <= 3) {
  246. tag = true
  247. }
  248. return tag
  249. },
  250. }
  251. //树的右键菜单
  252. const treeMenus = [
  253. { icon: 'draft', label: '编辑节点', key: 'edit' },
  254. { icon: 'refresh', label: '同步新增元素表单', key: 'sync1' },
  255. { icon: 'loop-left', label: '同步元素表单排序到合同段', key: 'sync3' },
  256. { icon: 'loop-right', label: '同步节点基础信息及表单URL', key: 'sync2' },
  257. { icon: 'sort-asc', label: '调整排序', key: 'sort' },
  258. { icon: 'delete-bin', label: '删除节点', key: 'del' },
  259. ]
  260. //菜单被点击
  261. const treeMenuClick = ({ key, node, data, keys }) => {
  262. }
  263. //懒加载树
  264. const treeLoadNode = async ({ item, level }, resolve) => {
  265. let pid = level !== 0 ? item.id : 0
  266. const { data } = await wbsPrivateApi.getLazytree({
  267. wbsId: wbsId.value,
  268. parentId: pid,
  269. tenantId: store.tenantId,
  270. projectId: projectInfo.value.id,
  271. wbsType: isType.value,
  272. })
  273. resolve(getArrValue(data))
  274. }
  275. //节点信息
  276. const nodeTableColumn = ref([
  277. { key: 'nodeName', name: '当前节点', align: 'center' },
  278. { key: 'nodeType', name: '节点类型', align: 'center' },
  279. { key: 'parentName', name: '上级节点', align: 'center' },
  280. ])
  281. const nodeTableData = ref([])
  282. //节点被点击
  283. const treeItem = ref({})
  284. const treeNodeClick = ({ node, data, keys }) => {
  285. //获取父节点名称
  286. let parentName = ''
  287. if (node?.parent?.data) {
  288. parentName = node.parent.data.title ?? ''
  289. }
  290. data.parentName = parentName
  291. //设置相关数据
  292. treeItem.value = getObjValue(data)
  293. setStore('project-wbs-tree-expand-keys', keys)
  294. treeExpandKeys.value = getArrValue(keys)
  295. //获取节点详情
  296. getTreeDetail()
  297. getInfoTableData()
  298. }
  299. //获取节点详情
  300. const treeInfo = ref({})
  301. const getTreeDetail = async () => {
  302. const { id, parentName } = treeItem.value
  303. const { data } = await wbsPrivateApi.detail({
  304. id,
  305. wbsId: wbsId.value,
  306. projectId: projectInfo.value.id,
  307. })
  308. const res = getObjValue(data)
  309. res.parentName = parentName
  310. treeInfo.value = res
  311. nodeTableData.value = [res]
  312. }
  313. //当前项目信息表
  314. const infoTableLoading = ref(false)
  315. const infoTableColumn = ref([
  316. { key: 'tableName', name: '表单名称', align: 'center' },
  317. { key: 'elementTotal', name: '字段总量', align: 'center' },
  318. { key: 'fillRate', name: '填报率', align: 'center' },
  319. { key: 'tableType', name: '表单类型', align: 'center' },
  320. { key: 'tableOwner', name: '所属方', align: 'center' },
  321. { key: 'action', name: '操作', width: 160, align: 'center' },
  322. ])
  323. const infoTableData = ref([])
  324. const getInfoTableData = async () => {
  325. const { id } = treeItem.value
  326. infoTableLoading.value = true
  327. const { data } = await wbsPrivateApi.findNodeTableByCondition({
  328. parentId: id,
  329. wbsId: wbsId.value,
  330. projectId: projectInfo.value.id,
  331. })
  332. infoTableData.value = getArrValue(data)
  333. infoTableLoading.value = false
  334. }
  335. //当前项目信息表删除
  336. const delInfoTableRow = async (item) => {
  337. const { error, code, msg } = await wbsPrivateApi.removeTableByCondition({
  338. id: item.id,
  339. wbsId: wbsId.value,
  340. projectId: projectInfo.value.id,
  341. })
  342. if (!error && code === 200) {
  343. window.$message.success('删除成功')
  344. getInfoTableData().then()
  345. } else {
  346. window.$message.error(msg ?? '删除失败')
  347. }
  348. }
  349. //表单设置
  350. const isFormSet = ref(true)
  351. const infoTableColumn1 = ref([
  352. { key: 'tableName', name: '表单名称', align: 'center' },
  353. { key: 'tableType', name: '表单类型', align: 'center' },
  354. { key: 'fillRate', name: '填报率', align: 'center' },
  355. { key: 'isLinkTable', name: '是否关联清表', align: 'center' },
  356. { key: 'tableOwner', name: '所属方', align: 'center' },
  357. { key: 'action', name: '操作', width: 430, align: 'center' },
  358. ])
  359. const setIsFormSetValue = () => {
  360. isFormSet.value = !isFormSet.value
  361. if (isFormSet.value) {
  362. getTreeDetail()
  363. }
  364. getInfoTableData()
  365. }
  366. //数据同步按钮菜单
  367. const dataSyncMenu = [
  368. { key: 'jdSync', name: '节点参数同步', load:false },
  369. { key: 'dqSync', name: '电签同步', load:false },
  370. { key: 'gsSync', name: '公式同步', load:false },
  371. ]
  372. const dataSyncMenuClick = (item) => {
  373. console.log( item)
  374. }
  375. </script>
  376. <style scoped lang="scss">
  377. .hc-project-wbs-tree {
  378. position: relative;
  379. background: #ececec;
  380. border-radius: 4px;
  381. height: 100%;
  382. flex-direction: column;
  383. overflow: hidden;
  384. .header {
  385. color: white;
  386. background: #54565A;
  387. padding: 10px 14px;
  388. flex-shrink: 0;
  389. .name {
  390. white-space:nowrap;
  391. overflow:hidden;
  392. text-overflow:ellipsis;
  393. }
  394. }
  395. .body {
  396. flex: 1;
  397. flex-basis: auto;
  398. position: relative;
  399. }
  400. }
  401. </style>
  402. <style lang="scss">
  403. .hc-project-wbs-tree .body {
  404. .el-card.hc-card-box {
  405. --el-card-padding: 12px;
  406. --el-card-border-radius: 5px;
  407. }
  408. .hc-page-split-content {
  409. position: relative;
  410. .body-top {
  411. position: relative;
  412. height: 119.5px;
  413. }
  414. .body-content {
  415. position: relative;
  416. margin-top: 10px;
  417. height: calc(100% - 129.5px);
  418. }
  419. }
  420. }
  421. </style>