index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // pages/password/index.js
  2. let myPro = require("../../../utils/wxRequest.js");
  3. let util = require("../../../utils/util.js");
  4. var app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. oldPW:'',
  11. newPW:'',
  12. againPW:''
  13. },
  14. oldPWInput(e) {
  15. this.setData({
  16. oldPW: e.detail.value
  17. })
  18. },
  19. newPWInput(e) {
  20. this.setData({
  21. newPW: e.detail.value
  22. })
  23. },
  24. againPWInput(e) {
  25. this.setData({
  26. againPW: e.detail.value
  27. })
  28. },
  29. changePassword() {
  30. if (this.data.oldPW == null || this.data.oldPW == undefined || this.data.oldPW == ''){
  31. Toast('请输入原密码')
  32. return
  33. }
  34. if (this.data.newPW == null || this.data.newPW == undefined || this.data.newPW == ''){
  35. Toast('请输入新密码')
  36. return
  37. }
  38. if (this.data.againPW == null || this.data.againPW == undefined || this.data.againPW == '') {
  39. Toast('请再次输入新密码')
  40. return
  41. }
  42. if (this.data.newPW == this.data.oldPW) {
  43. Toast('原密码和新密码相同,请检查')
  44. return
  45. }
  46. if (this.data.newPW != this.data.againPW) {
  47. Toast('两次输入的密码不一致,请检查')
  48. return
  49. }
  50. wx.showLoading({
  51. mask:true
  52. })
  53. var that = this;
  54. var params = {
  55. token: app.globalData.token,
  56. old_pwd:this.data.oldPW,
  57. new_pwd:this.data.newPW
  58. }
  59. myPro.wxRequest("staff/login","POST",params).then(res=>{
  60. wx.hideLoading()
  61. var res = res.data;
  62. if (res.code == 200) {
  63. Toast('修改密码成功,请重新登录');
  64. setTimeout(function() {
  65. wx.reLaunch({
  66. url: '/pages/login/index'
  67. })
  68. }, 1000);
  69. } else {
  70. if (res.code == 401) {
  71. Toast('登录失效');
  72. setTimeout(function() {
  73. wx.reLaunch({
  74. url: '/pages/login/index'
  75. })
  76. }, 1000);
  77. } else {
  78. Toast(res.msg)
  79. }
  80. }
  81. }).catch(err => {
  82. wx.hideLoading()
  83. console.log(err)
  84. })
  85. },
  86. /**
  87. * 生命周期函数--监听页面加载
  88. */
  89. onLoad: function (options) {
  90. },
  91. /**
  92. * 生命周期函数--监听页面初次渲染完成
  93. */
  94. onReady: function () {
  95. },
  96. /**
  97. * 生命周期函数--监听页面显示
  98. */
  99. onShow: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面隐藏
  103. */
  104. onHide: function () {
  105. },
  106. /**
  107. * 生命周期函数--监听页面卸载
  108. */
  109. onUnload: function () {
  110. },
  111. /**
  112. * 页面相关事件处理函数--监听用户下拉动作
  113. */
  114. onPullDownRefresh: function () {
  115. },
  116. /**
  117. * 页面上拉触底事件的处理函数
  118. */
  119. onReachBottom: function () {
  120. },
  121. /**
  122. * 用户点击右上角分享
  123. */
  124. onShareAppMessage: function () {
  125. }
  126. })