Newer
Older
KaiFengPC / src / views / preassess / scaleConfig / useColumns.jsx
@zhangdeliang zhangdeliang on 23 May 3 KB 初始化项目
  1. import { reactive } from 'vue'
  2. import { optTextMap, statusMap } from '@/utils/map'
  3. import {
  4. facilitiesSuggestRateConfigDel,
  5. facilitiesSuggestRateConfigCopy,
  6. facilitiesSuggestRateConfigEnable
  7. } from '@/api/preassess/scaleConfig'
  8. export default function useColumns(proxy, getTableList) {
  9. const visible = ref(false)
  10. const row = ref({})
  11. const opts = reactive({
  12. type: '',
  13. text: ''
  14. })
  15. const columns = reactive([
  16. {
  17. prop: 'configName',
  18. label: '记录名称',
  19. render: ({ row }) => {
  20. return <span style="color: #409eef">{ row.configName }</span>
  21. },
  22. width: 200,
  23. 'show-overflow-tooltip': true
  24. },
  25. {
  26. prop: 'startDatetime',
  27. label: '启用时间',
  28. align: 'center'
  29. },
  30. {
  31. prop: 'endDatetime',
  32. label: '停用时间',
  33. align: 'center'
  34. },
  35. {
  36. prop: 'updateBy',
  37. label: '修改人',
  38. align: 'center'
  39. },
  40. {
  41. prop: 'updateTime',
  42. label: '修改日期',
  43. align: 'center'
  44. },
  45. {
  46. prop: 'status',
  47. label: '使用状态',
  48. align: 'center',
  49. render: ({ row }) => {
  50. return (
  51. row.status ?
  52. <Fragment>
  53. <el-tag type={statusMap.get(row.status).type}>{ statusMap.get(row.status).text }</el-tag>
  54. </Fragment>
  55. : null
  56. )
  57. }
  58. },
  59. {
  60. label: '操作',
  61. render: ({ row }) => {
  62. return (
  63. <Fragment>
  64. <el-button type="primary" link onClick={ () => copy(row) }>复制</el-button>
  65. <el-button type="primary" link disabled={ row.status === '1' } onClick={ () => enable(row) }>启用</el-button>
  66. <el-button type="primary" link onClick={ () => openDialog(row, 'view') }>查看</el-button>
  67. <el-button type="primary" link onClick={ () => openDialog(row, 'edit') }>修改</el-button>
  68. <el-button type="danger" link onClick={ () => del(row) }>删除</el-button>
  69. </Fragment>
  70. )
  71. },
  72. align: 'center',
  73. width: 254
  74. }
  75. ])
  76.  
  77. const openDialog = (data, type) => {
  78. visible.value = true
  79. opts.type = type
  80. opts.text = optTextMap.get(type)
  81. row.value = data
  82. }
  83.  
  84. const del = (row) => {
  85. proxy.$modal
  86. .confirm("是否确认删除?")
  87. .then(async () => {
  88. const res = await facilitiesSuggestRateConfigDel(row.id)
  89. if(res?.code !== 200) return
  90. proxy.$modal.msgSuccess('操作成功!')
  91. getTableList()
  92. })
  93. .catch(() => {})
  94. }
  95.  
  96. const copy = (row) => {
  97. proxy.$modal
  98. .confirm("是否确认复制?")
  99. .then(async () => {
  100. const res = await facilitiesSuggestRateConfigCopy({ id: row.id })
  101. if(res?.code !== 200) return
  102. proxy.$modal.msgSuccess('操作成功!')
  103. getTableList()
  104. })
  105. .catch(() => {})
  106. }
  107.  
  108. const enable = (row) => {
  109. proxy.$modal
  110. .confirm("是否确认启用?")
  111. .then(async () => {
  112. const res = await facilitiesSuggestRateConfigEnable(row.id)
  113. if(res?.code !== 200) return
  114. proxy.$modal.msgSuccess('操作成功!')
  115. getTableList()
  116. })
  117. .catch(() => {})
  118. }
  119.  
  120. return {
  121. columns,
  122. visible,
  123. row,
  124. opts,
  125. openDialog,
  126. }
  127. }