password.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view class="container">
  3. <view class="row b-b">
  4. <text class="tit">手机号</text>
  5. <input class="input" disabled v-model="userInfo.phone" type="text" placeholder="请填写手机号" placeholder-class="placeholder" />
  6. </view>
  7. <view class="row b-b">
  8. <text class="tit">验证码</text>
  9. <input class="input" v-model="captcha" type="text" placeholder="请填写验证码" placeholder-class="placeholder" />
  10. <view class="code" @click="verification">{{ countDown == 0 ? '验证码' : countDown }}</view>
  11. </view>
  12. <view class="row b-b">
  13. <text class="tit">新密码</text>
  14. <input class="input" v-model="password" type="password" placeholder="请填写新密码" placeholder-class="placeholder" />
  15. </view>
  16. <button class="add-btn" :class="{ 'bg-gray': loding }" @click="loding ? '' : confirm()">提交</button>
  17. </view>
  18. </template>
  19. <script>
  20. import { verify } from '@/api/login.js';
  21. import { registerReset } from '@/api/set.js';
  22. import { mapState } from 'vuex';
  23. export default {
  24. data() {
  25. return {
  26. time: '', //保存倒计时对象
  27. countDown: 0, //倒计时
  28. account: '', //手机号
  29. captcha: '', //验证码
  30. password: '', //新密码
  31. loding: false //是否载入中
  32. };
  33. },
  34. computed:{
  35. ...mapState('user',['userInfo'])
  36. },
  37. onLoad() {
  38. this.account = this.userInfo.phone
  39. if(!this.userInfo.phone){
  40. uni.showModal({
  41. title: '提示',
  42. content: '请先绑定手机号!',
  43. showCancel: false,
  44. success: res => {
  45. uni.navigateTo({
  46. url:'./phone'
  47. })
  48. },
  49. fail: () => {},
  50. });
  51. }
  52. },
  53. watch: {
  54. // 监听倒计时
  55. countDown(i) {
  56. if (i == 0) {
  57. clearInterval(this.time);
  58. }
  59. }
  60. },
  61. methods: {
  62. //发送验证码
  63. verification() {
  64. let obj = this;
  65. if (this.account == '') {
  66. this.$api.msg('请输入电话号码');
  67. return;
  68. }
  69. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(this.account)) {
  70. this.$api.msg('请输入正确的手机号');
  71. return;
  72. }
  73. // 判断是否在倒计时
  74. if (obj.countDown > 0) {
  75. return false;
  76. } else {
  77. obj.countDown = 60;
  78. obj.time = setInterval(() => {
  79. obj.countDown--;
  80. }, 1000);
  81. //调用验证码接口
  82. verify({
  83. phone: obj.account,
  84. type: ''
  85. })
  86. .then(({ data }) => {})
  87. .catch(err => {
  88. console.log(err);
  89. });
  90. }
  91. },
  92. confirm(e) {
  93. this.loding = true;
  94. registerReset({
  95. account: this.account,
  96. captcha: this.captcha,
  97. password: this.password
  98. })
  99. .then(({ data }) => {
  100. this.loding = false;
  101. this.$api.msg('修改成功');
  102. })
  103. .catch(err => {
  104. this.loding = true;
  105. console.log(err);
  106. });
  107. }
  108. }
  109. };
  110. </script>
  111. <style lang="scss">
  112. page {
  113. background: $page-color-base;
  114. }
  115. .container {
  116. padding-top: 30rpx;
  117. }
  118. .row {
  119. display: flex;
  120. align-items: center;
  121. position: relative;
  122. padding: 0 30rpx;
  123. height: 110rpx;
  124. background: #fff;
  125. .tit {
  126. flex-shrink: 0;
  127. width: 120rpx;
  128. font-size: 30rpx;
  129. color: $font-color-dark;
  130. }
  131. .input {
  132. flex: 1;
  133. font-size: 30rpx;
  134. color: $font-color-dark;
  135. }
  136. .iconlocation {
  137. font-size: 36rpx;
  138. color: $font-color-light;
  139. }
  140. }
  141. .add-btn {
  142. display: flex;
  143. align-items: center;
  144. justify-content: center;
  145. width: 690rpx;
  146. height: 80rpx;
  147. margin: 60rpx auto;
  148. font-size: $font-lg;
  149. color: #fff;
  150. background-color: $base-color;
  151. border-radius: 10rpx;
  152. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  153. }
  154. .bg-gray {
  155. background-color: $color-gray;
  156. }
  157. .code {
  158. color: #5dbc7c;
  159. font-size: 23rpx;
  160. border-left: 1px solid #eeeeee;
  161. width: 150rpx;
  162. flex-shrink: 0;
  163. text-align: center;
  164. }
  165. </style>