setPhone.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view>
  3. <view class="content">
  4. <view class="input_box">
  5. <input type="text" v-model="mobile" placeholder="请输入手机号" placeholder-style="color:#999;"/>
  6. </view>
  7. <view class="send_box">
  8. <view class="send_code">
  9. <input type="text" v-model="vcode" placeholder="验证码" placeholder-style="color:#999;"/>
  10. </view>
  11. <view class="send_btn" @click="send_vcode()">
  12. {{send_text}}
  13. </view>
  14. </view>
  15. <view class="re_btn" @click="bang_phone()">
  16. 绑定
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. mobile:'',
  26. vcode:'',
  27. send_text:'发送验证码'
  28. };
  29. },
  30. methods:{
  31. send_vcode(){
  32. if(this.mobile.length < 11){
  33. uni.showToast({
  34. icon:'none',
  35. title:'请填写正确的手机号'
  36. })
  37. return
  38. }
  39. if(this.send_text = "发送验证码"){
  40. this.$api.sms_vcode({
  41. mobile:this.mobile
  42. }).then((res)=>{
  43. console.log(res.data)
  44. if(res.data.code == 3001){
  45. uni.showToast({
  46. icon:"none",
  47. title:"电话号码错误"
  48. })
  49. }else if(res.data.code == 3002){
  50. uni.showToast({
  51. icon:"none",
  52. title:"发送失败"
  53. })
  54. }else if(res.data.code == 0){
  55. uni.showToast({
  56. icon:"none",
  57. title:"验证码发送成功"
  58. })
  59. }
  60. })
  61. }
  62. this.send_text = "已发送"
  63. if(this.send_text = "已发送"){
  64. uni.showToast({
  65. icon:"none",
  66. title:"请勿重复发送"
  67. })
  68. }
  69. },
  70. bang_phone(){
  71. if(this.mobile == ''){
  72. uni.showToast({
  73. icon:'none',
  74. title:'手机号不能为空'
  75. })
  76. return
  77. }
  78. if(this.vcode == ''){
  79. uni.showToast({
  80. icon:'none',
  81. title:'验证码不能为空'
  82. })
  83. return
  84. }
  85. this.$api.user_mobile_set({
  86. mobile:this.mobile,
  87. vcode:this.vcode
  88. }).then((res)=>{
  89. console.log(res)
  90. console.log(res.data.data.mobile)
  91. if(res.data.code == 4002){
  92. uni.showToast({
  93. icon:'none',
  94. title:"验证码超时或者错误"
  95. })
  96. return
  97. }else{
  98. uni.setStorageSync('mobile', res.data.data.mobile)
  99. uni.showToast({
  100. icon:'none',
  101. title:'手机绑定成功'
  102. })
  103. this.send_text = "发送验证码"
  104. }
  105. setTimeout(function(){
  106. uni.switchTab({
  107. url:"../../tabbar/my/my",
  108. })
  109. },1000)
  110. })
  111. },
  112. },
  113. }
  114. </script>
  115. <style lang="scss">
  116. page{
  117. background-color: #f0f0f0;
  118. }
  119. .content{
  120. padding: 21rpx 30rpx 0;
  121. .input_box{
  122. margin-bottom: 20rpx;
  123. padding: 20rpx 25rpx;
  124. background-color: #fff;
  125. input{
  126. height: 60rpx;
  127. font-size: 34rpx;
  128. color: #333;
  129. }
  130. }
  131. .send_box{
  132. display: flex;
  133. justify-content: space-between;
  134. margin-bottom: 20rpx;
  135. .send_code{
  136. width: 400rpx;
  137. padding: 20rpx 25rpx;
  138. background-color: #fff;
  139. input{
  140. height: 60rpx;
  141. font-size: 34rpx;
  142. color: #333;
  143. }
  144. }
  145. .send_btn{
  146. width: 200rpx;
  147. background-color: #009FE8;
  148. text-align: center;
  149. color: #fff;
  150. font-size: 34rpx;
  151. line-height: 100rpx;
  152. }
  153. }
  154. .re_btn{
  155. background-color: #009FE8;
  156. text-align: center;
  157. color: #fff;
  158. font-size: 34rpx;
  159. line-height: 100rpx;
  160. }
  161. }
  162. </style>