userinfo.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <view class="container">
  3. <view class="row b-b flex jg">
  4. <text class="tit">头像</text>
  5. <image :src="userInfo.avatar" @click="imgsub"></image>
  6. </view>
  7. <view class="row b-b flex">
  8. <text class="tit">昵称</text>
  9. <input class="input" v-model="userInfo.nickname" type="text" placeholder-class="placeholder" />
  10. </view>
  11. <view class="row b-b flex">
  12. <text class="tit">邀请码</text>
  13. <input class="input" v-model="userInfo.uid" type="text" disabled="true" placeholder-class="placeholder" style="color: #999;" />
  14. </view>
  15. <view class="submit-box flex">
  16. <view class="submit dl" @click="edit">确认修改</view>
  17. <view class="submit " @click="toLogout">退出登录</view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import uniList from '@/components/uni-list/uni-list.vue';
  23. import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
  24. import { mapState, mapMutations } from 'vuex';
  25. import { logout } from '@/api/set.js';
  26. import { edit } from '@/api/user.js';
  27. import { upload } from '@/api/order.js';
  28. export default {
  29. components: {
  30. uniList,
  31. uniListItem
  32. },
  33. data() {
  34. return {
  35. userInfo: {},
  36. pics: []
  37. };
  38. },
  39. onLoad() {
  40. this.userInfo = uni.getStorageSync('userInfo') || '';
  41. console.log(this.userInfo);
  42. },
  43. methods: {
  44. ...mapMutations('user', ['logout']),
  45. //退出登录
  46. toLogout() {
  47. let obj = this;
  48. uni.showModal({
  49. content: '确定要退出登录么',
  50. success: e => {
  51. if (e.confirm) {
  52. logout({})
  53. .then(e => {
  54. obj.logout();
  55. uni.switchTab({
  56. url: '/pages/index/index'
  57. });
  58. })
  59. .catch(e => {
  60. console.log(e);
  61. });
  62. }
  63. }
  64. });
  65. },
  66. imgsub() {
  67. let obj = this;
  68. console.log('上传头像');
  69. // this.$util.uploadImageOne('upload/image', function(res) {
  70. // console.log('------',res);
  71. // this.pics.push(res.data.pathreplace(/http:\/\/mer.crmeb.net/,'https://hy.liuniu946.com'));
  72. // // obj.userInfo.avatar = res.data.path.replace(/http:\/\/mer.crmeb.net/,'http://zccy.frp.liuniu946.com')
  73. // obj.$set(this, 'pics', this.pics);
  74. // obj.$set(this, 'extract_pic', this.pics[0])
  75. // });
  76. // uploads({
  77. // filename: ''
  78. // }).then(data => {
  79. // console.log("data",data);
  80. // this.userInfo.avatar = data[0].url;
  81. // })
  82. upload({
  83. filename: ''
  84. }).then(res => {
  85. console.log(res[0].url);
  86. obj.userInfo.avatar = res[0].url;
  87. // console.log(obj.userInfo.avatar)
  88. });
  89. },
  90. edit() {
  91. const that = this;
  92. uni.showLoading({
  93. title: '提交中...',
  94. mask: true
  95. });
  96. edit({
  97. avatar: this.userInfo.avatar,
  98. nickname: this.userInfo.nickname
  99. })
  100. .then(e => {
  101. uni.hideLoading();
  102. that.$api.msg('修改成功');
  103. setTimeout(() => {
  104. uni.switchTab({
  105. url: '/pages/user/user'
  106. });
  107. }, 1000);
  108. })
  109. .catch(e => {
  110. console.log(e);
  111. that.$api.msg('修改失败');
  112. });
  113. }
  114. }
  115. };
  116. </script>
  117. <style lang="scss">
  118. /* page{
  119. background: $page-color-base;
  120. }
  121. .list-cell{
  122. display:flex;
  123. align-items:baseline;
  124. padding: 20rpx $page-row-spacing;
  125. line-height:60rpx;
  126. position:relative;
  127. background: #fff;
  128. justify-content: center;
  129. &.log-out-btn{
  130. margin-top: 40rpx;
  131. .cell-tit{
  132. color: $uni-color-primary;
  133. text-align: center;
  134. margin-right: 0;
  135. }
  136. }
  137. .cell-tit{
  138. flex: 1;
  139. font-size: $font-base + 2rpx;
  140. color: $font-color-dark;
  141. margin-right:10rpx;
  142. }
  143. .cell-tip{
  144. font-size: $font-base;
  145. color: $font-color-light;
  146. }
  147. switch{
  148. transform: translateX(16rpx) scale(.84);
  149. }
  150. } */
  151. page {
  152. background-color: #f3f3f3;
  153. min-height: 100%;
  154. .container {
  155. height: 100%;
  156. }
  157. }
  158. .row {
  159. background-color: #fff;
  160. padding: 42rpx 25rpx;
  161. font-size: 30rpx;
  162. color: #333333;
  163. image {
  164. width: 80rpx;
  165. height: 80rpx;
  166. border-radius: 50%;
  167. }
  168. .input {
  169. text-align: right;
  170. color: #333333;
  171. }
  172. }
  173. .submit-box {
  174. display: flex;
  175. flex-direction: column;
  176. padding-top: 157rpx;
  177. .submit {
  178. margin: 40rpx auto;
  179. width: 560rpx;
  180. background-color: #ffffff;
  181. color: #000000;
  182. text-align: center;
  183. padding: 26rpx 0rpx;
  184. border-radius: 50rpx;
  185. }
  186. .dl {
  187. background-color: #000000;
  188. color: #ffffff;
  189. }
  190. }
  191. .jg {
  192. margin-bottom: 20rpx;
  193. }
  194. </style>