大数据平台的小程序版本

index.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. const app = getApp()
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. title:{
  8. type:String,
  9. value:'绑定手机号'
  10. }
  11. },
  12. /**
  13. * 组件的初始数据
  14. */
  15. data: {
  16. phone:'',
  17. yzm:'',
  18. minute:60,
  19. timeMsg:'获取验证码',
  20. timer:1,
  21. },
  22. /**
  23. * 组件的方法列表
  24. */
  25. methods: {
  26. closeHint(){
  27. this.triggerEvent("closeHint")
  28. },
  29. bindPhoneEvent(){//绑定手机号,点击确定
  30. if(!(/^1[3456789]\d{9}$/.test(this.data.phone))){
  31. wx.showToast({
  32. title: '请输入正确的手机号',
  33. icon: 'none',
  34. duration: 2000
  35. })
  36. return;
  37. }
  38. if(this.data.yzm == ''){
  39. wx.showToast({
  40. title: '请输入验证码',
  41. icon: 'none',
  42. duration: 2000
  43. })
  44. return
  45. }
  46. wx.showLoading({ title: '加载中', })
  47. app.func.req(app.func.api.bind_phone, 'post', {
  48. code:this.data.yzm,
  49. phone:this.data.phone,
  50. }, (res) => {
  51. wx.hideLoading()
  52. if(res && res.errno == 0){
  53. wx.showToast({
  54. title: '绑定成功',
  55. icon: 'success',
  56. duration: 2000
  57. })
  58. wx.setStorageSync('phone', this.data.phone)
  59. this.triggerEvent("bindPhoneEvent")
  60. }else{
  61. wx.showToast({
  62. title: res.err,
  63. icon: 'none',
  64. duration: 2000
  65. })
  66. }
  67. },()=>{
  68. wx.hideLoading()
  69. })
  70. },
  71. bindPhone: function(e){//绑定手机号
  72. this.setData({
  73. phone: e.detail.value
  74. })
  75. },
  76. bindYzm: function(e){//验证码
  77. this.setData({
  78. yzm: e.detail.value
  79. })
  80. },
  81. getYzmButton(){//获取验证码
  82. if(this.data.timeMsg!='获取验证码'){
  83. return
  84. }
  85. if(!(/^1[3456789]\d{9}$/.test(this.data.phone))){
  86. wx.showToast({
  87. title: '请输入正确的手机号',
  88. icon: 'none',
  89. duration: 2000
  90. })
  91. return;
  92. }
  93. if(this.data.title == '换绑手机号' && (this.data.phone == wx.getStorageSync('phone'))){
  94. wx.showToast({
  95. title: '不可重复绑定同一手机号',
  96. icon: 'none',
  97. duration: 2000
  98. })
  99. return
  100. }
  101. wx.showLoading({ title: '加载中', })
  102. app.func.req(app.func.api.verification_code, 'get', {
  103. type:'bind',
  104. phone:this.data.phone,
  105. }, (res) => {
  106. wx.hideLoading()
  107. if(res && res.errno == 0){
  108. this.CountDown()
  109. }else{
  110. wx.showToast({
  111. title: res.err,
  112. icon: 'none',
  113. duration: 2000
  114. })
  115. }
  116. },()=>{
  117. wx.hideLoading()
  118. })
  119. },
  120. CountDown() {//倒计时
  121. var maxtime = this.data.minute
  122. this.setData({timeMsg:'获取验证码'})
  123. var timer = setInterval(()=>{
  124. if (maxtime >= 0) {
  125. this.setData({timeMsg: maxtime + "s"});
  126. --maxtime;
  127. } else{
  128. this.setData({timeMsg:'获取验证码'})
  129. clearInterval(this.data.timer);
  130. }
  131. },1000)
  132. this.setData({timer:timer})
  133. },
  134. }
  135. })