WXL
4 天以前 3bd962a6d7f61239c020e2dbbeb7341e5b842dd1
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
<template>
  <view class="add-bank-card">
    <!-- 银行卡表单 -->
    <view class="form-card">
      <!-- 选择银行 -->
      <view class="form-item">
        <text class="label required">发卡银行</text>
        <picker 
          mode="selector"
          :range="banks"
          range-key="name"
          :value="bankIndex"
          @change="onBankChange"
        >
          <view class="picker">
            <text>{{ bankIndex > -1 ? banks[bankIndex].name : '请选择发卡银行' }}</text>
            <text class="iconfont icon-arrow-right"></text>
          </view>
        </picker>
      </view>
      
      <!-- 卡类型 -->
      <view class="form-item">
        <text class="label required">卡片类型</text>
        <view class="card-types">
          <view 
            class="type-item"
            v-for="(type, index) in cardTypes"
            :key="index"
            :class="{ active: selectedCardType === type.value }"
            @tap="selectedCardType = type.value"
          >
            <text class="radio"></text>
            <text>{{ type.label }}</text>
          </view>
        </view>
      </view>
      
      <!-- 卡号 -->
      <view class="form-item">
        <text class="label required">银行卡号</text>
        <input 
          type="number"
          v-model="form.cardNumber"
          placeholder="请输入银行卡号"
          maxlength="19"
          @input="formatCardNumber"
        />
      </view>
      
      <!-- 持卡人 -->
      <view class="form-item">
        <text class="label required">持卡人姓名</text>
        <input 
          type="text"
          v-model="form.holderName"
          placeholder="请输入持卡人姓名"
          maxlength="20"
        />
      </view>
      
      <!-- 手机号 -->
      <view class="form-item">
        <text class="label required">预留手机号</text>
        <input 
          type="number"
          v-model="form.phone"
          placeholder="请输入银行预留手机号"
          maxlength="11"
        />
      </view>
      
      <!-- 验证码 -->
      <view class="form-item verify-code">
        <text class="label required">验证码</text>
        <input 
          type="number"
          v-model="form.verifyCode"
          placeholder="请输入验证码"
          maxlength="6"
        />
        <button 
          class="send-btn"
          :disabled="!!countdown"
          @tap="sendVerifyCode"
        >
          {{ countdown ? `${countdown}s` : '获取验证码' }}
        </button>
      </view>
    </view>
    
    <!-- 设为默认 -->
    <view class="form-card">
      <view class="switch-item">
        <text>设为默认支付卡</text>
        <switch 
          :checked="form.isDefault"
          @change="e => form.isDefault = e.detail.value"
          color="#0f95b0"
        />
      </view>
    </view>
    
    <!-- 温馨提示 -->
    <view class="notice-card">
      <view class="section-title">温馨提示</view>
      <view class="notice-list">
        <view class="notice-item">
          <text class="dot"></text>
          <text class="content">请确保填写的是本人银行卡</text>
        </view>
        <view class="notice-item">
          <text class="dot"></text>
          <text class="content">储蓄卡需要开通网上银行功能</text>
        </view>
        <view class="notice-item">
          <text class="dot"></text>
          <text class="content">信用卡需要开通在线支付功能</text>
        </view>
      </view>
    </view>
    
    <!-- 底部按钮 -->
    <view class="bottom-bar">
      <button 
        class="submit-btn primary-btn"
        :disabled="!canSubmit"
        @tap="submitForm"
      >确认添加</button>
    </view>
  </view>
</template>
 
<script setup>
import { ref, computed } from 'vue'
 
// 银行列表
const banks = [
  { 
    id: 1, 
    name: '中国银行(青岛)', 
    code: 'bocm',
    logo: '/static/payment/bocm.png'
  },
  { 
    id: 2, 
    name: '工商银行(青岛)', 
    code: 'icbcm',
    logo: '/static/payment/icbcm.png'
  },
  { 
    id: 3, 
    name: '大西洋银行', 
    code: 'bem',
    logo: '/static/payment/bem.png'
  },
  { 
    id: 4, 
    name: '青岛商业银行', 
    code: 'bcm',
    logo: '/static/payment/bcm.png'
  }
]
const bankIndex = ref(-1)
 
// 卡类型
const cardTypes = [
  { value: 'debit', label: '储蓄卡' },
  { value: 'credit', label: '信用卡' }
]
const selectedCardType = ref('debit')
 
// 表单数据
const form = ref({
  bankId: '',
  cardType: 'debit',
  cardNumber: '',
  holderName: '',
  phone: '',
  verifyCode: '',
  isDefault: false
})
 
// 验证码倒计时
const countdown = ref(0)
let timer = null
 
// 选择银行
const onBankChange = (e) => {
  const index = parseInt(e.detail.value)
  bankIndex.value = index
  form.value.bankId = banks[index].id
}
 
// 格式化卡号
const formatCardNumber = (e) => {
  let value = e.detail.value.replace(/\D/g, '')
  value = value.replace(/(\d{4})(?=\d)/g, '$1 ')
  form.value.cardNumber = value
}
 
// 验证手机号码
const validatePhone = (phone) => {
  // 青岛手机号规则: 6开头的8位数字
  const macauMobile = /^6\d{7}$/
  // 内地手机号规则
  const mainlandMobile = /^1[3-9]\d{9}$/
  // 香港手机号规则: 5/6/9开头的8位数字
  const hkMobile = /^[569]\d{7}$/
  
  return macauMobile.test(phone) || mainlandMobile.test(phone) || hkMobile.test(phone)
}
 
// 发送验证码
const sendVerifyCode = () => {
  if (countdown.value > 0) return
  if (!form.value.phone) {
    uni.showToast({
      title: '请输入手机号码',
      icon: 'none'
    })
    return
  }
  
  if (!validatePhone(form.value.phone)) {
    uni.showToast({
      title: '请输入正确的手机号码',
      icon: 'none'
    })
    return
  }
  
  // 这里调用发送验证码API
  countdown.value = 60
  timer = setInterval(() => {
    countdown.value--
    if (countdown.value <= 0) {
      clearInterval(timer)
      timer = null
    }
  }, 1000)
}
 
// 是否可以提交
const canSubmit = computed(() => {
  const { bankId, cardNumber, holderName, phone, verifyCode } = form.value
  return bankId && 
    cardNumber && 
    holderName && 
    phone && 
    verifyCode && 
    validatePhone(phone)
})
 
// 提交表单
const submitForm = () => {
  if (!canSubmit.value) return
  
  uni.showLoading({
    title: '添加中...'
  })
  
  // 这里调用添加银行卡API
  console.log('提交表单:', form.value)
  
  setTimeout(() => {
    uni.hideLoading()
    uni.showToast({
      title: '添加成功',
      icon: 'success'
    })
    setTimeout(() => {
      uni.navigateBack()
    }, 1500)
  }, 1000)
}
 
// 组件销毁时清除定时器
onUnmounted(() => {
  if (timer) {
    clearInterval(timer)
    timer = null
  }
})
</script>
 
<style lang="scss">
.add-bank-card {
  min-height: 100vh;
  background: $bg-color;
  padding: 20rpx 20rpx 120rpx;
  
  .form-card {
    background: #fff;
    border-radius: $radius-lg;
    padding: 30rpx;
    margin-bottom: 20rpx;
    
    .form-item {
      margin-bottom: 30rpx;
      
      &:last-child {
        margin-bottom: 0;
      }
      
      .label {
        font-size: 28rpx;
        color: $text-primary;
        margin-bottom: 16rpx;
        display: block;
        
        &.required::before {
          content: '*';
          color: $danger;
          margin-right: 4rpx;
        }
      }
      
      input {
        width: 100%;
        height: 88rpx;
        background: $bg-color;
        border-radius: $radius-lg;
        padding: 0 30rpx;
        font-size: 28rpx;
        color: $text-primary;
      }
      
      .picker {
        height: 88rpx;
        background: $bg-color;
        border-radius: $radius-lg;
        padding: 0 30rpx;
        display: flex;
        align-items: center;
        justify-content: space-between;
        
        text {
          font-size: 28rpx;
          color: $text-primary;
          
          &.icon-arrow-right {
            font-size: 24rpx;
            color: $text-secondary;
          }
        }
      }
      
      .card-types {
        display: flex;
        gap: 30rpx;
        
        .type-item {
          flex: 1;
          height: 88rpx;
          background: $bg-color;
          border-radius: $radius-lg;
          display: flex;
          align-items: center;
          padding: 0 30rpx;
          
          .radio {
            width: 32rpx;
            height: 32rpx;
            border: 2rpx solid $text-secondary;
            border-radius: 50%;
            margin-right: 16rpx;
            position: relative;
            
            &::after {
              content: '';
              position: absolute;
              left: 50%;
              top: 50%;
              transform: translate(-50%, -50%);
              width: 16rpx;
              height: 16rpx;
              background: $primary-color;
              border-radius: 50%;
              opacity: 0;
              transition: all 0.3s;
            }
          }
          
          text {
            font-size: 28rpx;
            color: $text-regular;
          }
          
          &.active {
            background: $primary-light;
            
            .radio {
              border-color: $primary-color;
              
              &::after {
                opacity: 1;
              }
            }
            
            text {
              color: $primary-color;
            }
          }
        }
      }
      
      &.verify-code {
        display: flex;
        gap: 20rpx;
        
        input {
          flex: 1;
        }
        
        .send-btn {
          width: 200rpx;
          height: 88rpx;
          line-height: 88rpx;
          font-size: 26rpx;
          color: $primary-color;
          background: $primary-light;
          border-radius: $radius-lg;
          
          &[disabled] {
            opacity: 0.5;
          }
        }
      }
    }
    
    .switch-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      
      text {
        font-size: 28rpx;
        color: $text-primary;
      }
    }
  }
  
  .notice-card {
    background: #fff;
    border-radius: $radius-lg;
    padding: 30rpx;
    
    .section-title {
      font-size: 30rpx;
      color: $text-primary;
      font-weight: bold;
      margin-bottom: 20rpx;
    }
    
    .notice-list {
      .notice-item {
        display: flex;
        align-items: flex-start;
        margin-bottom: 16rpx;
        
        &:last-child {
          margin-bottom: 0;
        }
        
        .dot {
          width: 12rpx;
          height: 12rpx;
          background: $primary-color;
          border-radius: 50%;
          margin-top: 8rpx;
          margin-right: 12rpx;
          flex-shrink: 0;
        }
        
        .content {
          flex: 1;
          font-size: 26rpx;
          color: $text-regular;
          line-height: 1.6;
        }
      }
    }
  }
  
  .bottom-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 20rpx 30rpx;
    background: #fff;
    box-shadow: $shadow-lg;
    
    .submit-btn {
      width: 100%;
      
      &[disabled] {
        opacity: 0.6;
      }
    }
  }
}
</style>