userinfo.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <view class="content">
  3. <view class="row1">
  4. <text class="tit">头像</text>
  5. <view class="background-img" @click="imgsub"><image class="background-img" v-model="userInfo.avatar" :src="userInfo.avatar" mode="aspectFill"></image></view>
  6. </view>
  7. <!-- #ifdef MP-WEIXIN -->
  8. <view class="row b-b flex">
  9. <text class="tit">昵称</text>
  10. <input class="input" v-model="userInfo.nickname" type="nickname" @blur="test" placeholder-class="placeholder" />
  11. </view>
  12. <!-- #endif -->
  13. <!-- #ifndef MP-WEIXIN -->
  14. <view class="row b-b flex">
  15. <text class="tit">昵称</text>
  16. <input class="input" v-model="userInfo.nickname" type="text" placeholder-class="placeholder" />
  17. </view>
  18. <!-- #endif -->
  19. <view class="row">
  20. <text class="tit">ID</text>
  21. <input class="input" type="text" disabled="true" v-model="userInfo.uid" placeholder-class="placeholder" />
  22. </view>
  23. <!-- <view class="row">
  24. <text class="tit">账户</text>
  25. <input class="input" type="text" disabled="true" v-model="userInfo.phone" placeholder-class="placeholder" />
  26. </view> -->
  27. <view class="add-btn1" @click="confirm">提交</view>
  28. <view class="add-btn" @click="cancel" style="margin-top: 20rpx;">退出</view>
  29. <uni-popup ref="popup" type="center">
  30. <view class="psw-wrapper">
  31. <view class="psw-title">请输入自己的账户</view>
  32. <input type="text" v-model="password" class="psw-ipt" />
  33. <view class="psw-btn">
  34. <text @click.stop="qx">取消</text>
  35. <text class="psw-qd" @click.stop="pswQd">确定</text>
  36. </view>
  37. </view>
  38. </uni-popup>
  39. </view>
  40. </template>
  41. <script>
  42. import { mapState, mapMutations } from 'vuex';
  43. import { upload } from '@/api/order.js';
  44. import { userEdit, logout } from '@/api/set.js';
  45. export default {
  46. data() {
  47. return {
  48. show: false,
  49. password: ''
  50. };
  51. },
  52. onLoad() {
  53. console.log(this.userInfo);
  54. },
  55. computed: {
  56. ...mapState('user', ['userInfo'])
  57. },
  58. onUnload() {
  59. if (this.userInfo.nickname == '微信用户') {
  60. logout({})
  61. .then(e => {
  62. this.logout();
  63. })
  64. .catch(e => {
  65. console.log(e);
  66. });
  67. }
  68. console.log('222');
  69. },
  70. methods: {
  71. ...mapMutations('user', ['logout']),
  72. imgsub() {
  73. console.log('上传头像');
  74. upload({
  75. filename: ''
  76. }).then(data => {
  77. console.log('data', data);
  78. this.userInfo.avatar = data[0].url;
  79. });
  80. },
  81. confirm() {
  82. userEdit({ avatar: this.userInfo.avatar, nickname: this.userInfo.nickname })
  83. .then(e => {
  84. this.$api.msg('修改成功');
  85. setTimeout(() => {
  86. uni.switchTab({
  87. url: '/pages/user/user'
  88. });
  89. }, 1000);
  90. console.log(e);
  91. })
  92. .catch(e => {
  93. console.log(e);
  94. });
  95. },
  96. toLogout() {
  97. let obj = this;
  98. uni.showModal({
  99. content: '确定要退出登录么',
  100. success: e => {
  101. if (e.confirm) {
  102. logout({})
  103. .then(e => {
  104. uni.navigateBack();
  105. })
  106. .catch(e => {
  107. console.log(e);
  108. });
  109. obj.logout();
  110. }
  111. }
  112. });
  113. },
  114. cancel() {
  115. // this.$refs.popup.open();
  116. let obj = this;
  117. uni.showModal({
  118. content: '确定要退出登录么',
  119. success: e => {
  120. if (e.confirm) {
  121. logout({})
  122. .then(e => {
  123. obj.logout();
  124. uni.switchTab({
  125. url: '/pages/index/index'
  126. });
  127. })
  128. .catch(e => {
  129. console.log(e);
  130. });
  131. }
  132. }
  133. });
  134. },
  135. qx() {
  136. this.password = '';
  137. this.$refs.popup.close();
  138. },
  139. pswQd() {
  140. if (this.password != this.userInfo.phone) {
  141. this.$refs.popup.close();
  142. this.password = '';
  143. this.$api.msg('请输入自己的账户');
  144. return;
  145. }
  146. this.$refs.popup.close();
  147. this.password = '';
  148. this.$api.msg('申请注销成功,请耐心等待审核');
  149. }
  150. }
  151. };
  152. </script>
  153. <style lang="scss">
  154. .row1 {
  155. display: flex;
  156. align-items: center;
  157. justify-content: space-between;
  158. position: relative;
  159. padding: 0 30upx;
  160. height: 110upx;
  161. background: #fff;
  162. margin-bottom: 20upx;
  163. .tit {
  164. flex-shrink: 0;
  165. width: 120upx;
  166. font-size: $font-lg;
  167. color: $font-color-dark;
  168. }
  169. .background-img {
  170. width: 80rpx;
  171. height: 80rpx;
  172. border-radius: 50%;
  173. background: #f2f2f2;
  174. }
  175. }
  176. .row {
  177. display: flex;
  178. align-items: center;
  179. padding: 0 30upx;
  180. height: 110upx;
  181. background: #fff;
  182. .tit {
  183. flex-shrink: 0;
  184. width: 120upx;
  185. font-size: $font-lg;
  186. color: $font-color-dark;
  187. }
  188. .input {
  189. flex: 1;
  190. text-align: right;
  191. font-size: $font-base;
  192. color: $color-gray;
  193. }
  194. }
  195. .add-btn {
  196. display: flex;
  197. align-items: center;
  198. justify-content: center;
  199. margin: 158rpx auto 30rpx;
  200. width: 560rpx;
  201. height: 80rpx;
  202. background: #dc262b;
  203. border-radius: 40px;
  204. color: #ffffff;
  205. }
  206. .add-btn1 {
  207. display: flex;
  208. align-items: center;
  209. justify-content: center;
  210. margin: 158rpx auto 30rpx;
  211. width: 560rpx;
  212. height: 80rpx;
  213. border: 1px solid #dc262b;
  214. color: #dc262b;
  215. border-radius: 40px;
  216. background: #ffffff;
  217. }
  218. .out {
  219. display: flex;
  220. align-items: center;
  221. justify-content: center;
  222. margin: 0 auto 30rpx;
  223. width: 560rpx;
  224. height: 80rpx;
  225. border: 1px solid #dc262b;
  226. background: #ffffff;
  227. border-radius: 40px;
  228. color: #dc262b;
  229. }
  230. .psw-wrapper {
  231. width: 548rpx;
  232. height: 344rpx;
  233. background-color: #ffffff;
  234. .psw-title {
  235. width: 100%;
  236. font-size: 35rpx;
  237. padding: 43rpx 0 49rpx;
  238. text-align: center;
  239. font-weight: 800;
  240. }
  241. .psw-ipt {
  242. display: block;
  243. background-color: #dce3ed;
  244. height: 90rpx;
  245. width: 464rpx;
  246. padding-left: 30rpx;
  247. margin: 0 auto;
  248. font-size: 80rpx;
  249. }
  250. .psw-btn text {
  251. display: inline-block;
  252. text-align: center;
  253. width: 50%;
  254. padding-top: 29rpx;
  255. font-size: 35rpx;
  256. }
  257. .psw-qd {
  258. color: #32c6ff;
  259. }
  260. }
  261. </style>