picker多选 vant_vant的Picker 选择器

本文介绍如何利用Vant的Picker组件实现货物类型的多选功能,包括打开货物类型选择、根据选中值更新二级选项、确认选择后的处理以及取消选择的操作。同时,详细展示了获取货物类型数据并初始化组件数据的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//打开货物类型

columnsGoodsShow(){//console.log(this.suoyin1)

this.columnsgoods_show = true;//如果没有选中过就不走里面

if(this.suoyin1.length != 0){//通过索引拿到数据表中选中的二级类全部数据

let obj1 = this.columnsgoods[0].values[this.suoyin1[0]]//将当前选中的一级类数据和二级类数据赋值给数据表

this.columnsgoods= [{values: this.columnsgoods[0].values},{values: obj1.children}]this.$nextTick(function(){//通过索引在数据表中找到选中的那一项

this.$refs.ppkk.setIndexes(this.suoyin1)

})

}

},//改变货物类型

onChangegoods(picker, values,index) {//values会得到当前选中的一级和二级,因为一级下带有所有的二级,所以在children中找

picker.setColumnValues(1, values[0].children.filter(item =>item.text));

},//货物类型确认按钮

onConfirmgoods(value, index) {//console.log(value, index)

this.goodstypeval = value[0].text + '-' + value[1].text;this.CategoryParentID = value[0].id;//一级id

this.CategoryID = value[1].id;//二级id

this.columnsgoods_show = false;//将当前选中的索引存起来

this.suoyin1 =index;

},//选择货物类型取消按钮,这里如果没有别的操作可以把他写到行内v-on:cancel="columnsgoods_show = false"

onCancelgoods() {this.columnsgoods_show = false;

},//货物类型

async goodsCategory(){

let self= this;

await getCategoryList(1).then(msg =>{//console.log(msg.row_data.record,'1')

if (msg.status.code == 1) {this.goodstypelistsource = msg.row_data.record;//数据源

let ary = [{id:0,text:'不限',children:[{id:0,text:'不限'}]}];//初始化就有第一项不限

let source =msg.row_data.record;//console.log(source)

source.forEach(item =>{if(item.ParentID==0){

let obj={};

obj.id=item.CategoryID;

obj.text=item.CategoryName;

ary.push(obj);

}

});//第一项不限不循环

for(let i=1;i

let cur=ary[i];

ary[i].children= [{id:0,text:'不限'}];

source.forEach(item=>{if(item.ParentID ==cur.id){

let obj={};

obj.id=item.CategoryID;

obj.text=item.CategoryName;

ary[i].children.push(obj);

}

})

}this.goodstypelist =ary;

console.log(this.goodstypelist)this.columnsgoods= [{values:this.goodstypelist.filter(item => item.text)},{values:this.goodstypelist[0].children.filter(item => item.text)}];//货物类型数据和初始化

//console.log(this.columnsgoods)

}else{

self.$toast(msg.status.msg)return;

};

}).catch(msg =>{

console.log(msg)//self.$toast(msg)

})

},

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值