index.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import React, { useCallback, useEffect, useMemo, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { D2_APIgetInfo, D2_APIgetProDel, D2_APIsave } from '@/store/action/D2approval'
  4. import { D2editTableType, D2editType } from '../data'
  5. import { Button, Radio } from 'antd'
  6. import TextArea from 'antd/es/input/TextArea'
  7. import MyTable from '@/components/MyTable'
  8. import { D2tableC2 } from '@/utils/tableData'
  9. import { MessageFu } from '@/utils/message'
  10. import MyPopconfirm from '@/components/MyPopconfirm'
  11. import D2lookPro from './D2lookPro'
  12. import D2addPro from './D2addPro'
  13. type Props = {
  14. sId: number
  15. closeFu: () => void
  16. upTableFu: () => void
  17. }
  18. function D2edit({ sId, closeFu, upTableFu }: Props) {
  19. const [info, setInfo] = useState({} as D2editType)
  20. const getInfoFu = useCallback(async () => {
  21. const res = await D2_APIgetInfo(sId)
  22. if (res.code === 0) {
  23. const data: D2editTableType[] = res.data.process || []
  24. setInfo({
  25. ...res.data,
  26. process: data.map((v, i) => ({
  27. ...v,
  28. sort: v.isUse === 0 ? '/' : v.sort,
  29. type: v.isUse === 0 ? '/' : v.type
  30. }))
  31. })
  32. }
  33. }, [sId])
  34. useEffect(() => {
  35. getInfoFu()
  36. }, [getInfoFu])
  37. // 点击删除
  38. const delTableFu = useCallback(
  39. async (id: number) => {
  40. const res: any = await D2_APIgetProDel(id)
  41. if (res.code === 0) {
  42. MessageFu.success('删除成功!')
  43. getInfoFu()
  44. }
  45. },
  46. [getInfoFu]
  47. )
  48. const tableLastBtn = useMemo(() => {
  49. return [
  50. {
  51. title: '操作',
  52. render: (item: D2editTableType) => {
  53. return item.isUse === 0 ? (
  54. '/'
  55. ) : (
  56. <>
  57. <Button size='small' type='text' onClick={() => setLookId(item.id)}>
  58. 查看办理人
  59. </Button>
  60. <Button size='small' type='text' onClick={() => setProId(item.id)}>
  61. 编辑
  62. </Button>
  63. <MyPopconfirm txtK='删除' onConfirm={() => delTableFu(item.id)} />
  64. </>
  65. )
  66. }
  67. }
  68. ]
  69. }, [delTableFu])
  70. // 环节的新增和编辑
  71. const [proId, setProId] = useState(0)
  72. // 查看办理人
  73. const [lookId, setLookId] = useState(0)
  74. // 点击保存
  75. const btnOk = useCallback(async () => {
  76. const res = await D2_APIsave({
  77. id: info.id,
  78. enabled: info.enabled,
  79. remark: info.remark
  80. })
  81. if (res.code === 0) {
  82. MessageFu.warning('编辑成功')
  83. upTableFu()
  84. closeFu()
  85. }
  86. }, [info, closeFu, upTableFu])
  87. return (
  88. <div className={styles.D2edit}>
  89. <div className='D2eRow'>
  90. <div>流程名称:</div>
  91. <div>{info.name}</div>
  92. </div>
  93. <div className='D2eRow'>
  94. <div>
  95. <span>* </span>流程状态:
  96. </div>
  97. <div>
  98. <Radio.Group
  99. value={info.enabled}
  100. onChange={e => setInfo({ ...info, enabled: e.target.value })}
  101. options={[
  102. { value: 1, label: '启用' },
  103. { value: 0, label: '禁用' }
  104. ]}
  105. />
  106. </div>
  107. </div>
  108. <div className='D2eRow'>
  109. <div>流程说明:</div>
  110. <div>
  111. <TextArea
  112. style={{ width: '90%' }}
  113. placeholder='请输入'
  114. maxLength={500}
  115. showCount
  116. value={info.remark}
  117. onChange={e => setInfo({ ...info, remark: e.target.value })}
  118. />
  119. </div>
  120. <div className='D2eBtn'>
  121. <Button type='primary' onClick={btnOk}>
  122. 保存
  123. </Button>
  124. <br />
  125. <br />
  126. <MyPopconfirm txtK='取消' onConfirm={closeFu} />
  127. </div>
  128. </div>
  129. <div className='D2eRow'>
  130. <div className='D2tablell'>审批环节:</div>
  131. <div>
  132. <Button type='primary' onClick={() => setProId(-1)}>
  133. 新增
  134. </Button>
  135. <div className='D2table'>
  136. <MyTable
  137. classKey='D2editTable'
  138. yHeight={492}
  139. list={info.process || []}
  140. columnsTemp={D2tableC2}
  141. lastBtn={tableLastBtn}
  142. pagingInfo={false}
  143. />
  144. </div>
  145. </div>
  146. </div>
  147. {proId ? (
  148. <D2addPro flowId={sId} sId={proId} closeFu={() => setProId(0)} succFu={getInfoFu} />
  149. ) : null}
  150. {lookId ? <D2lookPro sId={lookId} closeFu={() => setLookId(0)} /> : null}
  151. </div>
  152. )
  153. }
  154. const MemoD2edit = React.memo(D2edit)
  155. export default MemoD2edit