recommend.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 :isDynamics="dynamics" :userFair="dynamics" :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. getSecondHandHot
  38. } from '@/api/product.js';
  39. import WaterfallsFlow from '@/components/WaterfallsFlow/WaterfallsFlow.vue';
  40. import WaterfallsFlowItem from '@/components/WaterfallsFlowItem/WaterfallsFlowItem.vue';
  41. import TitleBox from '@/components/titleBox/index.vue';
  42. let app = getApp();
  43. export default {
  44. name: 'recommend',
  45. computed: mapGetters(['uid']),
  46. components: {
  47. WaterfallsFlow,
  48. TitleBox
  49. },
  50. props: {
  51. categoryId: {
  52. type: Number,
  53. default: function() {
  54. return 0;
  55. }
  56. },
  57. //是否显示头部
  58. isShowTitle: {
  59. type: Boolean,
  60. default: function() {
  61. return true;
  62. }
  63. },
  64. //是否使用本页面的请求数据
  65. isDefault: {
  66. type: Boolean,
  67. default: function() {
  68. return true;
  69. }
  70. },
  71. //使用的页面中调用数据传来的商品列表,isDefault为false时使用
  72. recommendList: {
  73. type: Array,
  74. default: function() {
  75. return [];
  76. }
  77. },
  78. dynamics: {
  79. type: Boolean,
  80. default: false
  81. },
  82. tabActive: {
  83. type: Number,
  84. default: 1
  85. }
  86. },
  87. data() {
  88. return {
  89. urlDomain: this.$Cache.get("imgHost"),
  90. theme: app.globalData.theme,
  91. goodScroll: false,
  92. params: { //精品推荐分页
  93. page: 1,
  94. limit: 10,
  95. cid: 0
  96. },
  97. loading: false,
  98. tempArr: []
  99. };
  100. },
  101. watch: {
  102. categoryId: function(val) { //监听props中的属性
  103. if (!this.isDefault) {
  104. this.params.page = 1;
  105. this.tempArr = [];
  106. this.goodScroll = false;
  107. this.get_host_product()
  108. }
  109. }
  110. },
  111. mounted() {
  112. if (this.isDefault) {
  113. this.params.page = 1;
  114. this.goodScroll = false;
  115. this.tempArr = [];
  116. this.get_host_product()
  117. }else{
  118. this.tempArr = this.recommendList
  119. };
  120. },
  121. methods: {
  122. /**
  123. * 获取我的推荐
  124. */
  125. get_host_product: function() {
  126. if (this.goodScroll) return;
  127. this.loading = true
  128. this.params.cid = this.categoryId;
  129. console.log(this.params, '推荐')
  130. if (this.tabActive == 0 && this.dynamics) {
  131. this.params.range = 'school'
  132. } else if (this.tabActive == 1 && this.dynamics) {
  133. this.params.range = 'city'
  134. this.params.city = uni.getStorageSync('cityName')
  135. } else if (this.tabActive == 2 && this.dynamics) {
  136. this.params.range = 'all'
  137. }
  138. let api = this.dynamics ? getSecondHandHot : getProductHot;
  139. api(this.params).then((res) => {
  140. this.$set(this.params, 'page', this.params.page + 1);
  141. this.goodScroll = this.params.page > res.data.totalPage;
  142. this.tempArr = this.tempArr.concat(res.data.list || []);
  143. this.$emit('getRecommendLength', this.tempArr.length);
  144. this.loading = false
  145. }).catch(err => {
  146. this.loading = false
  147. });
  148. }
  149. },
  150. onReachBottom() {
  151. if (this.isDefault) this.get_host_product();
  152. }
  153. }
  154. </script>
  155. <style scoped lang="scss">
  156. .mores-txt {
  157. width: 100%;
  158. align-items: center;
  159. justify-content: center;
  160. height: 70rpx;
  161. color: #999;
  162. font-size: 24rpx;
  163. .iconfont {
  164. margin-top: 2rpx;
  165. font-size: 20rpx;
  166. }
  167. }
  168. .recommend {
  169. .title {
  170. height: 120rpx;
  171. line-height: 120rpx;
  172. font-size: 32rpx;
  173. color: #333333;
  174. .iconfont {
  175. font-size: 170rpx;
  176. color: #454545;
  177. }
  178. }
  179. .name {
  180. margin: 0 28rpx;
  181. }
  182. }
  183. .recommendList{
  184. background-color: #f5f5f5;
  185. }
  186. </style>