personInfo.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <view>
  3. <view class="content">
  4. <view class="info-item">
  5. <view class="label">头像</view>
  6. <view class="right">
  7. <image class="head"
  8. :src="user.avatar==null?'https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/detault_head.jpg':user.avatar"
  9. mode=""></image>
  10. <button class="wx-head" type="balanced" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  11. </button>
  12. </view>
  13. </view>
  14. <view class="info-item">
  15. <view class="label">昵称</view>
  16. <view class="right">
  17. <input type="nickname" @blur="bindblur" @input="bindinput" v-model="user.nickname"
  18. class="input"></text>
  19. </view>
  20. </view>
  21. <view class="info-item">
  22. <view class="label">会员等级</view>
  23. <view class="right">{{user.level==1?'VIP会员':'普通会员'}}</view>
  24. </view>
  25. <view class="info-item">
  26. <view class="label">推广员</view>
  27. <view class="right">{{user.isPromoter==1?'是':'否'}}</view>
  28. </view>
  29. <view class="info-item">
  30. <view class="label">手机号</view>
  31. <view class="right" v-if="user!=null">{{utils.parsePhone(user.phone)}}</view>
  32. </view>
  33. </view>
  34. <view class="btn-box">
  35. <view class="sub-btn" @click="submit()">保存</view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import {
  41. getUserInfo,
  42. editUser
  43. } from '@/api/user'
  44. export default {
  45. data() {
  46. return {
  47. user: null
  48. }
  49. },
  50. onLoad() {
  51. this.getUserInfo()
  52. },
  53. methods: {
  54. bindblur(e) {
  55. this.user.nickname = e.detail.value; // 获取微信昵称
  56. },
  57. bindinput(e) {
  58. this.user.nickname = e.detail.value; //这里要注意如果只用blur方法的话用户在输入玩昵称后直接点击保存按钮,会出现修改不成功的情况。
  59. },
  60. onChooseAvatar(e) {
  61. let {
  62. avatarUrl
  63. } = e.detail;
  64. uni.uploadFile({
  65. url: uni.getStorageSync('requestPath') + '/app/common/uploadOSS', //仅为示例,非真实的接口地址
  66. filePath: avatarUrl,
  67. name: 'file',
  68. formData: {
  69. 'user': 'test' // 上传附带参数
  70. },
  71. success: (uploadFileRes) => {
  72. this.user.avatar = JSON.parse(uploadFileRes.data).url
  73. }
  74. });
  75. },
  76. submit() {
  77. this.user.nickName = this.user.nickname;
  78. console.log("nickname", this.user.nickname)
  79. editUser(this.user).then(
  80. res => {
  81. if (res.code == 200) {
  82. uni.showToast({
  83. icon: 'success',
  84. title: "修改成功",
  85. });
  86. setTimeout(function() {
  87. uni.navigateBack({
  88. delta: 1, //返回层数,2则上上页
  89. })
  90. }, 2000);
  91. } else {
  92. uni.showToast({
  93. icon: 'none',
  94. title: res.msg,
  95. });
  96. }
  97. },
  98. rej => {}
  99. );
  100. },
  101. getUserInfo() {
  102. getUserInfo().then(
  103. res => {
  104. if (res.code == 200) {
  105. if (res.user != null) {
  106. this.user = res.user;
  107. }
  108. } else {
  109. uni.showToast({
  110. icon: 'none',
  111. title: "请求失败",
  112. });
  113. }
  114. },
  115. rej => {}
  116. );
  117. },
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. .content {
  123. padding-top: 20rpx;
  124. }
  125. .info-item {
  126. height: 104upx;
  127. background: #FFFFFF;
  128. padding: 0 30upx;
  129. display: flex;
  130. align-items: center;
  131. justify-content: space-between;
  132. border-bottom: 1px solid #F5F6FA;
  133. &:last-child {
  134. border-bottom: none;
  135. }
  136. .label {
  137. font-size: 30upx;
  138. font-family: PingFang SC;
  139. font-weight: 400;
  140. color: #0F1826;
  141. }
  142. .right {
  143. display: flex;
  144. align-items: center;
  145. justify-content: center;
  146. position: relative;
  147. .wx-head {
  148. position: absolute;
  149. width: 80upx;
  150. height: 80upx;
  151. opacity: 0;
  152. }
  153. .text {
  154. font-size: 30upx;
  155. font-family: PingFang SC;
  156. font-weight: 400;
  157. color: #0F1826;
  158. }
  159. .head {
  160. border-radius: 50%;
  161. width: 80upx;
  162. height: 80upx;
  163. }
  164. .input {
  165. text-align: right;
  166. font-size: 30upx;
  167. font-family: PingFang SC;
  168. font-weight: 400;
  169. color: #0F1826;
  170. }
  171. }
  172. }
  173. .btn-box {
  174. margin-top: 20rpx;
  175. height: 120upx;
  176. padding: 0 30upx;
  177. display: flex;
  178. align-items: center;
  179. justify-content: center;
  180. .sub-btn {
  181. width: 100%;
  182. height: 88upx;
  183. line-height: 88upx;
  184. text-align: center;
  185. font-size: 30upx;
  186. font-family: PingFang SC;
  187. font-weight: bold;
  188. color: #FFFFFF;
  189. background: #2BC7B9;
  190. border-radius: 44upx;
  191. }
  192. }
  193. </style>