My_listbox.vue 3.5 KB

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