index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import {
  2. imgServerUrl
  3. } from '../../config/config.js'
  4. import $wuxCountDown from '../../utils/coutdown.js'
  5. import {
  6. sendPhoneCode
  7. } from '../../services/index.js'
  8. import {
  9. saveMinaPhone
  10. } from '../../services/wx.js'
  11. import {
  12. showToast
  13. } from '../../utils/tips.js'
  14. Page({
  15. /**
  16. * 页面的初始数据
  17. */
  18. data: {
  19. imgServerUrl: imgServerUrl,
  20. iphone: '',
  21. yzm: "",
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function(options) {
  27. },
  28. // 手机号输入
  29. bindPhoneInput(e) {
  30. this.setData({
  31. iphone: e.detail.value
  32. })
  33. },
  34. // 验证码号输入
  35. bindYzmInput(e) {
  36. this.setData({
  37. yzm: e.detail.value
  38. })
  39. },
  40. // 验证码发送
  41. sendCode(e) {
  42. if (this.data.iphone.length != 11) {
  43. showToast('请输入11位手机号码!')
  44. return
  45. }
  46. if (this.data.djs && this.data.djs != '获取验证码') {
  47. return false;
  48. }
  49. sendPhoneCode({
  50. phone: this.data.iphone
  51. }).then(data => {
  52. })
  53. this.vcode()
  54. },
  55. //倒计时
  56. vcode() {
  57. if (this.djs && this.djs.interval) return !1
  58. this.djs = new $wuxCountDown({
  59. date: +(new Date) + 60000,
  60. onEnd() {
  61. this.setData({
  62. djs: '获取验证码',
  63. })
  64. },
  65. render(date) {
  66. const sec = this.leadingZeros(date.sec, 2) + ' 秒 '
  67. date.sec !== 0 && this.setData({
  68. djs: '剩余' + sec + '',
  69. })
  70. },
  71. })
  72. },
  73. //绑定手机号
  74. phone_login() {
  75. if (this.data.iphone.length != 11) {
  76. return false;
  77. }
  78. if (this.data.yzm.length != 6) {
  79. return false;
  80. }
  81. var openId = wx.getStorageSync('openId');
  82. var sessionKey = wx.getStorageSync('sessionKey');
  83. var unionId = wx.getStorageSync('unionId');
  84. let paramsObj = {
  85. phone: this.data.iphone,
  86. code: this.data.yzm,
  87. openId: openId,
  88. unionId: unionId,
  89. sessionKey: sessionKey
  90. }
  91. Object.assign(paramsObj);
  92. saveMinaPhone(paramsObj).then(data => {
  93. console.log("save", data)
  94. wx.setStorageSync("hpuser", data.data.hpUser);
  95. wx.setStorageSync("hpMember", data.data.hpMember);
  96. wx.setStorageSync("user_id", data.data.hpUser.id);
  97. wx.setStorageSync("member_id", data.data.hpMember.id);
  98. wx.setStorageSync("user_token", data.data.hpUser.userToken);
  99. wx.setStorageSync("phone", data.data.hpUser.phone);
  100. showToast("登录成功");
  101. setTimeout(function() {
  102. wx.navigateBack();
  103. }, 500)
  104. })
  105. },
  106. })