userinfo.vue 4.5 KB

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