stores.vue
10.6 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
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
<template>
<view class="page-shell store-list-page">
<view class="page-blur"></view>
<view class="page-blur-secondary"></view>
<view class="page-blur-tertiary"></view>
<view class="page-content subpage-content">
<view class="subpage-nav">
<view class="subpage-back" @tap="goBack">‹</view>
<view class="subpage-title-wrap">
<text class="subpage-title">全部门店</text>
<text class="subpage-subtitle">门店较多时,也能更轻松地找到适合这次到店的那一家</text>
</view>
</view>
<view class="store-top-card glass-card">
<text class="hero-kicker">STORE GUIDE</text>
<text class="hero-title">三十余家门店,慢慢挑一间顺路又合心意的</text>
<text class="hero-desc">可以按区域、营业状态或距离轻松筛选,也可以直接搜索门店名与所在片区。</text>
</view>
<view class="search-card glass-card">
<view class="search-icon"></view>
<input
v-model="keyword"
class="search-input"
placeholder="搜索门店名、区域或街道"
placeholder-class="search-placeholder"
confirm-type="search"
/>
</view>
<scroll-view class="filter-scroll" scroll-x>
<view class="filter-row">
<view
v-for="item in filters"
:key="item.key"
class="filter-chip"
:class="{ active: activeFilter === item.key }"
@tap="activeFilter = item.key"
>
{{ item.label }}
</view>
</view>
</scroll-view>
<view class="section-head store-head">
<text class="section-title">为你找到 {{ filteredStores.length }} 家门店</text>
<text class="section-link">{{ headText }}</text>
</view>
<view
v-for="store in filteredStores"
:key="store.id"
class="store-list-card glass-card"
@tap="goDetail(store)"
>
<image v-if="store.cover" class="store-thumb" :src="store.cover" mode="aspectFill" />
<view v-else class="store-thumb store-thumb-empty"><text>{{ shortLabel(store.name) }}</text></view>
<view class="store-main">
<view class="store-title-row">
<text class="store-name">{{ store.name }}</text>
<text v-if="store.distance" class="store-distance">{{ store.distance }}</text>
</view>
<view class="store-tag-row">
<text v-if="store.city" class="store-chip">{{ store.city }}</text>
<text v-if="store.hours" class="store-chip rose">{{ store.hours }}</text>
</view>
<text class="store-address">{{ store.address || '暂无地址信息' }}</text>
<text v-if="store.phone" class="store-meta">联系电话 {{ store.phone }}</text>
<view class="store-actions">
<view v-if="store.phone" class="mini-button" @tap.stop="callStore(store)">电话</view>
<view class="mini-button" @tap.stop="openMap(store)">导航</view>
<view class="mini-button primary-mini" @tap.stop="bookStore(store)">预约</view>
</view>
</view>
</view>
<view v-if="loading" class="subpage-card">
<text class="empty-tip">门店加载中…</text>
</view>
<view v-else-if="!filteredStores.length" class="subpage-card">
<text class="empty-tip">暂时没有找到合适的门店,换个区域或关键词再看看。</text>
</view>
</view>
</view>
</template>
<script>
import { getPickupStores } from '@/api/mall'
import { normalizeStore, getUserLocation, attachDistance, sortByDistance } from '@/utils/store'
export default {
data() {
return {
stores: [],
loading: false,
keyword: '',
activeFilter: 'all',
userLocation: null
}
},
computed: {
// 城市/区域筛选项(按门店数据动态生成)
cityFilters() {
const set = []
this.stores.forEach((s) => {
if (s.city && set.indexOf(s.city) === -1) set.push(s.city)
})
return set
},
filters() {
const base = [
{ key: 'all', label: '全部' },
{ key: 'near', label: '离我较近' }
]
return base.concat(this.cityFilters.map(c => ({ key: c, label: c })))
},
filteredStores() {
let list = this.stores.slice()
if (this.activeFilter === 'near') {
list = sortByDistance(list)
} else if (this.activeFilter !== 'all') {
list = list.filter(item => item.city === this.activeFilter)
}
const keyword = String(this.keyword || '').trim()
if (keyword) {
list = list.filter(item =>
(item.name || '').indexOf(keyword) > -1 ||
(item.city || '').indexOf(keyword) > -1 ||
(item.address || '').indexOf(keyword) > -1
)
}
return list
},
headText() {
if (this.activeFilter === 'near') {
return this.userLocation ? '按距离排序' : '开启定位更准'
}
if (this.activeFilter !== 'all') {
return `${this.activeFilter}片区`
}
return '可按区域筛选'
}
},
onLoad() {
this.loadStores()
},
methods: {
loadStores() {
this.loading = true
getPickupStores({})
.then((list) => {
const rows = Array.isArray(list) ? list : []
this.stores = rows.map(normalizeStore)
return getUserLocation()
})
.catch(() => {
this.stores = []
return null
})
.then((loc) => {
this.userLocation = loc
attachDistance(this.stores, loc)
// 触发计算属性刷新
this.stores = this.stores.slice()
this.loading = false
})
},
shortLabel(name) {
return String(name || '门店').replace(/\s+/g, '').slice(0, 2)
},
goBack() {
uni.navigateBack({
fail: () => {
uni.redirectTo({ url: '/pages/home/home' })
}
})
},
goDetail(store) {
uni.navigateTo({
url: `/packageBooking/store-detail/store-detail?id=${store.id}`
})
},
callStore(store) {
if (!store.phone) return
uni.makePhoneCall({ phoneNumber: String(store.phone) })
},
openMap(store) {
if (store.latitude === null || store.longitude === null) {
uni.showToast({ title: '该门店暂无坐标,无法导航', icon: 'none' })
return
}
uni.openLocation({
latitude: store.latitude,
longitude: store.longitude,
name: store.name,
address: store.address || ''
})
},
bookStore(store) {
uni.redirectTo({ url: `/pages/booking/booking?storeId=${store.id}` })
}
}
}
</script>
<style lang="scss" scoped>
@import '@/styles/mixins.scss';
@import '@/styles/subpage.scss';
.store-top-card {
padding: 34rpx;
margin-bottom: 24rpx;
transition: transform 340ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 340ms ease;
}
.store-top-card:active {
transform: translateY(-4rpx);
}
.search-card {
display: flex;
align-items: center;
padding: 0 24rpx;
min-height: 92rpx;
margin-bottom: 20rpx;
transition: transform 320ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 320ms ease;
}
.search-card:active {
transform: translateY(-3rpx);
}
.search-icon {
width: 34rpx;
height: 34rpx;
margin-right: 16rpx;
border: 3rpx solid rgba(100, 140, 118, 0.52);
border-radius: 50%;
position: relative;
}
.search-icon::after {
content: '';
position: absolute;
right: -10rpx;
bottom: -7rpx;
width: 14rpx;
height: 3rpx;
border-radius: 999rpx;
background: rgba(100, 140, 118, 0.52);
transform: rotate(45deg);
}
.search-input {
flex: 1;
height: 92rpx;
font-size: 26rpx;
color: $text-primary;
}
.search-placeholder {
color: $text-tertiary;
}
.filter-scroll {
white-space: nowrap;
margin-bottom: 20rpx;
}
.filter-row {
display: inline-flex;
padding-bottom: 6rpx;
}
.filter-chip {
@include selection-chip;
min-width: 136rpx;
padding: 20rpx 26rpx;
margin-right: 16rpx;
text-align: center;
font-size: 24rpx;
color: $text-secondary;
transition: transform 240ms ease, box-shadow 240ms ease, background 240ms ease, color 240ms ease;
}
.filter-chip:active {
transform: translateY(-2rpx) scale(0.98);
}
.filter-chip.active {
@include selection-chip-active;
}
.store-head {
margin-bottom: 20rpx;
}
.store-list-card {
display: flex;
padding: 24rpx;
margin-bottom: 18rpx;
transition: transform 340ms cubic-bezier(0.22, 1, 0.36, 1), box-shadow 340ms ease;
animation: lfRevealUp 760ms cubic-bezier(0.22, 1, 0.36, 1) both;
}
.store-list-card:nth-of-type(1) { animation-delay: 0.08s; }
.store-list-card:nth-of-type(2) { animation-delay: 0.16s; }
.store-list-card:nth-of-type(3) { animation-delay: 0.24s; }
.store-list-card:nth-of-type(4) { animation-delay: 0.32s; }
.store-list-card:active {
transform: translateY(-5rpx);
}
.store-thumb {
width: 176rpx;
height: 176rpx;
border-radius: 28rpx;
flex-shrink: 0;
transition: transform 1.1s ease;
}
.store-list-card:active .store-thumb {
transform: scale(1.04);
}
.store-thumb-empty {
display: flex;
align-items: center;
justify-content: center;
background: rgba(241, 246, 241, 0.96);
border: 1rpx solid rgba(120, 146, 121, 0.14);
color: $brand-primary-deep;
font-size: 30rpx;
font-weight: 700;
letter-spacing: 2rpx;
}
.store-main {
flex: 1;
margin-left: 20rpx;
}
.store-title-row {
display: flex;
justify-content: space-between;
gap: 16rpx;
align-items: flex-start;
}
.store-name {
flex: 1;
font-size: 30rpx;
line-height: 1.45;
font-weight: 700;
color: $text-primary;
}
.store-distance {
font-size: 22rpx;
color: $brand-accent;
white-space: nowrap;
}
.store-tag-row {
display: flex;
flex-wrap: wrap;
gap: 10rpx;
margin-top: 12rpx;
}
.store-chip {
@include chip-soft;
padding: 8rpx 16rpx;
font-size: 20rpx;
transition: transform 240ms ease;
}
.store-chip.rose {
@include chip-rose;
padding: 8rpx 16rpx;
font-size: 20rpx;
}
.store-address,
.store-meta {
display: block;
font-size: 23rpx;
line-height: 1.7;
color: $text-secondary;
}
.store-address {
margin-top: 14rpx;
}
.store-meta {
margin-top: 4rpx;
}
.store-actions {
display: flex;
gap: 12rpx;
margin-top: 16rpx;
}
.mini-button {
@include secondary-button;
flex: 1;
min-width: 0;
height: 70rpx;
font-size: 24rpx;
letter-spacing: 1rpx;
transition: transform 240ms ease, box-shadow 240ms ease;
}
.mini-button:active {
transform: scale(0.97);
box-shadow: 0 10rpx 20rpx rgba(54, 77, 64, 0.08);
}
.primary-mini {
color: #fff;
background: $brand-primary-deep;
}
</style>