GoodsCollection.vue 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <div ref="container">
  3. <div class="collectionGoods" v-if="collectProductList.length > 0">
  4. <router-link
  5. :to="{ path: '/detail/' + item.pid }"
  6. class="item acea-row row-between-wrapper"
  7. v-for="(item, index) in collectProductList"
  8. :key="index"
  9. >
  10. <div class="pictrue"><img :src="item.image" /></div>
  11. <div class="text acea-row row-column-between">
  12. <div class="infor line1">{{ item.store_name }}</div>
  13. <div class="acea-row row-between-wrapper">
  14. <div class="money font-color-red">¥{{ item.price }}</div>
  15. <div class="delete" @click.prevent="delCollection(index)">删除</div>
  16. </div>
  17. </div>
  18. </router-link>
  19. </div>
  20. <Loading :loaded="loadend" :loading="loading"></Loading>
  21. <div
  22. class="noCommodity"
  23. style="background-color:#fff;"
  24. v-if="collectProductList.length < 1 && page > 1"
  25. >
  26. <div class="noPictrue">
  27. <img src="@assets/images/noCollection.png" class="image" />
  28. </div>
  29. <Recommend></Recommend>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import Recommend from "@components/Recommend";
  35. import { getCollectUser, getCollectDel } from "@api/user";
  36. import Loading from "@components/Loading";
  37. export default {
  38. name: "GoodsCollection",
  39. components: {
  40. Recommend,
  41. Loading
  42. },
  43. props: {},
  44. data: function() {
  45. return {
  46. page: 1,
  47. limit: 20,
  48. collectProductList: [],
  49. loadTitle: "",
  50. loading: false,
  51. loadend: false
  52. };
  53. },
  54. mounted: function() {
  55. this.get_user_collect_product();
  56. this.$scroll(this.$refs.container, () => {
  57. !this.loading && this.get_user_collect_product();
  58. });
  59. },
  60. methods: {
  61. get_user_collect_product: function() {
  62. let that = this;
  63. if (that.loading) return; //阻止下次请求(false可以进行请求);
  64. if (that.loadend) return; //阻止结束当前请求(false可以进行请求);
  65. that.loading = true;
  66. getCollectUser(that.page, that.limit).then(res => {
  67. that.loading = false;
  68. //apply();js将一个数组插入另一个数组;
  69. that.collectProductList.push.apply(that.collectProductList, res.data);
  70. that.loadend = res.data.length < that.limit; //判断所有数据是否加载完成;
  71. that.page = that.page + 1;
  72. });
  73. },
  74. //删除收藏;
  75. delCollection: function(index) {
  76. let that = this,
  77. id = that.collectProductList[index].pid,
  78. category = that.collectProductList[index].category;
  79. getCollectDel(id, category).then(function() {
  80. that.$dialog.toast({
  81. mes: "删除收藏成功!",
  82. callback: () => {
  83. that.collectProductList.splice(index, 1);
  84. that.$set(that, "collectProductList", that.collectProductList);
  85. }
  86. });
  87. });
  88. }
  89. }
  90. };
  91. </script>