Recommend.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div class="recommend" ref="container">
  3. <div class="title acea-row row-center-wrapper">
  4. <span class="iconfont icon-zhuangshixian"></span>
  5. <span class="name">为你推荐</span>
  6. <span class="iconfont icon-zhuangshixian lefticon"></span>
  7. </div>
  8. <div class="recommendList acea-row row-between-wrapper">
  9. <div
  10. @click="goDetail(item)"
  11. v-for="(item, index) in hostProduct"
  12. :key="index"
  13. class="item"
  14. >
  15. <div class="pictrue">
  16. <img :src="item.image" class="image" />
  17. <span
  18. class="pictrue_log_big pictrue_log_class"
  19. v-if="item.activity && item.activity.type === '1'"
  20. >秒杀</span
  21. >
  22. <span
  23. class="pictrue_log_big pictrue_log_class"
  24. v-if="item.activity && item.activity.type === '2'"
  25. >砍价</span
  26. >
  27. <span
  28. class="pictrue_log_big pictrue_log_class"
  29. v-if="item.activity && item.activity.type === '3'"
  30. >拼团</span
  31. >
  32. </div>
  33. <div class="name line1">{{ item.store_name }}</div>
  34. <div class="money font-color-red">
  35. ¥<span class="num">{{ item.price }}</span>
  36. </div>
  37. </div>
  38. </div>
  39. <Loading :loaded="loadend" :loading="loading"></Loading>
  40. </div>
  41. </template>
  42. <script>
  43. import { getHostProducts } from "@api/store";
  44. import Loading from "@components/Loading";
  45. import { goShopDetail } from "@libs/order";
  46. export default {
  47. name: "Recommend",
  48. props: {},
  49. components: {
  50. Loading
  51. },
  52. data: function() {
  53. return {
  54. hostProduct: [],
  55. page: 1,
  56. limit: 20,
  57. loadTitle: "",
  58. loading: false,
  59. loadend: false
  60. };
  61. },
  62. mounted: function() {
  63. this.hostProducts();
  64. this.$scroll(this.$refs.container.parentElement, () => {
  65. !this.loading && this.hostProducts();
  66. });
  67. },
  68. methods: {
  69. // 商品详情跳转
  70. goDetail(item) {
  71. goShopDetail(item).then(() => {
  72. this.$router.push({ path: "/detail/" + item.id });
  73. });
  74. },
  75. hostProducts: function() {
  76. let that = this;
  77. if (that.loading) return; //阻止下次请求(false可以进行请求);
  78. if (that.loadend) return; //阻止结束当前请求(false可以进行请求);
  79. that.loading = true;
  80. getHostProducts(that.page, that.limit).then(res => {
  81. that.loading = false;
  82. //apply();js将一个数组插入另一个数组;
  83. that.hostProduct.push.apply(that.hostProduct, res.data);
  84. that.loadend = res.data.length < that.limit; //判断所有数据是否加载完成;
  85. that.page = that.page + 1;
  86. });
  87. }
  88. }
  89. };
  90. </script>