tabsSwiper.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <!-- 选项卡列表 swiper高度自适应 -->
  3. <view class="">
  4. <view class="ads">
  5. <image src="https://music.nanyue6688.com/obsfile/e47815d1738640a09655b12efa4f59a9-%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20210705182001.png"></image>
  6. </view>
  7. <view class="tabsSwiper" style="position: relative;top: -150rpx;">
  8. <!-- <view class="location">
  9. <u-icon name="map-fill" color="#000"></u-icon>
  10. <text>保利中心</text>
  11. <u-icon name="arrow-down-fill" size="20"></u-icon>
  12. </view> -->
  13. <view class="search-form" @click="$jump('/pages/search/search')">
  14. <text class="cuIcon-search"></text>
  15. <text class="margin-left-20">请输入搜索内容</text>
  16. </view>
  17. <view class="tabs">
  18. <view class="tabs-con" :class="activeIndex==0?'active active0':'in_active in_active0'"
  19. @click="tabsChange(0)" :style="{ color: activeIndex == 0 ? activeColor : '' }">
  20. <view class="title">附近优惠</view>
  21. </view>
  22. <view class="tabs-con" :class="activeIndex==1?'active active1':'in_active in_active1'"
  23. @click="tabsChange(1)" :style="{ color: activeIndex == 1 ? activeColor : '' }">
  24. <view class="title">
  25. <text>线上</text>
  26. <text>/</text>
  27. <text>线下</text>
  28. 场景
  29. </view>
  30. </view>
  31. </view>
  32. <view class="list">
  33. <swiper :style="{ height: swiperHeight + 'rpx' }" :current="swiperCurrent" @change="swiperChange">
  34. <swiper-item style="height: 100%">
  35. <view class="list0">
  36. <view class="item">
  37. <slot name="swiper1">
  38. </slot>
  39. </view>
  40. </view>
  41. </swiper-item>
  42. <swiper-item style="height: 100%">
  43. <view class="list1">
  44. <view class="item">
  45. <slot name="swiper2">
  46. </slot>
  47. </view>
  48. </view>
  49. </swiper-item>
  50. </swiper>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. export default {
  57. name: "tabsSwiper",
  58. props: {
  59. activeColor: {
  60. type: String,
  61. default: "#ff9420",
  62. },
  63. },
  64. data() {
  65. return {
  66. activeIndex: 0, // tabs索引
  67. swiperCurrent: 0, // swiper索引
  68. swiperHeight: 0, //swiper高度
  69. };
  70. },
  71. mounted() {
  72. this.initSwiperHeight(".list0");
  73. },
  74. methods: {
  75. // 点击tabs
  76. tabsChange(index) {
  77. this.activeIndex = index;
  78. this.swiperCurrent = index;
  79. let list = ".list" + index;
  80. this.initSwiperHeight(list);
  81. this.$emit('currentChange',index)
  82. },
  83. // 点击商品
  84. touchItem(goods, cur) {
  85. this.$emit("touchItem", goods);
  86. },
  87. // 手势切换
  88. swiperChange(e) {
  89. let index=e.detail.current
  90. this.activeIndex = index;
  91. let list = ".list" + index;
  92. this.initSwiperHeight(list);
  93. this.$emit('currentChange',index)
  94. },
  95. // 计算高度
  96. initSwiperHeight(list) {
  97. const query = uni.createSelectorQuery().in(this);
  98. this.$nextTick(() => {
  99. query
  100. .select(list)
  101. .boundingClientRect((data) => {
  102. this.swiperHeight = Math.ceil(data.height / (uni.upx2px(data.height) / data
  103. .height));
  104. })
  105. .exec();
  106. });
  107. },
  108. },
  109. };
  110. </script>
  111. <style lang="scss">
  112. .ads {
  113. image{
  114. width: 100%;
  115. height: 450rpx;
  116. }
  117. }
  118. .location{
  119. font-weight: 800;
  120. font-size: 30rpx;
  121. display: flex;
  122. padding:20rpx 30rpx;
  123. text{
  124. margin: 0 4rpx;
  125. }
  126. }
  127. .search-form {
  128. background-color: #FFFFFF;
  129. border-radius: 50rpx;
  130. height: 60rpx;
  131. margin-bottom: 16rpx;
  132. display: flex;
  133. justify-content: flex-start;
  134. align-items: center;
  135. padding-left: 40rpx;
  136. color: #b9b9b9;
  137. font-size: 26rpx;
  138. }
  139. .tabsSwiper {
  140. padding: 14rpx;
  141. }
  142. .tabs {
  143. display: flex;
  144. width: 100%;
  145. .tabs-con {
  146. padding: 20rpx 0;
  147. color: #333;
  148. overflow: hidden;
  149. display: flex;
  150. justify-content: center;
  151. align-items: center;
  152. .des {
  153. font-size: 20rpx;
  154. width: 100%;
  155. }
  156. }
  157. }
  158. .active {
  159. width: 60%;
  160. z-index: 9;
  161. border-radius: 20rpx 20rpx 0 0;
  162. .title {
  163. font-weight: 800;
  164. font-size: 34rpx;
  165. color: #ff9420;
  166. }
  167. }
  168. .active0 {
  169. background: linear-gradient(-110deg, transparent 40rpx, #ffffff 0) top right;
  170. }
  171. .active1 {
  172. background: linear-gradient(120deg, transparent 60rpx, #ffffff 0) top left;
  173. }
  174. .in_active {
  175. width: 70%;
  176. margin-top: 14rpx;
  177. background-color: #fedcc3;
  178. }
  179. .in_active0 {
  180. margin-right: -100rpx;
  181. border-radius: 20rpx 0 0 0;
  182. background-color: #fedcc3;
  183. }
  184. .in_active1 {
  185. margin-left: -100rpx;
  186. border-radius: 0 20rpx 0 0;
  187. background-color: #fedcc3;
  188. }
  189. .list {
  190. background-color: #fefefe;
  191. padding: 16rpx;
  192. border-radius: 0 0 16rpx 16rpx;
  193. overflow: hidden;
  194. min-height: 100rpx;
  195. }
  196. </style>