submitModal.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import { Form, Input, message, Modal, Select } from "antd"
  2. import React, { useEffect, useState } from "react"
  3. import dayjs from "dayjs"
  4. import { randomString } from "@/utils/utils"
  5. import { useAjax } from "@/Hook/useAjax"
  6. import { getProjectGroupsAllListApi } from "@/pages/weComTask/API/groupManage"
  7. /**
  8. * 设置名称
  9. * @returns
  10. */
  11. interface Props {
  12. visible?: boolean,
  13. onClose?: () => void,
  14. onChange?: (data: any) => void
  15. loading?: boolean
  16. projectName?: string
  17. }
  18. const SubmitModal: React.FC<Props> = (props) => {
  19. /********************/
  20. const { visible, onClose, onChange, loading, projectName } = props
  21. const [form] = Form.useForm()
  22. const [groupList, setGroupList] = useState<{ label: string, value: number }[]>([])
  23. const getProjectGroupsAllList = useAjax(() => getProjectGroupsAllListApi())
  24. /********************/
  25. useEffect(() => {
  26. getProjectGroupsAllList.run().then(res => {
  27. setGroupList(res?.data?.map(item => ({ label: item.name, value: item.id })) || [])
  28. })
  29. }, [])
  30. const handleOk = () => {
  31. form.validateFields().then((values) => {
  32. const params = JSON.parse(JSON.stringify(values))
  33. onChange?.(params)
  34. }).catch(() => {
  35. form.submit()
  36. });
  37. }
  38. return <Modal
  39. title={<strong style={{ fontSize: 20 }}>{projectName ? projectName + '任务修改' : ''}提交</strong>}
  40. open={visible}
  41. confirmLoading={loading}
  42. onCancel={onClose}
  43. maskClosable={false}
  44. onOk={handleOk}
  45. >
  46. <Form
  47. name="basicSubmit"
  48. form={form}
  49. labelCol={{ span: 4 }}
  50. autoComplete="off"
  51. scrollToFirstError={{
  52. behavior: 'smooth',
  53. block: 'center'
  54. }}
  55. onFinishFailed={({ errorFields }) => {
  56. message.error(errorFields?.[0]?.errors?.[0])
  57. }}
  58. colon={false}
  59. labelAlign="left"
  60. initialValues={{
  61. projectName: projectName || '任务' + dayjs().format('MMDDHHmmss') + '_' + randomString(true, 3, 5)
  62. }}
  63. >
  64. <Form.Item label={<strong>任务名称</strong>} name="projectName" rules={[{ required: true, message: '请输入任务名称!' }]}>
  65. <Input placeholder="请输入任务名称" />
  66. </Form.Item>
  67. <Form.Item label={<strong>项目组</strong>} name="projectGroupId">
  68. <Select
  69. placeholder='请选择项目组'
  70. allowClear
  71. options={groupList}
  72. showSearch
  73. filterOption={(input, option) =>
  74. (option?.label ?? '').toLowerCase().includes(input.toLowerCase())
  75. }
  76. />
  77. </Form.Item>
  78. </Form>
  79. </Modal>
  80. }
  81. export default React.memo(SubmitModal)