Menu.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <view class="menu-list-box" v-if="carousel" :style="list.length <= menu ? `height:160rpx` : `height:320rpx`">
  3. <swiper
  4. class="menu-swiper-box"
  5. :style="list.length <= menu ? `height:160rpx` : `height:320rpx`"
  6. @change="onSwiper"
  7. circular
  8. :autoplay="false"
  9. :interval="3000"
  10. :duration="1000"
  11. >
  12. <swiper-item class="menu-swiper-item" v-for="(itemList, index) in carousel" :key="index" :style="list.length <= menu ? `height:200rpx` : `height:340rpx`">
  13. <view class="menu-tab-box">
  14. <view class="tab-list" v-for="item in itemList" :key="item.cateId" @tap="routerTo(item)">
  15. <image class="tab-img" :style="{ width: imgW + 'rpx', height: imgW + 'rpx' }" :src="item.imgUrl"></image>
  16. <text :class="cateId == item.cateId?'tab-title active':'tab-title'" >{{ item.cateName }}</text>
  17. </view>
  18. </view>
  19. </swiper-item>
  20. </swiper>
  21. <view class="menu-dots" v-if="carousel.length > 1">
  22. <text :class="menuCurrent === index ? 'dot-active' : 'dot'" v-for="(dot, index) in carousel.length" :key="index"></text>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. components: {},
  29. data() {
  30. return {
  31. cateId:0,
  32. menuCurrent: 0 //轮播下标
  33. };
  34. },
  35. props: {
  36. list: {
  37. type: Array,
  38. default: []
  39. },
  40. menu: {
  41. default: 4
  42. },
  43. imgW: {
  44. type: Number,
  45. default: 88
  46. }
  47. },
  48. computed: {
  49. carousel() {
  50. if (this.list) {
  51. let data = this.sortData(this.list, this.menu * 2);
  52. return data;
  53. }
  54. }
  55. },
  56. created() {},
  57. methods: {
  58. // 数据分层
  59. sortData(oArr, length) {
  60. let arr = [];
  61. let minArr = [];
  62. oArr.forEach(c => {
  63. if (minArr.length === length) {
  64. minArr = [];
  65. }
  66. if (minArr.length === 0) {
  67. arr.push(minArr);
  68. }
  69. minArr.push(c);
  70. });
  71. return arr;
  72. },
  73. // 轮播
  74. onSwiper(e) {
  75. this.menuCurrent = e.detail.current;
  76. },
  77. routerTo(item) {
  78. this.cateId=item.cateId;
  79. this.$emit('menuClick',item);
  80. }
  81. }
  82. };
  83. </script>
  84. <style lang="scss">
  85. .menu-list-box {
  86. padding: 0rpx;
  87. background: #fff;
  88. box-sizing: border-box;
  89. }
  90. .menu-list-box,
  91. .menu-swiper-box {
  92. position: relative;
  93. background: #fff;
  94. .menu-swiper-item {
  95. background: #fff;
  96. height: 100%;
  97. width: 100%;
  98. }
  99. .menu-tab-box {
  100. display: flex;
  101. flex-wrap: wrap;
  102. .tab-list {
  103. width: 25%;
  104. display: -webkit-box;
  105. display: -webkit-flex;
  106. display: flex;
  107. -webkit-box-orient: vertical;
  108. -webkit-box-direction: normal;
  109. -webkit-flex-direction: column;
  110. flex-direction: column;
  111. -webkit-box-align: center;
  112. -webkit-align-items: center;
  113. align-items: center;
  114. font-size: 22rpx;
  115. font-family: PingFang SC;
  116. font-weight: 500;
  117. color: rgba(51, 51, 51, 1);
  118. padding-bottom: 30rpx;
  119. .tab-img {
  120. border-radius: 25rpx;
  121. margin-bottom: 10rpx;
  122. }
  123. .tab-title{
  124. font-size: 24upx;
  125. font-family: PingFang SC;
  126. font-weight: 500;
  127. color: #111;
  128. margin-top: 10rpx;
  129. }
  130. .active{
  131. color: #E2C99E;
  132. }
  133. }
  134. }
  135. .menu-dots {
  136. display: flex;
  137. position: absolute;
  138. left: 50%;
  139. transform: translateX(-50%);
  140. .dot {
  141. width: 40rpx;
  142. height: 3rpx;
  143. background: #eeeeee;
  144. margin-right: 10rpx;
  145. }
  146. .dot-active {
  147. width: 40rpx;
  148. height: 3rpx;
  149. background: #2BC7B9;
  150. margin-right: 10rpx;
  151. }
  152. }
  153. }
  154. </style>