validate-tel.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. (function(vc){
  2. vc.extends({
  3. data:{
  4. validateParam:{
  5. tel:'',
  6. messageCode:'',
  7. },
  8. buttonInfo:'验证码'
  9. },
  10. _initMethod:function(){
  11. console.log("validate-tel _initMethod 方法调用");
  12. //vc.component.generateCode();
  13. },
  14. _initEvent:function(){
  15. },
  16. watch: {
  17. validateParam:{
  18. deep: true,
  19. handler:function(){
  20. console.log('通知号码信息',vc.component.validateParam.tel);
  21. vc.component.$emit('validate_tel_change_event',vc.component.validateParam);
  22. }
  23. }
  24. // messageCode:function(){
  25. // vc.component.$emit('validate_tel_change_event',vc.component.validateParam);
  26. // }
  27. },
  28. methods:{
  29. sendTelMessageCode(){
  30. if(!vc.validate.phone(vc.component.validateParam.tel)){
  31. vc.component.$emit('errorInfoEvent',"手机号码为空或不正确,不能发送验证码");
  32. return;
  33. }
  34. // 开启定时
  35. vc.component.messageCodeTimer();
  36. var param = {
  37. tel:vc.component.validateParam.tel,
  38. };
  39. console.log("validate-tel sendTelMessageCode",JSON.stringify(param));
  40. vc.http.post('validate-tel','sendTelMessageCode',
  41. JSON.stringify(param),
  42. {
  43. emulateJSON:true
  44. },
  45. function(json,res){
  46. //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
  47. if(res.status == 200){
  48. vc.component.registerInfo.validateInfo = json;
  49. return ;
  50. }
  51. vc.component.$emit('errorInfoEvent',json);
  52. },function(errInfo,error){
  53. console.log('请求失败处理',errInfo,error);
  54. vc.component.$emit('errorInfoEvent',errInfo);
  55. });
  56. },
  57. //验证码定时
  58. messageCodeTimer(){
  59. var num = 60;
  60. var _timer = vc.createTimer(function(){
  61. num --;
  62. vc.component.buttonInfo = num +" 秒后重试";
  63. if(num === 1){
  64. vc.clearTimer(_timer);
  65. vc.component.buttonInfo = "验证码";
  66. }
  67. },1000);
  68. }
  69. },
  70. _destroyedMethod:function(){
  71. console.log("登录页面销毁调用");
  72. }
  73. });
  74. })(window.vc);