applyAuth.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. const app = getApp();
  2. Page({
  3. data: {
  4. canClick:true,
  5. codeBtnTxt:"发送验证码"
  6. },
  7. onLoad: function (options) {
  8. this.getDeptList();
  9. var userInfo = wx.getStorageSync('userInfo')
  10. this.setData({
  11. loginName:userInfo.user.phonenumber
  12. })
  13. },
  14. goReg(){
  15. var that = this
  16. var phoneNumber = that.data.loginName
  17. var phonereg = /^[1][0-9]{10}$/;
  18. if (!phonereg.test(phoneNumber)) {
  19. app.showToptip(that, "worning", "手机号输入有误")
  20. return;
  21. }
  22. var smsCode = that.data.code
  23. if (!smsCode) {
  24. app.showToptip(that, "worning", "验证码输入有误")
  25. return;
  26. }
  27. var parentDeptId = that.data.parentDeptId
  28. if (!parentDeptId) {
  29. app.showToptip(that, "worning", "请选择上级所属单位")
  30. return;
  31. }
  32. return false;//提交功能APP还没开发,故在此屏蔽提交
  33. wx.showLoading({
  34. mask: true
  35. })
  36. app.requestP({
  37. url : "/register",
  38. needToken:false,
  39. contentType:"application/json",
  40. data: JSON.stringify({
  41. phoneNumber,
  42. smsCode,
  43. parentDeptId
  44. })
  45. }).then((res) => {
  46. app.showToptip(that,"success", res.data.msg)
  47. wx.redirectTo({
  48. url: '/pages/login/login?phoneNumber='+phoneNumber+"&password="+password,
  49. })
  50. }).catch((res) => {
  51. app.showToptip(that,"error", res.data.msg)
  52. });
  53. },
  54. setLoginName: function (e) {//手机号输入校验
  55. var loginName = e.detail.value.replace(/[^\d]/g, "").substr(0,11)
  56. //验证手机号
  57. var myreg = /^[1][0-9]{10}$/;
  58. this.setData({
  59. loginName,
  60. canClick : myreg.test(loginName)
  61. })
  62. },
  63. getValidCode:function(e){
  64. //验证手机号
  65. var myreg = /^[1][0-9]{10}$/;
  66. if (!myreg.test(this.data.loginName)) {
  67. app.showToptip(this, "worning", "手机号输入有误")
  68. return;
  69. }
  70. var that=this
  71. wx.showLoading({
  72. title: '发送中...',
  73. mask: true
  74. })
  75. app.requestP({
  76. url: "/mobileGetAuthCode",
  77. needToken:false,
  78. data: {
  79. phoneNumber: that.data.loginName
  80. }
  81. }).then((res) => {
  82. app.showToptip(that, "success","发送成功")
  83. that.data.lastSendTime = Date.now()
  84. that.setData({
  85. canClick: false
  86. })
  87. //定时器触发倒计时,
  88. var times = 60
  89. var i = setInterval(function () {
  90. times--
  91. if (times == 0) {
  92. that.setData({
  93. canClick: true,
  94. codeBtnTxt: "获取验证码",
  95. })
  96. clearInterval(i)
  97. } else {
  98. that.setData({
  99. codeBtnTxt: "重新获取" + times + "s",
  100. })
  101. }
  102. }, 1000)
  103. }).catch(function(r){
  104. app.showToptip(that, "error",r.data.msg)
  105. })
  106. },
  107. setCode:function(e){//验证码输入绑定
  108. this.setData({
  109. code: e.detail.value.replace(/[^\d]/g, "").substr(0,6)
  110. })
  111. },
  112. setDept(e){
  113. var that = this
  114. that.setData({
  115. parentDeptId:that.data.deptList[e.detail.value].deptId,
  116. deptindex:e.detail.value
  117. })
  118. },
  119. getDeptList(){
  120. var that=this
  121. app.requestP({
  122. url: "/deptlist",
  123. method:"get",
  124. needToken:false,
  125. }).then((res) => {
  126. that.setData({
  127. deptList: res.data.data
  128. })
  129. })
  130. }
  131. })