下拉选择 多选 手动加一个全选

下拉选择 多选 手动加一个全选

data(){
	retunrn{
		selectAll:false,
		selectNumber:0,
		formValidate: {内容未写}
	}
}
studentChange(e){
      if(this.selectNumber != this.formValidate.studentIdList.length){
        const isAll = e.findIndex((item)=>{
          return item =="all"
        });
        // 选中all 且 未全选之前    目标:选中所有
        if(isAll != -1 && ! this.selectAll ){
          this.selectAll = true;
          const studentIdList = this.userList.map(item=>{
            return item.value
          })
          this.formValidate.studentIdList = studentIdList;
        }else if(this.selectAll && isAll==-1){
        // 选中all 且 已全选    目标:取消所有
          this.selectAll = false;
          this.formValidate.studentIdList = [];
        }else if(isAll!=-1){
          this.selectAll = false;
          this.formValidate.studentIdList.splice(isAll,1)
          // console.log(ss,"ss")
          // 已全选  点击all以外的  删掉all
        }else if(isAll==-1&&e.length==this.userList.length-1){
          // 单独选中所有的项,达到全选效果
          this.selectAll = true;
          this.formValidate.studentIdList.unshift('all')
          // console.log(this.formValidate.studentIdList,"33333")
        }else{
          // console.log(';;;;;')
        }
        this.selectNumber = this.formValidate.studentIdList.length
      }
      else{
      }
    },

你可能感兴趣的:(前端,javascript)