BankCard.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <div class="container">
  3. <!-- Add Toast component -->
  4. <Toast ref="toast" />
  5. <!-- 导航栏 -->
  6. <div class="nav-bar">
  7. <div class="back-btn" @click="$router.back()">
  8. <i class="arrow-left"></i>
  9. </div>
  10. <div class="title">绑定银行卡</div>
  11. </div>
  12. <div class="main">
  13. <div class="form-containerr">
  14. <div class="bdyhk">
  15. <span class="bdyhkk">绑定银行卡</span>
  16. <svg t="1751273430369" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="30102" width="64" height="64"><path d="M481.8 767.8h-39.6c-7.5 0-13.1-6.7-11.8-14.1l18.3-103.8c1-5.7 6-9.9 11.8-9.9h39.6c7.5 0 13.1 6.7 11.8 14.1l-18.3 103.8c-1 5.7-6 9.9-11.8 9.9zM609.9 767.8h-39.6c-7.5 0-13.1-6.7-11.8-14.1l18.3-103.8c1-5.7 6-9.9 11.8-9.9h39.6c7.5 0 13.1 6.7 11.8 14.1l-18.3 103.8c-1 5.7-6 9.9-11.8 9.9zM801.8 767.8H698.4c-7.5 0-13.1-6.7-11.8-14.1l18.3-103.8c1-5.7 6-9.9 11.8-9.9h103.5c7.5 0 13.1 6.7 11.8 14.1l-18.3 103.8c-1 5.7-6 9.9-11.9 9.9z" fill="#a71fff" p-id="30103"></path><path d="M892.4 243.1c4.4 0 8 3.6 8 8v554.5c0 4.4-3.6 8-8 8h-761c-4.4 0-8-3.6-8-8V251.1c0-4.4 3.6-8 8-8h761m0-60h-761c-37.6 0-68 30.4-68 68v554.5c0 37.6 30.4 68 68 68h761c37.6 0 68-30.4 68-68V251.1c0-37.6-30.5-68-68-68z" fill="#a71fff" p-id="30104"></path><path d="M954.8 339.7H64.2v64.4h890.6v-64.4z" fill="#a71fff" p-id="30105"></path></svg>
  17. </div>
  18. </div>
  19. <div class="form-container">
  20. <div class="form-item">
  21. <div class="form-label" style="font-size: 20px;">填写银行卡信息</div>
  22. <div class="form-label">持卡姓名:<input
  23. type="text"
  24. class="form-input"
  25. placeholder="输入姓名"
  26. v-model="formData.lastname"
  27. /></div>
  28. </div>
  29. <div class="form-item">
  30. <div class="form-label">所属银行:<input
  31. type="text"
  32. class="form-input"
  33. placeholder="输入银行名称"
  34. v-model="formData.banktype"
  35. /></div>
  36. </div>
  37. <div class="form-item">
  38. <div class="form-label">开户行地址: <input
  39. type="text"
  40. class="form-input"
  41. placeholder="输入银行卡开户行"
  42. v-model="formData.address"
  43. /></div>
  44. </div>
  45. <div class="form-item">
  46. <div class="form-label">银行卡号:<input
  47. type="text"
  48. class="form-input"
  49. placeholder="输入银行卡号"
  50. v-model="banknumInput"
  51. @input="handleBanknumInput"
  52. /></div>
  53. </div>
  54. </div>
  55. <div style="display: flex;justify-content: center;align-items: center;">
  56. <button
  57. class="submit-btn"
  58. @click="handleSubmit"
  59. :disabled="bankInfo.status"
  60. >
  61. {{ bankInfo.status ? '已绑定' : '立即绑定' }}
  62. </button>
  63. </div>
  64. </div>
  65. </div>
  66. </template>
  67. <script>
  68. import { getBankInfo, setBankInfo } from '@/api/profile';
  69. import Toast from '@/components/Toast.vue';
  70. export default {
  71. name: 'BankCard',
  72. components: {
  73. Toast
  74. },
  75. data() {
  76. return {
  77. bankInfo: {},
  78. formData: {
  79. banktype: '',
  80. address: '',
  81. lastname: '',
  82. banknum: ''
  83. },
  84. banknumInput: ''
  85. }
  86. },
  87. created() {
  88. this.getBankInfo();
  89. },
  90. methods: {
  91. handleBanknumInput(event) {
  92. // Remove any non-digit characters
  93. const value = event.target.value.replace(/\D/g, '');
  94. this.banknumInput = value;
  95. this.formData.banknum = value; // 始终用字符串
  96. },
  97. async getBankInfo() {
  98. try {
  99. const res = await getBankInfo();
  100. if (res && res.data) {
  101. this.bankInfo = res.data;
  102. if (this.bankInfo && this.bankInfo.status) {
  103. // 填充表单数据,允许修改
  104. this.formData = {
  105. banktype: this.bankInfo.banktype || '',
  106. address: this.bankInfo.address || '',
  107. lastname: this.bankInfo.lastname || '',
  108. banknum: this.bankInfo.banknum || ''
  109. };
  110. this.banknumInput = this.bankInfo.banknum ? String(this.bankInfo.banknum) : '';
  111. }
  112. } else {
  113. this.bankInfo = {
  114. status: false
  115. };
  116. }
  117. } catch (error) {
  118. this.bankInfo = {
  119. status: false
  120. };
  121. console.error('获取银行卡信息失败:', error);
  122. }
  123. },
  124. async handleSubmit() {
  125. if (!this.formData.banktype) {
  126. this.$refs.toast.show('请输入开户银行', 'warning');
  127. return;
  128. }
  129. if (!this.formData.address) {
  130. this.$refs.toast.show('请输入开户地址', 'warning');
  131. return;
  132. }
  133. if (!this.formData.lastname) {
  134. this.$refs.toast.show('请输入卡号姓名', 'warning');
  135. return;
  136. }
  137. if (!this.formData.banknum) {
  138. this.$refs.toast.show('请输入银行账号', 'warning');
  139. return;
  140. }
  141. try {
  142. // Ensure all values are strings when sending to FormData
  143. const submitData = {
  144. banktype: this.formData.banktype.trim(),
  145. address: this.formData.address.trim(),
  146. lastname: this.formData.lastname.trim(),
  147. banknum: String(this.formData.banknum).trim()
  148. };
  149. const res = await setBankInfo(submitData);
  150. if (res.code === 1) {
  151. this.$refs.toast.show(this.bankInfo.status ? '修改成功' : '绑定成功', 'success');
  152. await this.getBankInfo();
  153. } else {
  154. this.$refs.toast.show(res.msg || '操作失败,请重试', 'error');
  155. }
  156. } catch (error) {
  157. console.error('操作失败:', error);
  158. this.$refs.toast.show('操作失败,请重试', 'error');
  159. }
  160. }
  161. }
  162. }
  163. </script>
  164. <style scoped>
  165. .container {
  166. min-height: 100vh;
  167. /* background: url('../assets/dabag.png') no-repeat; */
  168. background-color: #b43a39;
  169. background-size: cover;
  170. background-position: center;
  171. }
  172. .nav-bar {
  173. height: 44px;
  174. background-color: transparent;
  175. color: #fff;
  176. display: flex;
  177. align-items: center;
  178. position: relative;
  179. padding: 0 15px;
  180. }
  181. .back-btn {
  182. width: 24px;
  183. height: 44px;
  184. display: flex;
  185. align-items: center;
  186. cursor: pointer;
  187. }
  188. .arrow-left {
  189. width: 12px;
  190. height: 12px;
  191. border-left: 2px solid #fff;
  192. border-bottom: 2px solid #fff;
  193. transform: rotate(45deg);
  194. }
  195. .title {
  196. position: absolute;
  197. left: 50%;
  198. transform: translateX(-50%);
  199. font-size: 16px;
  200. font-weight: 500;
  201. }
  202. .header-text {
  203. padding: 40px 20px;
  204. color: #fff;
  205. }
  206. .title-text {
  207. font-size: 24px;
  208. font-weight: bold;
  209. margin-bottom: 15px;
  210. }
  211. .sub-text {
  212. font-size: 14px;
  213. line-height: 1.5;
  214. font-weight: bold;
  215. }
  216. .form-container {
  217. background: #fff;
  218. border-radius: 8px;
  219. margin: 0 20px;
  220. padding: 20px;
  221. }
  222. .form-item {
  223. /* margin-bottom: 20px; */
  224. }
  225. .form-label {
  226. font-size: 15px;
  227. font-weight: bold;
  228. color: #333;
  229. margin-bottom: 8px;
  230. }
  231. .form-input {
  232. width: 60%;
  233. height: 44px;
  234. border: none;
  235. background: #fff;
  236. font-size: 14px;
  237. padding: 0;
  238. color: #333;
  239. }
  240. .form-input::placeholder {
  241. color: #999;
  242. }
  243. .form-input:focus {
  244. outline: none;
  245. }
  246. .form-input:disabled {
  247. color: #666;
  248. background: #f5f5f5;
  249. }
  250. .submit-btn {
  251. width: 60%;
  252. height: 44px;
  253. background: #d89191;
  254. border-radius: 22px;
  255. border: none;
  256. color: #fff;
  257. font-size: 16px;
  258. font-weight: 500;
  259. margin-top: 10px;
  260. cursor: pointer;
  261. }
  262. .submit-btn:active {
  263. opacity: 0.9;
  264. }
  265. .submit-btn:disabled {
  266. background: #ccc;
  267. cursor: not-allowed;
  268. }
  269. .bdyhk{
  270. display: flex;
  271. justify-content: space-between;
  272. align-items: center;
  273. }
  274. .bdyhkk{
  275. font-size: 20px;
  276. font-weight: 500;
  277. color: #de3232;
  278. }
  279. .form-containerr {
  280. background: #f4c1c1;
  281. border-radius: 8px;
  282. margin: 0 20px;
  283. padding: 20px;
  284. margin-bottom: 50px;
  285. margin-top: 33px;
  286. }
  287. </style>