ReBindingMobile.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <div v-loading="loading">
  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" :model="phoneBindingForm" :ref="phoneBindingForm">
  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="newPhone">
  12. <el-input v-model="phoneBindingForm.newPhone"></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 :
  17. '获取验证码'}}
  18. </el-button>
  19. </el-input>
  20. <span v-if="hasVerifyCode">验证码已发送到您手机上</span>
  21. </el-form-item>
  22. <el-form-item>
  23. <el-button type="primary" plain @click="reBindingMobile">{{this.active===0 ?
  24. '下一步':'完成绑定'}}
  25. </el-button>
  26. </el-form-item>
  27. </el-form>
  28. </div>
  29. </template>
  30. <script>
  31. import Http from '@/js/http.js'
  32. import {storageGet} from '@/js/index'
  33. import {notify} from '@/constants/index'
  34. export default {
  35. name: "ReBindingMobile",
  36. data() {
  37. return {
  38. loading: false,
  39. active: 0,
  40. user: {},
  41. phoneBindingForm: {
  42. phone: '',
  43. verifyCode: '',
  44. newPhone: '',
  45. },
  46. hasVerifyCode: false,
  47. codeTime: 60,
  48. rules: {
  49. verifyCode: [
  50. {required: true, message: '请输入验证码', trigger: 'blur'},
  51. {min: 6, max: 6, message: '验证码长度为6个字符', trigger: 'blur'}
  52. ],
  53. phone: [
  54. {required: true, message: '请输入手机号', trigger: 'blur'},
  55. ],
  56. newPhone: [
  57. {required: true, message: '请输入手机号', trigger: 'blur'},
  58. {min: 11, max: 11, message: '手机号不合法', trigger: 'blur'}
  59. ],
  60. }
  61. }
  62. },
  63. methods: {
  64. setUserInfo() {
  65. let userId = storageGet('user') && storageGet('user').userVO.id;
  66. Http.get(`/api/user/${userId}`).then(res => {
  67. this.user = res.userVO;
  68. this.phoneBindingForm.phone = this.user.mobile;
  69. })
  70. },
  71. reBindingMobile() {
  72. this.showLoading();
  73. if (this.active === 0) {
  74. //1.验证原手机
  75. let params = {
  76. "id": this.user.id,
  77. "mobile": this.user.mobile,
  78. "verifyCode": this.phoneBindingForm.verifyCode
  79. }
  80. Http.put('/api/verify/old/mobile', params).then(res => {
  81. this.hideLoading();
  82. if (res.code === 20000) {
  83. notify('success', '验证成功');
  84. this.active = 1;
  85. this.phoneBindingForm.phone = '';
  86. this.phoneBindingForm.verifyCode = '';
  87. this.hasVerifyCode = false;
  88. this.codeTime = 60;
  89. this.setUserInfo();
  90. } else {
  91. notify('error', '验证原手机失败:' + res.data);
  92. this.codeTime = 60;
  93. this.hasVerifyCode = false;
  94. }
  95. }).catch(err => {
  96. this.phoneBindingForm.phone = '';
  97. this.phoneBindingForm.verifyCode = '';
  98. this.codeTime = 60;
  99. this.hasVerifyCode = false;
  100. this.hideLoading();
  101. notify('error', '验证原手机失败:' + err.data);
  102. })
  103. } else {
  104. let params = {
  105. "id": this.user.id,
  106. "mobile": this.phoneBindingForm.newPhone,
  107. "verifyCode": this.phoneBindingForm.verifyCode
  108. };
  109. Http.put('/api/user/mobile', params).then(res => {
  110. this.hideLoading();
  111. if (res.msg == "ERROR") {
  112. notify('error', '绑定失败:' + res.data);
  113. } else {
  114. notify('success', '绑定成功');
  115. this.$router.push({path: '/personal/phoneBinding'});
  116. }
  117. }).catch(err => {
  118. this.hideLoading();
  119. notify('error', '绑定失败:' + err.data);
  120. })
  121. }
  122. },
  123. getVerifyCode() {
  124. if (this.active === 0) {
  125. //1.验证原手机
  126. let params = {
  127. id: this.user.id,
  128. mobile: this.phoneBindingForm.phone
  129. }
  130. Http.put('/api/verify/mobile', params).then((res) => {
  131. let _this = this;
  132. if(res.msg == 'ERROR'){
  133. notify('error', '验证码获取失败:' + res.data);
  134. }else{
  135. this.hasVerifyCode = true;
  136. notify('success', res.data);
  137. let codeTimer = setInterval(function () {
  138. if (_this.codeTime > 0) {
  139. _this.codeTime--;
  140. } else {
  141. clearInterval(codeTimer);
  142. _this.hasVerifyCode = false;
  143. this.codeTime = 10;
  144. }
  145. }, 1000)
  146. }
  147. }).catch(err => {
  148. notify('error', '获取验证码失败:' + err.data);
  149. })
  150. } else {
  151. //2.验证新手机
  152. let params = {
  153. id: this.user.id,
  154. mobile: this.phoneBindingForm.newPhone
  155. }
  156. Http.put('/api/verify/mobile', params).then((res) => {
  157. let _this = this;
  158. if (res.msg == "ERROR") {
  159. notify('error', '验证码获取失败:' + res.data);
  160. }else{
  161. this.hasVerifyCode = true;
  162. notify('success', res.data);
  163. let codeTimer = setInterval(function () {
  164. if (_this.codeTime > 0) {
  165. _this.codeTime--;
  166. } else {
  167. clearInterval(codeTimer);
  168. _this.hasVerifyCode = false;
  169. this.codeTime = 10;
  170. }
  171. }, 1000)
  172. }
  173. }).catch(err => {
  174. notify('error', '获取验证码失败:' + err.data);
  175. })
  176. }
  177. },
  178. showLoading() {
  179. this.loading = true
  180. },
  181. hideLoading() {
  182. this.loading = false
  183. },
  184. },
  185. mounted() {
  186. this.setUserInfo();
  187. }
  188. }
  189. </script>
  190. <style scoped>
  191. </style>