personInfo.vue 4.5 KB

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