userinfo.vue 4.4 KB

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