recommend.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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: 0
  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.tabActive, '子组件响应0000000000000000000000')
  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. console.log(this.params, '推荐')
  140. api(this.params).then((res) => {
  141. this.$set(this.params, 'page', this.params.page + 1);
  142. this.goodScroll = this.params.page > res.data.totalPage;
  143. this.tempArr = this.tempArr.concat(res.data.list || []);
  144. this.$emit('getRecommendLength', this.tempArr.length);
  145. this.loading = false
  146. }).catch(err => {
  147. this.loading = false
  148. });
  149. },
  150. initParams(text) {
  151. this.params = { //精品推荐分页
  152. page: 1,
  153. limit: 10,
  154. cid: 0,
  155. keywords: text || ''
  156. };
  157. this.tempArr = [];
  158. this.goodScroll = false;
  159. this.get_host_product()
  160. }
  161. },
  162. onReachBottom() {
  163. if (this.isDefault) this.get_host_product();
  164. }
  165. }
  166. </script>
  167. <style scoped lang="scss">
  168. .mores-txt {
  169. width: 100%;
  170. align-items: center;
  171. justify-content: center;
  172. height: 70rpx;
  173. color: #999;
  174. font-size: 24rpx;
  175. .iconfont {
  176. margin-top: 2rpx;
  177. font-size: 20rpx;
  178. }
  179. }
  180. .recommend {
  181. .title {
  182. height: 120rpx;
  183. line-height: 120rpx;
  184. font-size: 32rpx;
  185. color: #333333;
  186. .iconfont {
  187. font-size: 170rpx;
  188. color: #454545;
  189. }
  190. }
  191. .name {
  192. margin: 0 28rpx;
  193. }
  194. }
  195. .recommendList{
  196. background-color: #f5f5f5;
  197. }
  198. </style>