people.js 1.27 KB
Component({
	properties:{
		seller:Object,
		//人数
		count:{
			type:Number,
			value:6
		},
	},
	data:{
		current:0
	},
	attached(){
		let peoplelist=[]
		for(let i=0;i<Math.ceil((30-4)/3);i++){
			peoplelist.push({
				list:[]
			})
		}
		for(let i=4;i<=30;i++){
			let thiscurrent=Math.floor((i-4)/3);
			peoplelist[thiscurrent]['list'].push({
				count:i,
				isactive:false
			})
			
		}
		this.setData({
			peoplelist:peoplelist
		})
	},
	ready(){
		this.editpeoplelist(this.data.count);
		this.triggerEvent('selectpeople',{people:this.data.count,action:'defalut'});
	},
	methods:{
		selectpeople(e){
			const target=e.currentTarget.dataset;
			this.setData({
				current:target.idx
			})
			this.editpeoplelist(target.count);
			this.triggerEvent('selectpeople',{people:target.count,action:'click'});
		},
		editpeoplelist(count){
			let peoplelist=this.data.peoplelist,setdata={};
			peoplelist.forEach((r,n)=>{
				r.list.forEach((v,i)=>{
					if(v.isactive){
						v.isactive=false;
						let setprevkey='peoplelist['+n+'].list['+i+'].isactive';
						setdata[setprevkey]=false;
					}
					if(v.count==count && !v.isactive){
						let setcurrentkey='peoplelist['+n+'].list['+i+'].isactive';
						setdata[setcurrentkey]=true;
					}
				})
				
			})
			this.setData(setdata)
		}
	}
})