addBankCard.vue 7.7 KB

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