You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.9 KiB

4 years ago
  1. <template>
  2. <view class="app">
  3. <mescroll-body
  4. ref="mescrollRef"
  5. @init="mescrollInit"
  6. :top="0"
  7. @down="downCallback"
  8. :up="upOption"
  9. @up="loadList"
  10. >
  11. <product-list ref="productList" :list="list" listType="column"></product-list>
  12. </mescroll-body>
  13. <mix-loading v-if="isLoading" :type="2"></mix-loading>
  14. </view>
  15. </template>
  16. <script>
  17. import productList from '@/pages/product/components/product-list'
  18. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  19. export default {
  20. components: {
  21. productList
  22. },
  23. mixins: [MescrollMixin],
  24. data() {
  25. return {
  26. list: [],
  27. upOption:{
  28. auto: false, // 是否自动加载
  29. page: {
  30. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  31. size: 6 // 每页数据的数量
  32. },
  33. noMoreSize: 6
  34. },
  35. }
  36. },
  37. methods: {
  38. //加载热门推荐列表
  39. async loadList(e){
  40. if(this.$refs.productList){
  41. this.$refs.productList.loadType = e.num === 1 ? 'refresh': 'add';
  42. }
  43. const res = await this.$request('favorite', 'get', {
  44. offset: (e.num - 1) * e.size,
  45. limit: e.size,
  46. });
  47. const curList = res.data.map(item=> {
  48. return {
  49. fav_id: item._id,
  50. ...item.product
  51. }
  52. })
  53. if(e.num === 1){
  54. this.list = [];
  55. this.loaded && curList.forEach(item=> {item.loaded = true;})
  56. }
  57. this.list = this.list.concat(curList); //追加新数据
  58. this.mescroll.endSuccess(curList.length); //结束加载状态
  59. },
  60. mescrollInit(mescroll){
  61. this.isLoading = true;
  62. this.mescroll = mescroll;
  63. this.mescroll.resetUpScroll(false)
  64. }
  65. }
  66. }
  67. </script>
  68. <style>
  69. page{
  70. background-color: #f8f8f8;
  71. }
  72. </style>
  73. <style scoped lang="scss">
  74. .app{
  75. padding-top: 20rpx;
  76. padding-bottom: 20rpx;
  77. }
  78. </style>