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.

96 lines
2.4 KiB

3 years ago
  1. // #ifdef MP-WEIXIN
  2. /* 小程序端 */
  3. export default{
  4. onLoad() {
  5. this.loadHotList('refresh');
  6. },
  7. onPullDownRefresh() {
  8. this.loadHotList('refresh');
  9. },
  10. onReachBottom(){
  11. this.loadHotList();
  12. },
  13. methods: {
  14. //加载热门推荐列表
  15. async loadHotList(type='add'){
  16. if(type === 'add'){
  17. if(this.loadingType === 2) return;
  18. this.page = this.page + 1;
  19. this.$refs.productList.loadType = 'add';
  20. }else{
  21. this.page = 1;
  22. this.hotList = [];
  23. if(this.$refs.productList){
  24. this.$refs.productList.loadType = 'refresh';
  25. }
  26. }
  27. this.loadingType = 1;
  28. const res = await this.$request('product', 'getHotList', {
  29. offset: (this.page - 1) * 10,
  30. limit: 10,
  31. });
  32. const curList = res.data;
  33. this.hotList = this.hotList.concat(curList); //追加新数据
  34. if(type === 'refresh'){
  35. uni.stopPullDownRefresh();//结束加载状态
  36. }
  37. setTimeout(()=>{
  38. this.loadingType = curList.length < 10 ? 2 : 0;
  39. }, 300)
  40. },
  41. },
  42. }
  43. // #endif
  44. // #ifndef MP-WEIXIN
  45. /* 非小程序端 */
  46. import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
  47. export default{
  48. mixins: [MescrollMixin],
  49. data() {
  50. return {
  51. upOption:{
  52. auto: false, // 是否自动加载
  53. page: {
  54. num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  55. size: 10 // 每页数据的数量
  56. },
  57. noMoreSize: 1,
  58. },
  59. }
  60. },
  61. computed: {
  62. headerHeight(){
  63. return 750 / uni.upx2px(750) * (this.systemInfo.navigationBarHeight + this.systemInfo.statusBarHeight);
  64. }
  65. },
  66. methods: {
  67. //加载热门推荐列表
  68. async loadHotList(e){
  69. if(e.num === 1){
  70. //第一页清空数据重载
  71. this.hotList = [];
  72. if(this.$refs.productList){
  73. this.$refs.productList.loadType = 'refresh';
  74. }
  75. }else{
  76. this.$refs.productList.loadType = 'add';
  77. }
  78. const res = await this.$request('product', 'getHotList', {
  79. offset: (e.num - 1) * e.size,
  80. limit: e.size,
  81. });
  82. const curList = res.data;
  83. this.hotList = this.hotList.concat(curList); //追加新数据
  84. this.mescroll.endSuccess(curList.length); //结束加载状态
  85. console.log(JSON.parse(JSON.stringify(res.data)));
  86. },
  87. mescrollInit(mescroll){
  88. this.isLoading = true;
  89. this.mescroll = mescroll;
  90. this.mescroll.resetUpScroll(false)
  91. }
  92. },
  93. }
  94. // #endif