en-list.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <view class="list">
  3. <Blank v-if="list.length<=0"></Blank>
  4. <view class="scroll-view" v-else>
  5. <scroll-view class="scroll-list" scroll-y="true" style="height: 100%;" @scrolltolower="onReachScollBottom"
  6. :scroll-top="scrollTop" @scroll="scroll">
  7. <slot name="listInfo" v-bind:pagingData="list"></slot>
  8. <view class="toMore" v-show="isAjax">{{$t('list.load')}}-----</view>
  9. </scroll-view>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. import Blank from 'components/en-utils/en-blank/en-blank'
  15. export default {
  16. components: {Blank},
  17. data() {
  18. return {
  19. list: [],
  20. scrollTop: 0,
  21. page: 1,
  22. total: null,
  23. isAjax: false,
  24. }
  25. },
  26. mounted() {
  27. this.getList()
  28. },
  29. methods: {
  30. scroll: function (e) {
  31. this.scrollTop = e.detail.scrollTop
  32. },
  33. onReachScollBottom() {
  34. if (this.isAjax || this.list.length === this.total) {
  35. return
  36. }
  37. this.getList()
  38. },
  39. getList() {
  40. this.isAjax = true
  41. this.$emit('getList', this.page)
  42. },
  43. startList() {
  44. this.list = []
  45. this.page = 1
  46. this.scrollTop = 0
  47. this.isAjax = false
  48. this.getList()
  49. },
  50. setList(list, total) {
  51. list.forEach((item) => {
  52. this.list.push(item)
  53. })
  54. this.total = total
  55. this.isAjax = false
  56. ++this.page;
  57. }
  58. },
  59. }
  60. </script>
  61. <style scoped lang="scss">
  62. .list {
  63. height: 100%;
  64. .scroll-view {
  65. flex: 1;
  66. overflow: auto;
  67. .scroll-list {
  68. width: 100%;
  69. max-height: 100vh;
  70. }
  71. }
  72. .toMore {
  73. color: #999;
  74. font-size: 20rpx;
  75. margin: 25rpx 0;
  76. text-align: center;
  77. }
  78. ::-webkit-scrollbar {
  79. display: none;
  80. width: 0;
  81. height: 0;
  82. background-color: transparent;
  83. }
  84. }
  85. </style>