setPhone.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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(() => {
  106. uni.navigateBack()
  107. }, 1500)
  108. })
  109. },
  110. },
  111. }
  112. </script>
  113. <style lang="scss">
  114. page{
  115. background-color: #f0f0f0;
  116. }
  117. .content{
  118. padding: 21rpx 30rpx 0;
  119. .input_box{
  120. margin-bottom: 20rpx;
  121. padding: 20rpx 25rpx;
  122. background-color: #fff;
  123. input{
  124. height: 60rpx;
  125. font-size: 34rpx;
  126. color: #333;
  127. }
  128. }
  129. .send_box{
  130. display: flex;
  131. justify-content: space-between;
  132. margin-bottom: 20rpx;
  133. .send_code{
  134. width: 400rpx;
  135. padding: 20rpx 25rpx;
  136. background-color: #fff;
  137. input{
  138. height: 60rpx;
  139. font-size: 34rpx;
  140. color: #333;
  141. }
  142. }
  143. .send_btn{
  144. width: 200rpx;
  145. background-color: #009FE8;
  146. text-align: center;
  147. color: #fff;
  148. font-size: 34rpx;
  149. line-height: 100rpx;
  150. }
  151. }
  152. .re_btn{
  153. background-color: #009FE8;
  154. text-align: center;
  155. color: #fff;
  156. font-size: 34rpx;
  157. line-height: 100rpx;
  158. }
  159. }
  160. </style>