bindPhone.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. const crypto=require("../../../utils/crypto")
  4. Page({
  5. data: {
  6. loginName: '',
  7. code: '',
  8. time: 0,
  9. userInfo: app.globalData.userInfo
  10. },
  11. onShow() {
  12. this.setData({ userInfo: app.globalData.userInfo });
  13. },
  14. sendCode() {
  15. let that = this;
  16. if(that.data.time>0) return false;
  17. if (util.isEmpty(this.data.loginName)) {
  18. util.showTips("请输入手机号码");
  19. return false;
  20. }
  21. if (util.isPhone(this.data.loginName)) {
  22. util.showTips("请输入正确的手机号码");
  23. return false;
  24. }
  25. if (this.data.loginName.length == 11 && this.data.userInfo.loginName == this.data.loginName) {
  26. util.showTips("当前手机号和绑定手机号一致,请勿重复绑定");
  27. return false;
  28. }
  29. let key=crypto.encrypted(this.data.loginName)
  30. util.sendMessage({ phone: this.data.loginName, type: "phone",time:120,key:key }, (res) => {
  31. that.setData({time:res.text})
  32. })
  33. },
  34. submit() {
  35. let that = this;
  36. if (util.isEmpty(this.data.loginName)) {
  37. util.showTips("请输入手机号码");
  38. return false;
  39. }
  40. if (util.isPhone(this.data.loginName)) {
  41. util.showTips("请输入正确的手机号码");
  42. return false;
  43. }
  44. if (util.isEmpty(this.data.code)) {
  45. util.showTips("请输入验证码");
  46. return false;
  47. }
  48. if (this.data.code.length != 6) {
  49. util.showTips("请输入6位验证码");
  50. return false;
  51. }
  52. util.ajax({
  53. func:'v2/user/phone',
  54. data:{ phone: that.data.loginName, vcode: that.data.code }
  55. },function(res){
  56. if (res.code == 0) {
  57. let userInfo = app.globalData.userInfo;
  58. userInfo.loginName = that.data.loginName;
  59. userInfo.phoneNum = that.data.loginName;
  60. app.globalData.userInfo = userInfo;
  61. wx.setStorageSync("WXuserInfo", userInfo)
  62. wx.navigateBack();
  63. } else {
  64. util.showTips(res.reason)
  65. }
  66. })
  67. },
  68. loginNameInput(e){
  69. this.setData({loginName:e.detail.value})
  70. if (e.detail.value.length == 11 && this.data.userInfo.loginName == e.detail.value) {
  71. util.showTips("当前手机号和绑定手机号一致,请勿重复绑定");
  72. }
  73. },
  74. codeInput(e) {
  75. this.setData({ code: e.detail.value })
  76. }
  77. })