Blame view

美国版/Food Labeling Management App UniApp/src/components/LocationPicker.vue 5.5 KB
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
1
2
  <template>
    <view class="loc-root">
6faaf539   杨鑫   APP 登录门店对接
3
      <view class="loc-trigger" @click.stop="openPicker">
3af4878d   杨鑫   产品 标签 关联
4
        <text class="loc-text">{{ displayLocationName || '—' }}</text>
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
        <AppIcon name="chevronDown" size="sm" color="white" />
      </view>
  
      <view v-if="showPicker" class="picker-mask" @click="showPicker = false">
        <view class="picker-body" @click.stop>
          <view class="picker-header">
            <text class="picker-title">Switch Location</text>
            <view class="picker-close" @click="showPicker = false">
              <AppIcon name="plus" size="sm" color="gray" />
            </view>
          </view>
          <view class="picker-list">
            <view
              v-for="s in stores"
              :key="s.id"
              class="picker-item"
              :class="{ active: currentId === s.id }"
              @click="handleSelect(s)"
            >
              <view class="picker-icon" :class="{ active: currentId === s.id }">
                <AppIcon name="mapPin" size="sm" :color="currentId === s.id ? 'white' : 'gray'" />
              </view>
              <view class="picker-info">
6faaf539   杨鑫   APP 登录门店对接
28
29
                <text class="picker-name">{{ s.locationName }}</text>
                <text class="picker-addr">{{ s.fullAddress }}</text>
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
30
31
32
33
34
35
36
37
38
39
40
41
              </view>
              <view v-if="currentId === s.id" class="picker-check">
                <AppIcon name="check" size="sm" color="white" />
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
  </template>
  
  <script setup lang="ts">
6faaf539   杨鑫   APP 登录门店对接
42
  import { ref, computed, watch } from 'vue'
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
43
44
  import { useI18n } from 'vue-i18n'
  import AppIcon from './AppIcon.vue'
6faaf539   杨鑫   APP 登录门店对接
45
46
47
48
49
50
  import {
    getCurrentStoreId,
    switchStore,
    getBoundLocations,
    getCurrentLocationCode,
  } from '../utils/stores'
3af4878d   杨鑫   产品 标签 关联
51
  import type { UsAppBoundLocationDto } from '../types/usAppBound'
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
52
53
  
  const { t } = useI18n()
6faaf539   杨鑫   APP 登录门店对接
54
  const stores = ref<UsAppBoundLocationDto[]>([])
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
55
56
57
  const currentId = ref(getCurrentStoreId())
  const showPicker = ref(false)
  
6faaf539   杨鑫   APP 登录门店对接
58
59
60
61
  function refreshList() {
    stores.value = getBoundLocations().filter((s) => s.state !== false)
  }
  
3af4878d   杨鑫   产品 标签 关联
62
63
64
65
  /** 药丸展示门店名称(与弹窗内选中项一致);无名称时再退回编码 */
  const displayLocationName = computed(() => {
    const fromStorage = uni.getStorageSync('storeName')
    if (typeof fromStorage === 'string' && fromStorage.trim()) return fromStorage.trim()
6faaf539   杨鑫   APP 登录门店对接
66
67
    if (currentId.value) {
      const row = stores.value.find((x) => x.id === currentId.value)
3af4878d   杨鑫   产品 标签 关联
68
      if (row?.locationName?.trim()) return row.locationName.trim()
6faaf539   杨鑫   APP 登录门店对接
69
    }
3af4878d   杨鑫   产品 标签 关联
70
71
72
73
74
75
76
    const id = getCurrentStoreId()
    if (id) {
      const row = getBoundLocations().find((x) => x.id === id)
      if (row?.locationName?.trim()) return row.locationName.trim()
    }
    const code = getCurrentLocationCode()
    return code || ''
6faaf539   杨鑫   APP 登录门店对接
77
78
79
80
81
82
83
84
85
86
87
88
89
  })
  
  function openPicker() {
    refreshList()
    currentId.value = getCurrentStoreId()
    showPicker.value = true
  }
  
  watch(showPicker, (v) => {
    if (v) refreshList()
  })
  
  const handleSelect = (s: UsAppBoundLocationDto) => {
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
90
91
92
93
    if (s.id === currentId.value) {
      showPicker.value = false
      return
    }
6faaf539   杨鑫   APP 登录门店对接
94
    switchStore(s.id, s.locationName, s.locationCode)
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
95
96
    currentId.value = s.id
    showPicker.value = false
6faaf539   杨鑫   APP 登录门店对接
97
    uni.showToast({ title: t('location.storeSwitched'), icon: 'success' })
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
98
99
    setTimeout(() => {
      const pages = getCurrentPages()
6faaf539   杨鑫   APP 登录门店对接
100
101
      const cur = pages[pages.length - 1] as { route?: string }
      if (cur?.route) {
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
        uni.redirectTo({ url: '/' + cur.route })
      }
    }, 800)
  }
  </script>
  
  <style scoped>
  .loc-trigger {
    display: flex;
    align-items: center;
    gap: 4rpx;
    padding: 4rpx 16rpx 4rpx 20rpx;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 999rpx;
    margin-top: 6rpx;
  }
  
  .loc-text {
    font-size: 22rpx;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
3af4878d   杨鑫   产品 标签 关联
123
124
125
126
    max-width: 320rpx;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
940fb6ea   “wangming”   又改了一个版本,这泰额太纠结了,一...
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
  }
  
  .loc-trigger .icon-wrap {
    opacity: 0.7;
  }
  
  /* Picker modal */
  .picker-mask {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
  }
  
  .picker-body {
    width: 100%;
    background: #fff;
    border-radius: 32rpx 32rpx 0 0;
    padding: 32rpx;
    max-height: 70vh;
    overflow-y: auto;
  }
  
  .picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24rpx;
  }
  
  .picker-title {
    font-size: 36rpx;
    font-weight: 700;
    color: #111827;
  }
  
  .picker-close {
    width: 56rpx;
    height: 56rpx;
    border-radius: 50%;
    background: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: rotate(45deg);
  }
  
  .picker-list {
    display: flex;
    flex-direction: column;
    gap: 12rpx;
  }
  
  .picker-item {
    display: flex;
    align-items: center;
    gap: 20rpx;
    padding: 28rpx 24rpx;
    border-radius: 16rpx;
    border: 2rpx solid #e5e7eb;
    background: #fff;
  }
  
  .picker-item.active {
    border-color: var(--theme-primary);
    background: var(--theme-primary-light);
  }
  
  .picker-icon {
    width: 56rpx;
    height: 56rpx;
    border-radius: 14rpx;
    background: #f3f4f6;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  
  .picker-icon.active {
    background: var(--theme-primary);
  }
  
  .picker-info {
    flex: 1;
    min-width: 0;
  }
  
  .picker-name {
    font-size: 30rpx;
    font-weight: 600;
    color: #111827;
    display: block;
    margin-bottom: 4rpx;
  }
  
  .picker-addr {
    font-size: 24rpx;
    color: #6b7280;
    display: block;
  }
  
  .picker-check {
    width: 44rpx;
    height: 44rpx;
    border-radius: 50%;
    background: var(--theme-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  </style>