级联选择器--选择了上级就不能选择下级

orgChange(itemIndex,everyIndex,e){
      console.log(itemIndex,everyIndex,e)
      this.$nextTick(()=>{
        // console.log(this.$refs[`${itemIndex}cascaderOrgg${everyIndex}`],"节点")
        // console.log(this.$refs[`${itemIndex}cascaderOrgg${everyIndex}`][0].getCheckedNodes())
      })
      let list = this.linkSetting.recordProcessList[this.digit].processStepDetailDtoList[itemIndex].processStepExcuteConditionList[everyIndex].list
      let checkResult = this.linkSetting.recordProcessList[this.digit].processStepDetailDtoList[itemIndex].processStepExcuteConditionList[everyIndex].checkResult
      const selectedOption = this.getOptionByValue(e[0],list); // 获取当前选中节点对应的选项对象
      console.log(selectedOption,"selectedOption")
      if (selectedOption && selectedOption.childrenList) {
        //如果匹配到了,则禁用节点
        console.log("走的第一个")
        let fun = (arrList)=>{
          arrList.forEach(child => {
            this.$set(child,'disabled',true)
            if(child.childrenList){
              fun(child.childrenList)
            }
          });
        }
        fun(selectedOption.childrenList)
      }else{
        //如果没有匹配到,则取消节点的禁用
        console.log("走的第二个")
        list.forEach((item,index)=>{
          this.$set(item,'disabled',false)
          let fun2 = (arr)=>{
            arr.forEach((ele,eleIndex)=>{
              this.$set(ele,'disabled',false)
              if(ele.childrenList){
                fun2(ele.childrenList)
              }
            })
          }
          if(item.childrenList && item.childrenList.length){
            fun2(item.childrenList)
          }
        })
      }
      //先选下级再选上级,选了上级之后要删除调上次选的下级
      if (this.lastSelectedOption && selectedOption && selectedOption.level < this.lastSelectedOption.level) {
        console.log(this.lastSelectedOption,"this.lastSelectedOption")
        console.log(selectedOption.level,"selectedOption.level")
        console.log(this.lastSelectedOption.level,"this.lastSelectedOption.level")
        // 如果当前选中节点的层级比上一次选中节点的层级小,则清空已选中的下级节点
        const lastSelectedValue = this.lastSelectedOption.orgId;
        const valueIndex = e.indexOf(lastSelectedValue);
        console.log(valueIndex,"valueIndex第几个")
        console.log(checkResult,"checkResult前")
        checkResult =checkResult.splice(valueIndex,1);
        console.log(checkResult,"checkResult")
      }
      this.lastSelectedOption = selectedOption; // 保存当前选中的选项对象
    },
    // 根据值找到对应的选项对象
    getOptionByValue(value,list) {
      let targetOption = null;
      const findOption = (options) => {
        options.some(option => {
          if (option.orgId === value) {
            targetOption = option;
            return true;
          }
          if (option.childrenList) {
            return findOption(option.childrenList);
          }
          return false;
        });
      };
      findOption(list);
      return targetOption;
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值