优惠券分享

register.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. var union_id = 0;
  2. var isClickFlag = true;//是否可以点击获取验证码
  3. window.onload = function () {
  4. union_id = getURLCode()['union_id'] || 0;
  5. if(union_id == 0){
  6. window.location.href='http://a.app.qq.com/o/simple.jsp?pkgname=com.kuxuan.coupon_liedou'
  7. }
  8. writeLogH5({action:'HB-register',channel:'H5',url:window.location.href});//海报手机注册
  9. _czc.push(["_trackEvent",'邀请海报','页面',]);
  10. }
  11. //获取手机验证码
  12. function getYzm () {
  13. var phoneNumber = getIdHtml("phone").value;
  14. var ttl = new Date().getTime();
  15. var sign = hex_md5('phone=' + phoneNumber + '&ttl=' + ttl + 'cNHWj7pqBSXTi2DS4uvxqMTzuXOk5xvL');
  16. if(phoneNumber.length != 11){
  17. showMsg('请正确输入手机号');
  18. return;
  19. }
  20. if(!isClickFlag){
  21. return;
  22. }
  23. axios.post('/api/v2/users/sendCode', {
  24. phone: phoneNumber,
  25. ttl: ttl,
  26. sign: sign,
  27. union_id: union_id
  28. },{
  29. headers:{
  30. source:6000
  31. }
  32. })
  33. .then(function (response) {
  34. var res = response.data,wait_time;
  35. if (res.errno == 0 && res.rst.success) {
  36. wait_time = res.rst.wait_time;
  37. var time = setInterval(function () {
  38. wait_time--;
  39. getIdHtml('yzmButton').innerHTML = wait_time + 's';
  40. isClickFlag = false;//不可获取验证码
  41. if(wait_time == 0){
  42. clearInterval(time);
  43. getIdHtml('yzmButton').innerHTML = '获取验证码';
  44. isClickFlag = true;//可以获取验证码
  45. }
  46. },1000)
  47. }else if(res.errno == 0 && !res.rst.success){
  48. showMsg('请稍后再试哦~')
  49. }else{//errno==1011 该手机号已绑定其他微信
  50. showMsg(res.err);
  51. }
  52. })
  53. .catch(function (error) {
  54. showMsg('请稍后再试哦~')
  55. });
  56. }
  57. //注册事件
  58. function registerEvent () {
  59. if(getIdHtml("phone").value.length != 11){
  60. showMsg('请正确输入手机号');
  61. return;
  62. }
  63. if((getIdHtml('yzm').value).trim().length == 0){
  64. showMsg('请输入手机验证码')
  65. return;
  66. }
  67. //验证注册
  68. axios.post('/api/v2/users/loginCode', {
  69. phone: getIdHtml("phone").value,
  70. code: getIdHtml('yzm').value,
  71. union_id: union_id
  72. },{
  73. headers:{
  74. source:6000
  75. }
  76. })
  77. .then(function (response) {
  78. var res = response.data;
  79. if (res.errno == 0) {
  80. document.getElementById('registerSuccess').style.visibility='visible';
  81. writeLogH5({action:'HB-success',channel:'H5',url:window.location.href});//手机注册成功
  82. _czc.push(["_trackEvent",'邀请海报','手机注册成功',]);
  83. }else if(res.errno == 1001){
  84. showMsg('请稍后再试哦~')
  85. }else{
  86. showMsg(res.err);
  87. }
  88. })
  89. .catch(function (error) {
  90. showMsg('请稍后再试哦~')
  91. });
  92. }
  93. function closeMake () {
  94. document.getElementById('registerSuccess').style.visibility='hidden';
  95. }
  96. //封装 id标签
  97. function getIdHtml (name){
  98. return document.getElementById(name)
  99. }
  100. //封装 class标签
  101. function getClassHtml (name){
  102. return document.getElementsByClassName(name)[0]
  103. }
  104. /**
  105. * [showMsg 提示各种错误信息,3s后消失]
  106. */
  107. function showMsg(msg) {
  108. var msgBox = document.getElementsByClassName('alert-info')[0];
  109. msgBox.getElementsByTagName("p")[0].innerHTML=msg;
  110. msgBox.style.display="block";
  111. setTimeout(function() {
  112. msgBox.style.display="none";
  113. }, 1000);
  114. }
  115. //获取地址栏参数
  116. function getURLCode () {
  117. var search = location.search.length > 0 ? location.search.substring(1) : '',
  118. args = {},
  119. items = search.length ? search.split('&') : [],
  120. item = null,
  121. name = null,
  122. value = null,
  123. i = 0,
  124. len = items.length,
  125. data = '';
  126. for (i = 0; i < len; i++) {
  127. item = items[i].split('=');
  128. name = decodeURIComponent(item[0]);
  129. value = decodeURIComponent(item[1]);
  130. if (item.length) {args[name] = value }
  131. }
  132. return args;
  133. }
  134. //埋点
  135. function writeLogH5 (data) {
  136. axios.post('/api/v2/channel/writeLogH5', data,{
  137. headers:{
  138. source:6000
  139. }
  140. })
  141. .then(function (response) {
  142. })
  143. .catch(function (error) {
  144. });
  145. }