register.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. const app = getApp();
  2. Page({
  3. data: {
  4. canClick:false,
  5. isVivo:false,
  6. codeBtnTxt:"发送验证码"
  7. },
  8. onLoad: function (options) {
  9. // this.getDeptList();
  10. var that = this
  11. //获取手机型号,vivo手机安全键盘bug
  12. wx.getSystemInfo({
  13. success:function(res){
  14. if(res.brand=="vivo"){
  15. that.data.isVivo = true;
  16. }
  17. }
  18. });
  19. },
  20. goReg(){
  21. var that = this
  22. var phoneNumber = that.data.loginName
  23. var phonereg = /^[1][0-9]{10}$/;
  24. if (!phonereg.test(phoneNumber)) {
  25. app.showToptip(that, "worning", "手机号输入有误")
  26. return;
  27. }
  28. var smsCode = that.data.code
  29. if (!smsCode) {
  30. app.showToptip(that, "worning", "验证码输入有误")
  31. return;
  32. }
  33. var password = that.data.password
  34. if (!password) {
  35. app.showToptip(that, "worning", "密码不能为空")
  36. return;
  37. }
  38. var repassword = that.data.password2
  39. if (password != repassword) {
  40. app.showToptip(that, "worning", "两次密码输入不一致")
  41. return;
  42. }
  43. var nickName = that.data.nickName
  44. if (!nickName) {
  45. app.showToptip(that, "worning", "姓名不能为空")
  46. return;
  47. }
  48. var identityId = that.data.cardNo && that.data.cardNo.replace(/\s/g, "")
  49. if (!identityId || [15,18].indexOf(identityId.length)<0) {
  50. app.showToptip(that, "worning", "身份证号输入有误")
  51. return;
  52. }
  53. var workUnit = that.data.workUnit
  54. if (!workUnit) {
  55. app.showToptip(that, "worning", "工作单位不能为空")
  56. return;
  57. }
  58. var parentDeptId = that.data.parentDeptId
  59. if (!parentDeptId) {
  60. app.showToptip(that, "worning", "请选择上级所属单位")
  61. return;
  62. }
  63. wx.showLoading({
  64. mask: true
  65. })
  66. app.requestP({
  67. url : "/register",
  68. needToken:false,
  69. contentType:"application/json",
  70. data: JSON.stringify({
  71. phoneNumber,
  72. smsCode,
  73. password,
  74. repassword,
  75. nickName,
  76. identityId,
  77. workUnit,
  78. parentDeptId
  79. })
  80. }).then((res) => {
  81. app.showToptip(that,"success", res.data.msg)
  82. wx.redirectTo({
  83. url: '/pages/login/login?phoneNumber='+phoneNumber+"&password="+password,
  84. })
  85. }).catch((res) => {
  86. app.showToptip(that,"error", res.data.msg)
  87. });
  88. },
  89. cardNoChange(e) {//借款人身份证验证
  90. var cardNo = e.detail.value.replace(/[^\dXx]/g, "").replace(/([\d]{6})(?=[\dXx])/g, '$1 ')
  91. this.setData({
  92. cardNo: cardNo.substr(0, 22)
  93. })
  94. },
  95. setWorkUnit: function (e) {
  96. if (e.detail.cursor == this.data.workUnitcursor) return
  97. var workUnit = e.detail.value
  98. this.setData({
  99. workUnitcursor: e.detail.cursor,
  100. workUnit: workUnit
  101. })
  102. } ,
  103. setNickName: function (e) {
  104. if (e.detail.cursor == this.data.nickNamecursor) return
  105. var nickName = e.detail.value.replace(/[^\u4e00-\u9fa5\da-zA-Z]/g, "");
  106. if (nickName.length >= 25) {
  107. nickName = nickName.substring(0, 25)
  108. }
  109. this.setData({
  110. nickNamecursor: e.detail.cursor,
  111. nickName: nickName
  112. })
  113. } ,
  114. setLoginName: function (e) {//手机号输入校验
  115. var loginName = e.detail.value.replace(/[^\d]/g, "").substr(0,11)
  116. //验证手机号
  117. var myreg = /^[1][0-9]{10}$/;
  118. this.setData({
  119. loginName,
  120. canClick : myreg.test(loginName)
  121. })
  122. },
  123. setPwd: function (e) {//密码输入绑定
  124. var password = e.detail.value
  125. this.setData({
  126. password: password
  127. })
  128. if(this.data.isVivo){//vivo密码键盘bug,超过1秒没输入收起键盘
  129. if(this.timer)clearTimeout(this.timer)
  130. this.timer = setTimeout(function(){
  131. wx.hideKeyboard();
  132. },1000)
  133. }
  134. },
  135. setPwd2: function (e) {//密码输入绑定
  136. var password2 = e.detail.value
  137. this.setData({
  138. password2: password2
  139. })
  140. if(this.data.isVivo){//vivo密码键盘bug,超过1秒没输入收起键盘
  141. if(this.timer)clearTimeout(this.timer)
  142. this.timer = setTimeout(function(){
  143. wx.hideKeyboard();
  144. },1000)
  145. }
  146. },
  147. getValidCode:function(e){
  148. //验证手机号
  149. var myreg = /^[1][0-9]{10}$/;
  150. if (!myreg.test(this.data.loginName)) {
  151. app.showToptip(this, "worning", "手机号输入有误")
  152. return;
  153. }
  154. var that=this
  155. wx.showLoading({
  156. title: '发送中...',
  157. mask: true
  158. })
  159. app.requestP({
  160. url: "/mobileGetAuthCode",
  161. needToken:false,
  162. data: {
  163. phoneNumber: that.data.loginName
  164. }
  165. }).then((res) => {
  166. app.showToptip(that, "success","发送成功")
  167. that.data.lastSendTime = Date.now()
  168. that.setData({
  169. canClick: false
  170. })
  171. //定时器触发倒计时,
  172. var times = 60
  173. var i = setInterval(function () {
  174. times--
  175. if (times == 0) {
  176. that.setData({
  177. canClick: true,
  178. codeBtnTxt: "获取验证码",
  179. })
  180. clearInterval(i)
  181. } else {
  182. that.setData({
  183. codeBtnTxt: "重新获取" + times + "s",
  184. })
  185. }
  186. }, 1000)
  187. }).catch(function(r){
  188. app.showToptip(that, "error",r.data.msg)
  189. })
  190. },
  191. setCode:function(e){//验证码输入绑定
  192. this.setData({
  193. code: e.detail.value.replace(/[^\d]/g, "").substr(0,6)
  194. })
  195. },
  196. setDept(e){
  197. var that = this
  198. that.setData({
  199. parentDeptId:that.data.deptList[e.detail.value].deptId,
  200. deptindex:e.detail.value
  201. })
  202. },
  203. getDeptList(){
  204. var that=this
  205. app.requestP({
  206. url: "/deptlist",
  207. method:"get",
  208. needToken:false,
  209. }).then((res) => {
  210. that.setData({
  211. deptList: res.data.data
  212. })
  213. })
  214. }
  215. })