personInfo.vue 4.1 KB

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