password.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="container">
  3. <view class="listBox">
  4. <view class="list">
  5. <view class="flex listItem">
  6. <view class="flex titleBox">
  7. <text class="title">手机号</text>
  8. </view>
  9. <view class="right flex">
  10. <input class="input" placeholder="请输入手机号" type="text" v-model="account"
  11. placeholder-class="placeholder" />
  12. </view>
  13. </view>
  14. <view class="flex listItem">
  15. <view class="flex titleBox">
  16. <text class="title">验证码</text>
  17. </view>
  18. <view class="right flex">
  19. <input class="input" v-model="captcha" type="text" placeholder="请填写验证码"
  20. placeholder-class="placeholder" />
  21. <view class="code" @click="verification">{{ countDown == 0 ? '验证码' : countDown }}</view>
  22. </view>
  23. </view>
  24. <view class="flex listItem">
  25. <view class="flex titleBox">
  26. <text class="title">新密码</text>
  27. </view>
  28. <view class="right flex">
  29. <input class="input" placeholder="请输入新密码" type="text" v-model="password"
  30. placeholder-class="placeholder" />
  31. </view>
  32. </view>
  33. <view class="flex listItem">
  34. <view class="flex titleBox">
  35. <text class="title">确认密码</text>
  36. </view>
  37. <view class="right flex">
  38. <input class="input" placeholder="再次输入密码" type="text" v-model="dbPassword"
  39. placeholder-class="placeholder" />
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- <view class="row b-b">
  45. <text class="tit">手机号</text>
  46. <input class="input" v-model="account" type="text" placeholder="请填写手机号" placeholder-class="placeholder" />
  47. </view>
  48. <view class="row b-b">
  49. <text class="tit">新密码</text>
  50. <input class="input" v-model="password" type="password" placeholder="请填写新密码" placeholder-class="placeholder" />
  51. </view> -->
  52. <view class="base-buttom" :class="{'bg-gray':loding}" @click="loding?'':confirm()">提交</view>
  53. </view>
  54. </template>
  55. <script>
  56. import {
  57. verify
  58. } from '@/api/login.js';
  59. import {
  60. mapState
  61. } from 'vuex';
  62. import {
  63. registerReset
  64. } from '@/api/set.js';
  65. export default {
  66. data() {
  67. return {
  68. time: '', //保存倒计时对象
  69. countDown: 0, //倒计时
  70. account: '', //原密码
  71. dbPassword: '', //对比密码
  72. password: '', //新密码
  73. loding: false, //是否载入中
  74. };
  75. },
  76. computed: {
  77. ...mapState(['userInfo'])
  78. },
  79. onLoad() {
  80. if (this.userInfo.phone == null) {
  81. this.account = '';
  82. } else {
  83. this.account = this.userInfo.phone;
  84. this.show = false;
  85. }
  86. },
  87. watch: {
  88. // 监听倒计时
  89. countDown(i) {
  90. if (i == 0) {
  91. clearInterval(this.time);
  92. }
  93. }
  94. },
  95. methods: {
  96. //发送验证码
  97. verification() {
  98. let obj = this;
  99. if (this.account == '') {
  100. uni.showToast({
  101. title:"请输入电话号码",
  102. icon:"none"
  103. })
  104. return;
  105. }
  106. if (!/(^1[3|4|5|7|8][0-9]{9}$)/.test(this.account)) {
  107. uni.showToast({
  108. title:"请输入正确的手机号",
  109. icon:"none"
  110. })
  111. return;
  112. }
  113. // 判断是否在倒计时
  114. if (obj.countDown > 0) {
  115. return false;
  116. } else {
  117. obj.countDown = 60;
  118. obj.time = setInterval(() => {
  119. obj.countDown--;
  120. }, 1000);
  121. //调用验证码接口
  122. verify({
  123. phone: obj.account,
  124. type: ''
  125. })
  126. .then(({
  127. data
  128. }) => {})
  129. .catch(err => {
  130. console.log(err);
  131. });
  132. }
  133. },
  134. confirm(e) {
  135. this.loding = true;
  136. if (this.dbPassword != this.password) {
  137. this.loding = false;
  138. uni.showModal({
  139. title: '请重新输入',
  140. content: '两次密码输入不一致',
  141. showCancel: false,
  142. });
  143. return
  144. }
  145. registerReset({
  146. account: this.account,
  147. captcha: this.captcha,
  148. password: this.password,
  149. })
  150. .then(({
  151. data
  152. }) => {
  153. this.loding = false;
  154. uni.showToast({
  155. title:"修改成功",
  156. icon:"success"
  157. })
  158. })
  159. .catch(err => {
  160. this.loding = false;
  161. console.log(err);
  162. });
  163. }
  164. }
  165. };
  166. </script>
  167. <style lang="scss">
  168. page {
  169. background: $page-color-base;
  170. }
  171. .container {
  172. padding-top: 30rpx;
  173. }
  174. .listBox {
  175. margin: $page-row-spacing;
  176. margin-top: 0;
  177. border-radius: 20rpx;
  178. overflow: hidden;
  179. background-color: #FFFFFF;
  180. }
  181. .list {
  182. .input {
  183. text-align: right;
  184. font-size: $font-base;
  185. color: $color-gray;
  186. width: 100%;
  187. }
  188. .listItem {
  189. padding: 35rpx 40rpx;
  190. border-bottom: 1px solid $page-color-light;
  191. .code {
  192. color: #5dbc7c;
  193. font-size: 23rpx;
  194. border-left: 1px solid #eeeeee;
  195. padding-left: 20rpx;
  196. flex-shrink: 0;
  197. text-align: center;
  198. }
  199. }
  200. .listIconImg {
  201. width: 36rpx;
  202. }
  203. .right {
  204. color: $font-color-light;
  205. font-size: $font-base;
  206. flex-grow: 1;
  207. .img {
  208. width: 26rpx;
  209. }
  210. }
  211. .titleBox {
  212. .title {
  213. color: $font-color-base;
  214. font-size: $font-base;
  215. }
  216. }
  217. }
  218. .bg-gray {
  219. background-color: $color-gray;
  220. }
  221. </style>