ReBindingMobile.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <div>
  3. <el-steps :active="active" process-status="finish" style="margin: 20px">
  4. <el-step title="验证原手机"></el-step>
  5. <el-step title="绑定新手机"></el-step>
  6. </el-steps>
  7. <el-form label-width="80px" style="width:400px;" :rules="rules">
  8. <el-form-item label="原手机号" v-if="active===0" prop="phone">
  9. <span v-model="phoneBindingForm.phone">{{this.user.mobile}}</span>
  10. </el-form-item>
  11. <el-form-item label="新手机号" v-if="active===1" prop="phone">
  12. <el-input v-model="phoneBindingForm.phone"></el-input>
  13. </el-form-item>
  14. <el-form-item label="验证码" prop="verifyCode">
  15. <el-input placeholder="验证码内容" v-model="phoneBindingForm.verifyCode" class="input-with-select">
  16. <el-button slot="append" @click="getVerifyCode" :disabled="hasVerifyCode">{{hasVerifyCode ? codeTime : '获取验证码'}}</el-button>
  17. </el-input>
  18. <span v-if="hasVerifyCode">验证码已发送到您手机上</span>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button type="primary" plain @click="reBindingMobile">{{this.active===0 ?
  22. '下一步':'完成绑定'}}
  23. </el-button>
  24. </el-form-item>
  25. </el-form>
  26. </div>
  27. </template>
  28. <script>
  29. import Http from '@/js/http.js'
  30. import {storageGet} from '@/js/index'
  31. import {notify} from '@/constants/index'
  32. export default {
  33. name: "ReBindingMobile",
  34. data() {
  35. return {
  36. active: 0,
  37. user: {},
  38. phoneBindingForm: {
  39. phone: '',
  40. verifyCode: ''
  41. },
  42. hasVerifyCode: false,
  43. codeTime: 60,
  44. rules: {
  45. verifyCode: [
  46. {required: true, message: '请输入验证码', trigger: 'blur'},
  47. ],
  48. phone: [
  49. {required: true, message: '请输入手机号', trigger: 'blur'},
  50. ],
  51. }
  52. }
  53. },
  54. methods: {
  55. setUserInfo() {
  56. let userId = storageGet('user') && storageGet('user').userVO.id;
  57. Http.get(`/api/user/${userId}`).then(res => {
  58. this.user = res.userVO;
  59. this.phoneBindingForm.phone = this.user.mobile;
  60. })
  61. },
  62. reBindingMobile() {
  63. if (this.active === 0) {
  64. //1.验证原手机
  65. let params = {
  66. "id": this.user.id,
  67. "mobile": this.user.mobile,
  68. "verifyCode": this.phoneBindingForm.verifyCode
  69. }
  70. Http.put('/api/verify/old/mobile', params).then(res => {
  71. if (res.code === 20000) {
  72. notify('success', '验证成功');
  73. this.active = 1;
  74. this.phoneBindingForm.phone = '';
  75. this.phoneBindingForm.verifyCode = '';
  76. this.setUserInfo();
  77. }
  78. }).catch(err => {
  79. notify('error', '验证原手机失败:' + err.data);
  80. })
  81. } else {
  82. let params = {
  83. "id": this.user.id,
  84. "mobile": this.phoneBindingForm.phone,
  85. "verifyCode": this.phoneBindingForm.verifyCode
  86. };
  87. Http.put('/api/user/mobile', params).then(res => {
  88. if (res.msg == "ERROR") {
  89. notify('error', '重新绑定失败:' + res.data);
  90. } else {
  91. notify('success', '重新绑定成功');
  92. this.$router.push({path: '/personal/phoneBinding'});
  93. }
  94. }).catch(err => {
  95. notify('error', '重新绑定失败:' + err.data);
  96. })
  97. }
  98. },
  99. getVerifyCode() {
  100. let params = {
  101. id: this.user.id,
  102. mobile: this.phoneBindingForm.phone
  103. }
  104. Http.put('/api/verify/mobile', params).then((res) => {
  105. this.hasVerifyCode = true;
  106. let _this = this;
  107. let codeTimer = setInterval(function () {
  108. if (_this.codeTime > 0) {
  109. _this.codeTime--;
  110. } else {
  111. clearInterval(codeTimer);
  112. _this.hasVerifyCode = false;
  113. this.codeTime = 10;
  114. }
  115. }, 1000)
  116. }).catch(err => {
  117. notify('error', '获取验证码失败:' + err.data);
  118. })
  119. }
  120. },
  121. mounted() {
  122. this.setUserInfo();
  123. }
  124. }
  125. </script>
  126. <style scoped>
  127. </style>