风险测评小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

275 lines
5.9 KiB

  1. <template>
  2. <view class="page__view">
  3. <navbar title="资料修改" leftClick @leftClick="$utils.navigateBack" />
  4. <view class="form">
  5. <view class="flex form-header">
  6. <view class="line"></view>
  7. <view>个人信息</view>
  8. </view>
  9. <uv-form
  10. ref="form"
  11. :model="form"
  12. :rules="rules"
  13. errorType="toast"
  14. >
  15. <view class="form-item">
  16. <uv-form-item prop="headImage" :customStyle="formItemStyle">
  17. <button class="btn btn-avatar" :plain="true" :hairline="false" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  18. <view class="flex flex-column avatar-box">
  19. <view v-if="form.headImage" class="avatar">
  20. <image class="img" :src="form.headImage" mode="aspectFill"></image>
  21. </view>
  22. <view v-else class="flex avatar">
  23. <image class="img" src="@/static/image/avatar-default.png" mode="scaleToFill"></image>
  24. </view>
  25. <view>点击更换头像</view>
  26. </view>
  27. </button>
  28. </uv-form-item>
  29. </view>
  30. <view class="form-item">
  31. <uv-form-item prop="nickName" :customStyle="formItemStyle">
  32. <view class="flex row">
  33. <view class="row-label">昵称</view>
  34. <view class="row-content input">
  35. <input
  36. v-model="form.nickName"
  37. type="nickname"
  38. placeholder="请输入"
  39. placeholderStyle="color: #999999; font-size: 30rpx; font-weight: 400;"
  40. style="text-align: right;"
  41. />
  42. </view>
  43. </view>
  44. </uv-form-item>
  45. </view>
  46. <view class="form-item">
  47. <uv-form-item prop="phone" :customStyle="formItemStyle">
  48. <view class="flex row">
  49. <view class="row-label">手机号</view>
  50. <view class="row-content input">
  51. <input
  52. v-model="form.phone"
  53. placeholder="请输入"
  54. placeholderStyle="color: #999999; font-size: 30rpx; font-weight: 400;"
  55. style="text-align: right;"
  56. :disabled="!!userInfo.phone"
  57. />
  58. </view>
  59. </view>
  60. </uv-form-item>
  61. </view>
  62. </uv-form>
  63. </view>
  64. <view class="bottom">
  65. <button class="btn" @click="onSubmit">保存</button>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import { mapState } from 'vuex'
  71. export default {
  72. props: {
  73. mode: {
  74. type: String,
  75. default: null,
  76. }
  77. },
  78. data() {
  79. return {
  80. form: {
  81. nickName: null,
  82. phone: null,
  83. headImage: null,
  84. },
  85. rules: {
  86. 'nickName': {
  87. type: 'string',
  88. required: true,
  89. message: '请输入昵称',
  90. },
  91. 'phone': {
  92. type: 'string',
  93. required: true,
  94. message: '请输入手机号',
  95. },
  96. 'headImage': {
  97. type: 'string',
  98. required: false,
  99. message: '请选择头像',
  100. },
  101. },
  102. formItemStyle: { padding: 0 },
  103. }
  104. },
  105. computed: {
  106. ...mapState(['userInfo']),
  107. },
  108. onLoad(arg) {
  109. this.mode = arg.mode
  110. this.form.nickName = this.userInfo.nickName || ''
  111. this.form.phone = this.userInfo.phone || ''
  112. this.form.headImage = this.userInfo.headImage || ''
  113. },
  114. methods: {
  115. onChooseAvatar(res) {
  116. this.$Oss.ossUpload(res.target.avatarUrl)
  117. .then(url => {
  118. this.form.headImage = url
  119. })
  120. },
  121. getPhone(e){
  122. this.$api('bindPhone', {
  123. code : e.detail.code
  124. }, res => {
  125. if(res.code == 200){
  126. if(res.success){
  127. this.form.phone = res.result
  128. }else{
  129. uni.showModal({
  130. title: res.message
  131. })
  132. }
  133. }
  134. })
  135. },
  136. async onSubmit() {
  137. try {
  138. await this.$refs.form.validate()
  139. const {
  140. nickName,
  141. phone,
  142. headImage,
  143. } = this.form
  144. const params = {
  145. nickName,
  146. phone,
  147. headImage,
  148. }
  149. await this.$fetch('updateInfo', params, false)
  150. uni.showToast({
  151. icon: 'success',
  152. title: '保存成功',
  153. });
  154. this.$store.commit('getUserInfo')
  155. setTimeout(uni.navigateBack, 1000, -1)
  156. } catch (err) {
  157. console.log('onSubmit err', err)
  158. }
  159. },
  160. },
  161. }
  162. </script>
  163. <style lang="scss" scoped>
  164. .form {
  165. padding: 34rpx 22rpx;
  166. &-header {
  167. justify-content: flex-start;
  168. padding: 0 18rpx;
  169. column-gap: 7rpx;
  170. font-family: PingFang SC;
  171. font-weight: 600;
  172. font-size: 36rpx;
  173. line-height: 1.4;
  174. color: #000000;
  175. margin-bottom: 24rpx;
  176. .line {
  177. width: 9rpx;
  178. height: 33rpx;
  179. background: #014FA2;
  180. border-radius: 5rpx;
  181. }
  182. }
  183. &-item {
  184. & + & {
  185. margin-top: 34rpx;
  186. border-bottom: 0.5rpx solid rgba($color: #707070, $alpha: 0.14);
  187. }
  188. }
  189. }
  190. .btn-avatar {
  191. margin-bottom: 27rpx;
  192. display: inline-block;
  193. width: auto;
  194. border: none;
  195. }
  196. .avatar-box {
  197. box-sizing: border-box;
  198. row-gap: 9rpx;
  199. font-size: 28rpx;
  200. color: rgba($color: #999999, $alpha: 0.5);
  201. }
  202. .avatar {
  203. position: relative;
  204. width: 157rpx;
  205. height: 157rpx;
  206. border-radius: 50%;
  207. overflow: hidden;
  208. .img {
  209. width: 100%;
  210. height: 100%;
  211. }
  212. }
  213. .row {
  214. padding: 12rpx 69rpx 12rpx 23rpx;
  215. justify-content: space-between;
  216. font-family: PingFang SC;
  217. font-weight: 400;
  218. line-height: 1.4;
  219. font-size: 30rpx;
  220. color: #8B8B8B;
  221. & + & {
  222. margin-top: 32rpx;
  223. }
  224. }
  225. .bottom {
  226. position: fixed;
  227. left: 0;
  228. bottom: 0;
  229. width: 100vw;
  230. padding: 0 78rpx 231rpx 78rpx;
  231. box-sizing: border-box;
  232. .btn {
  233. width: 100%;
  234. padding: 25rpx 0;
  235. box-sizing: border-box;
  236. font-size: 32rpx;
  237. color: #FFFFFF;
  238. background: #014FA2;
  239. border-radius: 41rpx;
  240. }
  241. }
  242. </style>