updatePassword.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // component/updatePassword/updatePassword.ts
  2. import { httpUtil } from "../../utils/restful";
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. },
  9. /**
  10. * 组件的初始数据
  11. */
  12. data: {
  13. width: 671,
  14. height: 713,
  15. initScale: 0,
  16. showAccPwd: true,
  17. scaleAnim: 0,
  18. inputPhoneNum: '',
  19. inputVCode: '',
  20. inputPwd: '',
  21. hasGetVCode: false,
  22. getVCodeText: "获取验证码",
  23. getvcodeInter: -5
  24. },
  25. lifetimes: {
  26. attached: function () {
  27. // 在组件实例被从页面节点树添加时执行
  28. //放大小动画()
  29. this.data.scaleAnim = setInterval(() => {
  30. if (this.data.initScale < 0.9) {
  31. this.setData({
  32. initScale: this.data.initScale + 0.1
  33. })
  34. } else {
  35. clearInterval(this.data.scaleAnim)
  36. }
  37. }, 15);
  38. },
  39. detached: function () {
  40. // 在组件实例被从页面节点树移除时执行
  41. },
  42. },
  43. /**
  44. * 组件的方法列表
  45. */
  46. methods: {
  47. //账号密码登录——---------------------------
  48. showAccountPwd: function (event: any) {
  49. if (this.data.showAccPwd) {
  50. this.setData({
  51. showAccPwd: false
  52. })
  53. } else {
  54. this.setData({
  55. showAccPwd: true
  56. })
  57. }
  58. },
  59. hideSelf: function () {
  60. //调用父组件方法移除自身
  61. this.triggerEvent('showUpdatePwdLayout');
  62. },
  63. bindPwdLoginPhoneInput: function (event: any) {
  64. this.setData({
  65. inputPhoneNum: event.detail.value
  66. })
  67. },
  68. bindVCodeInput: function (event: any) {
  69. this.setData({
  70. inputVCode: event.detail.value
  71. })
  72. },
  73. bindPassWordInput: function (event: any) {
  74. this.setData({
  75. inputPwd: event.detail.value
  76. })
  77. },
  78. // 获取验证码
  79. clickGetVCode: function (event: any) {
  80. if (this.data.hasGetVCode) {
  81. this.showToast("请勿频繁点击")
  82. return;
  83. }
  84. if (!this.data.inputPhoneNum) {
  85. this.showToast("请输入手机号")
  86. return;
  87. }
  88. let that = this;
  89. let time = 60;
  90. this.data.getvcodeInter = setInterval(function () {
  91. if (time <= 1) {
  92. clearInterval(that.data.getvcodeInter)
  93. that.setData({
  94. hasGetVCode: false,
  95. getVCodeText: '获取验证码',
  96. getvcodeInter: -5
  97. })
  98. return;
  99. }
  100. time--;
  101. that.setData({
  102. getVCodeText: time.toString(),
  103. hasGetVCode: true
  104. })
  105. }, 1000)
  106. let params = {
  107. mobileNo: this.data.inputPhoneNum
  108. }
  109. httpUtil.wxGet(httpUtil.interfaces.getVerifyCode, params).then((res) => {
  110. console.log("获取验证码成功:", res)
  111. }).catch((res) => {
  112. console.log("获取验证码失败:", res)
  113. })
  114. },
  115. submitInfo: function () {
  116. if (!this.data.inputPhoneNum) {
  117. this.showToast("请输入手机号")
  118. return;
  119. }
  120. if (!this.data.inputVCode) {
  121. this.showToast("请输入验证码")
  122. return;
  123. }
  124. let params = {
  125. mobile: this.data.inputPhoneNum,
  126. password: this.data.inputPwd,
  127. verifyCode: this.data.inputVCode
  128. }
  129. let that = this;
  130. httpUtil.wxPost(httpUtil.interfaces.updatePassWord, params).then((res) => {
  131. console.log("修改密码成功:", res)
  132. that.hideSelf()
  133. }).catch((res) => {
  134. console.log("修改密码失败:", res)
  135. that.showToast(res.data.message)
  136. })
  137. },
  138. showToast: function (message: string) {
  139. wx.showToast({
  140. title: message,
  141. icon: 'none'
  142. })
  143. }
  144. }
  145. })