demo5.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. =<template>
  2. <scroll-view class="swiper-tab" scroll-x :scroll-left="scrollLeft" :scroll-with-animation="true">
  3. <view v-for="(item, index) in qgItems"
  4. :key="item.index"
  5. :class="['swiper-tab-list',index == tabIndex ? 'qg_active' : '']"
  6. :id="index"
  7. @tap="gettqg(item, index)"
  8. >
  9. <view class="list-item" >
  10. <text>{{item.time}}</text>
  11. <text v-if="item.hs <= gettime && gettime <= item.he">进行中</text>
  12. <text v-if="gettime < item.hs">即将开始</text>
  13. <text v-if="gettime > item.he">已开始</text>
  14. <text v-if="index == tabIndex" class="qgactive-item"></text>
  15. <!-- <text v-if="item.hs <= gettime && gettime <= item.he" class="qgactive-item"></text> -->
  16. </view>
  17. </view>
  18. </scroll-view>
  19. </template>
  20. <script>
  21. export default {
  22. data() {
  23. return {
  24. tabIndex: 0, //选中项下标
  25. scrollLeft:0, //滚动位置
  26. qgItems:[{
  27. time:'0:00-8:00',
  28. hs:0,
  29. he:7
  30. },{
  31. time:'8:00-10:00',
  32. hs:8,
  33. he:9
  34. },{
  35. time:'10:00-12:00',
  36. hs:10,
  37. he:11
  38. },{
  39. time:'12:00-14:00',
  40. hs:12,
  41. he:13
  42. },{
  43. time:'14:00-16:00',
  44. hs:14,
  45. he:15
  46. },{
  47. time:'16:00-18:00',
  48. hs:16,
  49. he:17
  50. },{
  51. time:'18:00-20:00',
  52. hs:18,
  53. he:19
  54. },{
  55. time:'20:00-22:00',
  56. hs:20,
  57. he:21
  58. },{
  59. time:'22:00-24:00',
  60. hs:22,
  61. he:23
  62. }
  63. ]
  64. }
  65. },
  66. computed: {
  67. gettime(){
  68. // 计算时间
  69. let state = '已开抢'
  70. let nowTime = new Date();
  71. let h =nowTime.getHours();
  72. return h;
  73. }
  74. },
  75. mounted(){
  76. console.log(this.gettime)
  77. for(let i in this.qgItems){
  78. if (this.qgItems[i].hs <= this.gettime){
  79. this.tabIndex = i;
  80. this.scrollLeft = i*50;
  81. }
  82. }
  83. },
  84. methods: {
  85. gettqg(item, index) {
  86. console.log(JSON.stringify(item))
  87. if (this.tabIndex !== index) {
  88. this.tabIndex = index;
  89. this.scrollLeft = index*50;
  90. this.$emit('clickItem', item);
  91. }
  92. }
  93. },
  94. }
  95. </script>
  96. <style scoped>
  97. .list {
  98. width: 750upx;
  99. height: 100%;
  100. }
  101. .swiper-box {
  102. flex: 1;
  103. width: 100%;
  104. height: calc(100% - 100upx);
  105. }
  106. .swiper-tab {
  107. width: 100%;
  108. white-space: nowrap;
  109. line-height: 64upx;
  110. height: 116upx;
  111. border:0;
  112. font-size:24upx;
  113. }
  114. .swiper-tab-list {
  115. font-size: 30upx;
  116. width: 180upx;
  117. padding: 5px 0;
  118. display: inline-block;
  119. text-align: center;
  120. color: #fff;
  121. background: #000;
  122. line-height:20px;
  123. }
  124. .list-item{
  125. display:flex;
  126. flex-direction: column;
  127. align-items: center;
  128. }
  129. .qg_active {
  130. color: #fff;
  131. background:#FF502E;
  132. }
  133. .qgactive-item{
  134. width: 0;
  135. height: 0;
  136. border-width: 5px;
  137. border-style: solid;
  138. border-color: #FF502E transparent transparent transparent;
  139. position:absolute;
  140. margin-top:45px;
  141. }
  142. </style>