index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <a-card title="部门">
  3. <div slot="extra" class="drawer-bootom-button">
  4. <a-dropdown :trigger="['click']" placement="topCenter">
  5. <a-menu slot="overlay">
  6. <a-menu-item key="5" @click="expandAll">展开所有</a-menu-item>
  7. <a-menu-item key="6" @click="closeAll">合并所有</a-menu-item>
  8. </a-menu>
  9. <a-button>
  10. 树操作
  11. <a-icon type="up" />
  12. </a-button>
  13. </a-dropdown>
  14. </div>
  15. <div style="background: #fff;">
  16. <a-col :md="10" :sm="24">
  17. <template>
  18. <a-tree
  19. :show-line="true"
  20. :selected-keys="selectedKeys"
  21. :tree-data="treeData"
  22. :check-strictly="checkStrictly"
  23. :expanded-keys="iExpandedKeys"
  24. :auto-expand-parent="autoExpandParent"
  25. @select="onSelect"
  26. @expand="onExpand"
  27. :replaceFields="{children:'children', title:'label', key:'id', value: 'id' }"
  28. />
  29. </template>
  30. </a-col>
  31. </div>
  32. </a-card>
  33. </template>
  34. <script>
  35. import { getAction } from '@/api/request'
  36. export default {
  37. name: 'LeftTree',
  38. components: {},
  39. data() {
  40. return {
  41. iExpandedKeys: [100],
  42. loading: false,
  43. autoExpandParent: true,
  44. treeData: [],
  45. hiding: true,
  46. selectedKeys: [],
  47. currSelected: {},
  48. allTreeKeys: [],
  49. checkStrictly: true,
  50. url: {
  51. tree: '/system/dept/treeSelect'
  52. },
  53. orgCategoryDisabled: false
  54. }
  55. },
  56. computed: {},
  57. created() {
  58. this.loadTree()
  59. },
  60. methods: {
  61. loadData() {
  62. this.refresh()
  63. },
  64. loadTree() {
  65. var that = this
  66. that.treeData = []
  67. getAction(this.url.tree).then((res) => {
  68. if (res.code === 200) {
  69. // 部门全选后,再添加部门,选中数量增多
  70. this.allTreeKeys = []
  71. for (let i = 0; i < res.data.length; i++) {
  72. const temp = res.data[i]
  73. that.treeData.push(temp)
  74. that.setThisExpandedKeys(temp)
  75. that.getAllKeys(temp)
  76. }
  77. this.loading = false
  78. }
  79. })
  80. },
  81. setThisExpandedKeys(node) {
  82. if (node.children && node.children.length > 0) {
  83. this.iExpandedKeys.push(node.key)
  84. for (let a = 0; a < node.children.length; a++) {
  85. this.setThisExpandedKeys(node.children[a])
  86. }
  87. }
  88. },
  89. refresh() {
  90. this.loading = true
  91. this.loadTree()
  92. },
  93. onExpand(expandedKeys) {
  94. console.log('onExpand', expandedKeys)
  95. this.iExpandedKeys = expandedKeys
  96. this.autoExpandParent = false
  97. },
  98. onSelect(selectedKeys, e) {
  99. console.log('selected', selectedKeys, e)
  100. this.hiding = false
  101. const record = e.node.dataRef
  102. console.log('onSelect-record', record)
  103. this.currSelected = Object.assign({}, record)
  104. this.selectedKeys = [record.key]
  105. this.$emit('selected', this.currSelected)
  106. },
  107. onClearSelected() {
  108. this.hiding = true
  109. this.currSelected = {}
  110. this.selectedKeys = []
  111. },
  112. // ---- author:os_chengtgen -- date:20190827 -- for:切换父子勾选模式 =======------
  113. expandAll() {
  114. this.iExpandedKeys = this.allTreeKeys
  115. },
  116. closeAll() {
  117. this.iExpandedKeys = []
  118. },
  119. getAllKeys(node) {
  120. this.allTreeKeys.push(node.id)
  121. if (node.children && node.children.length > 0) {
  122. for (let a = 0; a < node.children.length; a++) {
  123. this.getAllKeys(node.children[a])
  124. }
  125. }
  126. }
  127. // ---- author:os_chengtgen -- date:20190827 -- for:切换父子勾选模式 =======------
  128. }
  129. }
  130. </script>
  131. <style lang="less" scoped>
  132. .ant-card {
  133. height: 100%;
  134. /deep/ .ant-card-head {
  135. padding: 0 15px;
  136. /deep/ .ant-card-head-title, /deep/ .ant-card-extra {
  137. padding: 10px 0;
  138. }
  139. }
  140. /deep/ .ant-card-body {
  141. padding: 10px;
  142. height: calc(100vh - 260px);
  143. overflow: auto;
  144. }
  145. }
  146. </style>