table.hbs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <el-row>
  3. <!-- 表格头部 -->
  4. <el-row class="mb-20">
  5. <span class="list-title">
  6. {{ title }}
  7. <Lookicon v-if="filterButton('lookicon')" ref="Lookicon" :look-status="searchParams.lookStatus" @changeLook="changeLook" />
  8. </span>
  9. <el-button v-if="filterButton('add')" type="primary" :loading="global.loading" @click="$emit('rowOperation', {}, -1, 'add')">新增</el-button>
  10. <!-- <el-button v-if="filterButton('export')" :loading="global.loading" @click="exportExcel">导出</el-button> -->
  11. </el-row>
  12. <!-- 表格内容 -->
  13. <TableElement
  14. :table-data="list"
  15. :colum-obj="columObj"
  16. :page-obj="pageObj"
  17. :loading="global.loading"
  18. @rowOperation="rowOperation"
  19. @selectionChange="selectionChange"
  20. @getList="getList()"
  21. />
  22. </el-row>
  23. </template>
  24. <script>
  25. import TableElement from '@/components/ElmTable/index.vue'
  26. import request from '@/utils/request'
  27. import { deepClone } from '@/utils'
  28. export default {
  29. components: { TableElement },
  30. inject: ['global'],
  31. props: {
  32. treeIds: { // 侧边栏
  33. type: String,
  34. default: ''
  35. },
  36. searchParams: { // 搜索栏
  37. type: Object,
  38. default: () => ({})
  39. }
  40. },
  41. data() {
  42. return {
  43. openExport: false,
  44. list: [], // 数据
  45. selectedList: [], // 选中的数据
  46. pageObj: { // 分页配置
  47. current: 1,
  48. size: 10,
  49. total: 0,
  50. pages: 0
  51. },
  52. columObj: { // 表格配置
  53. lazy: 'true',
  54. columnData: [
  55. { text: true, prop: 'id', label: '序号' },
  56. {
  57. isOperation: true, prop: 'operation', label: '操作', align: 'center', sortable: false, fixed: 'right',
  58. operation: [
  59. { operation: 'see', type: 'text', label: '查看', isShow: (row) => this.filterButton('see') },
  60. { operation: 'edit', type: 'text', label: '编辑', isShow: (row) => this.filterButton('edit') },
  61. { operation: 'delete', type: 'text', label: '删除', isShow: (row) => this.filterButton('delete') },
  62. ]
  63. }
  64. ]
  65. }
  66. }
  67. },
  68. methods: {
  69. async getList(params) { // 表格数据 - 获取
  70. this.global.loading = true
  71. if (params != null) this.searchParams = params
  72. try {
  73. // TODO: 获取数据
  74. const { data } = { data: { records: [{ name: 'test' }], pages: 1, total: 1 }}
  75. // const { data } = await request('/fs/personinout/tvoucherrecords/freezeList', { params: this.genQuery() })
  76. // const { data } = await getInvitationPage(this.genQuery())
  77. const { records, pages, total } = data
  78. this.list = this.filterTabledata(records)
  79. Object.assign(this.pageObj, { pages, total })
  80. } finally {
  81. this.global.loading = false
  82. }
  83. },
  84. filterTabledata(list) { // 表格数据 - 过滤
  85. return list.map(item => ({
  86. ...item
  87. // TODO: 表格数据展示是否要转换(看情况)
  88. }))
  89. },
  90. async exportExcel() { // 导出
  91. this.global.loading = true
  92. try {
  93. // TODO: 导出接口
  94. // const res = await request('/fs/personinout/tvoucherrecords/freezeExport', { params: this.genQuery() })
  95. // const res = await exportExchangeOrder(this.genQuery())
  96. // this.downloadExcel(res)
  97. } finally {
  98. this.global.loading = false
  99. }
  100. },
  101. genQuery() { // 产生最终参数
  102. const { current, size } = this.pageObj
  103. const query = Object.assign({ current, size }, this.filterSearchParams()) // 分页 & 查询
  104. return query
  105. },
  106. filterSearchParams() { // 查询字段过滤(请求数据过滤查询不影响原数据)
  107. // 复制一份
  108. const params = deepClone(this.searchParams)
  109. // 自定义部分
  110. // TODO: 搜索数据过滤
  111. // if (this.searchParams.timerange?.length) {
  112. // params['starttime'] = this.searchParams.timerange[0]
  113. // params['endtime'] = this.searchParams.timerange[1]
  114. // delete params.timerange
  115. // }
  116. // 过滤空数据
  117. Object.entries(params).forEach(([key, val]) => {
  118. if (val == null || val === '') delete params[key]
  119. })
  120. return params
  121. },
  122. rowOperation(row, idx, actionName, params) { // 行操作
  123. console.log(actionName, row)
  124. this.$emit('rowOperation', row, idx, actionName, params)
  125. },
  126. selectionChange(list) { // 行选择
  127. this.selectedList = list
  128. },
  129. changeLook(e) {
  130. this.searchParams.lookStatus = e
  131. this.getList()
  132. }
  133. }
  134. }
  135. </script>
  136. <style scoped>
  137. </style>