Blame view

src/components/sl-filter/sl-filter.vue 7.49 KB
e40e790a3   吉鹏   首页bug修改
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
  <template>
  	<view class="content">
  		<view :style="{height: tabHeight + 1 +'px'}">
  			<view :class="topFixed?'select-tab-fixed-top':'select-tab'" :style="{height: tabHeight+'px'}">
  				<view class="select-tab-item" :style="{width: itemWidth}" v-for="(item,index) in titleList" :key="index" @tap="showMenuClick(index)">
  					<text :style="{color:color}">{{item.title}}</text>
  					<text class="arrows sl-font" :class="statusList[index].isActive?up:down"></text>
  				</view>
  			</view>
  		</view>
  		<popup-layer ref="popupRef" :direction="'bottom'" @close="close" :isTransNav="isTransNav" :navHeight="navHeight"
  		 :tabHeight="tabHeight">
  			<sl-filter-view :ref="'slFilterView'" :independence="independence" :themeColor="themeColor" :menuList.sync="menuListTemp"
  			 ref="slFilterView" @confirm="filterResult"></sl-filter-view>
  		</popup-layer>
  	</view>
  
  </template>
  
  <script>
  	import popupLayer from '@/components/sl-filter/popup-layer.vue';
  	import slFilterView from '@/components/sl-filter/filter-view.vue';
  	export default {
  		components: {
  			popupLayer,
  			slFilterView
  		},
  		props: {
  			menuList: {
  				type: Array,
  				default () {
  					return []
  				}
  			},
  			themeColor: {
  				type: String,
  				default () {
  					return '#000000'
  				}
  			},
  			color: {
  				type: String,
  				default () {
  					return '#666666'
  				}
  			},
  			independence: {
  				type: Boolean,
  				default: false
  			},
  			isTransNav: {
  				type: Boolean,
  				default: false
  			},
  			navHeight: {
  				type: Number,
  				default: 0
  			},
  			topFixed: {
  				type: Boolean,
  				default: false
  			}
  		},
  
  		computed: {
  			itemWidth() {
  				return 'calc(100%/2)'
  			},
  			menuListTemp: {
  				get() {
  					return this.getMenuListTemp();
  				},
  				set(newObj) {
  					return newObj;
  				}
  			}
  		},
  		// #ifndef H5
  		onReady: function() {
  			let arr = [];
  			let titleArr = [];
  			let r = {};
  			for (let i = 0; i < this.menuList.length; i++) {
  				arr.push({
  					'isActive': false
  				});
  				// titleArr.push({
  				// 	'title': this.menuList[i].title,
  				// 	'key': this.menuList[i].key
  				// })
  
  				r[this.menuList[i].key] = this.menuList[i].title;
  
  				if (this.menuList[i].reflexTitle && this.menuList[i].defaultSelectedIndex > -1) {
  					titleArr.push({
  						'title': this.menuList[i].detailList[this.menuList[i].defaultSelectedIndex].title,
  						'key': this.menuList[i].key
  					})
  				} else {
  					titleArr.push({
  						'title': this.menuList[i].title,
  						'key': this.menuList[i].key
  					})
  				}
  
  			}
  			this.statusList = arr;
  			this.titleList = titleArr;
  			this.tempTitleObj = r;
  		},
  		// #endif
  
  		// #ifdef H5
  		created: function() {
  			let arr = [];
  			let titleArr = [];
  			let r = {};
  			for (let i = 0; i < this.menuList.length; i++) {
  				arr.push({
  					'isActive': false
  				});
  				// titleArr.push({
  				// 	'title': this.menuList[i].title,
  				// 	'key': this.menuList[i].key
  				// });
  				r[this.menuList[i].key] = this.menuList[i].title;
  
  				if (this.menuList[i].reflexTitle && this.menuList[i].defaultSelectedIndex > -1) {
  					titleArr.push({
  						'title': this.menuList[i].detailList[this.menuList[i].defaultSelectedIndex].title,
  						'key': this.menuList[i].key
  					})
  				} else {
  					titleArr.push({
  						'title': this.menuList[i].title,
  						'key': this.menuList[i].key
  					})
  				}
  
  			}
  			this.statusList = arr;
  			this.titleList = titleArr;
  			this.tempTitleObj = r;
  		},
  		// #endif
  		data() {
  			return {
  				down: 'sl-down',
  				up: 'sl-up',
  				tabHeight: 50,
  				statusList: [],
  				selectedIndex: '',
  				titleList: [],
  				tempTitleObj: {}
  			};
  		},
  		methods: {
  			getMenuListTemp() {
  				let arr = this.menuList;
  				for (let i = 0; i < arr.length; i++) {
  					let item = arr[i];
  					for (let j = 0; j < item.detailList.length; j++) {
  						let d_item = item.detailList[j];
  						if (j == 0) {
  							d_item.isSelected = true
  						} else {
  							d_item.isSelected = false
  						}
  					}
  				}
  				return arr;
  			},
  			// 重置所有选项,包括默认选项,并更新result
  			resetAllSelect(callback) {
  				this.$refs.slFilterView.resetAllSelect(function(e){
  					callback(e);
  				});
  			},
  			// 重置选项为设置的默认值,并更新result
  			resetSelectToDefault(callback) {
  				this.$refs.slFilterView.resetSelectToDefault(function(e){
  					callback(e);
  				});
  			},
  			resetMenuList(val) {
  				this.menuList = val;
  				this.$emit('update:menuList', val)
  				this.$forceUpdate();
  				this.$refs.slFilterView.resetMenuList(val)
  			},
  			showMenuClick(index) {
  				this.selectedIndex = index;
  				if (this.statusList[index].isActive == true) {
  					this.$refs.popupRef.close();
  					this.statusList[index].isActive = false
  				} else {
  					this.menuTabClick(index);
  					this.$refs.popupRef.show()
  				}
  			},
  			menuTabClick(index) {
  				this.$refs.slFilterView.menuTabClick(index);
  				for (let i = 0; i < this.statusList.length; i++) {
  					if (index == i) {
  						this.statusList[i].isActive = true;
  					} else {
  						this.statusList[i].isActive = false;
  					}
  				}
  			},
  			filterResult(obj) {
  				let val = obj.result;
  				let titlesObj = obj.titles;
  				// 处理选项映射到菜单title
  				if (this.independence) {
  					if (!this.menuList[this.selectedIndex].isMutiple || this.menuList[this.selectedIndex].isSort) {
  						let tempTitle = '';
  						for (let i = 0; i < this.menuList[this.selectedIndex].detailList.length; i++) {
  							let item = this.menuList[this.selectedIndex].detailList[i];
  							if (item.value == val[this.menuList[this.selectedIndex].key]) {
  								tempTitle = item.title;
  							}
  						}
  						if (this.menuList[this.selectedIndex].reflexTitle) {
  							this.titleList[this.selectedIndex].title = tempTitle;
  						}
  					}
  				} else {
  					for (let key in titlesObj) {
  						if (!Array.isArray(titlesObj[key])) {
  							this.tempTitleObj[key] = titlesObj[key];
  						}
  
  					}
  					for (let key in this.tempTitleObj) {
  						for (let i = 0; i < this.titleList.length; i++) {
  							if (this.titleList[i].key == key) {
  								this.titleList[i].title = this.tempTitleObj[key];
  							}
  						}
  					}
  				}
  
  				this.$refs.popupRef.close()
  				if (obj.isReset) {
  					
  				} else{
  					this.$emit("result", val)
  				}
  				
  
  			},
  			close() {
  				for (let i = 0; i < this.statusList.length; i++) {
  					this.statusList[i].isActive = false;
  				}
  			}
  		}
  	}
  </script>
  
  <style lang="scss">
  	@import 'iconfont/iconfont.css';
  	// .content{
  	// 	flex-shrink: 0;
  	// 	width: 100%;
  	// 	height: 44px;
  	// 	position: fixed;
  	// 	z-index: 997;
  	// 	flex-wrap: nowrap;
  	// 	display: flex;
  	// 	flex-direction: row;
  	// 	// top: var(--window-top);
  	// 	left: 0;
  	// 	view {
  	// 	  display: flex;
  	// 	  flex-wrap: nowrap;
  	// 	}
  	// }
  	.select-tab {
  		border-bottom: #F7F7F7 1px solid;
  		background-color: #FFFFFF;
  		display: flex;
  		width: 100%;
  	}
  
  	.select-tab-fixed-top {
  		border-bottom: #F7F7F7 1px solid;
  		background-color: #FFFFFF;
  		display: flex;
  		width: 100%;
  		position: fixed;
  		/* #ifdef H5 */
  		top: 44px;
  		/* #endif */
  		/* #ifndef H5 */
  		top: 0;
  		/* #endif */
  	}
  
  	.arrows {
  		margin-left: 5px;
  	}
  
  	.select-tab .select-tab-item,
  	.select-tab-fixed-top .select-tab-item {
  		display: flex;
  		justify-content: center;
  		align-items: center;
  	}
  
  	.select-tab .select-tab-item text,
  	.select-tab-fixed-top .select-tab-item text {
  		color: #666666;
  		font-size: 14px;
  	}
  </style>