conversion.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view class="form-box">
  3. <en-nav title="兑换码" :title-color="'#333'" >
  4. </en-nav>
  5. <view class="from-input" :class="{'apply-shake':codeShake}">
  6. <input type="text" class="input-item sys-height-44" v-model="code" placeholder="请输入兑换码"></input>
  7. </view>
  8. <view class="from-text sys-color-gray-9">
  9. 在输入框内正确输入兑换码
  10. </view>
  11. <view class="chang-phone-but sys-color-white sys-background-black sys-selected-but" @click="setPhone" :class="{'sys-unselected-but':!isLogin}">确认</view>
  12. </view>
  13. </template>
  14. <script>
  15. import EnNav from "@/components/en-utils/en-nav/en-nav";
  16. import tools from "@/service/tools";
  17. import {exchangeCode} from "@/api/my";
  18. export default {
  19. components: {EnNav},
  20. data() {
  21. return {
  22. code:'',
  23. codeShake:false,
  24. isLogin:false,
  25. isAjax:false
  26. }
  27. },
  28. watch:{
  29. 'code':function (){
  30. this.verifyIsLogin()
  31. },
  32. },
  33. methods: {
  34. verifyIsLogin(){
  35. this.isLogin = this.code !== '';
  36. },
  37. setShake(){
  38. this.codeShake=true
  39. setTimeout(()=>{
  40. this.codeShake=false
  41. },500)
  42. },
  43. setPhone(){
  44. if(this.code ===''){
  45. tools.error('请输入兑换码')
  46. this.setShake()
  47. tools.vibrate()
  48. return false
  49. }
  50. if(this.isAjax){
  51. return ;
  52. }
  53. this.isAjax=true
  54. exchangeCode({'code':this.code}).then((res)=>{
  55. if(res.code===0){
  56. tools.success('兑换成功')
  57. setTimeout(()=>{
  58. uni.redirectTo({
  59. 'url':'/pages/my/set'
  60. })
  61. },1500)
  62. }else {
  63. this.isAjax=false
  64. tools.error(res.msg)
  65. }
  66. })
  67. },
  68. }
  69. }
  70. </script>
  71. <style scoped lang="scss">
  72. .form-box{
  73. padding: 0 32rpx;
  74. position: relative;
  75. min-height: 100vh;
  76. .from-input{
  77. margin-top: 56rpx;
  78. background-color: #F2F2F2;
  79. border-radius: 16rpx;
  80. padding: 32rpx;
  81. .input-item{
  82. font-size: 28rpx;
  83. color: #333;
  84. }
  85. .input-item::placeholder{
  86. color: #999;
  87. }
  88. }
  89. .from-text{
  90. margin-top: 24rpx;
  91. font-size: 24rpx;
  92. }
  93. .chang-phone-but{
  94. position: absolute;
  95. bottom:calc(50rpx + env(safe-area-inset-bottom));
  96. left: 32rpx;
  97. width:calc(100vw - 64rpx);
  98. }
  99. }
  100. </style>