My_listbox.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 + '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. },
  49. data() {
  50. return {
  51. inRefresh: false, //下拉开启自定义项
  52. height: 0,
  53. scrollIntoView: "",
  54. pagingText: "",
  55. bottomTips: false,
  56. empty: false
  57. };
  58. },
  59. mounted() {
  60. if (this.automatic) this.setHeight()
  61. },
  62. methods: {
  63. /* 下拉刷新 */
  64. pullToRefresh() {
  65. this.inRefresh = true
  66. this.$emit("getlist", true)
  67. },
  68. /* 刷新完成 */
  69. RefreshToComplete() {
  70. setTimeout(() => {
  71. this.inRefresh = false
  72. }, 500)
  73. },
  74. /* 加载分页 */
  75. loadThePage() {
  76. this.$emit("getlist", false)
  77. },
  78. /* 设置组件高度 */
  79. setHeight(mode, num) {
  80. return new Promise((resolve) => {
  81. this.getHeight("#mylisttop", this).then(res => {
  82. let height = res;
  83. switch (mode) {
  84. case 'add':
  85. height = (res - 0) + (num - 0);
  86. break;
  87. case 'minus':
  88. height = res - num;
  89. break;
  90. }
  91. if (this.height != height) this.height = height;
  92. resolve(height)
  93. });
  94. })
  95. },
  96. /* 分页 */
  97. paging(content, res) {
  98. content.pageNumber = res.pageNumber + 1;
  99. content.pageTotal = res.pageTotal;
  100. // this.pagingText = content.pageNumber + ' / ' + content.pageTotal;
  101. this.bottomTips = res.total != 0 && content.pageNumber >= content.pageTotal;
  102. this.empty = res.total == 0;
  103. return content;
  104. }
  105. },
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .scroll-view {
  110. position: relative;
  111. .paging {
  112. width: 100vw;
  113. text-align: center;
  114. position: absolute;
  115. bottom: 15px;
  116. }
  117. }
  118. </style>