tableLists.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <div class="table-lists">
  3. <page-bar v-if="!hiddenFilter" class="top-bar">
  4. <slot name="filterContent"></slot>
  5. <slot name="filterButton">
  6. <Button type="primary" @click="reload()" v-if="filterType === 1">查 询</Button>
  7. <Button type="primary" @click="reload()" style="margin-left: 10px" v-if="filterReset === 1">重 置</Button>
  8. </slot>
  9. <div slot="right">
  10. <slot name="filterRight"></slot>
  11. </div>
  12. </page-bar>
  13. <slot></slot>
  14. <page-bar style="margin-top: 10px" :rightWidth="750">
  15. <slot name="options"></slot>
  16. <div slot="right">
  17. <Page
  18. @on-change="changePage"
  19. :current="page"
  20. :page-size="pageSizeData"
  21. :total="total"
  22. show-total
  23. show-elevator
  24. show-sizer
  25. @on-page-size-change="pageSizeChange"
  26. :page-size-opts="[10,20,50,100]"
  27. />
  28. </div>
  29. </page-bar>
  30. </div>
  31. </template>
  32. <script>
  33. import _ from 'lodash'
  34. export default {
  35. name: "tableLists",
  36. data() {
  37. return {
  38. page: 1,
  39. total: 0,
  40. pageSizeData: this.pageSize,
  41. };
  42. },
  43. props: {
  44. value: {
  45. type: [Array,Object],
  46. default: function () {
  47. return []
  48. }
  49. },
  50. filter: {
  51. type: Object,
  52. default: function () {
  53. return {}
  54. }
  55. },
  56. pageSize: {
  57. type: Number,
  58. default: 10
  59. },
  60. requestApi: {
  61. type: String,
  62. required: true
  63. },
  64. autoLoad: {
  65. type: Boolean,
  66. default: true
  67. },
  68. hiddenFilter: {
  69. type: Boolean,
  70. default: false
  71. },
  72. // 0 不显示查询按钮 1 搜索按钮触发 2 筛选条件发生变化触发筛选
  73. filterType: {
  74. type: Number,
  75. default: 1
  76. },
  77. // 0 不显示重置按钮 1 搜索按钮触发 2 筛选条件发生变化触发筛选
  78. filterReset: {
  79. type: Number,
  80. default: 1
  81. }
  82. },
  83. watch: {
  84. filter: {
  85. handler: function () {
  86. if (this.filterType === 2) {
  87. this.reload()
  88. }
  89. },
  90. deep: true
  91. }
  92. },
  93. created() {
  94. if (this.autoLoad) {
  95. this.load();
  96. }
  97. },
  98. methods: {
  99. changePage: function (page) {
  100. this.page = page;
  101. this.load();
  102. },
  103. pageSizeChange: function (size) {
  104. this.pageSizeData = size;
  105. this.reload();
  106. },
  107. load() {
  108. this.$emit('loading', true);
  109. this.$request(this.requestApi).data({
  110. offset: (this.page - 1) * this.pageSizeData,
  111. pageSize: this.pageSizeData,
  112. ..._.cloneDeep(this.filter)
  113. }).success((r) => {
  114. this.$emit('loading', false);
  115. this.total = r.data['total'];
  116. this.$emit('input', r.data);
  117. }).get()
  118. },
  119. reload(isPage) {
  120. if (!isPage) {
  121. this.page = 1;
  122. }
  123. this.load();
  124. },
  125. },
  126. }
  127. </script>
  128. <style lang="scss" scoped>
  129. .table-lists {
  130. .top-bar {
  131. padding: 10px 0;
  132. }
  133. }
  134. </style>