setPassword.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <!-- myPages/pages/setPassword/setPassword.wxml -->
  3. <view class="container">
  4. <view class="set-container">
  5. <form @submit="bindSubmit">
  6. <view class="form-container">
  7. <view class="form-item">
  8. <image src="/static/resource/images/shouji.png" class="form-img"></image>
  9. <input type="text" name="username" :placeholder="$t('请输入手机号')" class="form-input" :value="username" @input="bindUsernameInput" />
  10. <!-- image wx:if="{{ username }}" src="/resource/images/x.png" class="form-img-right" bindtap="bindUsernameClear"></image -->
  11. </view>
  12. <view class="form-item code-form">
  13. <image src="/static/resource/images/duanxin.png" class="form-img"></image>
  14. <input type="text" name="code" :placeholder="$t('请输入验证码')" class="form-input" />
  15. <view class="code-button" @tap="bindSendCode">
  16. <text class="code-text">{{ sec == 0 ? $t('获取验证码') : sec + $t('s后重发') }}</text>
  17. </view>
  18. <!-- image wx:if="{{ username }}" src="/resource/images/x.png" class="form-img-right" bindtap="bindUsernameClear"></image -->
  19. </view>
  20. <view class="form-item">
  21. <image src="/static/resource/images/mima.png" class="form-img"></image>
  22. <input type="text" password name="password" :placeholder="$t('请输入密码')" class="form-input" />
  23. <!-- image wx:if="{{ password }}" src="/resource/images/x.png" class="form-img-right" bindtap="bindPasswordClear"></image -->
  24. </view>
  25. <view class="form-item">
  26. <image src="/static/resource/images/mima.png" class="form-img"></image>
  27. <input type="text" password name="password2" :placeholder="$t('请确认密码')" class="form-input" />
  28. <!-- image wx:if="{{ password }}" src="/resource/images/x.png" class="form-img-right" bindtap="bindPasswordClear"></image -->
  29. </view>
  30. <view class="form-btn">
  31. <button class="login-btn" form-type="submit">{{$t('确定')}}</button>
  32. </view>
  33. </view>
  34. </form>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. // myPages/pages/setPassword/setPassword.js
  40. var config = require('../../../common/config.js');
  41. var http = require('../../../common/http.js');
  42. var common = require('../../../common/common.js');
  43. var storage = require('../../../common/storage.js');
  44. export default {
  45. data() {
  46. return {
  47. username: '',
  48. sec: 0,
  49. secTimer: null
  50. };
  51. }
  52. /**
  53. * 生命周期函数--监听页面加载
  54. */,
  55. onLoad: function (options) {
  56. uni.setNavigationBarTitle({
  57. title: this.$t('设置密码')
  58. });
  59. },
  60. /**
  61. * 生命周期函数--监听页面初次渲染完成
  62. */
  63. onReady: function () {},
  64. /**
  65. * 生命周期函数--监听页面显示
  66. */
  67. onShow: function () {},
  68. /**
  69. * 生命周期函数--监听页面隐藏
  70. */
  71. onHide: function () {},
  72. /**
  73. * 生命周期函数--监听页面卸载
  74. */
  75. onUnload: function () {},
  76. /**
  77. * 页面相关事件处理函数--监听用户下拉动作
  78. */
  79. onPullDownRefresh: function () {},
  80. /**
  81. * 页面上拉触底事件的处理函数
  82. */
  83. onReachBottom: function () {},
  84. /**
  85. * 用户点击右上角分享
  86. */
  87. onShareAppMessage: function () {},
  88. methods: {
  89. bindUsernameInput: function (e) {
  90. this.setData({
  91. username: e.detail.value
  92. });
  93. },
  94. bindSendCode() {
  95. if (this.sec == 0) {
  96. this.setData({
  97. sec: 60
  98. });
  99. this.secTimer = setInterval(() => {
  100. if (this.sec > 0) {
  101. this.setData({
  102. sec: this.sec - 1
  103. });
  104. } else {
  105. clearInterval(this.secTimer);
  106. }
  107. }, 1000);
  108. http.postApi(
  109. config.API_USER_VERIFY_CODE,
  110. {
  111. phone: this.username
  112. },
  113. (resp) => {
  114. if (resp.data.code === 200) {
  115. } else {
  116. common.simpleToast(this,resp.data.msg);
  117. }
  118. }
  119. );
  120. }
  121. },
  122. bindSubmit(e) {
  123. console.log(e.detail.value);
  124. const username = e.detail.value.username;
  125. const code = e.detail.value.code;
  126. const password = e.detail.value.password;
  127. const password2 = e.detail.value.password2;
  128. if (common.isEmpty(username)) {
  129. common.simpleToast(this,this.$t('请输入手机号'));
  130. return;
  131. }
  132. if (common.isEmpty(code)) {
  133. common.simpleToast(this,this.$t('请输入验证码'));
  134. return;
  135. }
  136. if (common.isEmpty(password)) {
  137. common.simpleToast(this,this.$t('请输入密码'));
  138. return;
  139. }
  140. if (password != password2) {
  141. common.simpleToast(this,this.$t('两次输入密码不一致'));
  142. return;
  143. }
  144. http.postApi(
  145. config.API_USER_CHANGE_PASSWORD,
  146. {
  147. phone: username,
  148. code: code,
  149. password: password
  150. },
  151. (resp) => {
  152. if (resp.data.code === 200) {
  153. common.simpleToast(this,this.$t('设置成功'));
  154. setTimeout(function () {
  155. uni.navigateBack({
  156. delta: 1
  157. });
  158. }, 1500);
  159. } else {
  160. common.simpleToast(this,resp.data.msg);
  161. }
  162. }
  163. );
  164. }
  165. }
  166. };
  167. </script>
  168. <style>
  169. @import './setPassword.css';
  170. </style>