userInfo.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. mui.init();
  2. var flag=mobile.getUrlVars("flag");
  3. /**
  4. *初始化、添加监听
  5. */
  6. mui.ready(function(){
  7. if(flag=="1"){
  8. $("#sex-div").hide();
  9. $("#type-div").hide();
  10. $(".mui-title").html("完善个人信息");
  11. $(".mui-btn-primary").html("我要推广");
  12. $("#sendCode").html(Math.floor(Math.random()*9000)+1000);
  13. }else{
  14. $("#code-div").hide();
  15. }
  16. $("#sendCode").on("tap",function(e){
  17. $("#sendCode").html(Math.floor(Math.random()*9000)+1000);
  18. });
  19. getByOpenid();
  20. $('#save').on('tap',function(){
  21. var id = $('#id').val();
  22. var username = $('#username').val();
  23. var mobilephone = $('#mobile').val();
  24. var nickname = $('#nickname').val();
  25. var sex = $('#sex').val();
  26. var code = $.trim($('#code').val());
  27. var is_share="0";
  28. if(!username){
  29. layer.open({content:'请输入姓名',time:3});
  30. return;
  31. }
  32. if(!mobilephone){
  33. layer.open({content:'请输入手机号码',time:3});
  34. return;
  35. }
  36. if(!mobile.checkMobile(mobilephone)){
  37. layer.open({content:'请输入正确手机号码',time:3});
  38. return;
  39. }
  40. if(flag=="1"){
  41. is_share="1";
  42. if(code!=$("#sendCode").html()){
  43. layer.open({content:'验证码错误',time:3});
  44. return;
  45. }
  46. }
  47. mobile.ajaxPost(base+'/users/save',{
  48. id:id,
  49. username:username,
  50. mobile:mobilephone,
  51. nickname:nickname,
  52. sex:sex,
  53. is_share:is_share
  54. },function(json){
  55. if(json.success){
  56. if(flag=="1"){
  57. layer.open({content:'注册成功,分享给朋友或朋友圈可推广赚钱',time:3});
  58. }else{
  59. layer.open({content:'保存成功',time:3});
  60. }
  61. }
  62. });
  63. });
  64. });
  65. /**
  66. *获取列表
  67. */
  68. function getByOpenid(){
  69. mobile.ajaxPost(base+'/users/getByOpenid',{},function(json){
  70. if(json.data){
  71. mobile.toForm(json.data);
  72. }
  73. });
  74. }