en-list.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. },
  49. setList(list, total) {
  50. list.forEach((item) => {
  51. this.list.push(item)
  52. })
  53. this.total = total
  54. this.isAjax = false
  55. ++this.page;
  56. }
  57. },
  58. }
  59. </script>
  60. <style scoped lang="scss">
  61. .list {
  62. height: 100%;
  63. .scroll-view {
  64. flex: 1;
  65. overflow: auto;
  66. .scroll-list {
  67. width: 100%;
  68. max-height: 100vh;
  69. }
  70. }
  71. .toMore {
  72. color: #999;
  73. font-size: 20rpx;
  74. margin: 25rpx 0;
  75. text-align: center;
  76. }
  77. ::-webkit-scrollbar {
  78. display: none;
  79. width: 0;
  80. height: 0;
  81. background-color: transparent;
  82. }
  83. }
  84. </style>