verificationPage.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 if (res.code == 300) {
  80. //#ifdef H5
  81. window.open(res.msg, '_blank'); // 在新标签页中打开
  82. //#endif
  83. //#ifdef APP-PLUS
  84. plus.runtime.openURL(res.msg)
  85. //#endif
  86. } else {
  87. uni.showToast({
  88. title: res.msg || '发送失败',
  89. icon: "error",
  90. duration: 3000
  91. });
  92. }
  93. } catch (error) {
  94. console.log(1);
  95. this.isSending = false; // 确保异常时也重置状态
  96. uni.hideLoading();
  97. uni.showToast({
  98. title: '网络错误,请重试',
  99. icon: "error",
  100. duration: 3000
  101. });
  102. console.error('发送验证码失败:', error);
  103. }
  104. },
  105. startCountdown() {
  106. if (this.countdownTimer) {
  107. clearInterval(this.countdownTimer);
  108. }
  109. this.codetime = 180;
  110. this.countdownTimer = setInterval(() => {
  111. this.codetime--;
  112. if (this.codetime <= 0) {
  113. clearInterval(this.countdownTimer);
  114. this.countdownTimer = null;
  115. }
  116. }, 1000);
  117. },
  118. beforeDestroy() {
  119. if (this.countdownTimer) {
  120. clearInterval(this.countdownTimer);
  121. }
  122. },
  123. async submit() {
  124. if (!this.smsCode) {
  125. return uni.showToast({
  126. title: '请输入验证码',
  127. icon: 'none'
  128. });
  129. }
  130. let res = await this.$http.post('/insurance/crawler/yaVerifySendCode', {
  131. companyId: this.companyId,
  132. smsCode: this.smsCode,
  133. });
  134. if (res.code == '200') {
  135. window.open(res.data);
  136. } else {
  137. uni.showToast({
  138. title: res.msg,
  139. icon: 'none'
  140. });
  141. }
  142. },
  143. },
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. page {
  148. background-color: #f8f8f8;
  149. }
  150. .page {
  151. padding: 20rpx;
  152. }
  153. .form {
  154. width: 100%;
  155. background-color: #fff;
  156. border-radius: 20rpx;
  157. padding: 20rpx;
  158. box-sizing: border-box;
  159. }
  160. .logout {
  161. width: 90%;
  162. height: 88rpx;
  163. margin: 40rpx auto 0;
  164. background: #0052FF;
  165. border-radius: 45rpx 45rpx 45rpx 45rpx;
  166. border: 1rpx solid #0052FF;
  167. font-size: 36rpx;
  168. color: #fff;
  169. }
  170. /* 第三方登录End */
  171. .yanzhengmaView1 {
  172. background: #FFFFFF;
  173. border-radius: 10rpx;
  174. width: 150rpx;
  175. padding: 5rpx 0;
  176. }
  177. .yanzhengmaView2 {
  178. background: #FFFFFF;
  179. border-radius: 10rpx;
  180. width: 220rpx;
  181. padding: 5rpx 0;
  182. }
  183. .bg-color {
  184. background-color: #0052FF;
  185. border-radius: 20px;
  186. }
  187. .bg-hover-color {
  188. background-color: #0052FF;
  189. opacity: 0.65;
  190. border-radius: 20px;
  191. }
  192. .text-color {
  193. color: #0052FF;
  194. }
  195. </style>