userinfo.vue 4.7 KB

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