index.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import useModal from '@/components/Modal'
  2. import { startTransition, useMemo, useState } from 'react'
  3. import { PageContainer } from '@ant-design/pro-layout'
  4. import { BusinessType, ExecutorSetType } from '@/enums/gc'
  5. import useScripts from './hooks/useScripts'
  6. import { Button } from 'antd'
  7. import ProTable, { ProColumnType } from '@ant-design/pro-table'
  8. import LeftMenu from '../RuleCode/components/LeftMenu'
  9. import { connect } from '@umijs/max'
  10. import { BusinessModelState } from '../model'
  11. export const menuOptions = [{ label: '预算业务审批', value: BusinessType.BUDGET }]
  12. type ProcessProps = {
  13. processMap: {
  14. [key: string]: API.ExecutorItem[]
  15. }
  16. }
  17. const Process: React.FC<ProcessProps> = ({ processMap }) => {
  18. const [state, setState] = useState({
  19. activeKey: ''
  20. })
  21. const [modal, ModalDOM] = useModal()
  22. const { total, query, loading, addOrEdit, del } = useScripts(modal, state.activeKey)
  23. const list = useMemo(() => {
  24. if (!state.activeKey) return []
  25. return processMap?.[state.activeKey] || []
  26. }, [state.activeKey, processMap])
  27. const columns: ProColumnType<API.ExecutorItem>[] = [
  28. {
  29. dataIndex: 'name',
  30. title: '执行者名称',
  31. width: 120,
  32. align: 'center',
  33. ellipsis: true
  34. },
  35. {
  36. dataIndex: 'setType',
  37. title: '配置方式',
  38. align: 'center',
  39. width: 100,
  40. valueEnum: {
  41. [ExecutorSetType.PERSET]: { text: '预置成员' },
  42. [ExecutorSetType.DYNAMIC]: { text: '步骤配置' }
  43. }
  44. },
  45. {
  46. dataIndex: 'members',
  47. title: '成员',
  48. onHeaderCell: () => ({ style: { textAlign: 'center' } }),
  49. ellipsis: true,
  50. renderText: (_, record) => (
  51. <div className="children:mx-1">
  52. {record?.members?.value?.map(item => (
  53. <span key={item?.ID}>{item?.name}</span>
  54. ))}
  55. </div>
  56. )
  57. },
  58. {
  59. dataIndex: 'opreate',
  60. title: '操作',
  61. align: 'center',
  62. width: 120,
  63. renderText: (_, record) => (
  64. <div className="divide-x divide-bg-gray-400 flex flex-row justify-center">
  65. <span
  66. className="pr-2 text-primary cursor-pointer hover:text-hex-967bbd"
  67. onClick={() => addOrEdit('edit', record)}>
  68. 编辑
  69. </span>
  70. <span
  71. className={'pl-2 text-red-500 cursor-pointer hover:text-red-600'}
  72. onClick={() => del(record.ID)}>
  73. 删除
  74. </span>
  75. </div>
  76. )
  77. }
  78. ]
  79. const handleMenuOnChange = (key: string) => {
  80. const [gatherID, businessType] = key.split('_')
  81. setState({ ...state, activeKey: key })
  82. startTransition(() => {
  83. !processMap?.[state.activeKey] && query({ gatherID, businessType, pageSize: 214000 })
  84. })
  85. }
  86. return (
  87. <PageContainer title={false}>
  88. <div className="h-full w-full flex flex-row">
  89. <LeftMenu title="业务列表" onChange={key => handleMenuOnChange(key)} />
  90. <div className="w-6/7 ml-8 bg-white rounded-20px">
  91. <ProTable
  92. toolbar={{
  93. actions: [
  94. <Button key="add_executor" type="primary" onClick={() => addOrEdit('add')}>
  95. 新建执行者
  96. </Button>
  97. ]
  98. }}
  99. rowKey="ID"
  100. search={false}
  101. columns={columns}
  102. dataSource={list}
  103. loading={loading}
  104. pagination={{ total }}
  105. />
  106. </div>
  107. </div>
  108. {ModalDOM}
  109. </PageContainer>
  110. )
  111. }
  112. export default connect(({ business }: { business: BusinessModelState }) => ({
  113. processMap: business.processMap
  114. }))(Process)