index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. const company = getApp().globalData.company
  2. let Parse = getApp().Parse;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. // 验证手机号
  9. loginPhone: false,
  10. loginPwd: false,
  11. loveChange: true,
  12. hongyzphone: '',
  13. // 验证码是否正确
  14. zhengLove: true,
  15. huoLove: '',
  16. getText2: '获取验证码',
  17. id: null,
  18. },
  19. // 手机验证
  20. lovePhone: function(e) {
  21. let phone = e.detail.value;
  22. this.setData({ hongyzphone: phone })
  23. if (!(/^1[34578]\d{9}$/.test(phone))) {
  24. this.setData({
  25. lovePhone: false
  26. })
  27. console.log(phone.length)
  28. if (phone.length >= 11) {
  29. wx.showToast({
  30. title: '手机号有误',
  31. icon: 'none',
  32. duration: 1000
  33. })
  34. }
  35. } else {
  36. this.setData({
  37. lovePhone: true
  38. })
  39. }
  40. },
  41. // 验证码输入
  42. yanLoveInput: function(e) {
  43. let that = this;
  44. let yanLove = e.detail.value;
  45. let huoLove = this.data.huoLove;
  46. that.setData({
  47. yanLove: yanLove,
  48. zhengLove: false,
  49. })
  50. if (yanLove.length >= 7) {
  51. if (yanLove == huoLove) {
  52. that.setData({
  53. zhengLove: true,
  54. })
  55. } else {
  56. that.setData({
  57. zhengLove: false,
  58. })
  59. wx.showModal({
  60. content: '输入验证码有误',
  61. showCancel: false,
  62. success: function(res) {}
  63. })
  64. }
  65. }
  66. },
  67. // 验证码按钮
  68. yanLoveBtn: function() {
  69. let loveChange = this.data.loveChange;
  70. console.log(loveChange)
  71. let lovePhone = this.data.lovePhone;
  72. console.log(lovePhone)
  73. let phone = this.data.hongyzphone;
  74. console.log(phone)
  75. let n = 59;
  76. let that = this;
  77. if (!lovePhone) {
  78. wx.showToast({
  79. title: '手机号有误',
  80. icon: 'success',
  81. duration: 1000
  82. })
  83. } else {
  84. if (loveChange) {
  85. this.setData({
  86. loveChange: false
  87. })
  88. let lovetime = setInterval(function() {
  89. let str = '(' + n + ')' + '重新获取'
  90. that.setData({
  91. getText2: str
  92. })
  93. if (n <= 0) {
  94. that.setData({
  95. loveChange: true,
  96. getText2: '重新获取'
  97. })
  98. clearInterval(lovetime);
  99. }
  100. n--;
  101. }, 1000);
  102. console.log(phone)
  103. wx.request({
  104. url: "https://server.fmode.cn/api/apig/message",
  105. method: "post", //请求方式
  106. data: { mobile: phone, company: company, },
  107. success(res) {
  108. console.log(res)
  109. }
  110. })
  111. }
  112. }
  113. },
  114. //form表单提交
  115. formSubmit(e) {
  116. let that = this
  117. let val = e.detail.value
  118. // console.log('val', val)
  119. var phone = val.phone //电话
  120. var phoneCode = val.phoneCode //验证码
  121. var openid = wx.getStorageSync('userInfo').openid
  122. console.log(openid)
  123. wx.request({
  124. url: 'https://server.fmode.cn/api/apig/verifyCode',
  125. method: "post", //请求方式
  126. data: { mobile: phone, code: phoneCode, openid: openid },
  127. success() {
  128. that.getuser(phone)
  129. }
  130. })
  131. },
  132. async getuser(phone) {
  133. let query = new Parse.Query("ShopStore")
  134. let ShopStore = await query.get(this.data.id)
  135. ShopStore.set("mobile", phone)
  136. ShopStore.save().then(res => {
  137. console.log(res)
  138. wx.showToast({
  139. title: '绑定成功',
  140. icon: 'none'
  141. })
  142. wx.navigateBack({
  143. delta: 1
  144. });
  145. })
  146. },
  147. /**
  148. * 生命周期函数--监听页面加载
  149. */
  150. onLoad: function(options) {
  151. console.log(options.id);
  152. let id = options.id
  153. this.setData({ id: id })
  154. },
  155. /**
  156. * 生命周期函数--监听页面初次渲染完成
  157. */
  158. onReady: function() {
  159. },
  160. /**
  161. * 生命周期函数--监听页面显示
  162. */
  163. onShow: function() {
  164. },
  165. /**
  166. * 生命周期函数--监听页面隐藏
  167. */
  168. onHide: function() {
  169. },
  170. /**
  171. * 生命周期函数--监听页面卸载
  172. */
  173. onUnload: function() {
  174. },
  175. /**
  176. * 页面相关事件处理函数--监听用户下拉动作
  177. */
  178. onPullDownRefresh: function() {
  179. },
  180. /**
  181. * 页面上拉触底事件的处理函数
  182. */
  183. onReachBottom: function() {
  184. },
  185. /**
  186. * 用户点击右上角分享
  187. */
  188. onShareAppMessage: function() {
  189. }
  190. })