edit-phone.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <view>
  3. <!--标题栏-->
  4. <bar-title bgColor="bg-white" isBack>
  5. <block slot="content">手机号换绑</block>
  6. <block slot="right">
  7. <text class="text-orange">保存</text>
  8. </block>
  9. </bar-title>
  10. <!--提示栏-->
  11. <view class="text-black text-center margin-top padding">完成短信验证进行换绑手机号</view>
  12. <view class="cu-list menu sm-border margin-top">
  13. <view class="cu-item">
  14. <view class="content">当前手机号</view>
  15. <view class="action">138****8000</view>
  16. </view>
  17. </view>
  18. <view class="cu-form-group solid-top">
  19. <view class="title">新手机号</view>
  20. <input value=""/>
  21. </view>
  22. <view class="cu-form-group code">
  23. <view class="title">验证码</view>
  24. <input value=""/>
  25. <text class="text-orange text-btn" @tap="checking" v-if="!state">发送验证码</text>
  26. <text class="text-orange text-btn" v-else>{{currentTime}}s</text>
  27. </view>
  28. <view class="text-sm text-gray padding-sm">验证码将会发送到您的手机号中~</view>
  29. <view class="bg-white wecanui-footer-fixed foot-pb">
  30. <view class="flex flex-direction padding-sm">
  31. <button class="cu-btn bg-red">换绑手机号</button>
  32. </view>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import barTitle from '@/components/zaiui-common/basics/bar-title';
  38. import _tool from '@/static/zaiui/util/tools.js'; //工具函数
  39. export default {
  40. components: {
  41. barTitle
  42. },
  43. data() {
  44. return {
  45. state: false, //是否开启倒计时
  46. totalTime: 120, //总时间,单位秒
  47. recordingTime: 0, //记录时间变量
  48. currentTime: 0, //显示时间变量
  49. }
  50. },
  51. onLoad() {
  52. },
  53. onReady() {
  54. _tool.setBarColor(true);
  55. uni.pageScrollTo({
  56. scrollTop: 0,
  57. duration: 0
  58. });
  59. },
  60. methods: {
  61. checking() {
  62. //把显示时间设为总时间
  63. this.currentTime = this.totalTime;
  64. //开始倒计时
  65. this.state = true;
  66. //执行倒计时
  67. this.checkingTime();
  68. },
  69. checkingTime(){
  70. let that = this;
  71. //判断是否开启
  72. if(this.state){
  73. //判断显示时间是否已到0,判断记录时间是否已到总时间
  74. if(this.currentTime > 0 && this.recordingTime <= this.totalTime){
  75. //记录时间增加 1
  76. this.recordingTime = this.recordingTime + 1;
  77. //显示时间,用总时间 - 记录时间
  78. this.currentTime = this.totalTime - this.recordingTime;
  79. //1秒钟后,再次执行本方法
  80. setTimeout(() => {
  81. //定时器内,this指向外部,找不到vue的方法,所以,需要用that变量。
  82. that.checkingTime();
  83. }, 1000)
  84. }else{
  85. //时间已完成,还原相关变量
  86. this.state = false; //关闭倒计时
  87. this.recordingTime = 0; //记录时间为0
  88. this.currentTime = this.totalTime; //显示时间为总时间
  89. }
  90. }else{
  91. //倒计时未开启,初始化默认变量
  92. this.state = false;
  93. this.recordingTime = 0;
  94. this.currentTime = this.totalTime;
  95. }
  96. },
  97. }
  98. }
  99. </script>
  100. <style lang="scss">
  101. /* #ifdef APP-PLUS */
  102. @import "../../static/colorui/main.css";
  103. @import "../../static/colorui/icon.css";
  104. @import "../../static/zaiui/style/app.scss";
  105. /* #endif */
  106. .cu-form-group {
  107. position: relative;
  108. input {
  109. text-align: right;
  110. padding-right: 0;
  111. }
  112. }
  113. .cu-form-group.code {
  114. .text-btn {
  115. margin-left: 27.27upx;
  116. }
  117. }
  118. </style>