newTableMixin.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import Vue from 'vue'
  2. import { cloneDeep } from 'lodash'
  3. export const newTableMixin = {
  4. data() {
  5. return {
  6. ipagination: {
  7. current: 1,
  8. pageSize: 10,
  9. pageSizeOptions: ['10', '20', '30', '50', '100'],
  10. showTotal: (total, range) => {
  11. return range[0] + '-' + range[1] + ' 共' + total + '条'
  12. },
  13. showQuickJumper: true,
  14. showSizeChanger: true,
  15. total: 0,
  16. },
  17. /* table选中keys*/
  18. selectedRowKeys: [],
  19. /* table选中records*/
  20. selectionRows: [],
  21. /* 排序参数 */
  22. isorter: {
  23. column: 'createTime',
  24. order: 'desc',
  25. },
  26. editableData: {},
  27. // colList: ['categoryName', 'newPosition', 'differenceCount', 'differenceReason'],
  28. colList: ['categoryName'],
  29. }
  30. },
  31. methods: {
  32. //table功能
  33. onSelectChange(selectedRowKeys, selectionRows) {
  34. this.selectedRowKeys = selectedRowKeys
  35. this.selectionRows = selectionRows
  36. },
  37. handleTableChange(pagination, filters, sorter) {
  38. //分页、排序、筛选变化时触发
  39. if (Object.keys(sorter).length > 0) {
  40. if (sorter.order) {
  41. this.isorter.column = sorter.field
  42. this.isorter.order = 'ascend' === sorter.order ? 'asc' : 'desc'
  43. } else {
  44. this.isorter.column = 'createTime'
  45. this.isorter.order = 'desc'
  46. }
  47. }
  48. if (pagination && pagination.current) {
  49. this.ipagination = pagination
  50. }
  51. this.getList()
  52. },
  53. //禁止点击表格某一行
  54. getCheckboxProps(record) {
  55. return {
  56. props: {
  57. disabled: record.taskStatus !== 1,
  58. },
  59. }
  60. },
  61. getTaskkboxProps(record) {
  62. return {
  63. props: {
  64. disabled: record.taskStatus !== 1 && record.taskStatus !== 4,
  65. },
  66. }
  67. },
  68. // --------------------------------------------------------------------
  69. formateTaskStatus(type) {
  70. switch (type) {
  71. case 1:
  72. return '未开始'
  73. case 2:
  74. return '进行中'
  75. case 3:
  76. return '已完成'
  77. case 4:
  78. return '已取消'
  79. default:
  80. return ''
  81. }
  82. },
  83. onSearch() {
  84. this.ipagination.current = 1
  85. this.getList()
  86. },
  87. onReset() {
  88. this.queryParam = {}
  89. this.onSearch()
  90. this.$forceUpdate()
  91. },
  92. edit(id, col) {
  93. this.editableData[id] = cloneDeep(this.dataSource.filter((item) => id === item.id)[0])
  94. this.$forceUpdate()
  95. },
  96. save(id) {
  97. Object.assign(this.dataSource.filter((item) => id === item.id)[0], this.editableData[id])
  98. delete this.editableData[id]
  99. },
  100. cancel(id) {
  101. delete this.editableData[id]
  102. },
  103. },
  104. }