NavBar.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view class="nav-bar-container">
  3. <swiper indicator-dots :style="{ height: swiperHeight }" @change="handleSwiperChange">
  4. <!-- <swiper @change="handleSwiperChange" indicator-dots style="height: 360upx;"> -->
  5. <swiper-item class="nav-item">
  6. <view class="item">
  7. <NavBarItem v-for="item in navbarOne" :key="item.storeName" :data="item" @click="$emit('view', item)">
  8. </NavBarItem>
  9. </view>
  10. <view class="item">
  11. <NavBarItem v-for="item in navbarTwo" :key="item.storeName" :data="item" @click="$emit('view', item)">
  12. </NavBarItem>
  13. </view>
  14. <view class="item">
  15. <NavBarItem v-for="item in navbarThree" :key="item.storeName" :data="item" @click="$emit('view', item)">
  16. </NavBarItem>
  17. </view>
  18. </swiper-item>
  19. <swiper-item class="nav-item">
  20. <view class="item">
  21. <NavBarItem v-for="item in navbarOne" :key="item.storeName" :data="item" @click="$emit('view', item)">
  22. </NavBarItem>
  23. </view>
  24. <view class="item">
  25. <NavBarItem v-for="item in navbarFour" :key="item.storeName" :data="item" @click="$emit('view', item)">
  26. </NavBarItem>
  27. </view>
  28. <view class="item">
  29. <NavBarItem v-for="item in navbarFive" :key="item.storeName" :data="item" @click="$emit('view', item)">
  30. </NavBarItem>
  31. </view>
  32. </swiper-item>
  33. </swiper>
  34. </view>
  35. </template>
  36. <script>
  37. import NavBarItem from './NavBarItem.vue'
  38. import { getShopCategoryLevelApi } from '../../../api/anotherTFInterface'
  39. import { navbarAll } from '../config'
  40. export default {
  41. name: 'NavBar',
  42. components: { NavBarItem },
  43. data() {
  44. return {
  45. classificationOneList: [],
  46. navbarOne: navbarAll.slice(0, 5),
  47. navbarTwo: navbarAll.slice(5, 10),
  48. navbarThree: navbarAll.slice(10, 15),
  49. navbarFour: navbarAll.slice(15, 20),
  50. navbarFive: navbarAll.slice(20, 25),
  51. swiperHeight: '512upx'
  52. }
  53. },
  54. async created() {
  55. const res = await getShopCategoryLevelApi({ levelId: 1 })
  56. this.classificationOneList = res.data || []
  57. if (this.classificationOneList.length) {
  58. this.navbarOne = this.classificationOneList.slice(0, 5).map((item) => {
  59. const tempIconObj = navbarAll.find((i) => i.storeName === item.storeName)
  60. return tempIconObj ? { ...item, ...tempIconObj } : { ...item, iconUrl: '', type: 0 }
  61. })
  62. }
  63. if (this.classificationOneList.length > 5) {
  64. this.navbarTwo = this.classificationOneList.slice(5, 10).map((item) => {
  65. const tempIconObj = navbarAll.find((i) => i.storeName === item.storeName)
  66. return tempIconObj ? { ...item, ...tempIconObj } : { ...item, iconUrl: '', type: 0 }
  67. })
  68. }
  69. if (this.classificationOneList.length > 10) {
  70. this.navbarThree = this.classificationOneList.slice(10, 15).map((item) => {
  71. const tempIconObj = navbarAll.find((i) => i.storeName === item.storeName)
  72. return tempIconObj ? { ...item, ...tempIconObj } : { ...item, iconUrl: '', type: 0 }
  73. })
  74. }
  75. if (this.classificationOneList.length > 15) {
  76. this.navbarFour = this.classificationOneList.slice(15, 20).map((item) => {
  77. const tempIconObj = navbarAll.find((i) => i.storeName === item.storeName)
  78. return tempIconObj ? { ...item, ...tempIconObj } : { ...item, iconUrl: '', type: 0 }
  79. })
  80. }
  81. if (this.classificationOneList.length > 20) {
  82. this.navbarFive = this.classificationOneList.slice(20, 25).map((item) => {
  83. const tempIconObj = navbarAll.find((i) => i.storeName === item.storeName)
  84. return tempIconObj ? { ...item, ...tempIconObj } : { ...item, iconUrl: '', type: 0 }
  85. })
  86. }
  87. },
  88. methods: {
  89. handleSwiperChange(e) {
  90. this.swiperHeight = (e.detail.current === 0) || (e.detail.current === 1) ? '512upx' : '360upx'
  91. }
  92. }
  93. }
  94. </script>
  95. <style lang="less" scoped>
  96. /deep/ .uni-swiper-dot-active,
  97. /deep/.uni-swiper-dot {
  98. width: 14upx;
  99. border-radius: 100px;
  100. height: 6upx;
  101. transition: all 350ms;
  102. }
  103. /deep/ .uni-swiper-dot-active {
  104. width: 47upx;
  105. background-color: #EF5511;
  106. }
  107. .nav-bar-container {
  108. width: 100%;
  109. background-color: #fff;
  110. margin: 24upx 0;
  111. border-radius: 20upx;
  112. .nav-item {
  113. padding: 15upx 20upx;
  114. box-sizing: border-box;
  115. .item {
  116. display: flex;
  117. align-items: center;
  118. padding-bottom: 20upx;
  119. }
  120. .item:last-child {
  121. padding-bottom: 0;
  122. }
  123. }
  124. }
  125. </style>