el-select 嵌入tree

场景:【用户管理】开始是: 部门选择在左边,选择某个部门,右边查询出的数据为该部门下

           但是: 这里的用户数据是所有的,部门只在某个应用下才有的

点击左边选择部门

改为下拉选择,物流平台时,显示部门下拉选择

最后结果:

<template>
<!-- 当所属应用是平台时 -->
          <el-select v-if="/platform/.test(listQuery.applicationKeyEqualTo)" v-model="deptName" placeholder="所属部门">
            <el-option :value="deptsValue" style="height: auto">
              <el-tree
                ref="tree1"
                node-key="id"
                :data="deptsList"
                default-expand-all
                show-checkbox
                check-strictly
                :props="defaultProps"
                :expand-on-click-node="false"
                highlight-current
                :filter-node-method="filterNode"
                @check="deptNodeClick"
              />
            </el-option>
          </el-select>
</template>
<script>
export default {
  data() {
    return {
         deptName: '',
         deptsValue: [],
         deptsList: [],
    },
    methods: {
    getDepts() {   // 对tree数据的组装回调
      reqForGet({}, `/auth/dept/alldept_tree`).then(response => {
        this.deptsList = []
        if (response.data !== undefined && response.data.length > 0) {
          const oldData = response.data
          for (let i = 0; i < oldData.length; i++) {
            const current = oldData[i]
            this.deptsList.push({ id: current.id, name: current.deptName, leaf: current.children.length === 0, children: [] })
            if (current.children.length > 0) {
              createData(current.children, this.deptsList[i]['children'])
            }
          }
        }
      })
      function createData(data, data1) {
        for (let i = 0; i < data.length; i++) {
          const current = data[i]
          data1.push({ id: current.id, name: current.deptName, leaf: current.children.length === 0 })
          data1[i]['children'] = []
          if (current.children !== null && current.children.length > 0) {
            createData(current.children, data1[i]['children'])
          }
        }
      }
    },
 deptNodeClick(data) {
      this.$refs.tree1.setCheckedNodes([{
        id: data.id,
        label: data.name
      }])
      this.deptsValue = [data]
      this.deptName = data.name
      this.listQuery.deptId = data.id
    },
    }
  }
}
</script>

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值