建材商城系统20241014
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.

106 lines
2.1 KiB

  1. function query(self, queryParams){
  2. // return (self.beforeGetData && self.beforeGetData()) ||
  3. // queryParams || self.queryParams
  4. // 深度合并对象
  5. return self.$utils.deepMergeObject(
  6. self.$utils.deepMergeObject(self.queryParams,
  7. (self.beforeGetData && self.beforeGetData()) || {}),
  8. queryParams)
  9. }
  10. export default {
  11. data() {
  12. return {
  13. queryParams: {
  14. pageNo: 1,
  15. pageSize: 10,
  16. },
  17. total : 0,
  18. List : [],
  19. hasMore: true, // 是否还有更多数据
  20. loading: false, // 是否正在加载
  21. }
  22. },
  23. onPullDownRefresh() {
  24. this.refreshList()
  25. },
  26. onReachBottom() {
  27. this.loadMore()
  28. },
  29. onLoad() {
  30. this.refreshList()
  31. },
  32. methods: {
  33. // 刷新列表
  34. refreshList() {
  35. this.queryParams.pageNo = 1;
  36. this.hasMore = true;
  37. this.List = [];
  38. this.loadList();
  39. },
  40. // 加载更多
  41. loadMore() {
  42. console.log(this.hasMore , this.loading);
  43. if (!this.hasMore || this.loading) return;
  44. this.queryParams.pageNo++;
  45. this.loadList();
  46. },
  47. // 加载订单列表
  48. loadList() {
  49. return new Promise((success, error) => {
  50. if(!this.mixinsListApi){
  51. return console.error('mixinsListApi 缺失');
  52. }
  53. if (this.loading) return;
  54. this.loading = true;
  55. const params = {
  56. ...this.queryParams,
  57. };
  58. this.$api(this.mixinsListApi, query(this, params), res => {
  59. this.loading = false;
  60. uni.stopPullDownRefresh();
  61. if (res.code === 200 && res.result) {
  62. this.getDataThen && this.getDataThen(res.result.records, res.result.total, res.result)
  63. success(res.result)
  64. const newList = res.result.records || [];
  65. this.total = res.result.total
  66. if (this.pageNo === 1) {
  67. this.List = newList;
  68. } else {
  69. this.List = [...this.List, ...newList];
  70. }
  71. // 判断是否还有更多数据
  72. this.hasMore = newList.length >= this.queryParams.pageSize;
  73. } else {
  74. uni.showToast({
  75. title: res.message || '加载失败',
  76. icon: 'none'
  77. });
  78. error(res)
  79. }
  80. })
  81. })
  82. },
  83. }
  84. }