小程序端工程代码
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.

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