Recommend.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. <!--<router-link-->
  10. <!--:to="{ path: '/detail/' + item.id }"-->
  11. <!--class="item"-->
  12. <!--v-for="(item, index) in hostProduct"-->
  13. <!--:key="index"-->
  14. <!--&gt;-->
  15. <div
  16. @click="goDetail(item)"
  17. v-for="(item, index) in hostProduct"
  18. :key="index"
  19. class="item"
  20. >
  21. <div class="pictrue">
  22. <img :src="item.image" class="image" />
  23. <span
  24. class="pictrue_log_big pictrue_log_class"
  25. v-if="item.activity && item.activity.type === '1'"
  26. >秒杀</span
  27. >
  28. <span
  29. class="pictrue_log_big pictrue_log_class"
  30. v-if="item.activity && item.activity.type === '2'"
  31. >砍价</span
  32. >
  33. <span
  34. class="pictrue_log_big pictrue_log_class"
  35. v-if="item.activity && item.activity.type === '3'"
  36. >拼团</span
  37. >
  38. </div>
  39. <div class="name line1">{{ item.store_name }}</div>
  40. <div class="money font-color-red">
  41. ¥<span class="num">{{ item.price }}</span>
  42. </div>
  43. </div>
  44. </div>
  45. <Loading :loaded="loadend" :loading="loading"></Loading>
  46. </div>
  47. </template>
  48. <script>
  49. import { getHostProducts } from "@api/store";
  50. import Loading from "@components/Loading";
  51. export default {
  52. name: "Recommend",
  53. props: {},
  54. components: {
  55. Loading
  56. },
  57. data: function() {
  58. return {
  59. hostProduct: [],
  60. page: 1,
  61. limit: 20,
  62. loadTitle: "",
  63. loading: false,
  64. loadend: false
  65. };
  66. },
  67. mounted: function() {
  68. this.hostProducts();
  69. this.$scroll(this.$refs.container.parentElement, () => {
  70. !this.loading && this.hostProducts();
  71. });
  72. },
  73. methods: {
  74. // 商品详情跳转
  75. goDetail(item) {
  76. if (item.activity && item.activity.type === "1") {
  77. this.$router.push({
  78. path:
  79. "/activity/seckill_detail/" +
  80. item.activity.id +
  81. "/" +
  82. item.activity.time +
  83. "/1"
  84. });
  85. } else if (item.activity && item.activity.type === "2") {
  86. this.$router.push({
  87. path: "/activity/dargain_detail/" + item.activity.id
  88. });
  89. } else if (item.activity && item.activity.type === "3") {
  90. this.$router.push({
  91. path: "/activity/group_detail/" + item.activity.id
  92. });
  93. } else {
  94. this.$router.push({ path: "/detail/" + item.id });
  95. }
  96. },
  97. hostProducts: function() {
  98. let that = this;
  99. if (that.loading) return; //阻止下次请求(false可以进行请求);
  100. if (that.loadend) return; //阻止结束当前请求(false可以进行请求);
  101. that.loading = true;
  102. getHostProducts(that.page, that.limit).then(res => {
  103. that.loading = false;
  104. //apply();js将一个数组插入另一个数组;
  105. that.hostProduct.push.apply(that.hostProduct, res.data);
  106. that.loadend = res.data.length < that.limit; //判断所有数据是否加载完成;
  107. that.page = that.page + 1;
  108. });
  109. }
  110. }
  111. };
  112. </script>