info.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <view style="padding: 20px;">
  3. <uni-forms :modelValue="postForm" ref="form" :rules="rules" :label-width="120">
  4. <uni-forms-item label="ID">
  5. <uni-easyinput type="text" v-model="postForm.id" disabled />
  6. </uni-forms-item>
  7. <uni-forms-item label="用户名">
  8. <uni-easyinput type="text" v-model="postForm.userName" disabled />
  9. </uni-forms-item>
  10. <uni-forms-item label="人脸照片" name="avatar">
  11. <yf-file-upload v-model="postForm.avatar"></yf-file-upload>
  12. </uni-forms-item>
  13. <uni-forms-item label="身份证正面照" name="face">
  14. <yf-file-upload v-model="postForm.face"></yf-file-upload>
  15. </uni-forms-item>
  16. <uni-forms-item label="姓名" name="realName">
  17. <uni-easyinput type="text" v-model="postForm.realName" placeholder="请输入姓名" />
  18. </uni-forms-item>
  19. <uni-forms-item label="身份证号" name="idCard">
  20. <uni-easyinput type="number" v-model="postForm.idCard" placeholder="请输入身份证号" />
  21. </uni-forms-item>
  22. <uni-forms-item label="手机号" name="mobile">
  23. <uni-easyinput type="text" v-model="postForm.mobile" placeholder="请输入手机号" />
  24. </uni-forms-item>
  25. <!-- <uni-forms-item label="邮箱">
  26. <uni-easyinput type="text" v-model="postForm.email" placeholder="请输入邮箱" />
  27. </uni-forms-item> -->
  28. </uni-forms>
  29. <button type="primary" @click="handleUpdate()">保存并登录</button>
  30. </view>
  31. </template>
  32. <script>
  33. import { info, update } from '@/api/user'
  34. export default {
  35. data() {
  36. return {
  37. postForm: {
  38. avatar: '',
  39. face: '',
  40. userName: '',
  41. realName: '',
  42. idCard: '',
  43. mobile: '',
  44. },
  45. rules: {
  46. realName: {
  47. rules: [{
  48. required: true,
  49. errorMessage: '姓名不能为空!'
  50. }]
  51. },
  52. idCard: {
  53. rules: [{
  54. required: true,
  55. errorMessage: '身份证号不能为空!'
  56. }, {
  57. pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
  58. errorMessage: '请输入正确身份证号!',
  59. }]
  60. },
  61. mobile: {
  62. rules: [{
  63. required: true,
  64. errorMessage: '手机号不能为空!'
  65. },{
  66. pattern: /^(1)\d{10}$/,
  67. errorMessage: '请输入正确手机号!'
  68. }]
  69. },
  70. avatar: {
  71. rules: [{
  72. required: true,
  73. errorMessage: '请上传人脸照片!'
  74. }]
  75. },
  76. face: {
  77. rules: [{
  78. required: true,
  79. errorMessage: '请上传身份证正面照!'
  80. }]
  81. }
  82. },
  83. }
  84. },
  85. mounted() {
  86. this.handleInfo()
  87. },
  88. methods: {
  89. handleInfo() {
  90. let token = uni.getStorageSync('token');
  91. info(token).then(res => {
  92. this.postForm = res
  93. })
  94. },
  95. handleUpdate() {
  96. this.$refs.form.validate().then(res => {
  97. uni.showLoading()
  98. update(this.postForm).then(() => {
  99. uni.showToast({
  100. title: '资料更新成功!'
  101. })
  102. uni.setStorageSync('idCard', this.postForm.idCard);
  103. uni.hideLoading()
  104. setTimeout(()=>{
  105. uni.switchTab({
  106. url: '/pages/index/index'
  107. })
  108. }, 2000)
  109. })
  110. }).catch(err => {
  111. })
  112. },
  113. bindMobile() {
  114. uni.navigateTo({
  115. url: `/pages/user/info/bind-mobile?type=${this.postForm.mobile?0:1}&mobile=${this.postForm.mobile|| ''}`
  116. })
  117. },
  118. }
  119. }
  120. </script>
  121. <style>
  122. .user-banner {
  123. height: 160px;
  124. display: flex;
  125. background: url('https://cdn.yfhl.net/static/user-bg.jpg') no-repeat;
  126. align-items: center;
  127. background-position: center;
  128. background-size: 100%;
  129. justify-content: center;
  130. width: 100%;
  131. flex-direction: column;
  132. }
  133. .user-banner .avatar {
  134. width: 80px;
  135. height: 80px;
  136. border: #3771CF 2px solid;
  137. border-radius: 50%;
  138. }
  139. .user-banner .points {
  140. position: absolute;
  141. top: 15px;
  142. right: 15px;
  143. color: #FDBF40;
  144. font-weight: bold;
  145. font-weight: 700;
  146. font-size: 16px;
  147. }
  148. .user-banner .name {
  149. color: #fff;
  150. font-weight: 700;
  151. font-size: 18px;
  152. }
  153. .user-banner .dept {
  154. color: #eee;
  155. font-weight: 700;
  156. font-size: 14px;
  157. }
  158. .mv-box{
  159. font-size: 16px;
  160. font-weight: 700;
  161. display: flex;
  162. align-items: center;
  163. }
  164. .mv-box .btn{
  165. margin-left: 10px;
  166. display: flex;
  167. align-items: center;
  168. }
  169. </style>