123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- Page({
- data: {
- accountTypes: [
- {
- type: 'bank',
- name: '银行卡',
- icon: '/static/images/bank-icon.png'
- },
- {
- type: 'alipay',
- name: '支付宝',
- icon: '/static/images/alipay-icon.png'
- },
- {
- type: 'wechat',
- name: '微信',
- icon: '/static/images/wechat-icon.png'
- }
- ],
- bankList: [
- { name: '中国银行', code: 'BOC', logo: '/static/images/bank-logos/boc.png' },
- { name: '工商银行', code: 'ICBC', logo: '/static/images/bank-logos/icbc.png' },
- { name: '农业银行', code: 'ABC', logo: '/static/images/bank-logos/abc.png' },
- { name: '建设银行', code: 'CCB', logo: '/static/images/bank-logos/ccb.png' },
- { name: '交通银行', code: 'COMM', logo: '/static/images/bank-logos/comm.png' },
- { name: '招商银行', code: 'CMB', logo: '/static/images/bank-logos/cmb.png' },
- { name: '邮政银行', code: 'PSBC', logo: '/static/images/bank-logos/psbc.png' },
- { name: '浦发银行', code: 'SPDB', logo: '/static/images/bank-logos/spdb.png' },
- { name: '民生银行', code: 'CMBC', logo: '/static/images/bank-logos/cmbc.png' },
- { name: '兴业银行', code: 'CIB', logo: '/static/images/bank-logos/cib.png' },
- { name: '光大银行', code: 'CEB', logo: '/static/images/bank-logos/ceb.png' },
- { name: '华夏银行', code: 'HXB', logo: '/static/images/bank-logos/hxb.png' },
- { name: '广发银行', code: 'GDB', logo: '/static/images/bank-logos/gdb.png' },
- { name: '平安银行', code: 'PAB', logo: '/static/images/bank-logos/pab.png' }
- ],
- selectedAccountType: null,
- selectedBank: null,
- accountNumber: '',
- accountName: '',
- isDefault: false,
- showBankList: false
- },
- // 选择账户类型
- selectAccountType(e) {
- const { type } = e.currentTarget.dataset
- this.setData({
- selectedAccountType: type,
- selectedBank: type === 'bank' ? null : this.data.selectedBank,
- accountNumber: '',
- accountName: ''
- })
- },
- // 显示银行列表
- showBankList() {
- if (this.data.selectedAccountType === 'bank') {
- this.setData({ showBankList: true })
- }
- },
- // 隐藏银行列表
- hideBankList() {
- this.setData({ showBankList: false })
- },
- // 阻止事件冒泡
- preventTap() {},
- // 选择银行
- selectBank(e) {
- const { code } = e.currentTarget.dataset
- this.setData({
- selectedBank: this.data.bankList.find(bank => bank.code === code),
- showBankList: false
- })
- },
- // 输入账号
- onAccountNumberInput(e) {
- this.setData({
- accountNumber: e.detail.value
- })
- },
- // 输入姓名
- onAccountNameInput(e) {
- this.setData({
- accountName: e.detail.value
- })
- },
- // 切换默认状态
- toggleDefault() {
- this.setData({
- isDefault: !this.data.isDefault
- })
- },
- // 保存账户
- saveAccount() {
- const {
- selectedAccountType,
- selectedBank,
- accountNumber,
- accountName,
- isDefault
- } = this.data
- // 验证账户类型
- if (!selectedAccountType) {
- wx.showToast({
- title: '请选择账户类型',
- icon: 'none'
- })
- return
- }
- // 验证银行(如果是银行卡)
- if (selectedAccountType === 'bank' && !selectedBank) {
- wx.showToast({
- title: '请选择银行',
- icon: 'none'
- })
- return
- }
- // 验证账号
- if (!accountNumber) {
- wx.showToast({
- title: '请输入账号',
- icon: 'none'
- })
- return
- }
- // 验证姓名
- if (!accountName) {
- wx.showToast({
- title: '请输入姓名',
- icon: 'none'
- })
- return
- }
- // 准备提交数据
- const accountData = {
- type: selectedAccountType,
- bankName: selectedAccountType === 'bank' ? selectedBank.name : null,
- accountNumber,
- accountName,
- isDefault
- }
- // TODO: 调用后端API保存账户
- wx.showLoading({ title: '保存中...' })
-
- setTimeout(() => {
- wx.hideLoading()
- wx.showToast({
- title: '账户添加成功',
- icon: 'success',
- success: () => {
- wx.navigateBack()
- }
- })
- }, 1500)
- }
- })
|