addBankCard.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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. <!-- <input
  9. class="form-input"
  10. v-model="formData.bankName"
  11. placeholder="请输入开户行"
  12. placeholder-class="text-placeholder"
  13. /> -->
  14. <view style="flex:1" @click="openBankPicker">
  15. <view class="form-input picker-input" :class="{ placeholder: !formData.bankName }">
  16. {{ getBankLabel() || '请选择开户行' }}
  17. <image class="w32 h32" src="/static/image/icon_my_more.png" mode=""></image>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="divider"></view>
  22. <view class="form-item">
  23. <view class="form-label">支行</view>
  24. <input
  25. class="form-input"
  26. v-model="formData.bankBranch"
  27. placeholder="请输入支行"
  28. placeholder-class="text-placeholder"
  29. />
  30. </view>
  31. <view class="divider"></view>
  32. <view class="form-item">
  33. <view class="form-label">银行卡号</view>
  34. <input
  35. class="form-input "
  36. v-model="formData.bankCardNo"
  37. placeholder="请输入银行卡号"
  38. type="number"
  39. maxlength="19"
  40. placeholder-class="text-placeholder"
  41. />
  42. </view>
  43. </view>
  44. <!-- 注意事项 -->
  45. <view class="notes-section">
  46. <view class="notes-title">注意:</view>
  47. <view class="notes-item">1、只能绑定认证用户本人的银行卡;</view>
  48. <view class="notes-item">2、每次更换次数不得超过三次。</view>
  49. </view>
  50. </scroll-view>
  51. <!-- 银行搜索弹窗 -->
  52. <view class="search-picker-popup" v-if="showBankPicker" @click="closeBankPicker">
  53. <view class="popup-content" @click.stop>
  54. <view class="popup-header">
  55. <text class="popup-title">选择开户行</text>
  56. <view class="popup-close" @click="closeBankPicker">×</view>
  57. </view>
  58. <view class="search-box">
  59. <input
  60. class="search-input"
  61. v-model="bankSearchKeyword"
  62. placeholder="请输入银行名称搜索"
  63. @blur="onBankSearch"
  64. />
  65. </view>
  66. <scroll-view class="search-list" scroll-y>
  67. <view
  68. class="search-item"
  69. v-for="(item, index) in filteredBankList"
  70. :key="index"
  71. :class="{ active: formData.bankName === item.label }"
  72. @click="selectBank(item)"
  73. >
  74. <text>{{ item.label }}</text>
  75. <text v-if="formData.bankName === item.label" class="check-icon">✓</text>
  76. </view>
  77. <view class="search-empty" v-if="filteredBankList.length === 0">
  78. <text>暂无匹配结果</text>
  79. </view>
  80. </scroll-view>
  81. </view>
  82. </view>
  83. <!-- 底部按钮 -->
  84. <view class="bottom-bar">
  85. <view class="submit-btn" @click="handleSubmit">确认添加</view>
  86. </view>
  87. </view>
  88. </template>
  89. <script>
  90. import {getBankTypeList} from '@/api/certification'
  91. import { addBankCard } from '@/api/bankCard'
  92. export default {
  93. data() {
  94. return {
  95. formData: {
  96. "bankBranch": "",
  97. "bankCardNo": "",
  98. "bankName": ""
  99. },
  100. showBankPicker: false,
  101. bankSearchKeyword: '',
  102. filteredBankList: []
  103. }
  104. },
  105. onLoad() {
  106. this.loadBankList()
  107. },
  108. methods: {
  109. goBack() {
  110. uni.navigateBack()
  111. },
  112. getBankLabel() {
  113. return this.formData.bankName || ''
  114. },
  115. openBankPicker() {
  116. this.showBankPicker = true
  117. this.bankSearchKeyword = ''
  118. },
  119. openBankPicker() {
  120. this.showBankPicker = true
  121. this.bankSearchKeyword = ''
  122. },
  123. closeBankPicker() {
  124. this.showBankPicker = false
  125. },
  126. async onBankSearch() {
  127. const keyword = this.bankSearchKeyword.trim()
  128. this.loadBankList(keyword)
  129. },
  130. selectBank(item) {
  131. this.formData.bankName = item.label
  132. this.closeBankPicker()
  133. },
  134. // 加载银行列表
  135. async loadBankList(keyword) {
  136. const params = {}
  137. // 如果传入了关键词,就用传入的
  138. if (keyword) {
  139. params.bankName = keyword.trim()
  140. }
  141. try {
  142. const res = await getBankTypeList(params)
  143. if (res.code === 200) {
  144. const arr = res.data
  145. this.filteredBankList = arr.map(item => ({
  146. label: item.bankName,
  147. value: item.id
  148. })).filter(opt => opt.label)
  149. }
  150. } catch (err) {
  151. console.log('银行类型加载失败', err)
  152. }
  153. },
  154. async handleSubmit() {
  155. // 表单验证
  156. if (!this.formData.bankName || !this.formData.bankName.trim()) {
  157. uni.showToast({
  158. icon: 'none',
  159. title: '请选择开户行'
  160. })
  161. return
  162. }
  163. if (!this.formData.bankBranch || !this.formData.bankBranch.trim()) {
  164. uni.showToast({
  165. icon: 'none',
  166. title: '请输入支行'
  167. })
  168. return
  169. }
  170. if (!this.formData.bankCardNo) {
  171. uni.showToast({
  172. icon: 'none',
  173. title: '请输入银行卡号'
  174. })
  175. return
  176. }
  177. // 银行卡号验证(简单验证)
  178. if (this.formData.bankCardNo.length < 16) {
  179. uni.showToast({
  180. icon: 'none',
  181. title: '请输入正确的银行卡号'
  182. })
  183. return
  184. }
  185. // uni.navigateTo({
  186. // url: '/pages_user/editBankCard'
  187. // })
  188. try {
  189. uni.showLoading({ title: '添加中...' })
  190. const res = await addBankCard(this.formData)
  191. uni.hideLoading()
  192. if (res.code === 200) {
  193. uni.showToast({
  194. icon: 'success',
  195. title: '添加成功'
  196. })
  197. setTimeout(() => {
  198. uni.navigateBack()
  199. }, 1500)
  200. } else {
  201. uni.showToast({
  202. icon: 'none',
  203. title: res.msg || '添加失败'
  204. })
  205. }
  206. } catch (e) {
  207. uni.hideLoading()
  208. uni.showToast({
  209. icon: 'none',
  210. title: '添加失败'
  211. })
  212. }
  213. }
  214. }
  215. }
  216. </script>
  217. <style lang="stylus">
  218. .text-placeholder{
  219. color: #C8C9CC !important;
  220. }
  221. </style>
  222. <style lang="scss" scoped>
  223. .container {
  224. // min-height: 100vh;
  225. background: #f5f5f5;
  226. display: flex;
  227. flex-direction: column;
  228. }
  229. .navbar {
  230. display: flex;
  231. align-items: center;
  232. justify-content: space-between;
  233. padding: 20rpx 24rpx;
  234. background: #fff;
  235. border-bottom: 1rpx solid #f0f0f0;
  236. .nav-left {
  237. width: 60rpx;
  238. .back-icon {
  239. font-size: 36rpx;
  240. color: #333;
  241. font-weight: bold;
  242. }
  243. }
  244. .nav-title {
  245. flex: 1;
  246. text-align: center;
  247. font-size: 36rpx;
  248. font-weight: bold;
  249. color: #333;
  250. }
  251. .nav-right {
  252. display: flex;
  253. align-items: center;
  254. gap: 24rpx;
  255. width: 60rpx;
  256. justify-content: flex-end;
  257. .more-icon {
  258. font-size: 32rpx;
  259. color: #333;
  260. }
  261. .eye-icon {
  262. font-size: 32rpx;
  263. color: #333;
  264. }
  265. }
  266. }
  267. .content {
  268. // flex: 1;
  269. // padding-bottom: 140rpx;
  270. }
  271. .form-section {
  272. background: #fff;
  273. // margin: 24rpx;
  274. // border-radius: 16rpx;
  275. overflow: hidden;
  276. .form-item {
  277. display: flex;
  278. align-items: center;
  279. justify-content: space-between;
  280. padding: 28rpx 32rpx;
  281. // min-height: 100rpx
  282. .form-label {
  283. font-family: PingFang SC, PingFang SC;
  284. font-weight: 400;
  285. font-size: 28rpx;
  286. color: #666666;
  287. width: 150rpx;
  288. }
  289. .form-input {
  290. flex: 1;
  291. font-size: 28rpx;
  292. color: #333;
  293. text-align: right;
  294. margin-left: 24rpx;
  295. &.picker-input {
  296. display: flex;
  297. align-items: center;
  298. justify-content: flex-end;
  299. .arrow-right {
  300. font-size: 32rpx;
  301. color: #999;
  302. margin-left: 8rpx;
  303. }
  304. }
  305. }
  306. }
  307. // placeholder 样式(需要独立定义,不能嵌套)
  308. .placeholder {
  309. color: #C8C9CC !important;
  310. }
  311. .divider {
  312. height: 1rpx;
  313. background: #EBEDF0;
  314. margin-left: 24rpx;
  315. }
  316. }
  317. .notes-section {
  318. // background: #fff;
  319. // border-radius: 16rpx;
  320. padding: 22rpx 32rpx;
  321. // margin: 0 24rpx 24rpx;
  322. .notes-title {
  323. font-family: PingFang SC, PingFang SC;
  324. font-weight: 400;
  325. font-size: 28rpx;
  326. color: #999999;
  327. line-height: 40rpx;
  328. }
  329. .notes-item {
  330. font-family: PingFang SC, PingFang SC;
  331. font-weight: 400;
  332. font-size: 28rpx;
  333. color: #999999;
  334. line-height: 40rpx;
  335. }
  336. }
  337. .bottom-bar {
  338. padding: 32rpx;
  339. .submit-btn {
  340. width: 100%;
  341. height: 88rpx;
  342. background: #388BFF;
  343. border-radius: 44rpx;
  344. display: flex;
  345. align-items: center;
  346. justify-content: center;
  347. font-size: 32rpx;
  348. font-weight: bold;
  349. color: #fff;
  350. }
  351. }
  352. .search-picker-popup {
  353. position: fixed;
  354. top: 0;
  355. left: 0;
  356. right: 0;
  357. bottom: 0;
  358. background: rgba(0, 0, 0, 0.5);
  359. z-index: 1000;
  360. display: flex;
  361. align-items: flex-end;
  362. .popup-content {
  363. width: 100%;
  364. height: 80vh;
  365. background: #fff;
  366. border-radius: 24rpx 24rpx 0 0;
  367. display: flex;
  368. flex-direction: column;
  369. }
  370. .popup-header {
  371. display: flex;
  372. align-items: center;
  373. justify-content: space-between;
  374. padding: 32rpx;
  375. border-bottom: 1rpx solid #f0f0f0;
  376. .popup-title {
  377. font-size: 32rpx;
  378. font-weight: bold;
  379. color: #333;
  380. }
  381. .popup-close {
  382. font-size: 48rpx;
  383. color: #999;
  384. line-height: 1;
  385. }
  386. }
  387. .search-box {
  388. padding: 24rpx 32rpx;
  389. .search-input {
  390. //width: 100%;
  391. height: 72rpx;
  392. background: #f5f5f5;
  393. border-radius: 36rpx;
  394. padding: 0 32rpx;
  395. font-size: 28rpx;
  396. }
  397. }
  398. .search-list {
  399. flex: 1;
  400. height: 60%;
  401. padding: 0 32rpx 40rpx;
  402. box-sizing: border-box;
  403. .search-item {
  404. display: flex;
  405. align-items: center;
  406. justify-content: space-between;
  407. padding: 28rpx 0;
  408. border-bottom: 1rpx solid #f5f5f5;
  409. &:last-child {
  410. border-bottom: none;
  411. }
  412. &.active {
  413. color: #388BFF;
  414. text {
  415. color: #388BFF;
  416. }
  417. }
  418. .check-icon {
  419. color: #388BFF;
  420. font-size: 32rpx;
  421. font-weight: bold;
  422. }
  423. text {
  424. font-size: 28rpx;
  425. color: #333;
  426. }
  427. }
  428. .search-empty {
  429. display: flex;
  430. align-items: center;
  431. justify-content: center;
  432. padding: 60rpx 0;
  433. text {
  434. font-size: 28rpx;
  435. color: #999;
  436. }
  437. }
  438. }
  439. }
  440. </style>