My_listbox.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <view class="container">
  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" />
  14. </view>
  15. <view id="bottom" />
  16. </scroll-view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. name: 'My_listbox',
  22. props: {
  23. getlist: Function,
  24. empty: Boolean,
  25. mode: {
  26. type: String,
  27. default: "data"
  28. },
  29. pullDown: {
  30. type: Boolean,
  31. default: true
  32. },
  33. occupyHeight: {
  34. type: Number,
  35. default: 50
  36. }
  37. },
  38. data() {
  39. return {
  40. inRefresh: false, //下拉开启自定义项
  41. height: 0,
  42. scrollIntoView: ""
  43. };
  44. },
  45. methods: {
  46. /* 下拉刷新 */
  47. pullToRefresh() {
  48. this.inRefresh = true
  49. this.$emit("getlist", true)
  50. },
  51. /* 刷新完成 */
  52. RefreshToComplete() {
  53. setTimeout(() => {
  54. this.inRefresh = false
  55. }, 500)
  56. },
  57. /* 加载分页 */
  58. loadThePage() {
  59. this.$emit("getlist", false)
  60. },
  61. /* 设置组件高度 */
  62. setHeight(mode, num) {
  63. return new Promise((resolve) => {
  64. this.getHeight("#mylisttop", this).then(res => {
  65. let height = res;
  66. switch (mode) {
  67. case 'add':
  68. height = (res - 0) + (num - 0);
  69. break;
  70. case 'minus':
  71. height = res - num;
  72. break;
  73. }
  74. if (this.height != height) this.height = height;
  75. resolve(height)
  76. });
  77. })
  78. }
  79. },
  80. }
  81. </script>
  82. <style lang="scss" scoped>
  83. .scroll-view {
  84. position: relative;
  85. }
  86. </style>