index.vue
13.1 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
529
530
531
532
533
534
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-08-06 12:03:17
* @FilePath: /jgdl/src/pages/collectionSettings/index.vue
* @Description: 收款设置
-->
<template>
<view class="collection-settings">
<!-- 设置列表 -->
<view class="settings-list">
<!-- 收款账号 -->
<view class="setting-item" @click="openAccountModal">
<view class="setting-left">
<text class="setting-label">收款账号</text>
</view>
<view class="setting-right">
<text class="setting-status" :class="{ 'status-set': accountInfo.bankName }">
{{ accountInfo.bankName ? '已设置' : '未设置' }}
</text>
<text class="arrow">></text>
</view>
</view>
<!-- 身份信息 -->
<view class="setting-item" @click="openIdentityModal">
<view class="setting-left">
<text class="setting-label">身份信息</text>
</view>
<view class="setting-right">
<text class="setting-status" :class="{ 'status-set': identityInfo.userName }">
{{ identityInfo.userName ? '已设置' : '未设置' }}
</text>
<text class="arrow">></text>
</view>
</view>
</view>
<!-- 收款账号弹窗 -->
<nut-popup
v-model:visible="showAccountModal"
position="bottom"
:style="{ width: '100%', height: '85%' }"
:catch-move="true"
closeable
close-icon-position="top-right"
@close="closeAccountModal"
>
<view class="modal-content">
<view class="modal-header">
<text class="modal-title">收款账号设置</text>
</view>
<view class="form-content">
<view class="form-item">
<text class="form-label">银行名称</text>
<view class="bank-selector" @click="showBankPicker">
<text class="bank-text" :class="{ 'bank-selected': tempAccountInfo.bankName }">
{{ tempAccountInfo.bankName || '请选择银行' }}
</text>
<text class="arrow-down">></text>
</view>
</view>
<view class="form-item">
<text class="form-label">银行账号</text>
<input
v-model="tempAccountInfo.bankAccount"
placeholder="请输入银行账号"
class="form-input custom-input native-input"
type="number"
:cursor-spacing="50"
/>
</view>
</view>
<view class="modal-footer">
<nut-button
type="default"
@click="closeAccountModal"
class="footer-btn footer-btn-cancel"
>
关闭
</nut-button>
<nut-button
type="primary"
@click="saveAccountInfo"
color="#ffa500"
:disabled="!tempAccountInfo.bankName || !tempAccountInfo.bankAccount"
class="footer-btn footer-btn-save"
>
保存
</nut-button>
</view>
</view>
</nut-popup>
<!-- 银行选择器弹窗 -->
<nut-popup
v-model:visible="showBankModal"
position="bottom"
>
<nut-picker
v-model="bankPickerValue"
:columns="bankOptions"
title="选择银行"
@confirm="onBankConfirm"
@cancel="showBankModal = false"
></nut-picker>
</nut-popup>
<!-- 身份信息弹窗 -->
<nut-popup
v-model:visible="showIdentityModal"
position="bottom"
:style="{ width: '100%', height: '85%' }"
:catch-move="true"
closeable
close-icon-position="top-right"
@close="closeIdentityModal"
>
<view class="modal-content">
<view class="modal-header">
<text class="modal-title">身份信息设置</text>
</view>
<view class="form-content">
<view class="form-item">
<text class="form-label">用户名称</text>
<input
v-model="tempIdentityInfo.userName"
placeholder="请输入真实姓名"
class="form-input native-input"
/>
</view>
<view class="form-item">
<text class="form-label">身份证号码</text>
<input
v-model="tempIdentityInfo.idCard"
placeholder="请输入身份证号码"
class="form-input native-input"
maxlength="18"
@blur="handleIdCardBlur"
:cursor-spacing="50"
/>
<text v-if="idCardError" class="error-text">{{ idCardError }}</text>
</view>
</view>
<view class="modal-footer">
<nut-button
type="default"
@click="closeIdentityModal"
class="footer-btn footer-btn-cancel"
>
关闭
</nut-button>
<nut-button
type="primary"
@click="saveIdentityInfo"
color="#ffa500"
:disabled="!tempIdentityInfo.userName || !tempIdentityInfo.idCard || !!idCardError"
class="footer-btn footer-btn-save"
>
保存
</nut-button>
</view>
</view>
</nut-popup>
<!-- 固定返回按钮 - 只有当参数target=sell时才显示 -->
<view v-if="showBackButton" class="fixed-back-btn" @click="goBack">
<text class="back-text">返回</text>
</view>
</view>
</template>
<script setup>
import { ref, onMounted, computed } from "vue";
import Taro from "@tarojs/taro";
import "./index.less";
// 导入接口
import { updateProfileAPI, getProfileAPI } from '@/api/index'
// 导入用户状态管理
import { useUserStore } from '@/stores/user'
// 获取页面参数
const instance = Taro.getCurrentInstance()
const { target } = instance.router?.params || {}
// 用户状态管理
const userStore = useUserStore()
/**
* 判断是否显示返回按钮
* 只有当参数target=sell时才显示
*/
const showBackButton = computed(() => {
return target === 'sell'
})
/**
* 收款账号信息
*/
const accountInfo = ref({
bankName: '',
bankAccount: ''
});
/**
* 身份信息
*/
const identityInfo = ref({
userName: '',
idCard: ''
});
/**
* 临时收款账号信息(用于弹窗编辑)
*/
const tempAccountInfo = ref({
bankName: '',
bankAccount: ''
});
/**
* 临时身份信息(用于弹窗编辑)
*/
const tempIdentityInfo = ref({
userName: '',
idCard: ''
});
/**
* 弹窗显示状态
*/
const showAccountModal = ref(false);
const showIdentityModal = ref(false);
const showBankModal = ref(false);
/**
* 身份证号码错误信息
*/
const idCardError = ref('');
// 银行选择器当前选中的值
const bankPickerValue = ref([]);
/**
* 银行列表数据(模拟数据,后期从接口获取)
*/
const bankOptions = ref([
{ text: '中国工商银行', value: '中国工商银行' },
{ text: '中国建设银行', value: '中国建设银行' },
{ text: '中国农业银行', value: '中国农业银行' },
{ text: '中国银行', value: '中国银行' },
{ text: '交通银行', value: '交通银行' },
{ text: '招商银行', value: '招商银行' },
{ text: '中信银行', value: '中信银行' },
{ text: '光大银行', value: '光大银行' },
{ text: '华夏银行', value: '华夏银行' },
{ text: '民生银行', value: '民生银行' },
{ text: '广发银行', value: '广发银行' },
{ text: '平安银行', value: '平安银行' },
{ text: '浦发银行', value: '浦发银行' },
{ text: '兴业银行', value: '兴业银行' },
{ text: '邮储银行', value: '邮储银行' }
]);
/**
* 获取用户信息
*/
const getUserInfo = async () => {
try {
const result = await getProfileAPI();
if (result.code && result.data) {
const userInfo = result.data;
// 设置收款账号信息
if (userInfo.bank && userInfo.bank_no) {
accountInfo.value = {
bankName: userInfo.bank,
bankAccount: userInfo.bank_no
};
}
// 设置身份信息
if (userInfo.name && userInfo.idcard) {
identityInfo.value = {
userName: userInfo.name,
idCard: userInfo.idcard
};
}
}
} catch (error) {
console.error('获取用户信息失败:', error);
}
};
/**
* 页面加载时获取用户信息
*/
onMounted(() => {
getUserInfo();
});
/**
* 身份证号码校验
* @param {string} idCard - 身份证号码
* @returns {boolean} - 是否有效
*/
const validateIdCard = (idCard) => {
if (!idCard) {
return { valid: false, error: '请输入身份证号码' };
}
// 身份证号码正则表达式
const idCardRegex = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
if (!idCardRegex.test(idCard)) {
return { valid: false, error: '身份证号码格式不正确' };
}
// 校验码验证
const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
const checkCodes = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
let sum = 0;
for (let i = 0; i < 17; i++) {
sum += parseInt(idCard[i]) * weights[i];
}
const checkCode = checkCodes[sum % 11];
const lastChar = idCard[17].toUpperCase();
if (checkCode !== lastChar) {
return { valid: false, error: '身份证号码校验失败' };
}
return { valid: true, error: '' };
};
/**
* 处理身份证号码失焦事件
*/
const handleIdCardBlur = () => {
const idCard = tempIdentityInfo.value.idCard;
if (idCard) {
const result = validateIdCard(idCard);
idCardError.value = result.error;
} else {
idCardError.value = '';
}
};
/**
* 显示银行选择弹窗
*/
const showBankPicker = () => {
// 设置当前选中的值
if (tempAccountInfo.value.bankName) {
bankPickerValue.value = [tempAccountInfo.value.bankName];
} else {
bankPickerValue.value = [bankOptions.value[0].value];
}
showBankModal.value = true;
};
/**
* 银行选择确认回调
*/
const onBankConfirm = ({ selectedValue }) => {
tempAccountInfo.value.bankName = selectedValue[0];
showBankModal.value = false;
};
/**
* 打开收款账号弹窗
*/
const openAccountModal = () => {
tempAccountInfo.value = { ...accountInfo.value };
showAccountModal.value = true;
};
/**
* 关闭收款账号弹窗
*/
const closeAccountModal = () => {
showAccountModal.value = false;
tempAccountInfo.value = { bankName: '', bankAccount: '' };
};
/**
* 保存收款账号信息
*/
const saveAccountInfo = async () => {
if (!tempAccountInfo.value.bankName || !tempAccountInfo.value.bankAccount) {
Taro.showToast({
title: '请填写完整信息',
icon: 'none'
});
return;
}
try {
// 调用API保存收款账号信息
const result = await updateProfileAPI({
bank: tempAccountInfo.value.bankName,
bank_no: tempAccountInfo.value.bankAccount
});
if (result.code) {
accountInfo.value = { ...tempAccountInfo.value };
// 更新全局用户状态
userStore.updateUserInfo({
bank: tempAccountInfo.value.bankName,
bank_no: tempAccountInfo.value.bankAccount
});
closeAccountModal();
Taro.showToast({
title: '保存成功',
icon: 'success'
});
}
} catch (error) {
console.error('保存收款账号失败:', error);
Taro.showToast({
title: '保存失败,请重试',
icon: 'none'
});
}
};
/**
* 打开身份信息弹窗
*/
const openIdentityModal = () => {
tempIdentityInfo.value = { ...identityInfo.value };
idCardError.value = '';
showIdentityModal.value = true;
};
/**
* 关闭身份信息弹窗
*/
const closeIdentityModal = () => {
showIdentityModal.value = false;
tempIdentityInfo.value = { userName: '', idCard: '' };
idCardError.value = '';
};
/**
* 保存身份信息
*/
const saveIdentityInfo = async () => {
if (!tempIdentityInfo.value.userName || !tempIdentityInfo.value.idCard) {
Taro.showToast({
title: '请填写完整信息',
icon: 'none'
});
return;
}
const validation = validateIdCard(tempIdentityInfo.value.idCard);
if (!validation.valid) {
Taro.showToast({
title: validation.error,
icon: 'none'
});
return;
}
try {
// 调用API保存身份信息
const result = await updateProfileAPI({
name: tempIdentityInfo.value.userName,
idcard: tempIdentityInfo.value.idCard
});
if (result.code) {
identityInfo.value = { ...tempIdentityInfo.value };
// 更新全局用户状态
userStore.updateUserInfo({
name: tempIdentityInfo.value.userName,
idcard: tempIdentityInfo.value.idCard
});
closeIdentityModal();
Taro.showToast({
title: '保存成功',
icon: 'success'
});
} else {
Taro.showToast({
title: result.message || '保存失败',
icon: 'none'
});
}
} catch (error) {
console.error('保存身份信息失败:', error);
Taro.showToast({
title: '保存失败,请重试',
icon: 'none'
});
}
};
/**
* 返回上一页
*/
const goBack = () => {
Taro.redirectTo({
url: '/pages/sell/index'
});
};
</script>
<script>
export default {
name: "collectionSettings",
};
</script>