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

102 lines
1.9 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. },
  25. onReachBottom() {
  26. },
  27. onShow() {
  28. },
  29. methods: {
  30. // 刷新列表
  31. refreshList() {
  32. this.pageNo = 1;
  33. this.hasMore = true;
  34. this.orderList = [];
  35. this.loadList();
  36. },
  37. // 加载更多
  38. loadMore() {
  39. if (!this.hasMore || this.loading) return;
  40. this.pageNo++;
  41. this.loadList();
  42. },
  43. // 加载订单列表
  44. loadList() {
  45. return new Promise((success, error) => {
  46. if(!this.mixinsListApi){
  47. return console.error('mixinsListApi 缺失');
  48. }
  49. if (this.loading) return;
  50. this.loading = true;
  51. const params = {
  52. ...this.queryParams,
  53. };
  54. this.$api(this.mixinsListApi, query(this, params))
  55. .then(res => {
  56. this.loading = false;
  57. uni.stopPullDownRefresh();
  58. if (res.code === 200 && res.result) {
  59. this.getDataThen && this.getDataThen(res.result.records, res.result.total, res.result)
  60. success(res.result)
  61. const newList = res.result.records || [];
  62. this.total = res.result.total
  63. if (this.pageNo === 1) {
  64. this.List = newList;
  65. } else {
  66. this.List = [...this.List, ...newList];
  67. }
  68. // 判断是否还有更多数据
  69. this.hasMore = newList.length >= this.pageSize;
  70. } else {
  71. uni.showToast({
  72. title: res.message || '加载失败',
  73. icon: 'none'
  74. });
  75. error(res)
  76. }
  77. })
  78. })
  79. },
  80. }
  81. }