index.vue
10.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
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-08-05 18:35:51
* @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: '80%' }"
: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>
<nut-input
v-model="tempAccountInfo.bankName"
placeholder="请输入银行名称"
class="form-input"
/>
</view>
<view class="form-item">
<text class="form-label">银行账号</text>
<nut-input
v-model="tempAccountInfo.bankAccount"
placeholder="请输入银行账号"
class="form-input"
type="number"
/>
</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="showIdentityModal"
position="bottom"
:style="{ width: '100%', height: '80%' }"
: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>
<nut-input
v-model="tempIdentityInfo.userName"
placeholder="请输入真实姓名"
class="form-input"
/>
</view>
<view class="form-item">
<text class="form-label">身份证号码</text>
<nut-input
v-model="tempIdentityInfo.idCard"
placeholder="请输入身份证号码"
class="form-input"
maxlength="18"
@blur="handleIdCardBlur"
/>
<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>
</view>
</template>
<script setup>
import { ref, onMounted } from "vue";
import Taro from "@tarojs/taro";
import "./index.less";
// 导入接口
import { updateProfileAPI, getProfileAPI } from '@/api/index'
/**
* 收款账号信息
*/
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 idCardError = ref('');
/**
* 获取用户信息
*/
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 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 };
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 };
closeIdentityModal();
Taro.showToast({
title: '保存成功',
icon: 'success'
});
} else {
Taro.showToast({
title: result.message || '保存失败',
icon: 'none'
});
}
} catch (error) {
console.error('保存身份信息失败:', error);
Taro.showToast({
title: '保存失败,请重试',
icon: 'none'
});
}
};
</script>
<script>
export default {
name: "collectionSettings",
};
</script>