小程序端工程代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
6.2 KiB

  1. <template>
  2. <view class="group-goods pa20 mx20 mb10" v-if="detail.length>0">
  3. <view class="title-box x-bc" @tap="$yrouter.push({ path: '/pages/shop/HotNewGoods/index',query:{type:2} })">
  4. <text class="title">热门榜单</text>
  5. <view class="group-people x-f">
  6. <text class="tip">更多</text>
  7. <text class="cuIcon-right"></text>
  8. </view>
  9. </view>
  10. <view class="goods-box swiper-box x-f">
  11. <swiper class="carousel" circular @change="swiperChange" :autoplay="true" duration="2000">
  12. <swiper-item v-for="(goods, index) in goodsList" :key="index" class="carousel-item">
  13. <view class="goods-list-box x-f">
  14. <block v-for="mgoods in goods" :key="mgoods.id">
  15. <view class="min-goods" @tap="jump('/pages/shop/GoodsCon/index',{id:mgoods.id})">
  16. <view class="img-box">
  17. <view class="tag">hot</view>
  18. <image class="img" :src="mgoods.image" mode="widthFix"></image>
  19. </view>
  20. <view class="price-box">
  21. <view class="y-f">
  22. <text class="seckill-current">{{ mgoods.price }}</text>
  23. <text class="original">销量{{ mgoods.sales }}{{mgoods.unitName}}</text>
  24. </view>
  25. </view>
  26. <view class="title">
  27. <slot name="titleText"></slot>
  28. </view>
  29. </view>
  30. </block>
  31. </view>
  32. </swiper-item>
  33. </swiper>
  34. <view class="swiper-dots" v-if="goodsList.length > 1">
  35. <text :class="swiperCurrent === index ? 'dot-active' : 'dot'" v-for="(dot, index) in goodsList.length"
  36. :key="index"></text>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import shActivityGoods from '@/components/sh-activity-goods.vue';
  43. export default {
  44. name: "HotCommodity",
  45. components: {
  46. shActivityGoods
  47. },
  48. data() {
  49. return {
  50. goodsList: [],
  51. swiperCurrent: 0
  52. };
  53. },
  54. props: {
  55. detail: Array
  56. },
  57. computed: {},
  58. created() {},
  59. watch: {
  60. detail(next) {
  61. this.goodsList = this.sortData(next, 4);
  62. }
  63. },
  64. methods: {
  65. swiperChange(e) {
  66. this.swiperCurrent = e.detail.current;
  67. },
  68. // 数据分层
  69. sortData(oArr, length) {
  70. let arr = [];
  71. let minArr = [];
  72. oArr.forEach(c => {
  73. if (minArr.length === length) {
  74. minArr = [];
  75. }
  76. if (minArr.length === 0) {
  77. arr.push(minArr);
  78. }
  79. minArr.push(c);
  80. });
  81. return arr;
  82. },
  83. jump(path, query) {
  84. this.$yrouter.push({
  85. path,
  86. query,
  87. });
  88. },
  89. }
  90. }
  91. </script>
  92. <style lang="scss" scoped>
  93. .group-goods {
  94. position: relative;
  95. z-index: 9;
  96. }
  97. .swiper-box,
  98. .carousel {
  99. width: 700rpx;
  100. height: 240upx;
  101. position: relative;
  102. border-radius: 20rpx;
  103. .carousel-item {
  104. width: 100%;
  105. height: 100%;
  106. // padding: 0 28upx;
  107. overflow: hidden;
  108. }
  109. .swiper-image {
  110. width: 100%;
  111. height: 100%;
  112. // border-radius: 10upx;
  113. background: #ccc;
  114. }
  115. }
  116. .swiper-dots {
  117. display: flex;
  118. position: absolute;
  119. left: 50%;
  120. transform: translateX(-50%);
  121. bottom: 0rpx;
  122. z-index: 66;
  123. .dot {
  124. width: 45rpx;
  125. height: 3rpx;
  126. background: #eee;
  127. border-radius: 50%;
  128. margin-right: 10rpx;
  129. }
  130. .dot-active {
  131. width: 45rpx;
  132. height: 3rpx;
  133. background: #a8700d;
  134. border-radius: 50%;
  135. margin-right: 10rpx;
  136. }
  137. }
  138. // 今日必拼+限时抢购
  139. .group-goods {
  140. background: #fff;
  141. border-radius: 20rpx;
  142. overflow: hidden;
  143. .title-box {
  144. padding-bottom: 20rpx;
  145. .title {
  146. font-size: 32rpx;
  147. font-weight: bold;
  148. }
  149. .group-people {
  150. .time-box {
  151. font-size: 26rpx;
  152. color: #edbf62;
  153. .count-text-box {
  154. width: 30rpx;
  155. height: 34rpx;
  156. background: #edbf62;
  157. text-align: center;
  158. line-height: 34rpx;
  159. font-size: 24rpx;
  160. border-radius: 6rpx;
  161. color: rgba(#fff, 0.9);
  162. margin: 0 8rpx;
  163. }
  164. }
  165. .head-box {
  166. .head-img {
  167. width: 40rpx;
  168. height: 40rpx;
  169. border-radius: 50%;
  170. background: #ccc;
  171. }
  172. }
  173. .tip {
  174. font-size: 28rpx;
  175. padding-left: 30rpx;
  176. color: #666;
  177. }
  178. .cuIcon-right {
  179. font-size: 30rpx;
  180. line-height: 28rpx;
  181. color: #666;
  182. }
  183. }
  184. }
  185. .goods-box {
  186. .goods-item {
  187. margin-right: 22rpx;
  188. &:nth-child(4n) {
  189. margin-right: 0;
  190. }
  191. }
  192. }
  193. .min-goods{
  194. margin-right: 22rpx;
  195. }
  196. }
  197. </style>