personInfo.vue 4.3 KB

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