choose-time.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <script setup lang="ts">
  2. const props = withDefaults(defineProps<{
  3. data?: [string, string][]
  4. }>(), {
  5. data: () => [],
  6. })
  7. const emits = defineEmits(['change'])
  8. const active = defineModel()
  9. function handleTab(val: string) {
  10. active.value = val
  11. emits('change', val)
  12. console.log(active)
  13. }
  14. </script>
  15. <template>
  16. <view>
  17. <!-- 影院时间 -->
  18. <scroll-view class="tabList" :scroll-x="true" scroll-with-animation :scroll-into-view="`tab${active}`">
  19. <view
  20. v-for="(item, index) in props.data" :id="`tab${item[0]}`" :key="index" class="tab"
  21. :class="[active == item[0] ? 'active' : '']" @click="handleTab(item[0])"
  22. >
  23. <!-- {{ filterDay(item) }} {{ timeFormat(new Date(item).getTime(), 'MM-dd') }} -->
  24. {{ `${item[1]} ${item[0]}` }}
  25. </view>
  26. </scroll-view>
  27. </view>
  28. </template>
  29. <style lang="scss" scoped>
  30. .tabList {
  31. white-space: nowrap;
  32. width: 100%;
  33. border-bottom: 1rpx solid #F0F0F0;
  34. padding-top: 20rpx;
  35. background: #fff;
  36. .tab {
  37. display: inline-block;
  38. padding: 0 12rpx 20rpx;
  39. font-weight: 400;
  40. font-size: 28rpx;
  41. color: #AAAAAA;
  42. }
  43. .tab.active {
  44. position: relative;
  45. color: #222222;
  46. &::after {
  47. content: '';
  48. position: absolute;
  49. bottom: 0%;
  50. left: 50%;
  51. transform: translateX(-50%);
  52. width: 28rpx;
  53. height: 6rpx;
  54. background: var(--them-color);
  55. border-radius: 4rpx 4rpx 4rpx 4rpx;
  56. }
  57. }
  58. }
  59. </style>