JS+Vue实现三级全选单选

发布时间:2022-11-13 16:30

本文实例为大家分享了JS+Vue实现三级全选单选的具体代码,供大家参考,具体内容如下

JS+Vue实现三级全选单选_第1张图片

HTML

需求分类
全选
{{ itns.name }}
{{ cd.name }}

js

data () {
    classiFications: [], //需求分类 接口给的集合
    demandChecked: false, // 需求分类全选
    ficationsCheck: [], //一级分类的单个全选
    childrenCheck: [], //二级分类的全选
    demandCheckedShow: false, //二级全选不触发接口
}
 
methods: {
    // 需求分类全选
    handledemandChecked() {
        
        if (this.demandChecked) {
            this.classiFications.forEach((it, is) => {
            this.ficationsCheck[is] = true;
            this.handleFicationsCheck(is);
            });
        } else {
            this.classiFications.forEach((it, is) => {
            this.ficationsCheck[is] = false;
            this.handleFicationsCheck(is);
            });
        }
        },
        //一级分类所选
        async handleFicationsCheck(id) {
        
        this.demandCheckedShow = true;
        let tmp = this.classiFications[id].childrenIds; //当前选择的id子集合
        let tmpAdd = this.childrenCheck; //当前选择的id子集合
        if (this.ficationsCheck[id]) {
            tmp.forEach((item) => {
            for (let i = 0; i < tmp.length; i++) {
                if (tmpAdd.indexOf(item) === -1) {
                this.childrenCheck.push(item);
                }
            }
            });
        } else {
            tmp.forEach((item) => {
            for (let i = 0; i < tmp.length; i++) {
                if (tmpAdd.indexOf(item) !== -1) {
                this.childrenCheck.splice(this.childrenCheck.indexOf(item), 1);
                }
            }
            });
        }
        // this.handleType();
        this.currentPage = 0;
        await this.initSolutionAllPage();
        this.demandCheckedShow = false;
        },
        //二级分类所选
        handlechildrenCheck(ids, cd) {
      
        console.log(cd);
        let cont = 0;
        // let conts = 0;
        let tmp = this.classiFications[ids].childrenIds; //当前选择的id子集合
        let tmpAdd = this.childrenCheck; //当前选择的id子集合
        if (this.ficationsCheck[ids]) {
            tmp.forEach((item) => {
            for (let i = 0; i < tmp.length; i++) {
                if (tmpAdd.indexOf(item) === -1) {
                this.ficationsCheck[ids] = false;
                }
            }
            });
        } else {
            let tmpl = tmp.length === 1 ? 1 : tmp.length - 1;
            tmp.forEach((item) => {
            for (let i = 0; i < tmpl; i++) {
                if (tmpAdd.indexOf(item) !== -1) {
                // console.log(item);
                cont = cont + 1;
                }
            }
            });
            if (cont === this.classiFications[ids].childrenIds.length) {
            this.ficationsCheck[ids] = true;
            }
        }
        // this.handleType();
        if (!this.demandCheckedShow) {
            this.currentPage = 0;
            this.initSolutionAllPage();
        }
    },
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

ItVuer - 免责声明 - 关于我们 - 联系我们

本网站信息来源于互联网,如有侵权请联系:561261067@qq.com

桂ICP备16001015号