logs.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { get,post } from "../../common/request.js"
  2. import pathmap from "../../common/pathmap"
  3. var app = getApp();
  4. export const logs = {
  5. openLog:function(){
  6. this.setData({openlog:true});
  7. },
  8. closeLog:function(){
  9. this.setData({openlog:false});
  10. if(typeof this.closeLogBack=="function"){
  11. this.closeLogBack();
  12. }
  13. },
  14. phoneInput:function(e){
  15. var number = e.detail.value;
  16. var newdata = {mobilenumber:number};
  17. if(number.length==11){
  18. if(/^[1][3|4|5|6|7|8|9][0-9]{9}$/.test(number)){
  19. if(this.data.codebtword=="获取验证码"){
  20. //this.setData({,codeenable:true})
  21. newdata.codeenable = true
  22. }
  23. }else{
  24. wx.showToast({
  25. title:"输入手机号不合法!",
  26. duration:1000,
  27. icon:"none"
  28. })
  29. }
  30. }
  31. this.setData(newdata)
  32. },
  33. codeInput:function(e){
  34. var code = e.detail.value;
  35. this.setData({logcode:code});
  36. },
  37. getCode:function(){
  38. var _self = this;
  39. if(this.data.codeenable){
  40. get(pathmap.yzm,{mobile:this.data.mobilenumber},function(json){
  41. if(json.data.code=="验证码已发送"){
  42. wx.showToast({
  43. title:"验证码已发送!"
  44. })
  45. _self.startTimeing();
  46. }else{
  47. wx.showToast({
  48. title:json.data.message,
  49. icon:"none"
  50. })
  51. }
  52. })
  53. //_self.startTimeing();
  54. }
  55. },
  56. startTimeing:function(){
  57. var length = 60;
  58. var _self = this;
  59. this.timeingtool = setInterval(function(){
  60. length--;
  61. if(length>=0){
  62. _self.setData({codebtword:length+"s"});
  63. }else{
  64. _self.endTimeing();
  65. }
  66. },1000)
  67. this.setData({codeenable:false,logenable:true});
  68. },
  69. endTimeing:function(){
  70. try{
  71. clearTimeout(this.timeingtool);
  72. }catch(e){}
  73. if(/^[1][3|4|5|6|7|8|9][0-9]{9}$/.test(this.data.mobilenumber)){
  74. this.setData({codeenable:true,codebtword:"获取验证码"})
  75. }else{
  76. this.setData({codeenable:false,codebtword:"获取验证码"})
  77. }
  78. },
  79. logIn:function(){
  80. var _self = this;
  81. if(this.data.logenable){
  82. wx.request({
  83. url: app.globalData.serverpath+pathmap.login,
  84. method: "POST",
  85. header:{
  86. "Content-Type": "application/x-www-form-urlencoded"
  87. },
  88. data:{
  89. mobile:this.data.mobilenumber,
  90. code:this.data.logcode
  91. },
  92. success: function (res){
  93. //app.globalData.Authorization = res.data.authorization;
  94. if(res.data.authorization){
  95. try{
  96. wx.setStorageSync("mobile",_self.data.mobilenumber);
  97. wx.setStorageSync("authorization",res.data.authorization);
  98. }catch(e){
  99. }
  100. _self.setData({openlog:false});
  101. _self.endTimeing();
  102. if(typeof _self.loginback=="function"){
  103. _self.loginback();
  104. }
  105. }else{
  106. wx.showToast({
  107. title:res.data.message,
  108. icon:"none"
  109. })
  110. }
  111. },
  112. fail: function (error){
  113. }
  114. })
  115. }
  116. }
  117. }
  118. const bindLogs = function(pages){
  119. pages.setData({openlog:false,codeenable:false,logenable:false,codebtword:"获取验证码",mobilenumber:""});
  120. //Object.assign(pages,logs);
  121. }
  122. export default bindLogs;