verificationPage.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <view class="page">
  3. <view class="form">
  4. <view class="mt-2 position-relative border-bottom dis a-c">
  5. <text>手机号</text>
  6. <input type="text" v-model="phone" class="uni-input common-input" maxlength="11" disabled
  7. style="padding-left: 56rpx;" placeholder="手机号" />
  8. </view>
  9. <view class="mt-2 position-relative border-bottom dis a-c">
  10. <text>验证码</text>
  11. <input type="text" v-model="smsCode" class="uni-input common-input" maxlength="6"
  12. style="padding-right:120px;padding-left: 56rpx;" placeholder="请输入验证码" />
  13. <view class="position-absolute top-0 right-0 d-flex a-center j-center text-light-muted"
  14. style="width: 240rpx;height: 100%;" @tap="getCheckNum">
  15. <view class="d-flex a-center j-center "
  16. :class="!codetime?'yanzhengmaView1 text-color':'yanzhengmaView2'">
  17. {{!codetime?'获取验证码':codetime+' S'+'后重新获取'}}
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="logout dis a-c j-c" @tap="submit">
  23. <text>提交</text>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. phone: "", //手机号
  32. countdownTimer: null, //计时器
  33. smsCode: "",
  34. codetime: 0, //验证码获取倒计时
  35. companyId: "", //订单号
  36. isSending: false, // 新增发送状态标志
  37. }
  38. },
  39. onShow() {
  40. },
  41. async onLoad(params) {
  42. if (params.companyId) {
  43. this.companyId = params.companyId;
  44. const res = await this.$http.get('/insurance/crawler/yaGetMobile', {
  45. companyId: this.companyId,
  46. });
  47. if (res.code == 200) {
  48. this.phone = res.msg;
  49. }
  50. }
  51. },
  52. methods: {
  53. async getCheckNum() {
  54. try {
  55. // 1. 防止重复点击
  56. if (this.isSending || this.codetime > 0) return;
  57. uni.hideKeyboard();
  58. this.isSending = true; // 标记为发送中
  59. // 2. 显示加载状态
  60. uni.showLoading({
  61. title: '发送中...',
  62. mask: true
  63. });
  64. // 3. 发送验证码请求
  65. const res = await this.$http.post('/insurance/crawler/yaSendCode', {
  66. companyId: this.companyId,
  67. smsCode: this.smsCode,
  68. });
  69. uni.hideLoading();
  70. this.isSending = false; // 重置发送状态
  71. if (res.code == 200) {
  72. uni.showToast({
  73. title: "验证码发送成功",
  74. icon: "success",
  75. duration: 2000
  76. });
  77. // 启动倒计时
  78. this.startCountdown();
  79. } else {
  80. uni.showToast({
  81. title: res.msg || '发送失败',
  82. icon: "error",
  83. duration: 3000
  84. });
  85. }
  86. } catch (error) {
  87. console.log(1);
  88. this.isSending = false; // 确保异常时也重置状态
  89. uni.hideLoading();
  90. uni.showToast({
  91. title: '网络错误,请重试',
  92. icon: "error",
  93. duration: 3000
  94. });
  95. console.error('发送验证码失败:', error);
  96. }
  97. },
  98. startCountdown() {
  99. if (this.countdownTimer) {
  100. clearInterval(this.countdownTimer);
  101. }
  102. this.codetime = 180;
  103. this.countdownTimer = setInterval(() => {
  104. this.codetime--;
  105. if (this.codetime <= 0) {
  106. clearInterval(this.countdownTimer);
  107. this.countdownTimer = null;
  108. }
  109. }, 1000);
  110. },
  111. beforeDestroy() {
  112. if (this.countdownTimer) {
  113. clearInterval(this.countdownTimer);
  114. }
  115. },
  116. async submit() {
  117. if (!this.smsCode) {
  118. return uni.showToast({
  119. title: '请输入验证码',
  120. icon: 'none'
  121. });
  122. }
  123. let res = await this.$http.post('/insurance/crawler/yaVerifySendCode', {
  124. companyId: this.companyId,
  125. smsCode: this.smsCode,
  126. });
  127. if (res.code == '200') {
  128. window.open(res.data);
  129. } else {
  130. uni.showToast({
  131. title: res.msg,
  132. icon: 'none'
  133. });
  134. }
  135. },
  136. },
  137. }
  138. </script>
  139. <style lang="scss" scoped>
  140. page {
  141. background-color: #f8f8f8;
  142. }
  143. .page {
  144. padding: 20rpx;
  145. }
  146. .form {
  147. width: 100%;
  148. background-color: #fff;
  149. border-radius: 20rpx;
  150. padding: 20rpx;
  151. box-sizing: border-box;
  152. }
  153. .logout {
  154. width: 90%;
  155. height: 88rpx;
  156. margin: 40rpx auto 0;
  157. background: #0052FF;
  158. border-radius: 45rpx 45rpx 45rpx 45rpx;
  159. border: 1rpx solid #0052FF;
  160. font-size: 36rpx;
  161. color: #fff;
  162. }
  163. /* 第三方登录End */
  164. .yanzhengmaView1 {
  165. background: #FFFFFF;
  166. border-radius: 10rpx;
  167. width: 150rpx;
  168. padding: 5rpx 0;
  169. }
  170. .yanzhengmaView2 {
  171. background: #FFFFFF;
  172. border-radius: 10rpx;
  173. width: 220rpx;
  174. padding: 5rpx 0;
  175. }
  176. .bg-color {
  177. background-color: #0052FF;
  178. border-radius: 20px;
  179. }
  180. .bg-hover-color {
  181. background-color: #0052FF;
  182. opacity: 0.65;
  183. border-radius: 20px;
  184. }
  185. .text-color {
  186. color: #0052FF;
  187. }
  188. </style>