addBankCard.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <template>
  2. <view class="container">
  3. <!-- 表单区域 -->
  4. <scroll-view class="content" scroll-y>
  5. <view class="form-section">
  6. <view class="form-item">
  7. <view class="form-label">开户行</view>
  8. <picker mode="selector" :range="bankList" range-key="name" @change="onBankChange">
  9. <view class="form-input picker-input" :class="{ placeholder: !formData.bank }">
  10. {{ formData.bank || '请选择开户行' }}
  11. <image class="w36 h36" src="@/static/image/icon_my_more.png" mode=""></image>
  12. </view>
  13. </picker>
  14. </view>
  15. <view class="divider"></view>
  16. <view class="form-item">
  17. <view class="form-label">支行</view>
  18. <picker mode="selector" :range="branchList" range-key="name" @change="onBranchChange">
  19. <view class="form-input picker-input" :class="{ placeholder: !formData.branch }">
  20. {{ formData.branch || '请选择支行' }}
  21. <image class="w36 h36" src="@/static/image/icon_my_more.png" mode=""></image>
  22. </view>
  23. </picker>
  24. </view>
  25. <view class="divider"></view>
  26. <view class="form-item">
  27. <view class="form-label">银行卡号</view>
  28. <input
  29. class="form-input "
  30. v-model="formData.cardNumber"
  31. placeholder="请输入银行卡号"
  32. type="number"
  33. maxlength="19"
  34. placeholder-class="text-placeholder"
  35. />
  36. </view>
  37. </view>
  38. <!-- 注意事项 -->
  39. <view class="notes-section">
  40. <view class="notes-title">注意:</view>
  41. <view class="notes-item">1、只能绑定认证用户本人的银行卡;</view>
  42. <view class="notes-item">2、每次更换次数不得超过三次。</view>
  43. </view>
  44. </scroll-view>
  45. <!-- 底部按钮 -->
  46. <view class="bottom-bar">
  47. <view class="submit-btn" @click="handleSubmit">确认添加</view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import { addBankCard1, getBankList, getBranchList } from '@/api-js/bankCard'
  53. export default {
  54. data() {
  55. return {
  56. formData: {
  57. bank: '',
  58. branch: '',
  59. cardNumber: ''
  60. },
  61. bankList: [],
  62. branchList: []
  63. }
  64. },
  65. onLoad() {
  66. this.loadBankList()
  67. },
  68. methods: {
  69. async loadBankList() {
  70. try {
  71. const res = await getBankList()
  72. if (res.code === 200 && res.data) {
  73. this.bankList = res.data
  74. } else {
  75. // 默认数据
  76. this.bankList = [
  77. { name: '中国工商银行', id: 1 },
  78. { name: '中国建设银行', id: 2 },
  79. { name: '中国银行', id: 3 },
  80. { name: '中国农业银行', id: 4 }
  81. ]
  82. }
  83. } catch (e) {
  84. console.error('加载银行列表失败', e)
  85. this.bankList = [
  86. { name: '中国工商银行', id: 1 },
  87. { name: '中国建设银行', id: 2 },
  88. { name: '中国银行', id: 3 },
  89. { name: '中国农业银行', id: 4 }
  90. ]
  91. }
  92. },
  93. async loadBranchList(bankId) {
  94. try {
  95. const res = await getBranchList({ bankId })
  96. if (res.code === 200 && res.data) {
  97. this.branchList = res.data
  98. } else {
  99. this.branchList = [
  100. { name: '北京支行', id: 1 },
  101. { name: '上海支行', id: 2 },
  102. { name: '广州支行', id: 3 }
  103. ]
  104. }
  105. } catch (e) {
  106. this.branchList = [
  107. { name: '北京支行', id: 1 },
  108. { name: '上海支行', id: 2 },
  109. { name: '广州支行', id: 3 }
  110. ]
  111. }
  112. },
  113. onBankChange(e) {
  114. const index = e.detail.value
  115. this.formData.bank = this.bankList[index].name
  116. this.formData.bankId = this.bankList[index].id
  117. this.formData.branch = '' // 清空支行选择
  118. if (this.formData.bankId) {
  119. this.loadBranchList(this.formData.bankId)
  120. }
  121. },
  122. onBranchChange(e) {
  123. const index = e.detail.value
  124. this.formData.branch = this.branchList[index].name
  125. this.formData.branchId = this.branchList[index].id
  126. },
  127. goBack() {
  128. uni.navigateBack()
  129. },
  130. async handleSubmit() {
  131. // 表单验证
  132. // if (!this.formData.bank) {
  133. // uni.showToast({
  134. // icon: 'none',
  135. // title: '请选择开户行'
  136. // })
  137. // return
  138. // }
  139. // if (!this.formData.branch) {
  140. // uni.showToast({
  141. // icon: 'none',
  142. // title: '请选择支行'
  143. // })
  144. // return
  145. // }
  146. // if (!this.formData.cardNumber) {
  147. // uni.showToast({
  148. // icon: 'none',
  149. // title: '请输入银行卡号'
  150. // })
  151. // return
  152. // }
  153. // // 银行卡号验证(简单验证)
  154. // if (this.formData.cardNumber.length < 16) {
  155. // uni.showToast({
  156. // icon: 'none',
  157. // title: '请输入正确的银行卡号'
  158. // })
  159. // return
  160. // }
  161. uni.navigateTo({
  162. url: '/pages_user/editBankCard'
  163. })
  164. // try {
  165. // uni.showLoading({ title: '添加中...' })
  166. // const res = await addBankCard1(this.formData)
  167. // uni.hideLoading()
  168. // if (res.code === 200) {
  169. // uni.showToast({
  170. // icon: 'success',
  171. // title: '添加成功'
  172. // })
  173. // setTimeout(() => {
  174. // uni.navigateBack()
  175. // }, 1500)
  176. // } else {
  177. // uni.showToast({
  178. // icon: 'none',
  179. // title: res.msg || '添加失败'
  180. // })
  181. // }
  182. // } catch (e) {
  183. // uni.hideLoading()
  184. // uni.showToast({
  185. // icon: 'none',
  186. // title: '添加失败'
  187. // })
  188. // }
  189. }
  190. }
  191. }
  192. </script>
  193. <style lang="stylus">
  194. .text-placeholder{
  195. color: #C8C9CC !important;
  196. }
  197. </style>
  198. <style lang="scss" scoped>
  199. .container {
  200. // min-height: 100vh;
  201. background: #f5f5f5;
  202. display: flex;
  203. flex-direction: column;
  204. }
  205. .navbar {
  206. display: flex;
  207. align-items: center;
  208. justify-content: space-between;
  209. padding: 20rpx 24rpx;
  210. background: #fff;
  211. border-bottom: 1rpx solid #f0f0f0;
  212. .nav-left {
  213. width: 60rpx;
  214. .back-icon {
  215. font-size: 36rpx;
  216. color: #333;
  217. font-weight: bold;
  218. }
  219. }
  220. .nav-title {
  221. flex: 1;
  222. text-align: center;
  223. font-size: 36rpx;
  224. font-weight: bold;
  225. color: #333;
  226. }
  227. .nav-right {
  228. display: flex;
  229. align-items: center;
  230. gap: 24rpx;
  231. width: 60rpx;
  232. justify-content: flex-end;
  233. .more-icon {
  234. font-size: 32rpx;
  235. color: #333;
  236. }
  237. .eye-icon {
  238. font-size: 32rpx;
  239. color: #333;
  240. }
  241. }
  242. }
  243. .content {
  244. // flex: 1;
  245. // padding-bottom: 140rpx;
  246. }
  247. .form-section {
  248. background: #fff;
  249. // margin: 24rpx;
  250. // border-radius: 16rpx;
  251. overflow: hidden;
  252. .form-item {
  253. display: flex;
  254. align-items: center;
  255. justify-content: space-between;
  256. padding: 28rpx 32rpx;
  257. // min-height: 100rpx
  258. .form-label {
  259. font-family: PingFang SC, PingFang SC;
  260. font-weight: 400;
  261. font-size: 28rpx;
  262. color: #666666;
  263. width: 150rpx;
  264. }
  265. .form-input {
  266. flex: 1;
  267. font-size: 28rpx;
  268. color: #333;
  269. text-align: right;
  270. margin-left: 24rpx;
  271. &.picker-input {
  272. display: flex;
  273. align-items: center;
  274. justify-content: flex-end;
  275. .arrow-right {
  276. font-size: 32rpx;
  277. color: #999;
  278. margin-left: 8rpx;
  279. }
  280. }
  281. }
  282. }
  283. // placeholder 样式(需要独立定义,不能嵌套)
  284. .placeholder {
  285. color: #C8C9CC !important;
  286. }
  287. .divider {
  288. height: 1rpx;
  289. background: #EBEDF0;
  290. margin-left: 24rpx;
  291. }
  292. }
  293. .notes-section {
  294. // background: #fff;
  295. // border-radius: 16rpx;
  296. padding: 22rpx 32rpx;
  297. // margin: 0 24rpx 24rpx;
  298. .notes-title {
  299. font-family: PingFang SC, PingFang SC;
  300. font-weight: 400;
  301. font-size: 28rpx;
  302. color: #999999;
  303. line-height: 40rpx;
  304. }
  305. .notes-item {
  306. font-family: PingFang SC, PingFang SC;
  307. font-weight: 400;
  308. font-size: 28rpx;
  309. color: #999999;
  310. line-height: 40rpx;
  311. }
  312. }
  313. .bottom-bar {
  314. padding: 32rpx;
  315. .submit-btn {
  316. width: 100%;
  317. height: 88rpx;
  318. background: #388BFF;
  319. border-radius: 44rpx;
  320. display: flex;
  321. align-items: center;
  322. justify-content: center;
  323. font-size: 32rpx;
  324. font-weight: bold;
  325. color: #fff;
  326. }
  327. }
  328. </style>