forgetpass.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <view>
  3. <z-navbar title="重置密码" back></z-navbar>
  4. <z-card width="630" class="mt-30 flex-n fac step_area">
  5. <view class="step_area_item flex-n fac">
  6. <view class="step_area_num" :class="step==0?'step_area_num_choose':''">1</view>
  7. <view class="step_area_text" :class="step==0?'step_area_text_choose':''">验证手机号码</view>
  8. </view>
  9. <view class="line flex-1 mlr-20"></view>
  10. <view class="step_area_item flex-n fac">
  11. <view class="step_area_num" :class="step==1?'step_area_num_choose':''">2</view>
  12. <view class="step_area_text" :class="step==1?'step_area_text_choose':''">设置新密码</view>
  13. </view>
  14. </z-card>
  15. <template v-if="step==0">
  16. <z-card class="mt-40">
  17. <view class="mlr-40 card_area">
  18. <view class="flex-n fac card_area_item">
  19. <view class="card_icon iconfont iconyuanjiaojuxing2"></view>
  20. <z-input class="ml-19" type="number" align="left" placeholder="请输入手机号码" v-model="phone"></z-input>
  21. </view>
  22. <view class="line"></view>
  23. <view class="flex-n fac card_area_item">
  24. <view class="card_icon iconfont iconjuxing11" style="font-size: 30rpx;"></view>
  25. <z-input class="ml-19 flex-1" align="left" placeholder="请输入短信验证码" v-model="code"></z-input>
  26. <view class="card_send_message" v-if="sendCodeState!=2" type="primary" @click="sendCode(phone)">{{sendCodeState=='0'?'发送验证码':'重新获取'}}
  27. </view>
  28. <view class="card_send_message" v-else disabled type="primary">{{countdown}}s</view>
  29. </view>
  30. </view>
  31. </z-card>
  32. <z-button class="mt-50" @click="nextStep">下一步</z-button>
  33. </template>
  34. <template v-else>
  35. <z-card class="mt-40">
  36. <view class="mlr-40 card_area">
  37. <view class="flex-n fac card_area_item">
  38. <view class="card_icon iconfont iconsuotou"></view>
  39. <z-input class="ml-19 flex-1" type="password" placeholder="请设置6-20位新的登录密码" v-model="password"></z-input>
  40. </view>
  41. <view class="line"></view>
  42. <view class="flex-n fac card_area_item">
  43. <view class="card_icon iconfont iconsuotou"></view>
  44. <z-input class="ml-19 flex-1" type="password" placeholder="请再次输入新的登录密码" v-model="repeatpassword"></z-input>
  45. </view>
  46. </view>
  47. </z-card>
  48. <z-button class="mt-50" @click="submit">提 交</z-button>
  49. </template>
  50. <u-toast ref="uToast"></u-toast>
  51. </view>
  52. </template>
  53. <script>
  54. export default {
  55. data() {
  56. return {
  57. //入参
  58. phone: '',
  59. code:'',
  60. id:'',
  61. password:'',
  62. repeatpassword:'',
  63. step: 0,//下一步
  64. sendCodeState: 0,//发送验证码 0 重新发送 1 倒计时2
  65. countdown: 60,//倒计时
  66. cleartime: '',//清除定时器
  67. }
  68. },
  69. mounted() {
  70. },
  71. watch:{
  72. countdown(newval, oldval) {
  73. if (newval == 0) {
  74. clearInterval(this.cleartime);
  75. this.countdown = 60;
  76. this.sendCodeState = 1;
  77. }
  78. },
  79. },
  80. methods: {
  81. //发送验证码
  82. sendCode(phone) {
  83. this.$axios.post('sms/sendSms', {
  84. "phone": phone,
  85. "type": "SEND_CODE"
  86. }).then(res => {
  87. this.$refs.uToast.success('验证码发送成功');
  88. this.sendCodeState = 2;
  89. this.cleartime = setInterval(() => {
  90. this.countdown--;
  91. }, 1000)
  92. }).catch(err => {
  93. this.$refs.uToast.error(err.msg);
  94. })
  95. },
  96. //下一步
  97. nextStep() {
  98. this.$axios.post('sms/validCodeRetUserId', {
  99. "phone": this.phone,
  100. "code": this.code
  101. }).then(res => {
  102. this.id=res.data.userId;
  103. this.step = 1;
  104. this.countdown = 0;//清除倒计时
  105. }).catch(err => {
  106. this.$refs.uToast.error(err.msg);
  107. })
  108. },
  109. submit(){
  110. if(this.password==''||this.password.length<6||this.password.length>20){
  111. return this.$refs.uToast.error('请输入6-20位新的登录密码');
  112. }
  113. if(this.repeatpassword==''){
  114. return this.$refs.uToast.error('请再次输入新的登录密码');
  115. }
  116. if(this.password!=this.repeatpassword){
  117. return this.$refs.uToast.error('两次输入的登录密码不同');
  118. }
  119. this.$axios.post('app/appUser/resetPassword', {
  120. "id": this.id,
  121. "passWord": this.password
  122. }).then(res => {
  123. // this.$refs.uToast.success('密码修改成功,请在登录页重新登录');
  124. uni.showToast({
  125. title:'密码修改成功,请在登录页重新登录',
  126. icon: 'none',
  127. duration: 2000
  128. })
  129. uni.reLaunch({
  130. url: '../../login/newlogin'
  131. });
  132. }).catch(err => {
  133. this.$refs.uToast.error(err.msg);
  134. })
  135. }
  136. },
  137. beforeDestroy() {
  138. clearTimeout(this.cleartime);
  139. }
  140. }
  141. </script>
  142. <style lang="scss" scoped>
  143. .step_area {
  144. padding: 24rpx 30rpx;
  145. .step_area_item {
  146. .step_area_num {
  147. width: 54rpx;
  148. height: 54rpx;
  149. border: 1px solid #999999;
  150. border-radius: 50%;
  151. text-align: center;
  152. line-height: 54rpx;
  153. color: #999999;
  154. font-size: 30rpx;
  155. }
  156. .step_area_num_choose {
  157. background: #2481EE;
  158. color: white;
  159. border: 1px solid #2481EE;
  160. }
  161. .step_area_text_choose {
  162. color: #2481EE !important;
  163. }
  164. .step_area_text {
  165. color: #999999;
  166. font-size: 30rpx;
  167. margin-left: 25rpx;
  168. }
  169. }
  170. }
  171. .card_area {
  172. .card_area_item {
  173. height: 100rpx;
  174. }
  175. .card_icon {
  176. font-size: 40rpx;
  177. min-width: 40rpx;
  178. color: gray;
  179. }
  180. .card_send_message {
  181. font-size: 28rpx;
  182. color: #2481EE;
  183. }
  184. }
  185. </style>