ListTemplate.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div v-loading="loading">
  3. <m-search v-if="showSearch" class="mb-3" :items="searchItems" v-model="searchQuery" @search="onSearch" @reset="onSearch">
  4. <template #button>
  5. <slot name="button"></slot>
  6. </template>
  7. </m-search>
  8. <m-table
  9. :card-title="cardTitle"
  10. :items="items"
  11. :headers="headers"
  12. :total="total"
  13. :page-size="pageInfo.size"
  14. :page-current="pageInfo.current"
  15. v-bind="$attrs"
  16. @page-change="onPageChange"
  17. @sort-change="onSortChange"
  18. >
  19. <template #card-tools>
  20. <slot name="tool"></slot>
  21. </template>
  22. <template #actions="{ row }">
  23. <slot name="actions" :row="row"></slot>
  24. </template>
  25. </m-table>
  26. </div>
  27. </template>
  28. <script>
  29. import {
  30. getSolutionPage
  31. } from '@/api/salary'
  32. export default {
  33. name: 'salary-solution-list',
  34. props: {
  35. cardTitle: String,
  36. showSearch: {
  37. type: Boolean,
  38. default: true
  39. },
  40. history: {
  41. type: Number,
  42. default: 0
  43. },
  44. uuid: String
  45. },
  46. inject: ['env'],
  47. data () {
  48. return {
  49. searchQuery: {
  50. title: null
  51. },
  52. searchItems: [
  53. {
  54. label: '名称',
  55. prop: 'title',
  56. type: 'input',
  57. options: {
  58. placeholder: '请输入规则名称'
  59. }
  60. }
  61. ],
  62. items: [],
  63. headers: [
  64. { label: '名称', prop: 'title' },
  65. { label: '描述', prop: 'tag' },
  66. { label: '创建日期', prop: 'createDate' },
  67. { label: '操作', prop: 'actions' }
  68. ],
  69. loading: false,
  70. total: 0,
  71. orders: [{
  72. asc: false,
  73. column: 'performance_solution_id'
  74. }],
  75. pageInfo: {
  76. current: 1,
  77. size: 10
  78. },
  79. query: {}
  80. }
  81. },
  82. methods: {
  83. async onInit (entity, headers) {
  84. this.headers = headers ?? this.headers
  85. this.query = entity ? { ...entity } : {}
  86. this.getList()
  87. },
  88. async getList () {
  89. this.loading = true
  90. try {
  91. const { data } = await getSolutionPage({
  92. page: {
  93. ...this.pageInfo,
  94. orders: this.orders
  95. },
  96. entity: {
  97. ...this.searchQuery,
  98. history: this.history,
  99. uuid: this.uuid,
  100. env: this.env,
  101. ...this.query
  102. }
  103. })
  104. this.items = data.records.map(e => e.entity)
  105. this.total = data.total
  106. } catch (error) {
  107. this.$message.error(error)
  108. } finally {
  109. this.loading = false
  110. }
  111. },
  112. onSearch () {
  113. this.pageInfo.current = 1
  114. this.getList()
  115. },
  116. onPageChange (page) {
  117. this.pageInfo.current = page
  118. this.getList()
  119. },
  120. onSortChange (v) {
  121. this.orders = v
  122. this.getList()
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. </style>