index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. :selected-keys="selectedKeys"
  20. :checked-keys="checkedKeys"
  21. :tree-data="departTree"
  22. :check-strictly="checkStrictly"
  23. :expanded-keys="iExpandedKeys"
  24. :auto-expand-parent="autoExpandParent"
  25. @select="onSelect"
  26. @check="onCheck"
  27. @expand="onExpand"
  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: [],
  42. loading: false,
  43. autoExpandParent: true,
  44. currFlowId: '',
  45. currFlowName: '',
  46. treeData: [],
  47. departTree: [],
  48. hiding: true,
  49. checkedKeys: [],
  50. selectedKeys: ['1'],
  51. currSelected: {},
  52. allTreeKeys: [],
  53. checkStrictly: true,
  54. url: {
  55. tree: '/system/sjConfigProcess/queryTreeList'
  56. },
  57. orgCategoryDisabled: false
  58. }
  59. },
  60. computed: {},
  61. created() {
  62. this.currFlowId = this.$route.params.id
  63. this.currFlowName = this.$route.params.name
  64. // this.loadTree()
  65. },
  66. methods: {
  67. loadData() {
  68. this.refresh()
  69. },
  70. loadTree() {
  71. var that = this
  72. that.treeData = []
  73. that.departTree = []
  74. getAction(this.url.tree).then((res) => {
  75. if (res.success) {
  76. // 部门全选后,再添加部门,选中数量增多
  77. this.allTreeKeys = []
  78. for (let i = 0; i < res.result.length; i++) {
  79. const temp = res.result[i]
  80. that.treeData.push(temp)
  81. that.departTree.push(temp)
  82. that.setThisExpandedKeys(temp)
  83. that.getAllKeys(temp)
  84. // console.log(temp.id)
  85. }
  86. this.loading = false
  87. }
  88. })
  89. },
  90. setThisExpandedKeys(node) {
  91. if (node.children && node.children.length > 0) {
  92. this.iExpandedKeys.push(node.key)
  93. for (let a = 0; a < node.children.length; a++) {
  94. this.setThisExpandedKeys(node.children[a])
  95. }
  96. }
  97. },
  98. refresh() {
  99. this.loading = true
  100. this.loadTree()
  101. },
  102. onExpand(expandedKeys) {
  103. console.log('onExpand', expandedKeys)
  104. this.iExpandedKeys = expandedKeys
  105. this.autoExpandParent = false
  106. },
  107. nodeModalOk() {
  108. this.loadTree()
  109. },
  110. nodeModalClose() {
  111. },
  112. onCheck(checkedKeys, info) {
  113. console.log('onCheck', checkedKeys, info)
  114. this.hiding = false
  115. // ---- author:os_chengtgen -- date:20190827 -- for:切换父子勾选模式 =======------
  116. if (this.checkStrictly) {
  117. this.checkedKeys = checkedKeys.checked
  118. } else {
  119. this.checkedKeys = checkedKeys
  120. }
  121. // ---- author:os_chengtgen -- date:20190827 -- for:切换父子勾选模式 =======------
  122. },
  123. onSelect(selectedKeys, e) {
  124. console.log('selected', selectedKeys, e)
  125. this.hiding = false
  126. const record = e.node.dataRef
  127. console.log('onSelect-record', record)
  128. this.currSelected = Object.assign({}, record)
  129. this.selectedKeys = [record.key]
  130. this.$emit('selected', this.currSelected)
  131. },
  132. getCurrSelectedTitle() {
  133. return !this.currSelected.title ? '' : this.currSelected.title
  134. },
  135. onClearSelected() {
  136. this.hiding = true
  137. this.checkedKeys = []
  138. this.currSelected = {}
  139. this.selectedKeys = []
  140. this.$refs.departAuth.departId = ''
  141. },
  142. // ---- author:os_chengtgen -- date:20190827 -- for:切换父子勾选模式 =======------
  143. expandAll() {
  144. this.iExpandedKeys = this.allTreeKeys
  145. },
  146. closeAll() {
  147. this.iExpandedKeys = []
  148. },
  149. getAllKeys(node) {
  150. // console.log('node',node);
  151. this.allTreeKeys.push(node.key)
  152. if (node.children && node.children.length > 0) {
  153. for (let a = 0; a < node.children.length; a++) {
  154. this.getAllKeys(node.children[a])
  155. }
  156. }
  157. }
  158. // ---- author:os_chengtgen -- date:20190827 -- for:切换父子勾选模式 =======------
  159. }
  160. }
  161. </script>
  162. <style lang="less" scoped>
  163. .ant-card {
  164. height: 100%;
  165. /deep/ .ant-card-head {
  166. padding: 0 15px;
  167. /deep/ .ant-card-head-title, /deep/ .ant-card-extra {
  168. padding: 10px 0;
  169. }
  170. }
  171. /deep/ .ant-card-body {
  172. padding: 10px;
  173. height: calc(100vh - 225px);
  174. overflow: auto;
  175. }
  176. }
  177. </style>