index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. const md5 = require("../../../../utils/md5");
  2. const _Http = getApp().globalData.http;
  3. import Toast from '@vant/weapp/toast/toast';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. from: {
  10. password: "", //原密码
  11. newPassword: "", //新密码
  12. verifyNewPassword: "" //确认密码
  13. },
  14. disabled: true,
  15. loading: false,
  16. confirmPassword: "",
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad(options) {
  22. },
  23. /* 修改密码 */
  24. changePassword() {
  25. if (this.data.disabled || this.data.loading) return;
  26. if (this.data.confirmPassword != true) return Toast({
  27. message: '请检查新密码与确认密码',
  28. position: 'bottom'
  29. });
  30. let from = this.data.from;
  31. this.setData({
  32. loading: true
  33. })
  34. _Http.basic({
  35. "classname": "common.usercenter.usercenter",
  36. "method": "changePassWord",
  37. "content": {
  38. "password": md5.hexMD5(from.password),
  39. "newpassword": md5.hexMD5(from.newPassword)
  40. }
  41. }).then(res => {
  42. console.log(res)
  43. this.setData({
  44. loading: false
  45. })
  46. if (res.msg != '成功') return wx.showToast({
  47. title: res.msg,
  48. icon: "none"
  49. })
  50. /* Toast({
  51. message: res.msg,
  52. position: 'bottom'
  53. }); */
  54. this.setData({
  55. disabled: true
  56. })
  57. wx.showToast({
  58. title: '修改成功!',
  59. })
  60. setTimeout(() => {
  61. wx.navigateBack({
  62. delta: 0
  63. })
  64. }, 300)
  65. })
  66. },
  67. /* 表单输入 */
  68. formInput(e) {
  69. let v = e.detail.value.trim(),
  70. name = e.currentTarget.dataset.name;
  71. this.setData({
  72. [`from.${name}`]: v
  73. });
  74. let disabled = false,
  75. from = this.data.from;
  76. for (let i in from) {
  77. if (from[i] == '') disabled = true;
  78. }
  79. this.setData({
  80. disabled
  81. })
  82. },
  83. /* 验证确认密码 */
  84. passwordBlur() {
  85. let {
  86. from
  87. } = this.data,
  88. confirmPassword = from.newPassword == from.verifyNewPassword;
  89. if (from.newPassword == '' || from.verifyNewPassword == '') confirmPassword = ""
  90. this.setData({
  91. confirmPassword
  92. })
  93. },
  94. /* 清除确认密码 */
  95. clearNewPassword() {
  96. this.setData({
  97. ['from.verifyNewPassword']: '',
  98. confirmPassword: ""
  99. })
  100. },
  101. })