el-tree懒加载,并加入搜索功能(后台搜)

},
computed: {},
watch: {
gettreeData(val) {}
//设置输入框输入时自动过滤,无需点击搜索按钮
// filterText(val) {
// this.KaTeX parse error: Expected 'EOF', got '}' at position 31: …r(val); // }̲ }, methods…message.error(res.data.msg);
}
})
.catch(() => {
let data = [];
return resolve(data);
});
} else {
this.isthis = 1;
this.treedata = [];
SEARCH({ searchName: this.filterText }).then(res => {
console.log(res);
this.treedata = res.data.data;
});
}
},
//查询
search() {
this.commonSearch();
},
//enter
submit() {
this.commonSearch();
},

commonSearchT(val, resolve) {
  // 查找顶级对象
  searchPvtree(val)
    .then(res => {
      if (res.data.success) {
        return resolve(res.data.data);
      } else {
        this.$message.error(res.data.msg);
      }
    })
    .catch(() => {
      console.log("错误");
      let data = [];
      return resolve(data);
    });
},
// 加载树结点
loadNode(node, resolve) {
  // isthis为0则调取全searchPvtree
  if (this.isthis == 0) {
    // 如果是顶级的父节点
    if (node.level === 0) {
      let paraobj = { level: "0" };
      this.commonSearchT(paraobj, resolve);
    } else {
      if (node.data.PARENTID) {
        let paraobj = {
          oid: node.data.OID.toString(),
          level: node.level.toString(),
          parentId: node.data.PARENTID
        };
        this.commonSearchT(paraobj, resolve);
      }
      else{
      // 根据父节点id找寻下一级的所有节点
      let paraobj = {
        oid: node.data.OID.toString(),
        level: node.level.toString()
      };
      this.commonSearchT(paraobj, resolve);
      }
    }
  } else {
    // isthis为1则不调取
    let data = [];
    return resolve(data);
  }
},
//实现单选
setSelectedNode(data, obj) {
  console.log(data.LABEL, data);
  var that = this;
  //最下一级有字段ISLEAF
  //加一层判断必须要有checktype才允许校验
  if (data.CHECKTYPE) {
    console.log(99);
    this.oid = data.OID; //用于搜索部门列表
    this.label = data.LABEL;
    this.checktype = data.CHECKTYPE;
    this.setDkxoid(this.oid); //设置修改大块线oid,只有当他不为空是才赋值发生值改变
    this.setLabel(this.label);
    this.setchecktype(this.checktype);
  } else {
    this.setchecktype("");
    this.setDkxoid(""); //设置修改大块线oid,只有当他不为空是才赋值发生值改变
  }
},
//树的获取设置操作
getCheckedNodes() {
  // console.log(this.$refs.tree.getCheckedNodes());
},
getCheckedKeys() {
  // console.log(this.$refs.tree.getCheckedKeys());
},
setCheckedNodes() {
  this.$refs.tree.setCheckedNodes([
    {
      id: 5,
      label: "二级 2-1"
    },
    {
      id: 8,
      label: "二级 3-2"
    }
  ]);
},
setCheckedKeys() {
  this.$refs.tree.setCheckedKeys([13]);
},
resetChecked() {
  this.$refs.tree.setCheckedKeys([]);
},
//数内容筛选
filterNode(value, data) {
  if (!value) return true;
  return data.LABEL.indexOf(value) !== -1;
}

}
};

发布了19 篇原创文章 · 获赞 4 · 访问量 1515
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览