mainList.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. export default {
  2. data() {
  3. return {
  4. listData: [],
  5. listParams: {
  6. page: 0,
  7. limit: 15
  8. },
  9. listStatus: ''
  10. }
  11. },
  12. methods: {
  13. getList(params = {}, refresh = false) {
  14. if (!this.GetListFn) return
  15. if (!refresh && this.listStatus === 'loading') return
  16. this.listStatus = 'loading'
  17. if (refresh) {
  18. this.listOver = false
  19. this.listParams.page = 0
  20. }
  21. this.listParams.page++
  22. this.listParams = Object.assign(this.listParams, params)
  23. // 额外附加的参数
  24. if (this.getParams) {
  25. const params = this.getParams()
  26. this.listParams = Object.assign(this.listParams, params)
  27. }
  28. const flag = this.beforeGetList(this.listParams)
  29. if (!flag) {
  30. this.listStatus = 'more'
  31. return
  32. }
  33. this.GetListFn(this.listParams).then(res => {
  34. console.log('list refresh: ', refresh)
  35. if (this.listParams.page === 1) {
  36. this.listData = []
  37. }
  38. this.listData = this.listData.concat(res.list)
  39. // this.listData = res.list.slice(0, 2)
  40. if (res.hasOwnProperty('lastPage')) {
  41. this.listStatus = res.lastPage ? 'noMore' : 'more'
  42. } else {
  43. this.listStatus = res.list.length === 0 ? 'noMore' : 'more'
  44. }
  45. // console.log('list status: ', this.listStatus, res)
  46. // 列表数据获取完成后回调
  47. if (this.getListCallback) {
  48. this.getListCallback(res)
  49. }
  50. }).catch(() => {
  51. this.listStatus = 'more'
  52. })
  53. },
  54. getParams() {
  55. return {}
  56. },
  57. beforeGetList() {
  58. return true
  59. }
  60. }
  61. }