updatePwd.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view class="wrap">
  3. <view class="content">
  4. <u-field v-model="password" type="password" label="新密码" placeholder="请填写新密码">
  5. </u-field>
  6. <u-field v-model="rePassword" type="password" label="重复密码" placeholder="请重复填写新密码">
  7. </u-field>
  8. <u-field v-model="smsCode" label="验证码" placeholder="请填写验证码">
  9. <u-button size="mini" slot="right" type="success" :disabled="smsCodeDisabled" @click="getSmsCode">{{codeText}}</u-button>
  10. </u-field>
  11. </view>
  12. <view class="u-m-t-20 u-p-20">
  13. <u-button @click="submit" type="warning">确定</u-button>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. tel: '',
  22. password: '',
  23. rePassword: '',
  24. smsCode: '',
  25. codeText: '发送验证码',
  26. smsCodeDisabled: false,
  27. nums:60,
  28. clock:undefined
  29. }
  30. },
  31. computed: {
  32. inputStyle() {
  33. let style = {};
  34. if (this.tel && this.tel.length == 11 && this.tel.startsWith('1')) {
  35. style.color = "#fff";
  36. style.backgroundColor = this.$u.color['warning'];
  37. }
  38. return style;
  39. }
  40. },
  41. methods: {
  42. submit() {
  43. if (this.password != this.rePassword) {
  44. this.$u.toast('前后密码不一致');
  45. return;
  46. }
  47. this.$u.post('user/updatePassword_v2/' + this.password + '/' + this.smsCode).then(res => {
  48. this.$u.route({
  49. type: 'switchTab',
  50. url: '/pages/user/profile'
  51. })
  52. }).catch(res => {
  53. console.log("err", res);
  54. this.$u.toast(res.msg);
  55. })
  56. },
  57. goPage(url) {
  58. this.$u.route({
  59. url: url
  60. })
  61. },
  62. getSmsCode() {
  63. const user = this.vuex_user;
  64. this.$u.post('sendSmsCode?mobile=' + user.mobile).then(response => {
  65. this.smsCodeDisabled = true
  66. this.codeText = this.nums + '秒后重新获取';
  67. this.clock = setInterval(this.doLoop, 1000); //一秒执行一次
  68. })
  69. },
  70. doLoop() {
  71. this.nums--;
  72. if (this.nums > 0) {
  73. this.codeText = this.nums + '秒后重新获取';
  74. } else {
  75. clearInterval(this.clock); //清除js定时器
  76. this.codeText = '发送验证码'
  77. this.smsCodeDisabled = false
  78. this.nums = 60; //重置时间
  79. }
  80. }
  81. }
  82. };
  83. </script>
  84. <style lang="scss" scoped>
  85. .wrap {
  86. font-size: 28rpx;
  87. .content {
  88. margin: 50rpx 50rpx;
  89. input {
  90. text-align: left;
  91. margin-bottom: 10rpx;
  92. padding-bottom: 6rpx;
  93. }
  94. .tips {
  95. padding: 30rpx 30rpx;
  96. color: $u-type-info;
  97. margin-bottom: 60rpx;
  98. margin-top: 8rpx;
  99. }
  100. }
  101. }
  102. </style>