微信小店联盟带货小程序

add.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. Page({
  2. data: {
  3. accountTypes: [
  4. {
  5. type: 'bank',
  6. name: '银行卡',
  7. icon: '/static/images/bank-icon.png'
  8. },
  9. {
  10. type: 'alipay',
  11. name: '支付宝',
  12. icon: '/static/images/alipay-icon.png'
  13. },
  14. {
  15. type: 'wechat',
  16. name: '微信',
  17. icon: '/static/images/wechat-icon.png'
  18. }
  19. ],
  20. bankList: [
  21. { name: '中国银行', code: 'BOC', logo: '/static/images/bank-logos/boc.png' },
  22. { name: '工商银行', code: 'ICBC', logo: '/static/images/bank-logos/icbc.png' },
  23. { name: '农业银行', code: 'ABC', logo: '/static/images/bank-logos/abc.png' },
  24. { name: '建设银行', code: 'CCB', logo: '/static/images/bank-logos/ccb.png' },
  25. { name: '交通银行', code: 'COMM', logo: '/static/images/bank-logos/comm.png' },
  26. { name: '招商银行', code: 'CMB', logo: '/static/images/bank-logos/cmb.png' },
  27. { name: '邮政银行', code: 'PSBC', logo: '/static/images/bank-logos/psbc.png' },
  28. { name: '浦发银行', code: 'SPDB', logo: '/static/images/bank-logos/spdb.png' },
  29. { name: '民生银行', code: 'CMBC', logo: '/static/images/bank-logos/cmbc.png' },
  30. { name: '兴业银行', code: 'CIB', logo: '/static/images/bank-logos/cib.png' },
  31. { name: '光大银行', code: 'CEB', logo: '/static/images/bank-logos/ceb.png' },
  32. { name: '华夏银行', code: 'HXB', logo: '/static/images/bank-logos/hxb.png' },
  33. { name: '广发银行', code: 'GDB', logo: '/static/images/bank-logos/gdb.png' },
  34. { name: '平安银行', code: 'PAB', logo: '/static/images/bank-logos/pab.png' }
  35. ],
  36. selectedAccountType: null,
  37. selectedBank: null,
  38. accountNumber: '',
  39. accountName: '',
  40. isDefault: false,
  41. showBankList: false
  42. },
  43. // 选择账户类型
  44. selectAccountType(e) {
  45. const { type } = e.currentTarget.dataset
  46. this.setData({
  47. selectedAccountType: type,
  48. selectedBank: type === 'bank' ? null : this.data.selectedBank,
  49. accountNumber: '',
  50. accountName: ''
  51. })
  52. },
  53. // 显示银行列表
  54. showBankList() {
  55. if (this.data.selectedAccountType === 'bank') {
  56. this.setData({ showBankList: true })
  57. }
  58. },
  59. // 隐藏银行列表
  60. hideBankList() {
  61. this.setData({ showBankList: false })
  62. },
  63. // 阻止事件冒泡
  64. preventTap() {},
  65. // 选择银行
  66. selectBank(e) {
  67. const { code } = e.currentTarget.dataset
  68. this.setData({
  69. selectedBank: this.data.bankList.find(bank => bank.code === code),
  70. showBankList: false
  71. })
  72. },
  73. // 输入账号
  74. onAccountNumberInput(e) {
  75. this.setData({
  76. accountNumber: e.detail.value
  77. })
  78. },
  79. // 输入姓名
  80. onAccountNameInput(e) {
  81. this.setData({
  82. accountName: e.detail.value
  83. })
  84. },
  85. // 切换默认状态
  86. toggleDefault() {
  87. this.setData({
  88. isDefault: !this.data.isDefault
  89. })
  90. },
  91. // 保存账户
  92. saveAccount() {
  93. const {
  94. selectedAccountType,
  95. selectedBank,
  96. accountNumber,
  97. accountName,
  98. isDefault
  99. } = this.data
  100. // 验证账户类型
  101. if (!selectedAccountType) {
  102. wx.showToast({
  103. title: '请选择账户类型',
  104. icon: 'none'
  105. })
  106. return
  107. }
  108. // 验证银行(如果是银行卡)
  109. if (selectedAccountType === 'bank' && !selectedBank) {
  110. wx.showToast({
  111. title: '请选择银行',
  112. icon: 'none'
  113. })
  114. return
  115. }
  116. // 验证账号
  117. if (!accountNumber) {
  118. wx.showToast({
  119. title: '请输入账号',
  120. icon: 'none'
  121. })
  122. return
  123. }
  124. // 验证姓名
  125. if (!accountName) {
  126. wx.showToast({
  127. title: '请输入姓名',
  128. icon: 'none'
  129. })
  130. return
  131. }
  132. // 准备提交数据
  133. const accountData = {
  134. type: selectedAccountType,
  135. bankName: selectedAccountType === 'bank' ? selectedBank.name : null,
  136. accountNumber,
  137. accountName,
  138. isDefault
  139. }
  140. // TODO: 调用后端API保存账户
  141. wx.showLoading({ title: '保存中...' })
  142. setTimeout(() => {
  143. wx.hideLoading()
  144. wx.showToast({
  145. title: '账户添加成功',
  146. icon: 'success',
  147. success: () => {
  148. wx.navigateBack()
  149. }
  150. })
  151. }, 1500)
  152. }
  153. })