groupList.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <!-- 父组件使用 -->
  3. <view :class="['qn-page-' + theme]">
  4. <scroll-view scroll-y class="goods-scroll" lower-threshold="100px" @scrolltolower="lower">
  5. <Aempty text="暂无数据" src="https://onlineimg.qianniao.vip/search.png" v-if="shoppingList.length === 0"></Aempty>
  6. <!-- 循环item出来为对象 -->
  7. <block v-for="(item, index) in shoppingList" :key="index"><GoodsItem :isList="is_list" :item="item" @addCart="addCard(item.id)"></GoodsItem></block>
  8. <u-loadmore margin-top="20" v-if="shoppingList.length" :status="loading_status" />
  9. </scroll-view>
  10. <CartFloat />
  11. <AddCardModel @close="is_add_show = false" :isShow="is_add_show" @change="cardModelPopChange" :goodsId="goods_id" />
  12. </view>
  13. </template>
  14. <script>
  15. import GoodsItem from '@/components/GoodsItem.vue';
  16. import CartFloat from '../components/CartFloat.vue';
  17. import AddCardModel from '@/components/AddCardModel';
  18. export default {
  19. components: {
  20. GoodsItem,
  21. CartFloat,
  22. AddCardModel
  23. },
  24. data() {
  25. return {
  26. tab_current: 0,
  27. is_list: false,
  28. is_add_show: false,
  29. goods_id: 0,
  30. shoppingList: [],
  31. groupId: 1,
  32. page: 1,
  33. pageSize: 10,
  34. loading_status: 'loadmore'
  35. };
  36. },
  37. // 下拉刷新
  38. onPullDownRefresh() {
  39. this.getGoodsByCategory();
  40. },
  41. async onLoad(options) {
  42. this.groupId = options.id;
  43. await this.getGoodsByCategory();
  44. uni.setNavigationBarTitle({
  45. title: options.name || ''
  46. });
  47. },
  48. methods: {
  49. // 切换商品列表展示样式
  50. changeStyle() {
  51. this.is_list = !this.is_list;
  52. },
  53. cardModelPopChange(obj) {
  54. if (!obj.show) {
  55. this.is_add_show = false;
  56. }
  57. },
  58. addCard(id) {
  59. this.goods_id = id;
  60. this.is_add_show = true;
  61. },
  62. // 上拉加载
  63. lower() {
  64. if (this.pageTotal / this.pageSize > this.page) {
  65. this.page += 1;
  66. this.getGoodsByCategory();
  67. }
  68. },
  69. // 获取商品列表
  70. getGoodsByCategory() {
  71. this.loading_status = 'loading';
  72. this.$u.api
  73. .getGoodsByCategory({
  74. goodsGroups: this.groupId,
  75. page: this.page,
  76. pageSize: this.pageSize
  77. })
  78. .then(data => {
  79. uni.stopPullDownRefresh();
  80. if (this.page === 1) {
  81. this.shoppingList = data.data;
  82. } else {
  83. this.shoppingList = this.shoppingList.concat(data.data);
  84. }
  85. this.pageTotal = data.pageTotal;
  86. this.loading_status = this.$_utils.loadStatus(this.page, this.pageSize, this.pageTotal);
  87. });
  88. },
  89. }
  90. };
  91. </script>
  92. <style lang="scss" scoped>
  93. .goods-scroll {
  94. padding: 0;
  95. height: 100vh;
  96. }
  97. .flist-no {
  98. padding-top: 0;
  99. height: 100vh;
  100. }
  101. </style>