userinfo.vue 5.8 KB

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