feat(collectionSettings): 添加银行卡图片上传功能
新增银行卡正面照片上传组件,包含上传、预览和删除功能 - 添加样式文件定义上传组件外观和交互效果 - 实现图片选择、上传至服务器功能 - 添加预览和删除图片功能 - 更新表单数据结构和API调用以支持银行卡图片
Showing
2 changed files
with
222 additions
and
7 deletions
| ... | @@ -275,3 +275,84 @@ | ... | @@ -275,3 +275,84 @@ |
| 275 | font-weight: 500; | 275 | font-weight: 500; |
| 276 | } | 276 | } |
| 277 | } | 277 | } |
| 278 | + | ||
| 279 | +// 银行卡图片上传样式 | ||
| 280 | +.bank-img-container { | ||
| 281 | + margin-top: 16rpx; | ||
| 282 | + | ||
| 283 | + .bank-img-upload { | ||
| 284 | + width: 100%; | ||
| 285 | + height: 200rpx; | ||
| 286 | + border: 2rpx dashed #ddd; | ||
| 287 | + border-radius: 12rpx; | ||
| 288 | + display: flex; | ||
| 289 | + flex-direction: column; | ||
| 290 | + align-items: center; | ||
| 291 | + justify-content: center; | ||
| 292 | + background-color: #fafafa; | ||
| 293 | + transition: all 0.3s ease; | ||
| 294 | + | ||
| 295 | + &:active { | ||
| 296 | + background-color: #f0f0f0; | ||
| 297 | + border-color: #ccc; | ||
| 298 | + } | ||
| 299 | + | ||
| 300 | + .upload-icon { | ||
| 301 | + font-size: 48rpx; | ||
| 302 | + color: #999; | ||
| 303 | + margin-bottom: 8rpx; | ||
| 304 | + } | ||
| 305 | + | ||
| 306 | + .upload-text { | ||
| 307 | + font-size: 28rpx; | ||
| 308 | + color: #666; | ||
| 309 | + } | ||
| 310 | + } | ||
| 311 | + | ||
| 312 | + .bank-img-preview { | ||
| 313 | + width: 100%; | ||
| 314 | + position: relative; | ||
| 315 | + | ||
| 316 | + .bank-img-image { | ||
| 317 | + width: 100%; | ||
| 318 | + height: 200rpx; | ||
| 319 | + border-radius: 12rpx; | ||
| 320 | + object-fit: cover; | ||
| 321 | + } | ||
| 322 | + | ||
| 323 | + .bank-img-actions { | ||
| 324 | + display: flex; | ||
| 325 | + justify-content: space-between; | ||
| 326 | + margin-top: 16rpx; | ||
| 327 | + gap: 16rpx; | ||
| 328 | + | ||
| 329 | + .change-img-btn, | ||
| 330 | + .delete-img-btn { | ||
| 331 | + flex: 1; | ||
| 332 | + text-align: center; | ||
| 333 | + padding: 16rpx; | ||
| 334 | + border-radius: 8rpx; | ||
| 335 | + font-size: 28rpx; | ||
| 336 | + transition: all 0.3s ease; | ||
| 337 | + } | ||
| 338 | + | ||
| 339 | + .change-img-btn { | ||
| 340 | + background-color: #f97316; | ||
| 341 | + color: #fff; | ||
| 342 | + | ||
| 343 | + &:active { | ||
| 344 | + background-color: #ea580c; | ||
| 345 | + } | ||
| 346 | + } | ||
| 347 | + | ||
| 348 | + .delete-img-btn { | ||
| 349 | + background-color: #ef4444; | ||
| 350 | + color: #fff; | ||
| 351 | + | ||
| 352 | + &:active { | ||
| 353 | + background-color: #dc2626; | ||
| 354 | + } | ||
| 355 | + } | ||
| 356 | + } | ||
| 357 | + } | ||
| 358 | +} | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-09-19 14:11:06 | 2 | * @Date: 2022-09-19 14:11:06 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-08-06 17:43:18 | 4 | + * @LastEditTime: 2025-08-07 14:52:58 |
| 5 | * @FilePath: /jgdl/src/pages/collectionSettings/index.vue | 5 | * @FilePath: /jgdl/src/pages/collectionSettings/index.vue |
| 6 | * @Description: 收款设置 | 6 | * @Description: 收款设置 |
| 7 | --> | 7 | --> |
| ... | @@ -74,6 +74,29 @@ | ... | @@ -74,6 +74,29 @@ |
| 74 | :cursor-spacing="50" | 74 | :cursor-spacing="50" |
| 75 | /> | 75 | /> |
| 76 | </view> | 76 | </view> |
| 77 | + | ||
| 78 | + <!-- 银行卡正面照片上传 --> | ||
| 79 | + <view class="form-item"> | ||
| 80 | + <text class="form-label">银行卡正面照</text> | ||
| 81 | + <view class="bank-img-container"> | ||
| 82 | + <view v-if="tempAccountInfo.bankImg" class="bank-img-preview"> | ||
| 83 | + <image | ||
| 84 | + :src="tempAccountInfo.bankImg" | ||
| 85 | + class="bank-img-image" | ||
| 86 | + mode="aspectFill" | ||
| 87 | + @tap="previewBankImg" | ||
| 88 | + /> | ||
| 89 | + <view class="bank-img-actions"> | ||
| 90 | + <text class="change-img-btn" @tap="changeBankImg">重新上传</text> | ||
| 91 | + <text class="delete-img-btn" @tap="deleteBankImg">删除</text> | ||
| 92 | + </view> | ||
| 93 | + </view> | ||
| 94 | + <view v-else class="bank-img-upload" @tap="changeBankImg"> | ||
| 95 | + <text class="upload-icon">+</text> | ||
| 96 | + <text class="upload-text">上传银行卡正面照</text> | ||
| 97 | + </view> | ||
| 98 | + </view> | ||
| 99 | + </view> | ||
| 77 | </view> | 100 | </view> |
| 78 | 101 | ||
| 79 | <view class="modal-footer"> | 102 | <view class="modal-footer"> |
| ... | @@ -187,6 +210,7 @@ import "./index.less"; | ... | @@ -187,6 +210,7 @@ import "./index.less"; |
| 187 | // 导入接口 | 210 | // 导入接口 |
| 188 | import { updateProfileAPI, getProfileAPI } from '@/api/index' | 211 | import { updateProfileAPI, getProfileAPI } from '@/api/index' |
| 189 | import { getBanksAPI } from '@/api/other' | 212 | import { getBanksAPI } from '@/api/other' |
| 213 | +import BASE_URL from '@/utils/config' | ||
| 190 | 214 | ||
| 191 | // 导入用户状态管理 | 215 | // 导入用户状态管理 |
| 192 | import { useUserStore } from '@/stores/user' | 216 | import { useUserStore } from '@/stores/user' |
| ... | @@ -211,7 +235,8 @@ const showBackButton = computed(() => { | ... | @@ -211,7 +235,8 @@ const showBackButton = computed(() => { |
| 211 | */ | 235 | */ |
| 212 | const accountInfo = ref({ | 236 | const accountInfo = ref({ |
| 213 | bankName: '', | 237 | bankName: '', |
| 214 | - bankAccount: '' | 238 | + bankAccount: '', |
| 239 | + bankImg: '' | ||
| 215 | }); | 240 | }); |
| 216 | 241 | ||
| 217 | /** | 242 | /** |
| ... | @@ -227,7 +252,8 @@ const identityInfo = ref({ | ... | @@ -227,7 +252,8 @@ const identityInfo = ref({ |
| 227 | */ | 252 | */ |
| 228 | const tempAccountInfo = ref({ | 253 | const tempAccountInfo = ref({ |
| 229 | bankName: '', | 254 | bankName: '', |
| 230 | - bankAccount: '' | 255 | + bankAccount: '', |
| 256 | + bankImg: '' | ||
| 231 | }); | 257 | }); |
| 232 | 258 | ||
| 233 | /** | 259 | /** |
| ... | @@ -289,7 +315,8 @@ const getUserInfo = async () => { | ... | @@ -289,7 +315,8 @@ const getUserInfo = async () => { |
| 289 | if (userInfo.bank_id && userInfo.bank_no) { | 315 | if (userInfo.bank_id && userInfo.bank_no) { |
| 290 | accountInfo.value = { | 316 | accountInfo.value = { |
| 291 | bankName: userInfo.bank_id, // 存储银行ID | 317 | bankName: userInfo.bank_id, // 存储银行ID |
| 292 | - bankAccount: userInfo.bank_no | 318 | + bankAccount: userInfo.bank_no, |
| 319 | + bankImg: userInfo.bank_img || '' // 存储银行卡图片 | ||
| 293 | }; | 320 | }; |
| 294 | } | 321 | } |
| 295 | 322 | ||
| ... | @@ -410,7 +437,7 @@ const openAccountModal = () => { | ... | @@ -410,7 +437,7 @@ const openAccountModal = () => { |
| 410 | */ | 437 | */ |
| 411 | const closeAccountModal = () => { | 438 | const closeAccountModal = () => { |
| 412 | showAccountModal.value = false; | 439 | showAccountModal.value = false; |
| 413 | - tempAccountInfo.value = { bankName: '', bankAccount: '' }; | 440 | + tempAccountInfo.value = { bankName: '', bankAccount: '', bankImg: '' }; |
| 414 | }; | 441 | }; |
| 415 | 442 | ||
| 416 | /** | 443 | /** |
| ... | @@ -429,7 +456,8 @@ const saveAccountInfo = async () => { | ... | @@ -429,7 +456,8 @@ const saveAccountInfo = async () => { |
| 429 | // 调用API保存收款账号信息 | 456 | // 调用API保存收款账号信息 |
| 430 | const result = await updateProfileAPI({ | 457 | const result = await updateProfileAPI({ |
| 431 | bank_id: tempAccountInfo.value.bankName, // 发送银行ID | 458 | bank_id: tempAccountInfo.value.bankName, // 发送银行ID |
| 432 | - bank_no: tempAccountInfo.value.bankAccount | 459 | + bank_no: tempAccountInfo.value.bankAccount, |
| 460 | + bank_img: tempAccountInfo.value.bankImg // 发送银行卡图片 | ||
| 433 | }); | 461 | }); |
| 434 | 462 | ||
| 435 | if (result.code) { | 463 | if (result.code) { |
| ... | @@ -438,7 +466,8 @@ const saveAccountInfo = async () => { | ... | @@ -438,7 +466,8 @@ const saveAccountInfo = async () => { |
| 438 | // 更新全局用户状态 | 466 | // 更新全局用户状态 |
| 439 | userStore.updateUserInfo({ | 467 | userStore.updateUserInfo({ |
| 440 | bank_id: tempAccountInfo.value.bankName, // 存储银行ID | 468 | bank_id: tempAccountInfo.value.bankName, // 存储银行ID |
| 441 | - bank_no: tempAccountInfo.value.bankAccount | 469 | + bank_no: tempAccountInfo.value.bankAccount, |
| 470 | + bank_img: tempAccountInfo.value.bankImg // 存储银行卡图片 | ||
| 442 | }); | 471 | }); |
| 443 | 472 | ||
| 444 | closeAccountModal(); | 473 | closeAccountModal(); |
| ... | @@ -476,6 +505,111 @@ const closeIdentityModal = () => { | ... | @@ -476,6 +505,111 @@ const closeIdentityModal = () => { |
| 476 | }; | 505 | }; |
| 477 | 506 | ||
| 478 | /** | 507 | /** |
| 508 | + * 上传银行卡正面照 | ||
| 509 | + */ | ||
| 510 | +const changeBankImg = () => { | ||
| 511 | + Taro.chooseImage({ | ||
| 512 | + count: 1, | ||
| 513 | + sizeType: ['compressed'], | ||
| 514 | + sourceType: ['album', 'camera'], | ||
| 515 | + success: function (res) { | ||
| 516 | + const tempFilePath = res.tempFilePaths[0] | ||
| 517 | + uploadBankImage(tempFilePath) | ||
| 518 | + }, | ||
| 519 | + fail: function () { | ||
| 520 | + Taro.showToast({ | ||
| 521 | + title: '选择图片失败', | ||
| 522 | + icon: 'none' | ||
| 523 | + }) | ||
| 524 | + } | ||
| 525 | + }) | ||
| 526 | +} | ||
| 527 | + | ||
| 528 | +/** | ||
| 529 | + * 上传银行卡图片到服务器 | ||
| 530 | + * @param {String} filePath - 图片文件路径 | ||
| 531 | + */ | ||
| 532 | +const uploadBankImage = (filePath) => { | ||
| 533 | + // 显示上传中提示 | ||
| 534 | + Taro.showLoading({ | ||
| 535 | + title: '上传中', | ||
| 536 | + mask: true | ||
| 537 | + }) | ||
| 538 | + | ||
| 539 | + // 上传图片 | ||
| 540 | + wx.uploadFile({ | ||
| 541 | + url: BASE_URL + '/admin/?m=srv&a=upload', | ||
| 542 | + filePath, | ||
| 543 | + name: 'file', | ||
| 544 | + header: { | ||
| 545 | + 'content-type': 'multipart/form-data', | ||
| 546 | + }, | ||
| 547 | + success: function (res) { | ||
| 548 | + let upload_data = JSON.parse(res.data); | ||
| 549 | + Taro.hideLoading({ | ||
| 550 | + success: () => { | ||
| 551 | + if (res.statusCode === 200) { | ||
| 552 | + tempAccountInfo.value.bankImg = upload_data.data.src; | ||
| 553 | + Taro.showToast({ | ||
| 554 | + title: '上传成功', | ||
| 555 | + icon: 'success' | ||
| 556 | + }) | ||
| 557 | + } else { | ||
| 558 | + Taro.showToast({ | ||
| 559 | + icon: 'error', | ||
| 560 | + title: '服务器错误,稍后重试!', | ||
| 561 | + mask: true | ||
| 562 | + }) | ||
| 563 | + } | ||
| 564 | + }, | ||
| 565 | + }); | ||
| 566 | + }, | ||
| 567 | + fail: function (res) { | ||
| 568 | + Taro.hideLoading({ | ||
| 569 | + success: () => { | ||
| 570 | + Taro.showToast({ | ||
| 571 | + icon: 'error', | ||
| 572 | + title: '上传失败,稍后重试!', | ||
| 573 | + mask: true | ||
| 574 | + }) | ||
| 575 | + }, | ||
| 576 | + }); | ||
| 577 | + } | ||
| 578 | + }) | ||
| 579 | +} | ||
| 580 | + | ||
| 581 | +/** | ||
| 582 | + * 预览银行卡图片 | ||
| 583 | + */ | ||
| 584 | +const previewBankImg = () => { | ||
| 585 | + if (tempAccountInfo.value.bankImg) { | ||
| 586 | + Taro.previewImage({ | ||
| 587 | + urls: [tempAccountInfo.value.bankImg], | ||
| 588 | + current: tempAccountInfo.value.bankImg | ||
| 589 | + }) | ||
| 590 | + } | ||
| 591 | +} | ||
| 592 | + | ||
| 593 | +/** | ||
| 594 | + * 删除银行卡图片 | ||
| 595 | + */ | ||
| 596 | +const deleteBankImg = () => { | ||
| 597 | + Taro.showModal({ | ||
| 598 | + title: '确认删除', | ||
| 599 | + content: '确定要删除银行卡照片吗?', | ||
| 600 | + success: function (res) { | ||
| 601 | + if (res.confirm) { | ||
| 602 | + tempAccountInfo.value.bankImg = '' | ||
| 603 | + Taro.showToast({ | ||
| 604 | + title: '删除成功', | ||
| 605 | + icon: 'success' | ||
| 606 | + }) | ||
| 607 | + } | ||
| 608 | + } | ||
| 609 | + }) | ||
| 610 | +} | ||
| 611 | + | ||
| 612 | +/** | ||
| 479 | * 保存身份信息 | 613 | * 保存身份信息 |
| 480 | */ | 614 | */ |
| 481 | const saveIdentityInfo = async () => { | 615 | const saveIdentityInfo = async () => { | ... | ... |
-
Please register or login to post a comment