smsAlert.vue 3.1 KB

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