changePhoneNumber.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="page">
  3. <view class="info">
  4. <u--form labelPosition="left" :model="info" ref="ownerForm" labelWidth="80" errorType="message"
  5. :labelStyle="{fontWeight:'bold',color:'#333'}">
  6. <u-form-item label="手机号" borderBottom>
  7. <u--input v-model="info.mobile" border="none" clearable placeholder="请输入新手机号"
  8. placeholderStyle="color:#999"></u--input>
  9. </u-form-item>
  10. <u-form-item label="验证码" borderBottom>
  11. <!-- #ifdef H5 -->
  12. <u--input v-model="info.smsCode" border="none" clearable placeholder="请输入手机验证码" maxlength="6"
  13. placeholderStyle="color:#999">
  14. <template slot="suffix">
  15. <u-code ref="uCode2" @change="codeChange2" uniqueKey="changePhoneNumber" keep-running
  16. start-text="发送验证码" style="color: #F9E000;"></u-code>
  17. <view @tap="getCode2" :text="tips2" class="u-page__code-text">{{tips2}}</view>
  18. </template>
  19. </u--input>
  20. <!-- #endif -->
  21. <!-- #ifdef APP-PLUS -->
  22. <u-input v-model="info.smsCode" border="none" clearable placeholder="请输入手机验证码" maxlength="6"
  23. placeholderStyle="color:#999">
  24. <template slot="suffix">
  25. <u-code ref="uCode2" @change="codeChange2" uniqueKey="changePhoneNumber" keep-running
  26. start-text="发送验证码" style="color: #F9E000;"></u-code>
  27. <view @tap="getCode2" :text="tips2" class="u-page__code-text">{{tips2}}</view>
  28. </template>
  29. </u-input>
  30. <!-- #endif -->
  31. </u-form-item>
  32. </u--form>
  33. </view>
  34. <view class="btn dis a-c j-c " @click="save">
  35. 确定
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import {
  41. mapState,
  42. mapMutations
  43. } from "vuex"
  44. export default {
  45. data() {
  46. return {
  47. tips2: "",
  48. info: {
  49. mobile: "",
  50. smsCode: "",
  51. userId: "",
  52. },
  53. }
  54. },
  55. onShow() {
  56. },
  57. onLoad(options) {
  58. if (options.userId) {
  59. this.info.userId = options.userId;
  60. }
  61. },
  62. computed: {},
  63. methods: {
  64. ...mapMutations(['emptyUserInfo']),
  65. codeChange2(text) {
  66. this.tips2 = text;
  67. },
  68. getCode2() {
  69. if (!this.info.mobile) {
  70. uni.showToast({
  71. title: '手机号为空',
  72. icon: 'none'
  73. });
  74. return;
  75. }
  76. if (this.$refs.uCode2.canGetCode) {
  77. this.smsCode(); // 向后端请求验证码
  78. uni.showLoading({
  79. title: '正在获取验证码'
  80. })
  81. setTimeout(() => {
  82. uni.hideLoading();
  83. // 这里此提示会被this.start()方法中的提示覆盖
  84. uni.$u.toast('验证码已发送');
  85. // 通知验证码组件内部开始倒计时
  86. this.$refs.uCode2.start();
  87. }, 1000);
  88. } else {
  89. uni.$u.toast('倒计时结束后再发送');
  90. }
  91. },
  92. //获取验证码
  93. async smsCode() {
  94. let res = await this.$http.get('/auth/sendSmsCode?mobile=' + this.info.mobile);
  95. },
  96. //更换手机号
  97. async save() {
  98. let res = await this.$http.post('/auth/sendSmsCodeMobile', this.info);
  99. if (res.code == '200') {
  100. uni.showToast({
  101. title: '更换成功,请重新登录',
  102. icon: 'none'
  103. });
  104. this.emptyUserInfo();
  105. setTimeout(() => {
  106. uni.reLaunch({
  107. url: "/pages/login/login"
  108. })
  109. }, 500);
  110. } else {
  111. uni.showToast({
  112. title: res.msg,
  113. icon: 'none'
  114. });
  115. }
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="scss" scoped>
  121. page {
  122. background-color: #fff;
  123. padding: 30rpx 60rpx;
  124. box-sizing: border-box;
  125. }
  126. .info {}
  127. .btn {
  128. padding: 20rpx;
  129. box-sizing: border-box;
  130. background: #FDE935;
  131. border-radius: 45rpx 45rpx 45rpx 45rpx;
  132. margin-top: 100rpx;
  133. font-size: 36rpx;
  134. color: #1F1F1F;
  135. font-weight: bold;
  136. }
  137. ::v-deep {
  138. .u-form-item__body {
  139. padding: 34rpx 0;
  140. }
  141. }
  142. .u-page__code-text {
  143. padding: 4rpx 18rpx;
  144. background: rgba(253, 233, 53, 0.2);
  145. border-radius: 6rpx 6rpx 6rpx 6rpx;
  146. border: 1rpx solid #FDE935;
  147. color: #333333;
  148. font-size: 26rpx;
  149. }
  150. </style>