set.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="content">
  3. <view class="row1">
  4. <text class="tit">头像</text>
  5. <view class="background-img" @click="upload"><image class="background-img" v-model="avatar" :src="avatar" mode="aspectFill"></image></view>
  6. </view>
  7. <view class="row">
  8. <text class="tit">昵称</text>
  9. <input class="input" type="button" v-model="name" placeholder-class="placeholder" />
  10. </view>
  11. <view class="row">
  12. <text class="tit">修改密码</text>
  13. <input class="input" type="text" v-model="password" placeholder-class="placeholder" />
  14. </view>
  15. <view class="row">
  16. <text class="tit">请输入手机号</text>
  17. <input class="input" type="text" v-model="account" placeholder-class="placeholder" />
  18. </view>
  19. <view class="row">
  20. <text class="tit">验证码</text>
  21. <input class="input" type="text" v-model="captcha" placeholder-class="placeholder" />
  22. <view class="code" @click="verification">{{ countDown == 0 ? $t('password.a7') : countDown }}</view>
  23. </view>
  24. <view class="row">
  25. <text class="tit">账号</text>
  26. <input class="input" disabled type="text" v-model="phone" placeholder-class="placeholder" />
  27. </view>
  28. <button class="add-btn" @click="confirm">修改</button>
  29. </view>
  30. </template>
  31. <script>
  32. import { mapState,mapMutations } from 'vuex';
  33. import { userEdit,logout } from '@/api/set.js';
  34. import { upload } from '@/api/order.js'
  35. export default {
  36. data() {
  37. return {
  38. name: '', // 昵称
  39. password:'', //修改密码
  40. captcha:'', //验证码
  41. account:'', //请输入手机号
  42. phone:'',
  43. avatar: '',
  44. };
  45. },
  46. computed: {
  47. ...mapState('user',['userInfo']),
  48. startDate() {
  49. console.log('start');
  50. },
  51. endDate() {
  52. console.log('end');
  53. }
  54. },
  55. onShow(option) {
  56. console.log('111',this.userInfo);
  57. this.name = this.userInfo.nickname + '';
  58. this.password = '',
  59. this.captcha = '',
  60. this.account = '',
  61. this.avatar = this.userInfo.avatar || '';
  62. this.phone = this.userInfo.phone || '';
  63. },
  64. methods: {
  65. ...mapMutations('user', ['logout']),
  66. // 上传头像
  67. upload() {
  68. console.log("111111")
  69. upload({
  70. filename: ''
  71. }).then(data => {
  72. this.avatar = data[0].url;
  73. console.log(this.avatar, 'tup')
  74. setTimeout(() => {
  75. uni.hideLoading()
  76. }, 500)
  77. });
  78. },
  79. confirm() {
  80. userEdit({
  81. nickname: this.name,
  82. avatar: this.avatar,
  83. password: this.password,
  84. captcha: this.captcha,
  85. account: this.account
  86. }).then(e => {
  87. this.$api.msg('修改成功');
  88. // 清空输入框
  89. this.password = '',
  90. setTimeout(() => {
  91. uni.switchTab({
  92. url: '/pages/user/user'
  93. });
  94. }, 1000);
  95. console.log(e);
  96. })
  97. .catch(e => {
  98. console.log(e);
  99. });
  100. },
  101. //发送验证码
  102. verification() {
  103. let obj = this;
  104. if (this.account == '') {
  105. this.$api.msg('请输入电话号码');
  106. return;
  107. }
  108. if (this.account.length < 11) {
  109. this.$api.msg('请输入正确的手机号');
  110. return;
  111. }
  112. // 判断是否在倒计时
  113. if (obj.countDown > 0) {
  114. return false;
  115. } else {
  116. obj.countDown = 60;
  117. obj.time = setInterval(() => {
  118. obj.countDown--;
  119. }, 1000);
  120. //调用验证码接口
  121. verify({
  122. account: obj.account,
  123. type: 'login'
  124. })
  125. .then(({ data }) => {})
  126. .catch(err => {
  127. console.log(err);
  128. });
  129. }
  130. },
  131. // loginout() {
  132. // let obj = this;
  133. // uni.showModal({
  134. // content: '确定要退出登录么',
  135. // success: e => {
  136. // if (e.confirm) {
  137. // uni.removeStorageSync('canChange')
  138. // logout({}).then()
  139. // uni.navigateBack();
  140. // obj.logout();
  141. // }
  142. // }
  143. // });
  144. // }
  145. loginout() {
  146. uni.navigateTo({
  147. url: '/pages/switch/switch'
  148. })
  149. }
  150. }
  151. };
  152. </script>
  153. <style lang="scss">
  154. .content {
  155. background-color: #fff;
  156. }
  157. .row1 {
  158. display: flex;
  159. align-items: center;
  160. justify-content: space-between;
  161. position: relative;
  162. padding: 0 30upx;
  163. height: 110upx;
  164. background: #fff;
  165. .tit {
  166. flex-shrink: 0;
  167. width: 120upx;
  168. font-size: $font-lg;
  169. }
  170. .background-img {
  171. width: 80rpx;
  172. height: 80rpx;
  173. border-radius: 50%;
  174. background: #f2f2f2;
  175. }
  176. }
  177. .row {
  178. display: flex;
  179. align-items: center;
  180. justify-content: space-between;
  181. position: relative;
  182. padding: 0 30upx;
  183. height: 110upx;
  184. background: #fff;
  185. .tit {
  186. flex-shrink: 0;
  187. font-size: $font-lg;
  188. color: $font-color-dark;
  189. }
  190. .tit1 {
  191. flex-shrink: 0;
  192. width: 150upx;
  193. font-size: $font-lg;
  194. color: $font-color-dark;
  195. }
  196. .input {
  197. text-align: right;
  198. flex: 1;
  199. font-size: $font-base;
  200. color: $color-gray;
  201. }
  202. .iconlocation {
  203. font-size: 36upx;
  204. color: $font-color-light;
  205. }
  206. }
  207. .add-btn {
  208. display: flex;
  209. align-items: center;
  210. justify-content: center;
  211. width: 560upx;
  212. height: 80upx;
  213. margin: 60upx auto;
  214. font-size: $font-lg;
  215. color: #fff;
  216. background: $base-color;
  217. border-radius: 40upx;
  218. }
  219. .loginout {
  220. display: flex;
  221. align-items: center;
  222. justify-content: center;
  223. width: 560upx;
  224. height: 80upx;
  225. margin: 60upx auto;
  226. font-size: $font-lg;
  227. color: #fff;
  228. }
  229. </style>