people.js
1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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)
}
}
})