MerchantList.uvue
10.8 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
<template>
<view class="fade-in-up">
<MerchantListSkeleton v-if="!flag" :count="6" />
<view v-if="flag" class="list-container">
<template v-if="loginUserInfoList.length > 0">
<view v-for="(item, index) in loginUserInfoList"
:key="index"
class="items"
:class="[item.active ? 'active' : '', (index + 1) % 2 === 0 ? 'item-even' : '', pressedIndex === index ? 'pressed' : '']"
@touchstart="handleTouchStart(index)"
@touchend="handleTouchEnd"
@click="chooseMerchantItem(item)">
<view class="left">
<view class="store-badge">
<view class="sprite-icon icon-store"></view>
</view>
<view class="info">
<text class="name">{{ item.merchantName }}</text>
<text class="text_no">商户号:{{ item.merchantId }}</text>
</view>
</view>
</view>
</template>
<no-data v-else />
</view>
</view>
</template>
<script setup lang="uts">
import { defineExpose, ref } from "vue";
import { apiGetSceneMerchantRefStoreList, apiGetYqMerchantSceneConfigAPI, apiSelectMerchantScene } from "@/api/user-api.uts";
import NoData from "./NoData.uvue";
import MerchantListSkeleton from "./Skeleton/MerchantListSkeleton.uvue";
import { storage } from "@/utils/storage.uts";
type MerchantItem = {
active: boolean
merchantId: string
merchantName: string
}
const emit = defineEmits(["chooseMerchant"]);
const loginUserInfoList = ref<MerchantItem[]>([]);
const copyLoginUserInfoList = ref<MerchantItem[]>([]);
const flag = ref<boolean>(false);
const selectMerchantId = ref<string>("");
const pressedIndex = ref<number>(-1);
let userInfo: null | UTSJSONObject = null;
function handleTouchStart(index: number): void {
pressedIndex.value = index;
}
function handleTouchEnd(): void {
pressedIndex.value = -1;
}
function jumpPage(item: MerchantItem, openSceneArr: number[]): void {
const shopMerchantName = item.merchantName;
const shopMerchantId = item.merchantId;
const usedCarSceneType = 7;
const currentUserInfo = userInfo;
if (currentUserInfo == null) {
return;
}
if (openSceneArr.length === 0) {
const isSuper = currentUserInfo.isSuper as boolean | null;
if (isSuper != true) {
uni.showToast({ title: "暂无开通业务,请联系总部管理员", icon: "none" });
return;
}
}
let finalOpenSceneArr = openSceneArr;
const isSuperVal = currentUserInfo.isSuper as boolean | null;
if (isSuperVal == true) {
finalOpenSceneArr = [1, 0, usedCarSceneType];
}
const newUserInfo: UTSJSONObject = {};
for (const k in currentUserInfo) {
newUserInfo[k] = currentUserInfo[k];
}
newUserInfo.openSceneArr = finalOpenSceneArr;
newUserInfo.shopMerchantName = shopMerchantName;
newUserInfo.shopMerchantId = shopMerchantId;
newUserInfo.default4SStoreInfo = {
merchantId: shopMerchantId,
merchantName: shopMerchantName
};
newUserInfo.default4SStoreInfo_crowdFunding = {
merchantId: shopMerchantId,
merchantName: shopMerchantName
};
newUserInfo.default4SStoreInfo_newCarConversion = {
merchantId: shopMerchantId,
merchantName: shopMerchantName
};
if (finalOpenSceneArr.length == 1 && finalOpenSceneArr[0] == usedCarSceneType) {
apiSelectMerchantScene({
merchantId: shopMerchantId,
merchantName: shopMerchantName,
sceneType: usedCarSceneType
}).then((data: any): void => {
if (data != null) {
const loginRole = (data as UTSJSONObject).loginRoleOnSelectMerchant;
if (loginRole != null) {
newUserInfo.loginRoleOnSelectMerchant = loginRole;
}
}
newUserInfo.sceneType = usedCarSceneType;
storage.set("userInfo", newUserInfo, 0);
uni.switchTab({
url: "/pages/index/index",
fail: (_err: any) => {
uni.reLaunch({ url: "/pages/index/index" });
}
});
}).catch((error): void => {
uni.showToast({ title: "网络异常", icon: "none" });
});
return;
}
emit("chooseMerchant", newUserInfo);
}
function getSceneArr(shopMerchantId: string): Promise<number[]> {
return new Promise((resolve) => {
const currentUserInfo = userInfo;
if (currentUserInfo == null) {
resolve([]);
return;
}
// 对齐老项目:优先使用子账号所属的 yqMerchantId
const yqMerchantId = (currentUserInfo.subLoginUser as null | UTSJSONObject)?.merchantId;
const yqId = yqMerchantId != null ? `${yqMerchantId}` : "";
const params: UTSJSONObject = {
yqMerchantId: yqId,
merchantId: shopMerchantId
};
apiGetYqMerchantSceneConfigAPI(params).then((res: any): void => {
const code = (res as UTSJSONObject).code as null | string;
if (code == "0") {
const data = (res as UTSJSONObject).data as any[] | null;
const openSceneArr: number[] = [];
if (data != null) {
let i = 0;
while (i < data.length) {
const val = data[i] as null | UTSJSONObject;
if (val != null) {
const sceneOpenFlag = val.sceneOpenFlag as null | number;
if (sceneOpenFlag == 0) {
const scene = val.scene as null | number;
if (scene != null) {
openSceneArr.push(scene);
}
}
}
i++;
}
}
resolve(openSceneArr);
} else {
resolve([]);
}
}).catch((error) => {
console.error("getSceneArr 失败:", error);
resolve([]);
});
});
}
function chooseMerchantItem(item: MerchantItem): void {
console.log(`选择4s店${ item.merchantName }!`);
const list = loginUserInfoList.value;
let i = 0;
while (i < list.length) {
list[i].active = list[i].merchantId == item.merchantId;
i++;
}
loginUserInfoList.value = list;
selectMerchantId.value = item.merchantId;
getSceneArr(item.merchantId).then((openSceneArr: number[]): void => {
jumpPage(item, openSceneArr);
});
}
function getMerchantList(): void {
loginUserInfoList.value = [];
copyLoginUserInfoList.value = [];
flag.value = false;
const currentUserInfo = userInfo;
if (currentUserInfo == null) {
return;
}
const isSuper = currentUserInfo.isSuper as boolean | null;
const params: UTSJSONObject = {
merchantId: isSuper == true ? "" : `${currentUserInfo.merchantId ?? ""}`,
staffUUID: isSuper == true ? "" : `${currentUserInfo.uuid ?? ""}`
};
apiGetSceneMerchantRefStoreList(params).then((res: any): void => {
const code = (res as UTSJSONObject).code as null | string;
if (code == "0") {
const data = (res as UTSJSONObject).data as any[] | null;
if (data != null) {
const list: MerchantItem[] = [];
let i = 0;
while (i < data.length) {
const item = data[i] as null | UTSJSONObject;
if (item != null) {
const mid = item.merchantId;
list.push({
merchantId: mid != null ? `${mid}` : "",
merchantName: (item.merchantName as null | string) ?? "",
active: false
});
}
i++;
}
loginUserInfoList.value = list;
copyLoginUserInfoList.value = list;
flag.value = true;
if (list.length == 1) {
chooseMerchantItem(list[0]);
}
} else {
flag.value = true;
}
} else {
flag.value = true;
const msg = (res as UTSJSONObject).message as null | string;
uni.showToast({ title: msg ?? "获取4S店列表失败", icon: "none" });
}
}).catch((error) => {
flag.value = true;
console.error("getMerchantList 失败:", error);
uni.showToast({ title: "网络异常,请稍后重试", icon: "none" });
});
}
function init(info: any): void {
console.log("进入选择4s店页面!");
// 将 any 转换为 UTSJSONObject
userInfo = info as UTSJSONObject;
getMerchantList();
}
function searchEvent(searchValue: string): void {
const copyList = copyLoginUserInfoList.value;
const uuid = selectMerchantId.value;
const list = loginUserInfoList.value;
let i = 0;
while (i < copyList.length) {
copyList[i].active = copyList[i].merchantId == uuid;
i++;
}
if (searchValue == "" || searchValue == null) {
loginUserInfoList.value = copyList;
return;
}
const filterArr: MerchantItem[] = [];
let j = 0;
while (j < copyList.length) {
const val = copyList[j];
const nameMatch = val.merchantName.includes(searchValue);
const idMatch = val.merchantId == searchValue;
if (nameMatch || idMatch) {
filterArr.push(val);
}
j++;
}
loginUserInfoList.value = filterArr;
}
defineExpose({
init,
searchEvent
});
</script>
<style scoped lang="scss">
.list-container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
width: 100%;
}
.items {
min-height: 72px;
background-color: var(--bg-card);
border-radius: 14px;
padding: 12px 14px;
display: flex;
flex-direction: row;
align-items: center;
box-sizing: border-box;
border: 1px solid rgba(226, 232, 240, 0.6);
box-shadow:
0 2px 8px rgba(15, 23, 42, 0.04),
0 6px 18px rgba(15, 23, 42, 0.05);
transition: all 0.1s ease-out;
position: relative;
overflow: hidden;
// 竖屏默认2列
width: 48%;
margin-right: 4%;
margin-bottom: 12px;
// 每行第二个元素(偶数)去掉右边距
&.item-even {
margin-right: 0;
}
&:active,
&.pressed {
transform: scale(0.95);
box-shadow:
0 1px 2px rgba(15, 23, 42, 0.08),
0 2px 6px rgba(15, 23, 42, 0.1);
border-color: rgba(22, 119, 255, 0.4);
background-color: var(--bg-pressed);
}
}
.items .left {
flex: 1;
display: flex;
flex-direction: row;
align-items: center;
min-width: 0; // 允许文字截断
.store-badge {
flex-shrink: 0;
margin-right: 10px;
.sprite-icon {
width: 36px;
height: 36px;
border-radius: 10px;
background-color: var(--bg-icon);
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 1px 4px rgba(22, 119, 255, 0.08);
transition: all 0.3s ease;
}
}
.info {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
min-width: 0;
}
}
.items .name {
font-weight: 600;
font-size: 13px;
color: #1e293b;
margin-bottom: 3px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
letter-spacing: 0.2px;
line-height: 1.3;
}
.items .text_no {
font-size: 10px;
color: #94a3b8;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
letter-spacing: 0.1px;
}
.items.active {
background-color: var(--bg-active);
border-color: rgba(22, 119, 255, 0.25);
box-shadow:
0 3px 12px rgba(22, 119, 255, 0.1),
0 8px 24px rgba(22, 119, 255, 0.12);
}
.items.active .name {
color: #1677FF;
font-weight: 700;
}
.items.active .left .store-badge .sprite-icon {
background-color: rgba(22, 119, 255, 0.1);
box-shadow: 0 2px 8px rgba(22, 119, 255, 0.15);
transform: scale(1.08);
}
</style>