Element 两颗树tree(一颗单选 一颗多选) 互斥选择

前言

在开发过程中,我们遇见流程审批,有些流程需要发送给不同部门人员,这里我使用的是树形结构进行人员选择,一颗为单选,一颗为多选,只能选择其中一条流程往下继续执行,请看演示视频

Video_2023-04-13_110320


html代码如下

	<div class="childTasks">
        <div v-for="(item, index) in approverList" :key="index">
          <p>{{ item.key }}</p>
          <el-tree v-if="item.status === '0'" :ref="item.nodeId" class="treeRadio" :data="item.treeList" show-checkbox check-strictly node-key="id" @check="handleClick($event,item)" />
          <el-tree v-else-if="item.status === '1'" :ref="item.nodeId" show-checkbox :data="item.treeList" node-key="id" @check="handleClick($event,item)" />
        </div>
    </div>

示例数据如下

 	approverList: [
        {
          key: "部门审批",
          nodeId: "department",
          status: "0",
          treeList: [
            {
              id: 1,
              label: "部门一",
              children: [
                {
                  id: 2,
                  label: "张三"
                },
                {
                  id: 3,
                  label: "李四"
                }
              ]
            },
            {
              id: 4,
              label: "部门二",
              children: [
                {
                  id: 5,
                  label: "王五"
                },
                {
                  id: 6,
                  label: "孙六"
                },
                {
                  id: 7,
                  label: "张八"
                },
                {
                  id: 8,
                  label: "小明"
                },
                {
                  id: 9,
                  label: "小谢"
                }
              ]
            }
          ]
        },
        {
          key: "领导审批",
          nodeId: "lead",
          status: "1",
          treeList: [
            {
              id: 10,
              label: "部门一",
              children: [
                {
                  id: 11,
                  label: "领导一"
                }
              ]
            },
            {
              id: 12,
              label: "部门二",
              children: [
                {
                  id: 13,
                  label: "领导二"
                },
                {
                  id: 14,
                  label: "领导三"
                }
              ]
            }
          ]
        }
      ],

处理函数如下

 	handleClick(data, item) {
 		const personList = []
     	if (item.status === '0') {
       		this.$refs[item.nodeId][0].setCheckedKeys([]); // 删除所有选中节点
        	this.$refs[item.nodeId][0].setCheckedNodes([data]); // 选中已选中节点
      	}	
      	personList = this.$refs[item.nodeId][0].getCheckedKeys(true)
      	this.approverList.forEach((e) => {
        	if (e.nodeId !== item.nodeId) {
          		e.nextUserIds = []
          		this.$refs[e.nodeId][0].setCheckedKeys([]);
        	}
      	})
      	return personlist
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值