index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <div class="quality-recommend">
  3. <div class="slider-banner swiper">
  4. <view class="swiper">
  5. <swiper indicator-dots="true" :autoplay="autoplay" :circular="circular" :interval="interval" :duration="duration"
  6. indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff">
  7. <block v-for="(item,index) in imgUrls" :key="index">
  8. <swiper-item>
  9. <image :src="item.pic" class="slide-image"></image>
  10. </swiper-item>
  11. </block>
  12. </swiper>
  13. </view>
  14. </div>
  15. <div class="title acea-row row-center-wrapper">
  16. <div class="line"></div>
  17. <div class="name">
  18. <span class="iconfont" :class="icon"></span>{{ name }}
  19. </div>
  20. <div class="line"></div>
  21. </div>
  22. <view class="wrapper">
  23. <GoodList :bastList="goodsList" :is-sort="false" />
  24. <view class="txt-bar" v-if="goodsList.length>0 && !isScroll">我是有底线的~</view>
  25. <emptyPage v-if="goodsList.length === 0 && !isScroll" title="暂无数据~"></emptyPage>
  26. </view>
  27. </div>
  28. </template>
  29. <script>
  30. import emptyPage from '@/components/emptyPage.vue'
  31. import GoodList from "@/components/goodList";
  32. import * as ProductSpuApi from '@/api/product/spu.js';
  33. import * as PromotionActivityApi from '@/api/promotion/activity.js';
  34. import * as ProductUtil from '@/utils/product.js';
  35. export default {
  36. name: "HotNewGoods",
  37. components: {
  38. GoodList,
  39. emptyPage,
  40. },
  41. props: {},
  42. data: function() {
  43. return {
  44. imgUrls: [], // TODO @芋艿:没想好,读取哪里的 banner
  45. goodsList: [],
  46. name: "",
  47. icon: "",
  48. type: 0,
  49. autoplay: true,
  50. circular: true,
  51. interval: 3000,
  52. duration: 500,
  53. recommendType: '',
  54. page: 1,
  55. limit: 8,
  56. isScroll: true
  57. };
  58. },
  59. onLoad: function(option) {
  60. this.type = option.type
  61. this.titleInfo();
  62. this.getIndexGroomList();
  63. },
  64. methods: {
  65. titleInfo: function() {
  66. if (this.type === "1") {
  67. this.name = "精品推荐";
  68. this.icon = "icon-jingpintuijian";
  69. uni.setNavigationBarTitle({
  70. title:"精品推荐"
  71. })
  72. this.recommendType = 'best';
  73. } else if (this.type === "2") {
  74. this.name = "热门榜单";
  75. this.icon = "icon-remen";
  76. uni.setNavigationBarTitle({
  77. title:"热门榜单"
  78. })
  79. this.recommendType = 'hot';
  80. } else if (this.type === "3") {
  81. this.name = "首发新品";
  82. this.icon = "icon-xinpin";
  83. uni.setNavigationBarTitle({
  84. title:"首发新品"
  85. })
  86. this.recommendType = 'new';
  87. } else if (this.type === "4") {
  88. this.name = "促销单品";
  89. this.icon = "icon-xinpin";
  90. uni.setNavigationBarTitle({
  91. title:"促销单品"
  92. })
  93. this.recommendType = 'benefit';
  94. }
  95. },
  96. /**
  97. * 获得推荐商品列表
  98. */
  99. getIndexGroomList: function() {
  100. if(!this.isScroll) {
  101. return
  102. }
  103. ProductSpuApi.getSpuPage({
  104. recommendType: this.recommendType,
  105. pageNo: this.page,
  106. pageSize: this.limit
  107. }).then(res => {
  108. const good_list = res.data.list;
  109. this.isScroll = good_list.length >= this.limit
  110. this.page++
  111. // 设置营销活动
  112. const spuIds = good_list.map(item => item.id);
  113. if (spuIds.length > 0) {
  114. PromotionActivityApi.getActivityListBySpuIds(spuIds).then(res => {
  115. ProductUtil.setActivityList(good_list, res.data);
  116. this.goodsList = this.goodsList.concat(good_list); // 放在此处,避免 Vue 监控不到数组里的元素变化
  117. });
  118. }
  119. }).catch(res => {
  120. this.$util.Tips({ title: res });
  121. });
  122. }
  123. },
  124. onReachBottom() {
  125. this.getIndexGroomList()
  126. }
  127. };
  128. </script>
  129. <style lang="scss">
  130. /deep/ .empty-box{
  131. background-color: #f5f5f5;
  132. }
  133. .swiper,swiper,swiper-item,.slide-image{
  134. width: 100%;
  135. height: 280rpx;
  136. }
  137. .quality-recommend {
  138. .wrapper{
  139. background: #fff;
  140. }
  141. .title {
  142. height: 120rpx;
  143. font-size:32rpx;
  144. color: #282828;
  145. background-color: #f5f5f5;
  146. .line{
  147. width: 230rpx;
  148. height: 2rpx;
  149. background-color: #e9e9e9;
  150. }
  151. }
  152. }
  153. .txt-bar{
  154. padding: 20rpx 0;
  155. text-align: center;
  156. font-size: 26rpx;
  157. color: #666;
  158. background-color: #f5f5f5;
  159. }
  160. </style>