拓恒河湖长制全民护河平台WEB端
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.

97 lines
2.6KB

  1. // components/List/index.js
  2. import { getDataByPath } from "../../utils/util"
  3. import { get } from "../../utils/api"
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. url: {
  10. type: String
  11. },
  12. dataPath: {
  13. type: String
  14. },
  15. list: {
  16. type: Array
  17. },
  18. params: {
  19. type: Object,
  20. },
  21. limit: {
  22. type: Number,
  23. value: 10
  24. },
  25. scrolling:{
  26. type:Boolean,
  27. value:true,
  28. },
  29. emptyText:{
  30. type:String,
  31. value:"暂无数据"
  32. }
  33. },
  34. /**
  35. * 组件的初始数据
  36. */
  37. data: {
  38. page: 1,
  39. limit: 10,
  40. more: true,
  41. loading: false
  42. },
  43. // 数据监听器
  44. observers: {
  45. "url,params"(url) {
  46. if (!url) return
  47. this.resetPage();
  48. },
  49. },
  50. /**
  51. * 组件的方法列表
  52. */
  53. methods: {
  54. loadMore() {
  55. let page = this.data.page + 1;
  56. this.setData({ page })
  57. this.getData();
  58. },
  59. getData() {
  60. if (!this.data.more) return
  61. if (!this.data.loading && (!this.data.params || Object.keys(this.data.params).length > 0)) {
  62. this.setData({ loading: true })
  63. // 增加租户id
  64. let {tenantId} = wx.getStorageSync('tenant')
  65. if(this.data?.params) {
  66. this.data.params.tenantId = tenantId
  67. }
  68. get(this.data.url, Object.assign({}, { page: this.data.page, limit: this.data.limit }, this.data.params || {})).then(res => {
  69. let records;
  70. if (res.code == 0) {
  71. records = getDataByPath(res, this.data.dataPath || "data.records")
  72. } else {
  73. records = [];
  74. }
  75. if (records.length < this.data.limit) {
  76. this.setData({ more: false })
  77. }
  78. this.triggerEvent("update-list", records)
  79. }).catch(e => {
  80. wx.showToast({
  81. title: e || '系统错误',
  82. duration: 1500,
  83. });
  84. }).finally(() => {
  85. this.setData({ loading: false })
  86. })
  87. }
  88. },
  89. resetPage() {
  90. this.setData({ more: true, page: 1 })
  91. this.triggerEvent('reset-list')
  92. this.getData();
  93. }
  94. }
  95. })