LeftChecklist.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <div class="content-container">
  3. <div class="tool-bar">
  4. <div class="content-title">
  5. <i class="el-icon-document-checked" /> 清单列表
  6. </div>
  7. </div>
  8. <div class="content-body">
  9. <vuescroll :ops="ops">
  10. <el-tree
  11. ref="leftChecklist"
  12. node-key="checklistId"
  13. :data="treeData"
  14. :expand-on-click-node="false"
  15. :default-expand-all="true"
  16. :props="defaultProps"
  17. :highlight-current="true"
  18. :default-expanded-keys="expandDefault"
  19. @node-click="handleNodeClick"
  20. />
  21. </vuescroll>
  22. </div>
  23. </div>
  24. </template>
  25. <script>
  26. import Vuescroll from 'vuescroll'
  27. import { getChecklistByList } from '@/api/system/checklistApi'
  28. export default {
  29. components: {
  30. Vuescroll
  31. },
  32. data() {
  33. return {
  34. ops: {
  35. bar: {
  36. keepShow: false,
  37. background: 'rgba(144, 147, 153, 0.4)',
  38. onlyShowBarOnScroll: false
  39. }
  40. },
  41. listLoading: false,
  42. treeData: [],
  43. defaultProps: {
  44. children: 'children',
  45. label: 'checklistTitle'
  46. },
  47. expandDefault: [],
  48. checkDefault: [],
  49. conditions: {
  50. checklistCatId: 3
  51. }
  52. }
  53. },
  54. watch: {
  55. checkDefault(val) {
  56. this.$nextTick(() => {
  57. document.querySelector('.el-tree-node__content').click()
  58. })
  59. }
  60. },
  61. mounted() {
  62. this.getData()
  63. },
  64. methods: {
  65. getData() {
  66. this.listLoading = true
  67. getChecklistByList(this.conditions).then((resp) => {
  68. this.listLoading = false
  69. const { code, data, msg } = resp
  70. if (code === 200) {
  71. this.treeData = data
  72. if (data.length > 0) {
  73. const node = data[0]
  74. this.handleTreeInit(node)
  75. this.checkDefault.push(node.checklistId)
  76. }
  77. } else {
  78. this.$message.error(msg)
  79. }
  80. }).catch((error) => {
  81. console.log(error)
  82. })
  83. },
  84. clickItem(event, data) {
  85. this.$contextmenu({
  86. items: [
  87. ],
  88. event,
  89. // x: event.clientX,
  90. // y: event.clientY,
  91. customClass: 'class-a',
  92. zIndex: 3,
  93. minWidth: 230
  94. })
  95. return false
  96. },
  97. handleNodeClick(data) {
  98. this.$emit('selectItem', data.checklistId)
  99. },
  100. handleTreeInit(data) {
  101. this.$emit('treeInit', data)
  102. }
  103. }
  104. }
  105. </script>
  106. <style lang="scss" scoped>
  107. .content-container {
  108. height: calc(100vh - 90px);
  109. .content-body {
  110. margin-top: 20px;
  111. .custom-tree-node {
  112. position: relative;
  113. width: 100%;
  114. .right-icon {
  115. position: absolute;
  116. right: 10px;
  117. top: 14px;
  118. background: #5181A2;
  119. color: #FFFFFF;
  120. width: 14px;
  121. height: 14px;
  122. border: 1px solid #3D6F91;
  123. line-height: 14px;
  124. font-size: 10px;
  125. display: none;
  126. cursor: pointer;
  127. .icon {
  128. position: relative;
  129. top: -2px;
  130. }
  131. }
  132. &:hover {
  133. .right-icon {
  134. display: block;
  135. }
  136. }
  137. }
  138. }
  139. }
  140. </style>