editBankCard.vue 8.9 KB

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