changePhone.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. var businessT = require('../../../../../tool/business-tool.js')
  2. var sysT = require('../../../../../tool/sys-tool.js')
  3. var url = require('../../../../../constant/url.js')
  4. import Net from '../../../../../tool/net.js'
  5. var net = new Net()
  6. var app = getApp()
  7. Page({
  8. data: {
  9. time:60
  10. },
  11. inputAction(e){
  12. if(e.currentTarget.dataset.type=='phone'){
  13. this.setData({
  14. newPhone:e.detail.value
  15. })
  16. }else{
  17. this.setData({
  18. code:e.detail.value
  19. })
  20. }
  21. if(this.data.newPhone&&this.data.code){
  22. this.setData({
  23. canSave:true
  24. })
  25. }else{
  26. this.setData({
  27. canSave:false
  28. })
  29. }
  30. },
  31. getCode() {
  32. if(!this.data.newPhone||this.data.newPhone.length!=11){
  33. swan.showToast({
  34. title: '请输入正确的手机号',
  35. icon: 'none',
  36. mask: true
  37. });
  38. }else {
  39. net.connect({
  40. url: url.app_host + url.getVerifyCode,
  41. data: { phone: this.data.newPhone },
  42. method: "POST",
  43. })
  44. var time = 60
  45. this.setData({ countDown: true })
  46. var timer1 = setInterval(() => {
  47. time -= 1
  48. this.setData({ time: time })
  49. }, 1000)
  50. var timer2 = setTimeout(() => {
  51. this.setData({ countDown: false, time: '60' })
  52. clearInterval(timer1)
  53. clearTimeout(timer2)
  54. }, 60000)
  55. }
  56. },
  57. btnAction(){
  58. if(this.data.newPhone.length!=11){
  59. swan.showToast({
  60. title: '请输入正确的手机号',
  61. icon: 'none',
  62. mask: true
  63. });
  64. }else{
  65. net.connectNeedLogin({
  66. url:url.app_host+url.changePhone,
  67. data:{phone:this.data.newPhone,verify_code:this.data.code},
  68. success:(err,res)=>{
  69. app.globalData.userInfo.phone=this.data.newPhone
  70. swan.hideLoading();
  71. swan.showToast({
  72. title: '修改成功',
  73. icon: 'none',
  74. mask: true
  75. });
  76. swan.navigateBack()
  77. },
  78. fail:(err,res)=>{
  79. swan.hideLoading();
  80. businessT.showFailTips(err)
  81. }
  82. },true)
  83. }
  84. },
  85. onLoad: function () {
  86. // 监听页面加载的生命周期函数
  87. },
  88. onReady: function() {
  89. // 监听页面初次渲染完成的生命周期函数
  90. },
  91. onShow: function() {
  92. // 监听页面显示的生命周期函数
  93. },
  94. onHide: function() {
  95. // 监听页面隐藏的生命周期函数
  96. },
  97. onUnload: function() {
  98. // 监听页面卸载的生命周期函数
  99. },
  100. onPullDownRefresh: function() {
  101. // 监听用户下拉动作
  102. },
  103. onReachBottom: function() {
  104. // 页面上拉触底事件的处理函数
  105. },
  106. onShareAppMessage: function () {
  107. // 用户点击右上角转发
  108. }
  109. });