index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <view>
  3. <view class="ChangePassword">
  4. <view class="list">
  5. <view class="item" v-if="isNew">
  6. <input type='number' disabled='true' placeholder-class='placeholder' v-model="userInfo.mobile" />
  7. </view>
  8. <view class="item" v-if="!isNew">
  9. <input type='number' placeholder='填写新的手机号码' placeholder-class='placeholder' v-model="phone" />
  10. </view>
  11. <view class="item acea-row row-between-wrapper">
  12. <input type='number' placeholder='填写验证码' placeholder-class='placeholder' class="codeIput" v-model="captcha" />
  13. <button class="code font-color" :class="disabled === true ? 'on' : ''" :disabled='disabled' @click="code">
  14. {{ text }}
  15. </button>
  16. </view>
  17. </view>
  18. <button form-type="submit" v-if="isNew" class="confirmBnt bg-color" @click="next">下一步</button>
  19. <button form-type="submit" v-if="!isNew" class="confirmBnt bg-color" @click="editPwd">保存</button>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import { toLogin } from '@/libs/login.js';
  25. import { mapGetters } from "vuex";
  26. import * as AuthUtil from '@/api/member/auth.js';
  27. import * as UserApi from '@/api/member/user.js';
  28. export default {
  29. data() {
  30. return {
  31. phone: '', // 需要更换的手机号
  32. captcha: '',
  33. isNew: true, // true 是第一步,校验老的手机号验证码;false 是第二步,校验新手机号的验证码;
  34. oldCaptcha: '', // 进入第二步时,需要使用它保存老的手机验证码
  35. timer: '',
  36. text: '获取验证码',
  37. nums: 60,
  38. disabled: false
  39. };
  40. },
  41. computed: mapGetters(['isLogin','userInfo']),
  42. onLoad() {
  43. if (!this.isLogin) {
  44. toLogin();
  45. }
  46. },
  47. methods: {
  48. getTimes() {
  49. this.nums = this.nums - 1;
  50. this.text = "剩余 " + this.nums + "s";
  51. if (this.nums < 0) {
  52. clearInterval(this.timer);
  53. }
  54. this.text = "剩余 " + this.nums + "s";
  55. if (this.text < "剩余 " + 0 + "s") {
  56. this.disabled = false;
  57. this.text = "重新获取";
  58. }
  59. },
  60. next() {
  61. if (!this.captcha) {
  62. return this.$util.Tips({
  63. title: '请填写验证码'
  64. });
  65. }
  66. // 校验验证码是否正确
  67. uni.showLoading({
  68. title: '加载中',
  69. mask: true
  70. });
  71. AuthUtil.validateSmsCode(
  72. this.userInfo.mobile,
  73. 2,
  74. this.captcha
  75. ).then(res => {
  76. uni.hideLoading();
  77. this.isNew = false;
  78. this.oldCaptcha = this.captcha;
  79. this.captcha = '';
  80. clearInterval(this.timer);
  81. this.disabled = false;
  82. this.text = "获取验证码";
  83. }).catch(err => {
  84. uni.hideLoading();
  85. return this.$util.Tips({
  86. title: err
  87. });
  88. })
  89. },
  90. editPwd: function() {
  91. if (!this.phone) {
  92. return this.$util.Tips({
  93. title: '请填写手机号码!'
  94. });
  95. }
  96. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(this.phone))) {
  97. return this.$util.Tips({
  98. title: '请输入正确的手机号码!'
  99. });
  100. }
  101. if (!this.captcha) {
  102. return this.$util.Tips({
  103. title: '请填写验证码'
  104. });
  105. }
  106. uni.showModal({
  107. title: '是否更换绑定账号',
  108. confirmText: '绑定',
  109. success: (res) => {
  110. if (!res.confirm) {
  111. return this.$util.Tips({
  112. title: '您已取消更换绑定!'
  113. }, {
  114. tab: 5,
  115. url: '/pages/users/user_info/index'
  116. });
  117. }
  118. UserApi.updateUserMobile({
  119. mobile: this.phone,
  120. code: this.captcha,
  121. oldCode: this.captcha
  122. }).then(res => {
  123. return this.$util.Tips({
  124. title: '手机修改成功',
  125. icon: 'success'
  126. }, {
  127. tab: 5,
  128. url: '/pages/users/user_info/index'
  129. });
  130. }).catch(err => {
  131. return this.$util.Tips({
  132. title: err
  133. });
  134. })
  135. }
  136. });
  137. },
  138. /**
  139. * 发送验证码
  140. */
  141. async code() {
  142. if (!this.isNew) {
  143. if (!this.phone) {
  144. return this.$util.Tips({
  145. title: '请填写手机号码!'
  146. });
  147. }
  148. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(this.phone))) {
  149. return this.$util.Tips({
  150. title: '请输入正确的手机号码!'
  151. });
  152. }
  153. }
  154. // 执行验证码的发送
  155. this.nums = 60;
  156. uni.showLoading({
  157. title: '加载中',
  158. mask: true
  159. });
  160. await AuthUtil.sendSmsCode(this.isNew ? this.userInfo.mobile : this.phone, 2).then(res => {
  161. this.$util.Tips({
  162. title: '验证码已发送'
  163. });
  164. this.timer = setInterval(this.getTimes, 1000);
  165. this.disabled = true;
  166. uni.hideLoading();
  167. }).catch(err => {
  168. return this.$util.Tips({
  169. title: err
  170. });
  171. uni.hideLoading();
  172. });
  173. }
  174. }
  175. }
  176. </script>
  177. <style lang="scss" scoped>
  178. .shading {
  179. display: flex;
  180. align-items: center;
  181. justify-content: center;
  182. width: 100%;
  183. /* #ifdef APP-VUE */
  184. margin-top: 50rpx;
  185. /* #endif */
  186. /* #ifndef APP-VUE */
  187. margin-top: 200rpx;
  188. /* #endif */
  189. image {
  190. width: 180rpx;
  191. height: 180rpx;
  192. }
  193. }
  194. page {
  195. background-color: #fff !important;
  196. }
  197. .ChangePassword .phone {
  198. font-size: 32rpx;
  199. font-weight: bold;
  200. text-align: center;
  201. margin-top: 55rpx;
  202. }
  203. .ChangePassword .list {
  204. width: 580rpx;
  205. margin: 53rpx auto 0 auto;
  206. }
  207. .ChangePassword .list .item {
  208. width: 100%;
  209. height: 110rpx;
  210. border-bottom: 2rpx solid #f0f0f0;
  211. }
  212. .ChangePassword .list .item input {
  213. width: 100%;
  214. height: 100%;
  215. font-size: 32rpx;
  216. }
  217. .ChangePassword .list .item .placeholder {
  218. color: #b9b9bc;
  219. }
  220. .ChangePassword .list .item input.codeIput {
  221. width: 340rpx;
  222. }
  223. .ChangePassword .list .item .code {
  224. font-size: 32rpx;
  225. // background-color: #fff;
  226. }
  227. .ChangePassword .list .item .code.on {
  228. color: #b9b9bc !important;
  229. }
  230. .ChangePassword .confirmBnt {
  231. font-size: 32rpx;
  232. width: 580rpx;
  233. height: 90rpx;
  234. border-radius: 45rpx;
  235. color: #fff;
  236. margin: 92rpx auto 0 auto;
  237. text-align: center;
  238. line-height: 90rpx;
  239. }
  240. </style>