| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482 |
- <template>
- <view class="container">
- <!-- 表单区域 -->
- <scroll-view class="content" scroll-y>
- <view class="form-section">
- <view class="form-item">
- <view class="form-label">开户行</view>
- <!-- <input
- class="form-input"
- v-model="formData.bankName"
- placeholder="请输入开户行"
- placeholder-class="text-placeholder"
- /> -->
- <view style="flex:1" @click="openBankPicker">
- <view class="form-input picker-input" :class="{ placeholder: !formData.bankName }">
- {{ getBankLabel() || '请选择开户行' }}
- <image class="w32 h32" src="/static/image/icon_my_more.png" mode=""></image>
- </view>
- </view>
- </view>
- <view class="divider"></view>
-
- <view class="form-item">
- <view class="form-label">支行</view>
- <input
- class="form-input"
- v-model="formData.bankBranch"
- placeholder="请输入支行"
- placeholder-class="text-placeholder"
- />
- </view>
- <view class="divider"></view>
-
- <view class="form-item">
- <view class="form-label">银行卡号</view>
- <input
- class="form-input "
- v-model="formData.bankCardNo"
- placeholder="请输入银行卡号"
- type="number"
- maxlength="19"
- placeholder-class="text-placeholder"
- />
- </view>
- </view>
-
- <!-- 注意事项 -->
- <view class="notes-section">
- <view class="notes-title">注意:</view>
- <view class="notes-item">1、只能绑定认证用户本人的银行卡;</view>
- <view class="notes-item">2、每次更换次数不得超过三次。</view>
- </view>
- </scroll-view>
- <!-- 银行搜索弹窗 -->
- <view class="search-picker-popup" v-if="showBankPicker" @click="closeBankPicker">
- <view class="popup-content" @click.stop>
- <view class="popup-header">
- <text class="popup-title">选择开户行</text>
- <view class="popup-close" @click="closeBankPicker">×</view>
- </view>
- <view class="search-box">
- <input
- class="search-input"
- v-model="bankSearchKeyword"
- placeholder="请输入银行名称搜索"
- @blur="onBankSearch"
- />
- </view>
- <scroll-view class="search-list" scroll-y>
- <view
- class="search-item"
- v-for="(item, index) in filteredBankList"
- :key="index"
- :class="{ active: formData.bankName === item.label }"
- @click="selectBank(item)"
- >
- <text>{{ item.label }}</text>
- <text v-if="formData.bankName === item.label" class="check-icon">✓</text>
- </view>
- <view class="search-empty" v-if="filteredBankList.length === 0">
- <text>暂无匹配结果</text>
- </view>
- </scroll-view>
- </view>
- </view>
- <!-- 底部按钮 -->
- <view class="bottom-bar">
- <view class="submit-btn" @click="handleSubmit">确认添加</view>
- </view>
- </view>
- </template>
- <script>
- import {getBankTypeList} from '@/api/certification'
- import { addBankCard } from '@/api/bankCard'
- export default {
- data() {
- return {
- formData: {
- "bankBranch": "",
- "bankCardNo": "",
- "bankName": ""
- },
- showBankPicker: false,
- bankSearchKeyword: '',
- filteredBankList: []
- }
- },
- onLoad() {
- this.loadBankList()
- },
- methods: {
- goBack() {
- uni.navigateBack()
- },
- getBankLabel() {
- return this.formData.bankName || ''
- },
- openBankPicker() {
- this.showBankPicker = true
- this.bankSearchKeyword = ''
- },
- openBankPicker() {
- this.showBankPicker = true
- this.bankSearchKeyword = ''
- },
- closeBankPicker() {
- this.showBankPicker = false
- },
- async onBankSearch() {
- const keyword = this.bankSearchKeyword.trim()
- this.loadBankList(keyword)
- },
- selectBank(item) {
- this.formData.bankName = item.label
- this.closeBankPicker()
- },
- // 加载银行列表
- async loadBankList(keyword) {
- const params = {}
- // 如果传入了关键词,就用传入的
- if (keyword) {
- params.bankName = keyword.trim()
- }
- try {
- const res = await getBankTypeList(params)
- if (res.code === 200) {
- const arr = res.data
- this.filteredBankList = arr.map(item => ({
- label: item.bankName,
- value: item.id
- })).filter(opt => opt.label)
- }
- } catch (err) {
- console.log('银行类型加载失败', err)
- }
- },
- async handleSubmit() {
- // 表单验证
- if (!this.formData.bankName || !this.formData.bankName.trim()) {
- uni.showToast({
- icon: 'none',
- title: '请选择开户行'
- })
- return
- }
- if (!this.formData.bankBranch || !this.formData.bankBranch.trim()) {
- uni.showToast({
- icon: 'none',
- title: '请输入支行'
- })
- return
- }
- if (!this.formData.bankCardNo) {
- uni.showToast({
- icon: 'none',
- title: '请输入银行卡号'
- })
- return
- }
- // 银行卡号验证(简单验证)
- if (this.formData.bankCardNo.length < 16) {
- uni.showToast({
- icon: 'none',
- title: '请输入正确的银行卡号'
- })
- return
- }
- // uni.navigateTo({
- // url: '/pages_user/editBankCard'
- // })
- try {
- uni.showLoading({ title: '添加中...' })
- const res = await addBankCard(this.formData)
- uni.hideLoading()
- if (res.code === 200) {
- uni.showToast({
- icon: 'success',
- title: '添加成功'
- })
- setTimeout(() => {
- uni.navigateBack()
- }, 1500)
- } else {
- uni.showToast({
- icon: 'none',
- title: res.msg || '添加失败'
- })
- }
- } catch (e) {
- uni.hideLoading()
- uni.showToast({
- icon: 'none',
- title: '添加失败'
- })
- }
- }
- }
- }
- </script>
- <style lang="stylus">
- .text-placeholder{
- color: #C8C9CC !important;
- }
- </style>
- <style lang="scss" scoped>
-
- .container {
- // min-height: 100vh;
- background: #f5f5f5;
- display: flex;
- flex-direction: column;
- }
- .navbar {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 20rpx 24rpx;
- background: #fff;
- border-bottom: 1rpx solid #f0f0f0;
-
- .nav-left {
- width: 60rpx;
-
- .back-icon {
- font-size: 36rpx;
- color: #333;
- font-weight: bold;
- }
- }
-
- .nav-title {
- flex: 1;
- text-align: center;
- font-size: 36rpx;
- font-weight: bold;
- color: #333;
- }
-
- .nav-right {
- display: flex;
- align-items: center;
- gap: 24rpx;
- width: 60rpx;
- justify-content: flex-end;
-
- .more-icon {
- font-size: 32rpx;
- color: #333;
- }
-
- .eye-icon {
- font-size: 32rpx;
- color: #333;
- }
- }
- }
- .content {
- // flex: 1;
- // padding-bottom: 140rpx;
- }
- .form-section {
- background: #fff;
- // margin: 24rpx;
- // border-radius: 16rpx;
- overflow: hidden;
-
- .form-item {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 28rpx 32rpx;
- // min-height: 100rpx
- .form-label {
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- font-size: 28rpx;
- color: #666666;
- width: 150rpx;
- }
- .form-input {
- flex: 1;
- font-size: 28rpx;
- color: #333;
- text-align: right;
- margin-left: 24rpx;
-
- &.picker-input {
- display: flex;
- align-items: center;
- justify-content: flex-end;
-
- .arrow-right {
- font-size: 32rpx;
- color: #999;
- margin-left: 8rpx;
- }
- }
- }
- }
- // placeholder 样式(需要独立定义,不能嵌套)
- .placeholder {
- color: #C8C9CC !important;
- }
-
- .divider {
- height: 1rpx;
- background: #EBEDF0;
- margin-left: 24rpx;
- }
- }
- .notes-section {
- // background: #fff;
- // border-radius: 16rpx;
- padding: 22rpx 32rpx;
- // margin: 0 24rpx 24rpx;
-
- .notes-title {
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- font-size: 28rpx;
- color: #999999;
- line-height: 40rpx;
- }
-
- .notes-item {
- font-family: PingFang SC, PingFang SC;
- font-weight: 400;
- font-size: 28rpx;
- color: #999999;
- line-height: 40rpx;
- }
- }
- .bottom-bar {
- padding: 32rpx;
-
- .submit-btn {
- width: 100%;
- height: 88rpx;
- background: #388BFF;
- border-radius: 44rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 32rpx;
- font-weight: bold;
- color: #fff;
- }
- }
- .search-picker-popup {
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- background: rgba(0, 0, 0, 0.5);
- z-index: 1000;
- display: flex;
- align-items: flex-end;
-
- .popup-content {
- width: 100%;
- height: 80vh;
- background: #fff;
- border-radius: 24rpx 24rpx 0 0;
- display: flex;
- flex-direction: column;
- }
-
- .popup-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 32rpx;
- border-bottom: 1rpx solid #f0f0f0;
-
- .popup-title {
- font-size: 32rpx;
- font-weight: bold;
- color: #333;
- }
-
- .popup-close {
- font-size: 48rpx;
- color: #999;
- line-height: 1;
- }
- }
-
- .search-box {
- padding: 24rpx 32rpx;
-
- .search-input {
- //width: 100%;
- height: 72rpx;
- background: #f5f5f5;
- border-radius: 36rpx;
- padding: 0 32rpx;
- font-size: 28rpx;
- }
- }
-
- .search-list {
- flex: 1;
- height: 60%;
- padding: 0 32rpx 40rpx;
- box-sizing: border-box;
- .search-item {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 28rpx 0;
- border-bottom: 1rpx solid #f5f5f5;
-
- &:last-child {
- border-bottom: none;
- }
-
- &.active {
- color: #388BFF;
-
- text {
- color: #388BFF;
- }
- }
-
- .check-icon {
- color: #388BFF;
- font-size: 32rpx;
- font-weight: bold;
- }
-
- text {
- font-size: 28rpx;
- color: #333;
- }
- }
-
- .search-empty {
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 60rpx 0;
-
- text {
- font-size: 28rpx;
- color: #999;
- }
- }
- }
- }
- </style>
|