userinfo.vue 4.4 KB

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