edit.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <view class="container">
  3. <!-- 顶部标题 -->
  4. <view class="header">
  5. <text class="title">资料填写</text>
  6. </view>
  7. <!-- 表单区域 -->
  8. <view class="form-container">
  9. <view class="form-item">
  10. <text class="label">银行名称</text>
  11. <input class="input" v-model="form.bankName" placeholder="请输入银行名称" />
  12. </view>
  13. <view class="form-item">
  14. <text class="label">银行账号</text>
  15. <input class="input" v-model="form.bankAccount" placeholder="请输入银行账号" type="number" />
  16. </view>
  17. <view class="form-item">
  18. <text class="label">开户人姓名</text>
  19. <input class="input" v-model="form.accountHolder" placeholder="请输入开户人姓名" />
  20. </view>
  21. <view class="form-item">
  22. <text class="label">身份证号码</text>
  23. <input class="input" v-model="form.idCardNumber" placeholder="请输入身份证号码" />
  24. </view>
  25. </view>
  26. <!-- 提交按钮 -->
  27. <view class="submit-btn" @click="submitForm">
  28. <text>保存资料</text>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import { mapState, mapMutations } from 'vuex';
  34. export default {
  35. computed: {
  36. ...mapState(['token', 'userInfo'])
  37. },
  38. data() {
  39. return {
  40. form: {
  41. bankName: '',
  42. bankAccount: '',
  43. accountHolder: '',
  44. idCardNumber: ''
  45. }
  46. };
  47. },
  48. onLoad() {
  49. this.loadProfile();
  50. },
  51. methods: {
  52. // 加载已有资料
  53. async loadProfile() {
  54. try {
  55. const res = await this.request("get", "rider/app/profile", this.token);
  56. if (res.code === 200 && res.data) {
  57. this.form = {
  58. bankName: res.data.bankName || '',
  59. bankAccount: res.data.bankAccount || '',
  60. accountHolder: res.data.accountHolder || '',
  61. idCardNumber: res.data.idCardNumber || ''
  62. };
  63. }
  64. } catch (error) {
  65. console.error('加载资料失败:', error);
  66. }
  67. },
  68. // 提交表单
  69. async submitForm() {
  70. if (!this.validateForm()) return;
  71. try {
  72. uni.showLoading({ title: '提交中...', mask: true });
  73. const res = await this.request("post", "rider/app/profile/update", this.token, this.form);
  74. uni.hideLoading();
  75. if (res.code === 200) {
  76. uni.showToast({ title: '资料保存成功', icon: 'success' });
  77. setTimeout(() => {
  78. uni.navigateBack();
  79. }, 1500);
  80. } else {
  81. uni.showToast({ title: res.msg || '保存失败', icon: 'none' });
  82. }
  83. } catch (error) {
  84. uni.hideLoading();
  85. uni.showToast({ title: '保存失败,请重试', icon: 'none' });
  86. console.error('保存资料失败:', error);
  87. }
  88. },
  89. // 表单验证
  90. validateForm() {
  91. if (!this.form.bankName) {
  92. uni.showToast({ title: '请输入银行名称', icon: 'none' });
  93. return false;
  94. }
  95. if (!this.form.bankAccount) {
  96. uni.showToast({ title: '请输入银行账号', icon: 'none' });
  97. return false;
  98. }
  99. if (!this.form.accountHolder) {
  100. uni.showToast({ title: '请输入开户人姓名', icon: 'none' });
  101. return false;
  102. }
  103. if (!this.form.idCardNumber) {
  104. uni.showToast({ title: '请输入身份证号码', icon: 'none' });
  105. return false;
  106. }
  107. // 简单的身份证格式验证
  108. if (!/^\d{17}[\dXx]$/.test(this.form.idCardNumber)) {
  109. uni.showToast({ title: '请输入正确的身份证号码', icon: 'none' });
  110. return false;
  111. }
  112. return true;
  113. }
  114. }
  115. };
  116. </script>
  117. <style lang="scss" scoped>
  118. .container {
  119. padding: 30rpx;
  120. min-height: 100vh;
  121. background-color: #f7f7f7;
  122. }
  123. .header {
  124. padding: 30rpx 0;
  125. text-align: center;
  126. .title {
  127. font-size: 36rpx;
  128. font-weight: bold;
  129. color: #333;
  130. }
  131. }
  132. .form-container {
  133. background-color: #fff;
  134. border-radius: 16rpx;
  135. padding: 0 30rpx;
  136. margin-bottom: 30rpx;
  137. box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.05);
  138. }
  139. .form-item {
  140. padding: 30rpx 0;
  141. border-bottom: 1rpx solid #f0f0f0;
  142. &:last-child {
  143. border-bottom: none;
  144. }
  145. .label {
  146. display: block;
  147. font-size: 30rpx;
  148. color: #333;
  149. margin-bottom: 20rpx;
  150. }
  151. .input {
  152. font-size: 28rpx;
  153. height: 50rpx;
  154. color: #333;
  155. }
  156. }
  157. .submit-btn {
  158. background-color: #437CE8;
  159. color: #fff;
  160. height: 90rpx;
  161. line-height: 90rpx;
  162. text-align: center;
  163. border-radius: 45rpx;
  164. font-size: 32rpx;
  165. margin-top: 50rpx;
  166. box-shadow: 0 4rpx 12rpx rgba(67, 124, 232, 0.3);
  167. }
  168. </style>