list.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. export default {
  2. watch: {
  3. 'list.loading'(val) {
  4. if (val) {
  5. // uni.showLoading({
  6. // title: '加载中...',
  7. // mask: true
  8. // });
  9. } else {
  10. // uni.hideLoading();
  11. }
  12. }
  13. },
  14. computed: {
  15. totalPages() {
  16. if (!this.$util.isEmpty(this.list.total)) {
  17. return Math.ceil(this.list.total / this.list.limit);
  18. }
  19. return 0;
  20. }
  21. },
  22. data() {
  23. return {
  24. list: {
  25. data: [],
  26. page: 1,
  27. pageSize: 10,
  28. loading: true,
  29. finished: false,
  30. total: 0
  31. }
  32. };
  33. },
  34. methods: {
  35. resetList() {
  36. this.list = {
  37. data: [],
  38. page: 1,
  39. pageSize: 10,
  40. loading: true,
  41. finished: false,
  42. total: null
  43. };
  44. },
  45. completes(res, listKey) {
  46. this.list.loading = false;
  47. // if (res.code !== 1) {
  48. // this.list.finished = true;
  49. // }
  50. this.list.data =
  51. this.list.page === 1
  52. ? res.list || res.data || res[listKey]
  53. : this.list.data.concat(res.list || res.data || res[listKey]);
  54. this.list.total = res.totalPage * this.list.pageSize;
  55. if (res.moreData == 0) {
  56. this.list.finished = true;
  57. } else {
  58. ++this.list.page;
  59. }
  60. }
  61. }
  62. };