| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <template>
- <a-card title="部门">
- <div slot="extra" class="drawer-bootom-button">
- <a-dropdown :trigger="['click']" placement="topCenter">
- <a-menu slot="overlay">
- <a-menu-item key="5" @click="expandAll">展开所有</a-menu-item>
- <a-menu-item key="6" @click="closeAll">合并所有</a-menu-item>
- </a-menu>
- <a-button>
- 树操作
- <a-icon type="up" />
- </a-button>
- </a-dropdown>
- </div>
- <div style="background: #fff;">
- <a-col :md="10" :sm="24">
- <template>
- <a-tree
- :show-line="true"
- :selected-keys="selectedKeys"
- :tree-data="treeData"
- :check-strictly="checkStrictly"
- :expanded-keys="iExpandedKeys"
- :auto-expand-parent="autoExpandParent"
- @select="onSelect"
- @expand="onExpand"
- :replaceFields="{children:'children', title:'label', key:'id', value: 'id' }"
- />
- </template>
- </a-col>
- </div>
- </a-card>
- </template>
- <script>
- import { getAction } from '@/api/request'
- export default {
- name: 'LeftTree',
- components: {},
- data() {
- return {
- iExpandedKeys: [100],
- loading: false,
- autoExpandParent: true,
- treeData: [],
- hiding: true,
- selectedKeys: [],
- currSelected: {},
- allTreeKeys: [],
- checkStrictly: true,
- url: {
- tree: '/system/dept/treeSelect'
- },
- orgCategoryDisabled: false
- }
- },
- computed: {},
- created() {
- this.loadTree()
- },
- methods: {
- loadData() {
- this.refresh()
- },
- loadTree() {
- var that = this
- that.treeData = []
- getAction(this.url.tree).then((res) => {
- if (res.code === 200) {
- // 部门全选后,再添加部门,选中数量增多
- this.allTreeKeys = []
- for (let i = 0; i < res.data.length; i++) {
- const temp = res.data[i]
- that.treeData.push(temp)
- that.setThisExpandedKeys(temp)
- that.getAllKeys(temp)
- }
- this.loading = false
- }
- })
- },
- setThisExpandedKeys(node) {
- if (node.children && node.children.length > 0) {
- this.iExpandedKeys.push(node.key)
- for (let a = 0; a < node.children.length; a++) {
- this.setThisExpandedKeys(node.children[a])
- }
- }
- },
- refresh() {
- this.loading = true
- this.loadTree()
- },
- onExpand(expandedKeys) {
- console.log('onExpand', expandedKeys)
- this.iExpandedKeys = expandedKeys
- this.autoExpandParent = false
- },
- onSelect(selectedKeys, e) {
- console.log('selected', selectedKeys, e)
- this.hiding = false
- const record = e.node.dataRef
- console.log('onSelect-record', record)
- this.currSelected = Object.assign({}, record)
- this.selectedKeys = [record.key]
- this.$emit('selected', this.currSelected)
- },
- onClearSelected() {
- this.hiding = true
- this.currSelected = {}
- this.selectedKeys = []
- },
- // ---- author:os_chengtgen -- date:20190827 -- for:切换父子勾选模式 =======------
- expandAll() {
- this.iExpandedKeys = this.allTreeKeys
- },
- closeAll() {
- this.iExpandedKeys = []
- },
- getAllKeys(node) {
- this.allTreeKeys.push(node.id)
- if (node.children && node.children.length > 0) {
- for (let a = 0; a < node.children.length; a++) {
- this.getAllKeys(node.children[a])
- }
- }
- }
- // ---- author:os_chengtgen -- date:20190827 -- for:切换父子勾选模式 =======------
- }
- }
- </script>
- <style lang="less" scoped>
- .ant-card {
- height: 100%;
- /deep/ .ant-card-head {
- padding: 0 15px;
- /deep/ .ant-card-head-title, /deep/ .ant-card-extra {
- padding: 10px 0;
- }
- }
- /deep/ .ant-card-body {
- padding: 10px;
- height: calc(100vh - 260px);
- overflow: auto;
- }
- }
- </style>
|