index.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. 'use client'
  2. import { useCallback, useEffect, useState } from 'react'
  3. import { RiCloseLine } from '@remixicon/react'
  4. import s from './index.module.css'
  5. import cn from '@/utils/classnames'
  6. import Modal from '@/app/components/base/modal'
  7. import Button from '@/app/components/base/button'
  8. import { addKnowledge, editKnowledge, fetchDepts } from '@/service/common'
  9. import 'react-multi-email/dist/style.css'
  10. import Input from '@/app/components/base/input'
  11. import { TreeSelect as AntdTreeSelect } from 'antd'
  12. const InviteModal = ({
  13. transfer,
  14. onCancel,
  15. onSend,
  16. }: any) => {
  17. const [name, setName] = useState<string>(transfer.row?.name || '')
  18. const [options, setOptions] = useState<any>([])
  19. useEffect(() => {
  20. fetchDepts({
  21. url: '/xxx',
  22. params: {
  23. page: 1,
  24. limit: 1000,
  25. },
  26. }).then((res: any) => {
  27. setOptions(res.data || [])
  28. })
  29. }, [])
  30. const handleSave = useCallback(async () => {
  31. try {
  32. let res: any = () => {}
  33. if (transfer.mode === 'add') {
  34. res = await addKnowledge({
  35. url: '/123',
  36. body: { name, status: false },
  37. })
  38. }
  39. else {
  40. res = await editKnowledge({
  41. url: `/123/${transfer.row.id}`,
  42. body: { name },
  43. })
  44. }
  45. const { id }: any = res
  46. if (id) {
  47. onCancel()
  48. onSend()
  49. }
  50. }
  51. catch (e) { }
  52. }, [name, onCancel, onSend, transfer])
  53. return (
  54. <div className={cn(s.wrap)}>
  55. <Modal overflowVisible isShow onClose={() => { }} className={cn(s.modal)}>
  56. <div className='mb-2 flex justify-between'>
  57. <div className='text-xl font-semibold text-text-primary'>{transfer.mode === 'add' ? '新增' : '编辑'}部门</div>
  58. <RiCloseLine className='h-4 w-4 cursor-pointer text-text-tertiary' onClick={onCancel} />
  59. </div>
  60. <div>
  61. <div className={cn('flex flex-wrap items-center justify-between')}>
  62. <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'>
  63. 上级部门
  64. </div>
  65. <AntdTreeSelect
  66. showSearch
  67. style={{ width: '100%' }}
  68. value={name}
  69. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  70. placeholder="请选择上级部门"
  71. allowClear
  72. treeDefaultExpandAll
  73. onChange={v => setName(v || '')}
  74. treeData={options}
  75. fieldNames={{ label: 'name', value: 'id' }}
  76. />
  77. </div>
  78. <div className={cn('flex flex-wrap items-center justify-between')}>
  79. <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'>
  80. 部门名称
  81. </div>
  82. <Input
  83. value={name}
  84. onChange={e => setName(e.target.value)}
  85. className='h-9'
  86. placeholder='请输入部门名称'
  87. />
  88. </div>
  89. <Button
  90. tabIndex={0}
  91. className='mt-4 w-full'
  92. onClick={handleSave}
  93. disabled={!name.length}
  94. variant='primary'
  95. >
  96. 保存
  97. </Button>
  98. </div>
  99. </Modal>
  100. </div>
  101. )
  102. }
  103. export default InviteModal