index.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. 'use client'
  2. import { 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 { addDept, editDept, 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?.dept_name || '')
  18. const [parent, setParent] = useState<string>(transfer.row?.parent_dept_id || '')
  19. console.log(transfer)
  20. const [options, setOptions] = useState<any>([])
  21. useEffect(() => {
  22. fetchDepts({
  23. url: '/depts',
  24. }).then((res: any) => {
  25. setOptions(res.data || [])
  26. })
  27. }, [])
  28. const handleSave = async () => {
  29. try {
  30. let res: any = () => {}
  31. if (transfer.mode === 'add') {
  32. res = await addDept({
  33. url: '/depts',
  34. body: { dept_name: name, parent_dept_id: parent },
  35. })
  36. }
  37. else {
  38. res = await editDept({
  39. url: '/depts',
  40. body: { dept_name: name, parent_dept_id: parent, dept_id: transfer.row.dept_id },
  41. })
  42. }
  43. const { result }: any = res
  44. if (result === 'success') {
  45. onCancel()
  46. onSend()
  47. }
  48. }
  49. catch (e) { }
  50. }
  51. return (
  52. <div className={cn(s.wrap)}>
  53. <Modal overflowVisible isShow onClose={() => { }} className={cn(s.modal)}>
  54. <div className='mb-2 flex justify-between'>
  55. <div className='text-xl font-semibold text-text-primary'>{transfer.mode === 'add' ? '新增' : '编辑'}部门</div>
  56. <RiCloseLine className='h-4 w-4 cursor-pointer text-text-tertiary' onClick={onCancel} />
  57. </div>
  58. <div>
  59. <div className={cn('flex flex-wrap items-center justify-between')}>
  60. <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'>
  61. 上级部门
  62. </div>
  63. <AntdTreeSelect
  64. showSearch
  65. style={{ width: '100%' }}
  66. value={parent}
  67. dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
  68. placeholder="请选择上级部门"
  69. allowClear
  70. treeDefaultExpandAll
  71. onChange={(v) => {
  72. console.log('dept', v)
  73. setParent(v || '')
  74. }}
  75. treeData={options}
  76. fieldNames={{ label: 'dept_name', value: 'dept_id' }}
  77. />
  78. </div>
  79. <div className={cn('flex flex-wrap items-center justify-between')}>
  80. <div className='shrink-0 py-2 text-sm font-medium leading-[20px] text-text-primary'>
  81. 部门名称
  82. </div>
  83. <Input
  84. value={name}
  85. onChange={e => setName(e.target.value)}
  86. className='h-9'
  87. placeholder='请输入部门名称'
  88. />
  89. </div>
  90. <Button
  91. tabIndex={0}
  92. className='mt-4 w-full'
  93. onClick={handleSave}
  94. disabled={!name.length}
  95. variant='primary'
  96. >
  97. 保存
  98. </Button>
  99. </div>
  100. </Modal>
  101. </div>
  102. )
  103. }
  104. export default InviteModal