BindingMobile.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <div style="margin-top: 20px">
  3. <el-form label-width="80px" style="width:400px">
  4. <el-form-item label="手机号码" >
  5. <el-input v-model="phoneBindingForm.phone"></el-input>
  6. </el-form-item>
  7. <el-form-item label="验证码">
  8. <el-input placeholder="验证码内容" v-model="phoneBindingForm.verifyCode" class="input-with-select">
  9. <el-button slot="append" @click="getVerifyCode">{{hasVerifyCode ? codeTime : '获取验证码'}}</el-button>
  10. </el-input>
  11. <span v-if="hasVerifyCode">验证码已发送到您手机上</span>
  12. </el-form-item>
  13. </el-form>
  14. <el-button type="primary" plain style="margin-left: 80px" @click="bindingMobile">完成绑定</el-button>
  15. </div>
  16. </template>
  17. <script>
  18. import Http from '@/js/http.js'
  19. import {storageGet} from '@/js/index'
  20. import {notify} from '@/constants/index'
  21. export default {
  22. name: "BindingMobile",
  23. data(){
  24. return{
  25. phoneBindingForm:{
  26. phone:'',
  27. verifyCode:''
  28. },
  29. hasVerifyCode:false,
  30. codeTime:10,
  31. user:{}
  32. }
  33. },
  34. methods:{
  35. setUserInfo() {
  36. this.user = storageGet('user') && storageGet('user').userVO;
  37. },
  38. getVerifyCode(){
  39. let params = {
  40. id:this.user.id,
  41. mobile:this.phoneBindingForm.phone
  42. }
  43. Http.put('/api/verify/mobile',params).then((res)=>{
  44. this.hasVerifyCode = true;
  45. let _this = this;
  46. let codeTimer = setInterval(function () {
  47. if(_this.codeTime > 0 ){
  48. _this.codeTime--;
  49. }else{
  50. clearInterval(codeTimer);
  51. _this.hasVerifyCode = false;
  52. this.codeTime = 10;
  53. }
  54. },1000)
  55. }).catch(err=> {
  56. notify('error', '绑定手机失败:' + err.data);
  57. })
  58. },
  59. bindingMobile(){
  60. let params = {
  61. id:this.user.id,
  62. mobile:this.phoneBindingForm.phone,
  63. verifyCode: this.phoneBindingForm.verifyCode
  64. };
  65. Http.put('/api/user/mobile',params).then(res=>{
  66. if(res.code === 20000){
  67. notify('success', '绑定成功');
  68. this.$router.push({path:'/personal/phoneBinding'});
  69. //需要更改vuex和storage中得user
  70. console.log(storageGet(user));
  71. }
  72. }).catch(err=> {
  73. notify('error', err.data);
  74. })
  75. }
  76. },
  77. mounted() {
  78. this.setUserInfo()
  79. }
  80. }
  81. </script>
  82. <style scoped>
  83. </style>