modal.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import DatePicker from '@/components/DatePicker'
  2. import { tenderStore } from '@/store/mobx'
  3. import { handleAutoCode } from '@/utils/util'
  4. import { Form, Input, message, Modal } from 'antd'
  5. import locale from 'antd/es/date-picker/locale/zh_CN'
  6. import React, { useEffect } from 'react'
  7. import styles from './index.module.scss'
  8. interface iQualityCreateFormProps {
  9. visible: boolean;
  10. loading: boolean;
  11. onCreate: (values: any) => void;
  12. onCancel: () => void;
  13. }
  14. const QualityCreateForm: React.FC<iQualityCreateFormProps> = ({
  15. visible,
  16. loading,
  17. onCreate,
  18. onCancel
  19. }) => {
  20. const [ form ] = Form.useForm()
  21. const autoCode = async () => {
  22. const ruleArr = await handleAutoCode(tenderStore.bid, 'qualityRule')
  23. if (!ruleArr || !ruleArr.length) {
  24. return message.error('未设置编号规则')
  25. }
  26. form.setFieldsValue({ code: ruleArr.join('-') })
  27. }
  28. useEffect(() => {
  29. if (visible) {
  30. form.setFieldsValue({ bidsectionId: tenderStore.bid })
  31. form.resetFields([ 'code', 'inspection', 'createTime', 'position' ])
  32. }
  33. }, [ visible ])
  34. return (
  35. <Modal
  36. getContainer={false}
  37. visible={visible}
  38. title="新建质量巡检"
  39. okText="确认添加"
  40. cancelText="取消"
  41. onCancel={onCancel}
  42. confirmLoading={loading}
  43. okButtonProps={{ size: 'small' }}
  44. cancelButtonProps={{ size: 'small' }}
  45. onOk={() => {
  46. form
  47. .validateFields()
  48. .then((values) => {
  49. // form.resetFields()
  50. onCreate(values)
  51. })
  52. .catch(info => {
  53. console.log('Validate Failed:', info)
  54. })
  55. }}
  56. >
  57. <Form form={form} layout="vertical" size="middle" className={styles.SafeModalForm}>
  58. <Form.Item name="bidsectionId" hidden>
  59. <Input />
  60. </Form.Item>
  61. {/* <span className={[ styles.position, "pi-link-blue" ].join(" ")}>部位设置</span> */}
  62. {/* <Form.Item name="position" label="部位" rules={[ { required: true, message: '请选择' } ]}> */}
  63. {/* <span className={[ styles.position, "pi-link-blue" ].join(" ")}>部位设置</span> */}
  64. {/* <Input /> */}
  65. {/* </Form.Item> */}
  66. <Form.Item name="code" label="安全编号" rules={[ { required: true, message: '请输入/生成安全编号' } ]}>
  67. <Input addonAfter={<span className="pi-pd-lr-11"onClick={() => autoCode()}>自动编号</span>}/>
  68. </Form.Item>
  69. <Form.Item name="inspection" label="检查项" rules={[ { required: true, message: '请填写检查项' } ]}>
  70. <Input placeholder="请填写巡检项"/>
  71. </Form.Item>
  72. <Form.Item name="createTime" label="日期" rules={[ { required: true, message: '请选择日期' } ]}>
  73. <DatePicker locale={locale} allowClear className="pi-width-100P" />
  74. </Form.Item>
  75. <div className={styles.warningFooter}>添加后再补充完善其余信息</div>
  76. </Form>
  77. </Modal>
  78. )
  79. }
  80. export default QualityCreateForm