add-step2.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. var d = dialog({contentType:'load', skin:'bk-popup'});
  2. var dd = dialog({contentType:'load', skin:'bk-popup', content:'提交中...'});
  3. var num = 60, // 默认发送验证码时间
  4. timer; // 计时器
  5. var scroller1 = new IScrollPullUpDown('wrapper',{
  6. probeType:2,
  7. bounceTime: 250,
  8. bounceEasing: 'quadratic',
  9. mouseWheel:false,
  10. scrollbars:true,
  11. click:true,
  12. fadeScrollbars:true,
  13. interactiveScrollbars:false
  14. }, null, null);
  15. $(function(){
  16. // 判断是否登录
  17. checkUserAgent();
  18. var code = window.localStorage.getItem("familyCode");
  19. var name = window.localStorage.getItem("familyName");
  20. var mobile = window.localStorage.getItem("familyMobile");
  21. var imgUrl = window.localStorage.getItem("familyImgUrl");
  22. var relation = window.localStorage.getItem("familyRelation");
  23. var temp = name + ' <span>(' + mobile + ')</span>';
  24. // 头像为空设置默认头像
  25. if(imgUrl == undefined || imgUrl == null || imgUrl == ""){
  26. imgUrl = "../../../images/p-default.png";
  27. }
  28. $("#people").html(temp);
  29. $("#imgUrl").attr("src", getImgUrl(imgUrl));
  30. // 验证码
  31. $("#sendCode").bind("tap", function () {
  32. // 发送验证码
  33. var data = {};
  34. data.mobile = mobile;
  35. data.type = 10;
  36. data.status = 200;
  37. dd.show();
  38. sendPost("common/captcha", data, "json", "post", sendCodeFailed, sendCodeSuccesss);
  39. });
  40. // 确认提交
  41. $("#submit").bind("tap", function () {
  42. var captcha = $("#captcha").val();
  43. if (captcha.trim() == "") {
  44. dialog({contentType:'tipsbox', skin:'bk-popup' , content:'验证码不能为空'}).show();
  45. return false;
  46. }
  47. dd.show();
  48. var data = {};
  49. data.member = code;
  50. data.captcha = captcha;
  51. data.relation = relation;
  52. sendPost("patient/family/member_add", data, "json", "post", addFailed, addSuccesss);
  53. });
  54. });
  55. // 禁止拖动
  56. document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
  57. // 添加成功
  58. function addSuccesss (res) {
  59. if (res.status == 200) {
  60. dd.close();
  61. var d3 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  62. setTimeout(function () {
  63. window.location.href = "family.html";
  64. }, 1000);
  65. } else {
  66. //非200则为失败
  67. addFailed(res);
  68. }
  69. }
  70. // 添加失败
  71. function addFailed (res) {
  72. dd.close();
  73. if (res && res.msg) {
  74. var d1 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  75. } else {
  76. var d2 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show();
  77. }
  78. }
  79. // 验证码计时器
  80. function doLoop(){
  81. num--;
  82. if(num > 0){
  83. $("#message").html(num + '秒后可重新获取');
  84. }else{
  85. clearInterval(timer); //清除js定时器
  86. $("#code1").show();
  87. $("#code2").hide();
  88. num = 60; //重置时间
  89. }
  90. }
  91. // 发送验证码成功
  92. function sendCodeSuccesss (res) {
  93. if (res.status == 200) {
  94. dd.close();
  95. var d3 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  96. // 清除计时器
  97. $("#code1").hide();
  98. $("#message").html(num + '秒后可重新获取');
  99. $("#code2").show();
  100. timer = setInterval(doLoop, 1000); //一秒执行一次
  101. } else {
  102. //非200则为失败
  103. sendCodeFailed(res);
  104. }
  105. }
  106. // 发送验证码失败
  107. function sendCodeFailed (res) {
  108. dd.close();
  109. if (res && res.msg) {
  110. var d1 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
  111. } else {
  112. var d2 = dialog({contentType:'tipsbox', skin:'bk-popup' , content:'加载失败'}).show();
  113. }
  114. }