filter-group.js
3.86 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// components/2.0/filter/filter-group.js
import DA from '../../../pages/reserve/data';
import util from '../../../utils/util'
Component({
/**
* 组件的属性列表
*/
properties: {
height:Number,
disabled:Boolean,
filterParams:Object,//人均过滤初始值
},
/**
* 组件的初始数据
*/
data: {
multiArray: ['全部菜系'],
multiIndex: [0],
tags: [
{id: 1, name: '环境好'},
{id: 2, name: '菜品有特色'},
{id: 3, name: '超大包间'},
],
caixiOpened:false,
filterOpened:false,
},
attached(){
this.init()
this.filterParams= null
this.paramsData={}//过滤参数集合
setTimeout(()=>{
if(this.data.filterParams){
this.filterEvent({detail:{
type:'set',
data:this.data.filterParams,
}})
}
},0)
},
/**
* 组件的方法列表
*/
methods: {
async init(){
this.setData({
multiArray: [['全部菜系'].concat(await DA.getCates())]
})
this.filterParams= this.data.filterParams
},
caixiActive(e) {
console.log('caixiActive', e);
this.setData({
multiIndex: [e.detail]
})
if(e.detail>0){
DA.getCatesID(parseInt(e.detail) - 1).then(cuisine=>{
this.paramsData.cuisine=cuisine
this.eventPush()
})
}else{
this.paramsData.cuisine=""
this.eventPush()
}
this.hide()
},
caixiShow() {
if(this.data.multiArray[0].length==1){
return this.init()
}
if(this.data.disabled) return;
if(this.data.caixiOpened){
this.selectComponent('#caixi').hide();
this.setData({
caixiOpened:false,
})
}else{
this.selectComponent('#filter').hide();
this.selectComponent('#caixi').show();
this.setData({
caixiOpened:true,
filterOpened:false,
})
}
},
filterShow() {
if(this.data.disabled) return;
if(this.data.filterOpened){
this.selectComponent('#filter').hide();
this.setData({
filterOpened:false,
})
}else{
this.selectComponent('#caixi').hide();
this.selectComponent('#filter').show(this.filterParams);
this.setData({
filterOpened:true,
caixiOpened:false,
})
}
},
filterEvent(e) {
console.log('filterEvent', e)
if (e.detail.type == 'clean') {
this.filterParams = null
this.setData({
filterParams: null,
})
} else {
this.filterParams = e.detail.data
this.setData({
filterParams: this.filterParams,
})
}
this.paramsData.filterParams=this.filterParams
this.paramsData.average=""
if(this.filterParams){
let filterParams = this.filterParams.min + ',' + this.filterParams.max
if (this.filterParams.min == this.filterParams.max && this.filterParams.min == 300) {
filterParams = this.filterParams.min + ',' + parseInt(new Date() / 1000)
}
this.paramsData.average = filterParams
}
this.eventPush()
this.hide()
},
tagsChange(e) {
if(this.data.disabled) return;
let id = util.attr(e, 'id');
let tags = this.data.tags;
let tagsIds=[];
tags.forEach(t => {
if (t.id == id) {
t.active = !t.active
}
if (t.active) {
tagsIds.push(t.id)
}
})
this.setData({
tags:tags,
})
this.paramsData.tags=tagsIds.toString()
this.eventPush()
this.hide()
},
hide(){
this.selectComponent('#caixi').hide();
this.selectComponent('#filter').hide();
this.setData({
filterOpened:false,
caixiOpened:false,
})
},
eventPush(){
this.triggerEvent('event',this.paramsData);
},
}
})