recommend.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <view class='recommend'>
  3. <block v-if="tempArr.length">
  4. <title-box v-if="isShowTitle" title="热门推荐"></title-box>
  5. <view class='recommendList borderPad' :class="isShowTitle?'':'mt30'">
  6. <WaterfallsFlow :wfList='tempArr' :type="1" :isStore="1">
  7. <template slot-scope="{item}">{{item.name}}
  8. <WaterfallsFlowItem :item="item" :type="1" :isStore="1"/>
  9. </template>
  10. </WaterfallsFlow>
  11. </view>
  12. <view class='loadingicon acea-row row-center-wrapper' :hidden='loading==false'>
  13. <text class='loading iconfont icon-jiazai'></text>
  14. </view>
  15. <view class="mores-txt flex" v-if="goodScroll">
  16. <text>我是有底线的</text>
  17. </view>
  18. </block>
  19. </view>
  20. </template>
  21. <script>
  22. // +----------------------------------------------------------------------
  23. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  24. // +----------------------------------------------------------------------
  25. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  26. // +----------------------------------------------------------------------
  27. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  28. // +----------------------------------------------------------------------
  29. // | Author: CRMEB Team <admin@crmeb.com>
  30. // +----------------------------------------------------------------------
  31. import {
  32. mapGetters
  33. } from "vuex";
  34. import animationType from '@/utils/animationType.js'
  35. import {
  36. getProductHot
  37. } from '@/api/product.js';
  38. import WaterfallsFlow from '@/components/WaterfallsFlow/WaterfallsFlow.vue';
  39. import WaterfallsFlowItem from '@/components/WaterfallsFlowItem/WaterfallsFlowItem.vue';
  40. import TitleBox from '@/components/titleBox/index.vue';
  41. let app = getApp();
  42. export default {
  43. name: 'recommend',
  44. computed: mapGetters(['uid']),
  45. components: {
  46. WaterfallsFlow,
  47. TitleBox
  48. },
  49. props: {
  50. categoryId: {
  51. type: Number,
  52. default: function() {
  53. return 0;
  54. }
  55. },
  56. //是否显示头部
  57. isShowTitle: {
  58. type: Boolean,
  59. default: function() {
  60. return true;
  61. }
  62. },
  63. //是否使用本页面的请求数据
  64. isDefault: {
  65. type: Boolean,
  66. default: function() {
  67. return true;
  68. }
  69. },
  70. //使用的页面中调用数据传来的商品列表,isDefault为false时使用
  71. recommendList: {
  72. type: Array,
  73. default: function() {
  74. return [];
  75. }
  76. }
  77. },
  78. data() {
  79. return {
  80. urlDomain: this.$Cache.get("imgHost"),
  81. theme: app.globalData.theme,
  82. goodScroll: false,
  83. params: { //精品推荐分页
  84. page: 1,
  85. limit: 10,
  86. cid: 0
  87. },
  88. loading: false,
  89. tempArr: []
  90. };
  91. },
  92. watch: {
  93. categoryId: function(val) { //监听props中的属性
  94. if (!this.isDefault) {
  95. this.params.page = 1;
  96. this.tempArr = [];
  97. this.goodScroll = false;
  98. this.get_host_product()
  99. }
  100. }
  101. },
  102. mounted() {
  103. if (this.isDefault) {
  104. this.params.page = 1;
  105. this.goodScroll = false;
  106. this.tempArr = [];
  107. this.get_host_product()
  108. }else{
  109. this.tempArr = this.recommendList
  110. };
  111. },
  112. methods: {
  113. /**
  114. * 获取我的推荐
  115. */
  116. get_host_product: function() {
  117. if (this.goodScroll) return;
  118. this.loading = true
  119. this.params.cid = this.categoryId;
  120. getProductHot(
  121. this.params
  122. ).then((res) => {
  123. this.$set(this.params, 'page', this.params.page + 1);
  124. this.goodScroll = this.params.page > res.data.totalPage;
  125. this.tempArr = this.tempArr.concat(res.data.list || []);
  126. this.$emit('getRecommendLength', this.tempArr.length);
  127. this.loading = false
  128. }).catch(err => {
  129. this.loading = false
  130. });
  131. }
  132. },
  133. onReachBottom() {
  134. if (this.isDefault) this.get_host_product();
  135. }
  136. }
  137. </script>
  138. <style scoped lang="scss">
  139. .mores-txt {
  140. width: 100%;
  141. align-items: center;
  142. justify-content: center;
  143. height: 70rpx;
  144. color: #999;
  145. font-size: 24rpx;
  146. .iconfont {
  147. margin-top: 2rpx;
  148. font-size: 20rpx;
  149. }
  150. }
  151. .recommend {
  152. .title {
  153. height: 120rpx;
  154. line-height: 120rpx;
  155. font-size: 32rpx;
  156. color: #333333;
  157. .iconfont {
  158. font-size: 170rpx;
  159. color: #454545;
  160. }
  161. }
  162. .name {
  163. margin: 0 28rpx;
  164. }
  165. }
  166. .recommendList{
  167. background-color: #f5f5f5;
  168. }
  169. </style>