list.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. data() {
  15. return {
  16. list: {
  17. data: [],
  18. page: 1,
  19. pageSize: 20,
  20. loading: true,
  21. finished: false,
  22. total: 0,
  23. totalPage: 0
  24. }
  25. }
  26. },
  27. methods: {
  28. resetList() {
  29. this.list = {
  30. data: [],
  31. page: 1,
  32. pageSize: 20,
  33. loading: false,
  34. finished: false,
  35. total: null,
  36. totalPage: null
  37. }
  38. },
  39. completes(res, listKey) {
  40. this.list.loading = false
  41. if (res.code !== 1) {
  42. this.list.finished = true
  43. }
  44. let listArr = res.data.list || res.data.data || res.data[listKey]
  45. this.list.data = this.list.page === 1 ? listArr : this.list.data.concat(listArr)
  46. this.list.total = res.data.totalPage * this.list.pageSize
  47. this.list.totalPage = res.data.totalPage || res.totalPage
  48. // if(res.data.moreData) {
  49. // this.list.moreData = res.data.moreData
  50. // }
  51. if (!res.data.moreData) {
  52. this.list.finished = true
  53. } else {
  54. ++this.list.page
  55. }
  56. }
  57. }
  58. }