My_listbox.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <view class="container" :style="{ background: boxBackground }">
  3. <view id="mylisttop" />
  4. <scroll-view class="scroll-view" scroll-y :refresher-enabled='pullDown' :refresher-triggered='inRefresh'
  5. :style="{ height: (defaultHeight - 0 || height - 0) + 'px' }" :triggered='true'
  6. @refresherrefresh='pullToRefresh' :scroll-into-view="scrollIntoView" :lower-threshold='300'
  7. :scroll-with-animation="true" @scrolltolower='loadThePage'>
  8. <view v-if="isShowEmpty && empty"
  9. style="display: flex;align-items: center;width: 100vw;justify-content: center;"
  10. :style="{ height: (defaultHeight - 0 || height - 0) + 'px' }">
  11. <view :style="{ marginTop: '-' + tovw(bottomHeight) }">
  12. <u-empty :mode="mode" text="暂无数据" />
  13. </view>
  14. </view>
  15. <block v-else>
  16. <view id="header">
  17. <slot />
  18. </view>
  19. <view id="bottom" />
  20. <view v-if="pagingText" class="paging">
  21. {{ pagingText }}
  22. </view>
  23. <u-divider v-if="bottomTips" text="已经到底部" :dashed="true" />
  24. <view v-if="bottomHeight" :style="{ height: tovw(bottomHeight) }" />
  25. </block>
  26. </scroll-view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. name: 'My_listbox',
  32. props: {
  33. getlist: Function,
  34. automatic: {
  35. type: Boolean,
  36. default: true
  37. },
  38. mode: {
  39. type: String,
  40. default: "data"
  41. },
  42. pullDown: {
  43. type: Boolean,
  44. default: true
  45. },
  46. boxBackground: {
  47. type: String,
  48. default: ""
  49. },
  50. defaultHeight: {
  51. type: [String, Number],
  52. default: 0
  53. },
  54. isShowEmpty: {
  55. type: Boolean,
  56. default: true
  57. },
  58. bottomHeight: {
  59. type: [Number, String],
  60. default: 0
  61. }
  62. },
  63. data() {
  64. return {
  65. inRefresh: false, //下拉开启自定义项
  66. height: 0,
  67. scrollIntoView: "",
  68. pagingText: "",
  69. bottomTips: false,
  70. empty: false
  71. };
  72. },
  73. mounted() {
  74. if (this.automatic) setTimeout(() => {
  75. this.setHeight()
  76. }, 100);
  77. },
  78. methods: {
  79. /* 下拉刷新 */
  80. pullToRefresh() {
  81. this.inRefresh = true
  82. this.$emit("getlist", true)
  83. },
  84. /* 刷新完成 */
  85. RefreshToComplete() {
  86. setTimeout(() => {
  87. this.inRefresh = false
  88. }, 500)
  89. },
  90. /* 加载分页 */
  91. loadThePage() {
  92. this.$emit("getlist", false)
  93. },
  94. /* 设置组件高度 */
  95. setHeight(mode, num) {
  96. return new Promise((resolve) => {
  97. this.getHeight("#mylisttop", this).then(res => {
  98. let height = res;
  99. switch (mode) {
  100. case 'add':
  101. height = (res - 0) + (num - 0);
  102. break;
  103. case 'minus':
  104. height = res - num;
  105. break;
  106. }
  107. if (this.height != height) this.height = height;
  108. resolve(height)
  109. });
  110. })
  111. },
  112. /* 分页 */
  113. paging(data, res, update = false) {
  114. let content = JSON.parse(JSON.stringify(data))
  115. content.pageNumber = res.pageNumber + 1;
  116. content.pageTotal = res.pageTotal;
  117. // this.pagingText = content.pageNumber + ' / ' + content.pageTotal;
  118. if (!update) this.bottomTips = res.total != 0 && content.pageNumber >= content.pageTotal;
  119. if (this.isShowEmpty) this.empty = res.total == 0;
  120. return content;
  121. }
  122. },
  123. }
  124. </script>
  125. <style lang="scss" scoped>
  126. .scroll-view {
  127. position: relative;
  128. .paging {
  129. width: 100vw;
  130. text-align: center;
  131. position: absolute;
  132. bottom: 15px;
  133. }
  134. }
  135. </style>