tab-bar.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="footer">
  3. <view class="index" @click="swithTab(1)">
  4. <view><image src="../../static/tabbar/menu-1.png"></image></view>
  5. <view :class="[currentPage === 1?'current':'']">首页</view>
  6. </view>
  7. <view class="scan" @click="swithTab(2)">
  8. <view><image src="../../static/tabbar/menu-2.png"></image></view>
  9. <view class="hover">扫码换电</view>
  10. </view>
  11. <view class="index" @click="swithTab(3)">
  12. <view><image src="../../static/tabbar/menu-3.png"></image></view>
  13. <view :class="[currentPage === 3?'current':'']">我的</view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. name:"tab-bar",
  20. data() {
  21. return {
  22. currentPage:0,
  23. };
  24. },
  25. mounted() {
  26. this.getRoute()
  27. },
  28. onLoad() {
  29. },
  30. methods:{
  31. swithTab(num){
  32. if(num === 1){
  33. uni.switchTab({
  34. url: '/pages/index/index',
  35. });
  36. }else if(num === 2){
  37. if(this.$store.state.token){
  38. let stationCode='st001'
  39. let that=this
  40. // uni.scanCode({
  41. // success: function (res) {
  42. // let stationCode=res.result.split("=")[1]
  43. // that.$storage.set("stationCode",stationCode)
  44. // that.$http.getStationExchange({stationCode:stationCode}).then(res=>{
  45. // if(res.code === 0 && res.data){
  46. // that.$storage.set("exchangeNo",res.data)
  47. // uni.navigateTo({
  48. // url:'/pages/scan/index'
  49. // })
  50. // }else{
  51. // that.$utils.msg(res.msg)
  52. // }
  53. // })
  54. // }
  55. // });
  56. this.$storage.set("stationCode",stationCode)
  57. this.$http.getStationExchange({stationCode:stationCode}).then(res=>{
  58. if(res.code === 0 && res.data){
  59. this.$storage.set("exchangeNo",res.data)
  60. uni.navigateTo({
  61. url:'/pages/scan/index'
  62. })
  63. }else{
  64. this.$utils.msg(res.msg)
  65. }
  66. })
  67. }else{
  68. uni.navigateTo({
  69. url: '/pages/public/login',
  70. });
  71. }
  72. }else{
  73. if(this.$store.state.token){
  74. uni.switchTab({
  75. url: '/pages/ucenter/index',
  76. });
  77. }else{
  78. uni.navigateTo({
  79. url: '/pages/public/login',
  80. });
  81. }
  82. }
  83. },
  84. getRoute(){
  85. let curPage = getCurrentPages();
  86. let route = curPage[curPage.length - 1].route
  87. if(route === 'pages/index/index'){
  88. this.currentPage=1
  89. }else if(route === 'pages/ucenter/index'){
  90. this.currentPage=3
  91. }
  92. }
  93. }
  94. }
  95. </script>
  96. <style lang="scss" scoped>
  97. .footer{
  98. width: 100%;
  99. height: 106rpx;
  100. background-image: url(~@/static/bbg.png);
  101. background-size: 100% 100%;
  102. position: fixed;
  103. left: 0;
  104. right: 0;
  105. bottom: 0;
  106. display: flex;
  107. justify-content: space-around;
  108. padding-top: 15rpx;
  109. box-sizing: border-box;
  110. font-size: 26rpx;
  111. image{
  112. width: 39rpx;
  113. height: 39rpx;
  114. }
  115. .index{
  116. width: 300rpx;
  117. text-align: center;
  118. }
  119. .scan{
  120. position: relative;
  121. display: flex;
  122. flex: 1;
  123. text-align: center;
  124. view:first-child{
  125. position: absolute;
  126. bottom: 30rpx;
  127. width: 100%;
  128. }
  129. view:last-child{
  130. position: absolute;
  131. bottom: 6rpx;
  132. width: 100%;
  133. }
  134. image{
  135. width: 106rpx;
  136. height: 106rpx;
  137. }
  138. }
  139. .hover{
  140. color: #58be6b;
  141. }
  142. .current{
  143. color: #959ea8;
  144. }
  145. }
  146. </style>