AccountList.uvue
13.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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
<template>
<!-- 保持单根节点,确保父组件 v-show 生效 -->
<view class="fade-in-up">
<SingleColumnSkeleton v-if="!flag" :count="4" />
<view v-else class="list-container">
<template v-if="loginUserInfoList.length > 0">
<view v-for="(item, index) in loginUserInfoList"
:key="index"
class="items"
:class="[item.active ? 'active' : '', pressedIndex === index ? 'pressed' : '']"
@touchstart="handleTouchStart(index)"
@touchend="handleTouchEnd"
@click="chooseAccount(item)">
<view class="right">
<view class="midle" :class="[getMidleClass(item)]">
<text class="midle-text" :class="[getMidleClass(item)]">{{ getRoleText(item) }}</text>
</view>
</view>
<view class="left">
<text class="name">{{ item.merchantName }}</text>
<text class="shop_no">商户号:{{ item.merchantId }}</text>
</view>
</view>
</template>
<template v-else>
<no-data />
</template>
</view>
</view>
</template>
<script setup lang="uts">
import { defineExpose, onMounted, ref } from "vue";
import { apiGetListSelectAccount, apiGetSceneMerchantRefStoreList, apiSelectAccountLogin } from "@/api/user-api.uts";
import NoData from "./NoData.uvue";
import SingleColumnSkeleton from "./Skeleton/SingleColumnSkeleton.uvue";
import { storage } from "@/utils/storage.uts";
type AccountItem = {
active: boolean
isSuper: boolean
loginRole: number
merchantId: string
merchantName: string
userType: number
uuid: string
}
const emit = defineEmits(["chooseAccount"]);
const loginUserInfoList = ref<AccountItem[]>([]);
const copyLoginUserInfoList = ref<AccountItem[]>([]);
const selectedUuid = ref<string>("");
const flag = ref<boolean>(false);
const pressedIndex = ref<number>(-1);
function getRoleText(item: AccountItem): string {
if (item.isSuper == true) return "超管";
if (item.userType == 1) return "商户";
if (item.loginRole == 3) return "督导";
if (item.loginRole == 4) return "驻店";
return "员工";
}
function getMidleClass(item: AccountItem): string {
if (item.isSuper == true) return "midle_1";
if (item.userType == 1) return "midle_2";
if (item.loginRole == 3) return "midle_3";
if (item.loginRole == 4) return "midle_4";
return "midle_5";
}
function handleTouchStart(index: number): void {
pressedIndex.value = index;
}
function handleTouchEnd(): void {
pressedIndex.value = -1;
}
function get4SStoreList(loginUserObj: UTSJSONObject): void {
console.log("get4SStoreList:", loginUserObj);
if (loginUserObj.isSuper == true) {
emit("chooseAccount", loginUserObj);
return;
}
const params: UTSJSONObject = {
merchantId: loginUserObj.merchantId,
staffUUID: loginUserObj.uuid
};
apiGetSceneMerchantRefStoreList(params).then((res: any | null): void => {
console.log("getSceneMerchantRefStoreList 返回数据:", res);
if (res != null) {
const code = (res as UTSJSONObject).code as null | string;
if (code == "0") {
const data = (res as UTSJSONObject).data as any[] | null;
if (data != null) {
console.log("4S店列表数量:", data.length);
if (data.length == 1) {
const store = data[0] as null | UTSJSONObject;
if (store != null) {
const storeMerchantName = store.merchantName as null | string;
const storeMerchantId = store.merchantId as null | string;
const userInfoWithStore: UTSJSONObject = {
...loginUserObj,
staffUuid: loginUserObj.uuid,
shopMerchantName: storeMerchantName,
shopMerchantId: storeMerchantId,
default4SStoreInfo: {
merchantId: storeMerchantId,
merchantName: storeMerchantName
},
default4SStoreInfo_crowdFunding: {
merchantId: storeMerchantId,
merchantName: storeMerchantName
},
default4SStoreInfo_newCarConversion: {
merchantId: storeMerchantId,
merchantName: storeMerchantName
}
};
emit("chooseAccount", userInfoWithStore);
}
} else if (data.length === 0) {
uni.showToast({
title: "园区店关联的4s店商户账号无效,请联系总部管理员",
icon: "none"
});
} else {
emit("chooseAccount", loginUserObj);
}
}
} else {
const message = (res as UTSJSONObject).message as null | string;
uni.showToast({
title: message ?? "获取4S店列表失败",
icon: "none"
});
}
}
}).catch((error: any | null): void => {
console.error("get4SStoreList 失败:", error);
uni.showToast({
title: "网络异常,请稍后重试",
icon: "none"
});
});
}
function selectAccountLogin(id: string, merchantName: string, userInfo: AccountItem | null): void {
console.log(`选择账号${merchantName}登录!`);
const params: UTSJSONObject = {
id
};
apiSelectAccountLogin(params).then((res: UTSJSONObject): void => {
console.log("selectAccountLogin 返回数据:", res);
const code = res.code as null | string;
if (code == "0") {
const data = res.data as null | UTSJSONObject;
if (data != null) {
const loginUserInfoListData = data.loginUserInfoList as any[] | null;
if (loginUserInfoListData != null && loginUserInfoListData.length > 0 && userInfo != null) {
console.log("开始获取4S店列表");
console.log(loginUserInfoListData);
const info = loginUserInfoListData[0] as UTSJSONObject;
get4SStoreList(info);
} else {
uni.showToast({
title: "获取4S店列表失败",
icon: "none"
});
}
}
} else {
const message = res.message as null | string;
uni.showToast({
title: message ?? "选择账号失败",
icon: "none"
});
}
}).catch((error: any | null): void => {
console.error("selectAccountLogin 失败:", error);
uni.showToast({
title: "网络异常,请稍后重试",
icon: "none"
});
});
}
function choiceAccountLogin(): void {
const list = loginUserInfoList.value;
let id: null | string = null;
let merchantName: null | string = null;
let selectedItem: AccountItem | null = null;
let i = 0;
while (i < list.length) {
if (list[i].active) {
id = list[i].uuid;
merchantName = list[i].merchantName;
selectedItem = list[i];
break;
}
i++;
}
if (id == null || id == "") {
uni.showToast({
title: "请选择账号",
icon: "none"
});
return;
}
selectAccountLogin(id, merchantName ?? "", selectedItem);
}
function chooseAccount(item: AccountItem): void {
const list = loginUserInfoList.value;
let i = 0;
while (i < list.length) {
list[i].active = false;
if (list[i].uuid == item.uuid) {
list[i].active = true;
}
i++;
}
console.log("选择账号:", list);
loginUserInfoList.value = list;
selectedUuid.value = item.uuid;
choiceAccountLogin();
}
function searchEvent(searchValue: string): void {
const copyList = copyLoginUserInfoList.value;
const uuid = selectedUuid.value;
let i = 0;
while (i < copyList.length) {
copyList[i].active = false;
if (copyList[i].uuid == uuid) {
copyList[i].active = true;
}
i++;
}
if (searchValue == "" || searchValue == null) {
loginUserInfoList.value = copyList;
return;
}
const filterArr: AccountItem[] = [];
let j = 0;
while (j < copyList.length) {
const item = copyList[j];
const nameMatch = item.merchantName.includes(searchValue);
const idMatch = item.merchantId == searchValue;
if (nameMatch || idMatch) {
filterArr.push(item);
}
j++;
}
loginUserInfoList.value = filterArr;
}
function getListSelectAccount(autoLogin: boolean): void {
console.log("进入选择账号页面!autoLogin:", autoLogin);
flag.value = false;
const params: UTSJSONObject = {};
apiGetListSelectAccount(params).then((res: UTSJSONObject): void => {
console.log("getListSelectAccount 返回数据:", res);
const code = res.code as null | string;
if (code == "21") {
uni.reLaunch({
url: "/pages/common/login/index"
});
return;
}
if (code == "0") {
const data = res.data as null | UTSJSONObject;
if (data != null) {
const sessionId = data.sessionId as null | string;
if (sessionId != null) {
storage.set("sessionId", sessionId, 0);
console.log("保存 sessionId:", sessionId);
}
const list = data.loginUserInfoList as any[] | null;
console.log("loginUserInfoList:", list);
if (list != null) {
const accountList: AccountItem[] = [];
let i = 0;
while (i < list.length) {
const item = list[i] as null | UTSJSONObject;
if (item != null) {
console.log("账号项数据:", item);
const merchantIdValue = item.merchantId;
let merchantIdStr = "";
if (merchantIdValue != null) {
merchantIdStr = `${merchantIdValue}`;
}
accountList.push({
uuid: (item.uuid as null | string) ?? (item.id as null | string) ?? "",
merchantName: (item.merchantName as null | string) ?? (item.accountName as null | string) ?? "",
merchantId: merchantIdStr,
isSuper: (item.isSuper as boolean | null) ?? (item.accountLevel as null | number) == 1,
userType: (item.userType as null | number) ?? 0,
loginRole: (item.loginRole as null | number) ?? (item.accountLevel as null | number) ?? 0,
active: false
});
}
i++;
}
console.log("解析后的账号列表,数量:", accountList.length,accountList);
loginUserInfoList.value = accountList;
copyLoginUserInfoList.value = accountList;
flag.value = true;
console.log("设置 flag = true");
if (autoLogin && accountList.length > 0) {
console.log("自动选择第一个账号");
chooseAccount(accountList[0]);
}
} else {
console.log("loginUserInfoList 为空");
flag.value = true;
}
}
} else {
const message = res.message as null | string;
uni.showToast({
title: message ?? "获取账号列表失败",
icon: "none"
});
flag.value = true;
}
}).catch((error: any | null): void => {
flag.value = true;
console.error("getListSelectAccount 失败:", error);
uni.showToast({
title: "网络异常,请稍后重试",
icon: "none"
});
});
}
defineExpose({
getListSelectAccount,
searchEvent
});
onMounted(() => {
console.log("AccountList 组件已挂载,开始加载数据");
getListSelectAccount(false);
});
</script>
<style scoped lang="scss">
.list-container {
display: flex;
flex-direction: column;
width: 100%;
}
.items {
min-height: 92px;
background-color: var(--bg-card);
border-radius: 16px;
padding: 18px;
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 8px 24px rgba(15, 23, 42, 0.06);
transition: all 0.1s ease-out;
width: 100%;
margin-bottom: 16px;
position: relative;
overflow: hidden;
// 微妙的光泽效果
&::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(
90deg,
transparent 0%,
rgba(255, 255, 255, 0.3) 50%,
transparent 100%
);
transition: left 0.6s ease;
}
&:last-child {
margin-bottom: 0;
}
&:active,
&.pressed {
transform: scale(0.96);
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);
}
.left {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
.name {
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 16px;
color: #1e293b;
letter-spacing: 0.3px;
line-height: 1.4;
}
.shop_no {
font-weight: 400;
font-size: 13px;
margin-top: 6px;
color: #94a3b8;
letter-spacing: 0.2px;
}
}
.right {
flex-shrink: 0;
display: flex;
flex-direction: row;
align-items: center;
margin-right: 16px;
.midle {
width: 52px;
height: 52px;
border-radius: 26px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
transition: all 0.3s ease;
}
.midle-text {
font-size: 14px;
font-weight: 700;
text-align: center;
letter-spacing: 0.5px;
}
.midle_1 {
background-color: rgba(242, 71, 36, 0.1);
.midle-text { color: #f24724; }
}
.midle_2 {
background-color: rgba(255, 157, 10, 0.1);
.midle-text { color: #ff9d0a; }
}
.midle_3 {
background-color: rgba(52, 123, 255, 0.1);
.midle-text { color: #347bff; }
}
.midle_4 {
background-color: rgba(53, 195, 118, 0.1);
.midle-text { color: #35c376; }
}
.midle_5 {
background-color: rgba(53, 195, 118, 0.1);
.midle-text { color: #35c376; }
}
}
}
.active {
background-color: var(--bg-active);
border-color: rgba(22, 119, 255, 0.3);
box-shadow:
0 4px 16px rgba(22, 119, 255, 0.12),
0 12px 32px rgba(22, 119, 255, 0.16);
.left .name {
color: #1677FF;
font-weight: 700;
}
.right .midle {
box-shadow: 0 4px 12px rgba(22, 119, 255, 0.2);
transform: scale(1.05);
}
}
</style>