userinfo.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <view class="content">
  3. <view class="row1">
  4. <text class="tit">头像</text>
  5. <view class="background-img" @click="upload"><image class="background-img" v-model="avatar" :src="avatar" mode="aspectFill"></image></view>
  6. </view>
  7. <view class="row">
  8. <text class="tit">昵称</text>
  9. <input class="input" type="button" v-model="name" placeholder-class="placeholder" />
  10. </view>
  11. <view class="row">
  12. <text class="tit">邀请码</text>
  13. <input class="input" disabled type="text" v-model="uid" placeholder-class="placeholder" />
  14. </view>
  15. <view class="row">
  16. <text class="tit">账号</text>
  17. <input class="input" disabled type="text" v-model="phone" placeholder-class="placeholder" />
  18. </view>
  19. <button class="add-btn" @click="confirm">修改</button>
  20. <button class="loginout" @click="loginout">退出登录</button>
  21. </view>
  22. </template>
  23. <script>
  24. import { mapState,mapMutations } from 'vuex';
  25. import { userEdit,logout } from '@/api/set.js';
  26. import { upload } from '@/api/order.js'
  27. export default {
  28. data() {
  29. return {
  30. name: '', // 昵称
  31. uid: '',
  32. phone:'',
  33. avatar: '',
  34. };
  35. },
  36. computed: {
  37. ...mapState('user',['userInfo']),
  38. startDate() {
  39. console.log('start');
  40. },
  41. endDate() {
  42. console.log('end');
  43. }
  44. },
  45. onShow(option) {
  46. // 获取生日日期
  47. console.log(this.userInfo);
  48. this.name = this.userInfo.nickname + '';
  49. this.uid = this.userInfo.uid || '';
  50. this.avatar = this.userInfo.avatar || '';
  51. this.phone = this.userInfo.phone || '';
  52. },
  53. methods: {
  54. ...mapMutations('user', ['logout']),
  55. // 上传头像
  56. upload() {
  57. console.log("111111")
  58. upload({
  59. filename: ''
  60. }).then(data => {
  61. this.avatar = data[0].url;
  62. console.log(this.avatar, 'tup')
  63. setTimeout(() => {
  64. uni.hideLoading()
  65. }, 500)
  66. });
  67. },
  68. switchChange(e) {
  69. this.addressData.default = e.value;
  70. },
  71. confirm() {
  72. userEdit({
  73. nickname: this.name,
  74. avatar: this.avatar,
  75. }).then(e => {
  76. this.$api.msg('修改成功');
  77. setTimeout(() => {
  78. uni.switchTab({
  79. url: '/pages/user/user'
  80. });
  81. }, 1000);
  82. console.log(e);
  83. })
  84. .catch(e => {
  85. console.log(e);
  86. });
  87. },
  88. loginout() {
  89. let obj = this;
  90. uni.showModal({
  91. content: '确定要退出登录么',
  92. success: e => {
  93. if (e.confirm) {
  94. uni.removeStorageSync('canChange')
  95. logout({}).then()
  96. uni.navigateBack();
  97. obj.logout();
  98. }
  99. }
  100. });
  101. }
  102. }
  103. };
  104. </script>
  105. <style lang="scss">
  106. page {
  107. background: $page-color-base;
  108. }
  109. .row1 {
  110. display: flex;
  111. align-items: center;
  112. justify-content: space-between;
  113. position: relative;
  114. padding: 0 30upx;
  115. height: 110upx;
  116. background: #fff;
  117. margin-bottom: 20upx;
  118. .tit {
  119. flex-shrink: 0;
  120. width: 120upx;
  121. font-size: $font-lg;
  122. color: $font-color-dark;
  123. }
  124. .background-img {
  125. width: 80rpx;
  126. height: 80rpx;
  127. border-radius: 50%;
  128. background: #f2f2f2;
  129. }
  130. }
  131. .row {
  132. display: flex;
  133. align-items: center;
  134. justify-content: space-between;
  135. position: relative;
  136. padding: 0 30upx;
  137. height: 110upx;
  138. background: #fff;
  139. .tit {
  140. flex-shrink: 0;
  141. width: 120upx;
  142. font-size: $font-lg;
  143. color: $font-color-dark;
  144. }
  145. .tit1 {
  146. flex-shrink: 0;
  147. width: 150upx;
  148. font-size: $font-lg;
  149. color: $font-color-dark;
  150. }
  151. .input {
  152. text-align: right;
  153. flex: 1;
  154. font-size: $font-base;
  155. color: $color-gray;
  156. }
  157. .iconlocation {
  158. font-size: 36upx;
  159. color: $font-color-light;
  160. }
  161. }
  162. .add-btn {
  163. display: flex;
  164. align-items: center;
  165. justify-content: center;
  166. width: 560upx;
  167. height: 80upx;
  168. margin: 60upx auto;
  169. font-size: $font-lg;
  170. color: #fff;
  171. background: $base-color;
  172. border-radius: 40upx;
  173. }
  174. .loginout {
  175. display: flex;
  176. align-items: center;
  177. justify-content: center;
  178. width: 560upx;
  179. height: 80upx;
  180. margin: 60upx auto;
  181. font-size: $font-lg;
  182. color: $base-color;
  183. background: #FFFFFF;
  184. border: 1px solid $base-color;
  185. border-radius: 40upx;
  186. }
  187. </style>