bangding.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view class="index">
  3. <view class="title">
  4. 绑定手机号
  5. </view>
  6. <view class="phone u-flex">
  7. <input type="number" placeholder="请输入手机号" v-model="tel">
  8. </view>
  9. <view class="phone u-flex">
  10. <input type="number" placeholder="请输入短信验证码" v-model="code">
  11. <text class="code" @click="send">{{tips}}</text>
  12. </view>
  13. <view class="publish" @click="submit">
  14. 绑定
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. code:'',
  23. tel:'',
  24. tips:'获取验证码',
  25. s: 60,
  26. time: null,
  27. }
  28. },
  29. methods: {
  30. submit(){
  31. if (!this.tel) {
  32. this.$u.toast('请输入手机号')
  33. return
  34. }
  35. if (!this.tel) {
  36. this.$u.toast('请输入验证码')
  37. return
  38. }
  39. uni.$u.http.post('/api/user/binding_phone',{phone:this.tel,code:this.code}).then(res => {
  40. if(res.code==1){
  41. this.$u.toast(res.msg)
  42. setTimeout(()=>{
  43. uni.navigateBack({
  44. })
  45. },2000)
  46. }
  47. })
  48. },
  49. send() {
  50. if (this.s == 60) {
  51. if (!this.tel) {
  52. uni.showToast({
  53. title: "请输入手机号",
  54. duration: 2000,
  55. icon: "none",
  56. });
  57. return false;
  58. }
  59. uni.showLoading({
  60. mask: true,
  61. title: "请稍后"
  62. })
  63. var result = {}
  64. result.phone = this.tel
  65. result.event = 'register'
  66. this.$u.post('/api/Sms/send', result).then((res) => {
  67. uni.hideLoading()
  68. uni.showToast({
  69. title: res.msg,
  70. duration: 2000,
  71. icon: "none",
  72. });
  73. if (res.code == 1) {
  74. this.time = setInterval(() => {
  75. this.s--
  76. this.tips = `${this.s}s`
  77. if (this.s == 0) {
  78. this.s = 60
  79. this.tips = '重新发送'
  80. clearInterval(this.time)
  81. }
  82. }, 1000)
  83. }
  84. });
  85. } else {
  86. uni.showToast({
  87. title: "请稍后再试",
  88. duration: 2000,
  89. icon: "none",
  90. });
  91. return false;
  92. }
  93. },
  94. }
  95. }
  96. </script>
  97. <style lang="scss">
  98. .publish{
  99. margin: 128rpx auto;
  100. width: 650rpx;
  101. height: 104rpx;
  102. line-height: 104rpx;
  103. text-align: center;
  104. background: linear-gradient(270deg, #A890FE 0%, #FFAEAE 100%);
  105. border-radius: 52rpx;
  106. font-size: 36rpx;
  107. color: #fff;
  108. }
  109. .index{
  110. padding: 70rpx 60rpx 0;
  111. color: #222222;
  112. .title{
  113. font-size: 44rpx;
  114. font-weight: 600;
  115. margin-bottom: 50rpx;
  116. }
  117. .phone{
  118. height: 128rpx;
  119. line-height: 128rpx;
  120. border-bottom: 2rpx solid #F2F2F2;
  121. input{
  122. flex: 1;
  123. }
  124. .code{
  125. font-size: 32rpx;
  126. font-family: PingFangSC-Regular, PingFang SC;
  127. font-weight: 400;
  128. color: #999999;
  129. background: linear-gradient(270deg, #A890FE 0%, #FFAEAE 100%);
  130. -webkit-background-clip: text;
  131. -webkit-text-fill-color: transparent;
  132. }
  133. }
  134. }
  135. </style>