change-tel.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <view class="change-tel">
  3. <u-navbar back-icon-color="#000" :border-bottom="false" @leftClick = "return1"></u-navbar>
  4. <view class="change-header u-flex-col">
  5. <text>修改手机号</text>
  6. <text>当前手机号:{{mobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')}}</text>
  7. </view>
  8. <view class="change-new-item u-flex">
  9. <text class="text1">+86</text>
  10. <u-icon name="arrow-down-fill" size="12" color="rgba(0, 0, 0, 0.3)"></u-icon>
  11. <input class="input1" type="number" placeholder="请输入新的手机号" v-model="tel">
  12. </view>
  13. <view class="change-new-item u-flex">
  14. <input class="input2" type="number" placeholder="请输入短信验证码" v-model="code">
  15. <!-- <text class="text2" @click="getCode">{{tips}}</text> -->
  16. <view class="input-box u-flex u-row-between">
  17. <text class="send" @click="getCode" v-if="!timeEnd && !verificationTime ">获取验证码</text>
  18. <text class="send" v-else-if="verificationTime">{{verificationTime}}s</text>
  19. <text class="send" @click="getCode" v-else-if="timeEnd">重新获取验证码</text>
  20. </view>
  21. </view>
  22. <view class="change-btn" @click="save">
  23. 保存
  24. </view>
  25. <!-- <u-verification-code :seconds="seconds" ref="uCode" @change="codeChange"></u-verification-code> -->
  26. </view>
  27. </template>
  28. <script>
  29. import {
  30. index,
  31. getCode,
  32. changemobile
  33. } from "@/units/inquire.js"
  34. export default {
  35. data() {
  36. return {
  37. mobile: '',
  38. tel: '',
  39. code: '',
  40. tips: '',
  41. verificationTime: "",
  42. timeEnd:false
  43. }
  44. },
  45. onLoad() {
  46. this.getuser()
  47. },
  48. methods: {
  49. return1(){
  50. uni.navigateBack()
  51. },
  52. save() {
  53. if (!this.$u.test.mobile(this.tel)) {
  54. this.$u.toast("请输入正确的手机号")
  55. return
  56. }
  57. if (!this.code) {
  58. this.$u.toast("请输入验证码")
  59. return
  60. }
  61. uni.showLoading({
  62. mask: true,
  63. title: '请稍后'
  64. })
  65. changemobile({
  66. mobile: this.tel,
  67. captcha: this.code
  68. }).then(res => {
  69. if (res.code == 1) {
  70. this.$u.toast("修改成功");
  71. setTimeout(() => {
  72. uni.navigateBack()
  73. }, 800)
  74. }
  75. })
  76. },
  77. getCode() {
  78. if (!this.$u.test.mobile(this.tel)) {
  79. this.$u.toast("请输入正确的手机号")
  80. return
  81. }
  82. //获取验证码接口
  83. getCode({
  84. mobile: this.tel,
  85. event: 'changemobile'
  86. }).then(res => {
  87. // this.getcode = false
  88. if (res.code == 1) {
  89. uni.showLoading({
  90. title: '正在获取验证码',
  91. mask: true
  92. })
  93. uni.hideLoading();
  94. // 这里此提示会被this.start()方法中的提示覆盖
  95. this.$u.toast('验证码已发送');
  96. // 通知验证码组件内部开始倒计时
  97. // this.$refs.uCode.start();
  98. this.verificationTime = 30
  99. this.verificationDown()
  100. } else {
  101. this.$u.toast(res.msg)
  102. }
  103. })
  104. if (true) {
  105. // 模拟向后端请求验证码
  106. } else {
  107. this.$u.toast('倒计时结束后再发送');
  108. }
  109. },
  110. //验证码倒计时
  111. verificationDown() {
  112. // 设置定时器
  113. this.timer = setInterval(() => {
  114. this.verificationTime = this.verificationTime - 1
  115. if (this.verificationTime < 10) this.verificationTime = '0' + this.verificationTime
  116. if (this.verificationTime <= 0) {
  117. // 清除定时器
  118. clearInterval(this.timer)
  119. this.timeEnd = true
  120. this.verificationTime = false
  121. }
  122. }, 1000)
  123. },
  124. // getCode() {
  125. // if (this.$refs.uCode.canGetCode) {
  126. // // 模拟向后端请求验证码
  127. // if (!this.$u.test.mobile(this.tel)) {
  128. // this.$u.toast("请输入正确的手机号")
  129. // return
  130. // }
  131. // uni.showLoading({
  132. // mask: true,
  133. // title: '正在获取验证码'
  134. // })
  135. // this.$u.post('/api/sms/send', {
  136. // mobile: this.tel,
  137. // event: 'changemobile'
  138. // }).then(res => {
  139. // this.$u.toast(res.msg);
  140. // if (res.code == 1) {
  141. // // 通知验证码组件内部开始倒计时
  142. // this.$refs.uCode.start();
  143. // }
  144. // })
  145. // } else {
  146. // this.$u.toast('倒计时结束后再发送');
  147. // }
  148. // },
  149. getuser() {
  150. index().then(res => {
  151. this.mobile = res.data.mobile
  152. })
  153. },
  154. }
  155. }
  156. </script>
  157. <style lang="scss">
  158. .send {
  159. font-size: 32rpx;
  160. font-family: PingFangSC-Regular, PingFang SC;
  161. font-weight: 400;
  162. color: #0C66C2;
  163. }
  164. .change-tel {
  165. .change-btn {
  166. margin: 68rpx auto;
  167. width: 686rpx;
  168. line-height: 92rpx;
  169. background: #0C66C2;
  170. border-radius: 12rpx;
  171. text-align: center;
  172. font-size: 34rpx;
  173. font-family: PingFangSC-Regular, PingFang SC;
  174. font-weight: 400;
  175. color: #FFFFFF;
  176. }
  177. .change-new-item {
  178. height: 120rpx;
  179. border-bottom: 2rpx solid #F0F0F0;
  180. margin: 0 32rpx;
  181. .input2 {
  182. flex: 1;
  183. font-size: 36rpx;
  184. }
  185. .text2 {
  186. font-size: 32rpx;
  187. font-family: PingFangSC-Regular, PingFang SC;
  188. font-weight: 400;
  189. color: #0C66C2;
  190. width: 170rpx;
  191. text-align: center;
  192. }
  193. .text1 {
  194. font-size: 36rpx;
  195. font-family: SFPro-Regular, SFPro;
  196. font-weight: 400;
  197. color: #222222;
  198. margin-right: 8rpx;
  199. }
  200. .input1 {
  201. margin-left: 20rpx;
  202. flex: 1;
  203. font-size: 36rpx;
  204. }
  205. }
  206. .change-header {
  207. padding: 58rpx 32rpx;
  208. text:first-child {
  209. margin-bottom: 14rpx;
  210. font-size: 48rpx;
  211. font-family: PingFangSC-Medium, PingFang SC;
  212. font-weight: 500;
  213. color: #222222;
  214. }
  215. text:last-child {
  216. font-size: 28rpx;
  217. font-family: PingFangSC-Regular, PingFang SC;
  218. font-weight: 400;
  219. color: #555555;
  220. }
  221. }
  222. }
  223. </style>