en-list.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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="listStyle" @scrolltolower="onReachScollBottom"
  6. :scroll-top="scrollTop" @scroll="scroll">
  7. <slot name="listInfo" v-bind:pagingData="list"></slot>
  8. <view class="toMore" v-show="isAjax">加载中...</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. props:{
  18. 'height':{
  19. default:''
  20. },
  21. 'isAll':{
  22. type:Boolean,
  23. default:false
  24. }
  25. },
  26. data() {
  27. return {
  28. list: [],
  29. scrollTop: 0,
  30. page: 1,
  31. total: null,
  32. isAjax: false,
  33. listStyle:{
  34. 'height':'calc(100vh - env(safe-area-inset-bottom))'
  35. }
  36. }
  37. },
  38. watch: {
  39. 'height':function (){
  40. this.setHeight()
  41. },
  42. 'isAll':function () {
  43. this.setHeight()
  44. }
  45. },
  46. mounted() {
  47. this.getList()
  48. this.setHeight()
  49. },
  50. methods: {
  51. setHeight(){
  52. if(this.isAll){
  53. this.listStyle.height='100vh'
  54. }else {
  55. if(this.height){
  56. if(this.height>0){
  57. this.listStyle.height='calc(100vh - env(safe-area-inset-bottom) - '+this.height+'rpx)'
  58. }else if(this.height<0){
  59. this.listStyle.height='calc(100vh - env(safe-area-inset-bottom) + '+(this.height*-1)+'rpx)'
  60. }
  61. }
  62. }
  63. },
  64. scroll: function (e) {
  65. this.scrollTop = e.detail.scrollTop
  66. },
  67. onReachScollBottom() {
  68. if (this.isAjax || this.list.length === this.total) {
  69. return
  70. }
  71. this.getList()
  72. },
  73. getList() {
  74. this.isAjax = true
  75. this.$emit('getList', this.page)
  76. },
  77. startList() {
  78. this.list = []
  79. this.page = 1
  80. this.scrollTop = 0
  81. this.isAjax = false
  82. },
  83. setList(list, total) {
  84. list.forEach((item) => {
  85. this.list.push(item)
  86. })
  87. this.total = total
  88. this.isAjax = false
  89. ++this.page
  90. }
  91. },
  92. }
  93. </script>
  94. <style scoped lang="scss">
  95. .list {
  96. height: 100%;
  97. .scroll-view {
  98. flex: 1;
  99. overflow: auto;
  100. .scroll-list {
  101. width: 100%;
  102. max-height: 100vh;
  103. }
  104. }
  105. .toMore {
  106. color: #999;
  107. font-size: 20rpx;
  108. margin: 25rpx 0;
  109. text-align: center;
  110. }
  111. ::-webkit-scrollbar {
  112. display: none;
  113. width: 0;
  114. height: 0;
  115. background-color: transparent;
  116. }
  117. }
  118. </style>