smsAlert.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view class="">
  3. <u-popup v-model="show" mode="center" width="80%" border-radius="15" :closeable="true">
  4. <view class="sms-alert-container">
  5. <view class="title">短信验证</view>
  6. <view class="info-msg">验证码已发送至{{phoneInfo}}</view>
  7. <view class="input-box">
  8. <u-input class="input-content" type="number" maxlength="6" placeholder="请输入验证码" v-model="code" />
  9. <view class="code-button">
  10. <view v-if="sending==true">
  11. <u-loading mode="circle"></u-loading>
  12. </view>
  13. <view v-else-if="seconds > 0"><span class="text-red">{{seconds+'s '}} </span>可重发</view>
  14. <view v-else>
  15. <u-button @click="$u.debounce(sendMessage, 500)" plain size="mini">重新发送</u-button>
  16. </view>
  17. </view>
  18. </view>
  19. <u-button @click="$u.debounce(exchange, 500)" :custom-style="customStyle" shape="circle">确认</u-button>
  20. </view>
  21. </u-popup>
  22. <loading ref="loading" type="3"/>
  23. <toast ref="toast" ></toast>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. name: "smsAlert",
  29. data() {
  30. return {
  31. show: false,
  32. sending: true,
  33. phone: '',
  34. code: '',
  35. seconds: 60,
  36. smsParams: {},
  37. customStyle: {
  38. color: 'white',
  39. background: "#E72226",
  40. width: '400rpx'
  41. }
  42. };
  43. },
  44. computed: {
  45. phoneInfo() {
  46. return this.phone.substr(0, 4) + "****" + this.phone.substr(7, this.phone.length);
  47. }
  48. },
  49. methods: {
  50. getSeconds(){
  51. let timer= setInterval(()=>{
  52. this.seconds --
  53. if (this.seconds==0) {
  54. timer
  55. clearInterval(timer)
  56. }
  57. },1000)
  58. },
  59. async showSmsAndSend(params) {
  60. this.$refs.loading.showLoading()
  61. this.smsParams = params
  62. let phone = params.mobile
  63. if (!this.$u.test.mobile(phone)) {
  64. uni.showToast({
  65. title: '手机号码格式错误',
  66. icon: 'none'
  67. });
  68. return;
  69. }
  70. this.phone = phone;
  71. this.$refs.loading.hide()
  72. this.show = true;
  73. this.sending = false;
  74. this.getSeconds()
  75. },
  76. hideSms() {
  77. this.show = false;
  78. },
  79. async sendMessage() {
  80. this.sending = true;
  81. this.seconds=60
  82. this.getSeconds()
  83. let res = await this.$api.order.sendCmccSms(this.smsParams)
  84. if (!res.data.success) {
  85. this.$u.toast(res.data.msg)
  86. }
  87. // 发送验证码
  88. this.sending = false;
  89. },
  90. exchange() {
  91. if (this.$isEmpty(this.code)) {
  92. this.$u.toast('请输入验证码')
  93. return
  94. }
  95. let params=this.$u.deepClone(this.smsParams)
  96. params.smsCode=this.code
  97. params.mobile=this.phone
  98. this.$emit("exchange", params)
  99. },
  100. }
  101. }
  102. </script>
  103. <style lang="scss" scoped>
  104. .sms-alert-container {
  105. padding: 50rpx;
  106. .title {
  107. width: 100%;
  108. text-align: center;
  109. padding: 0rpx 10rpx 50rpx 10rpx;
  110. font-weight: 500;
  111. color: #353535;
  112. letter-spacing: 2rpx;
  113. font-size: 30rpx;
  114. }
  115. .info-msg {
  116. padding: 5rpx 5rpx 20rpx 5rpx;
  117. color: #353535;
  118. }
  119. .input-box {
  120. display: flex;
  121. align-items: center;
  122. justify-content: left;
  123. border: 1rpx solid #DDDDDD;
  124. border-radius: 10rpx;
  125. margin: 0 0 50rpx 0;
  126. padding: 5rpx 5rpx 5rpx 30rpx;
  127. }
  128. .input-content {
  129. width: 66%;
  130. }
  131. .code-button {
  132. width: 34%;
  133. border-left: 1rpx solid #DDDDDD;
  134. text-align: center;
  135. }
  136. }
  137. </style>