AddRecord.jsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import React, { useState } from 'react'
  2. import { Form, Radio, DatePicker, Switch, Modal } from 'antd'
  3. import { dayjsFormat } from '@/utils/utils'
  4. import dayjs from 'dayjs'
  5. import { ProFormTextArea } from '@ant-design/pro-form'
  6. const AddRecord = props => {
  7. const [formRef] = Form.useForm()
  8. const { onConfirm, ...resetModalProps } = props
  9. const [state, setState] = useState({
  10. showExtraItem: false,
  11. loading: false
  12. })
  13. const onChange = value => {
  14. setState({ ...state, showExtraItem: value })
  15. }
  16. const disabledDate = current => {
  17. return current && current < dayjs().endOf('day')
  18. }
  19. return (
  20. <Modal
  21. {...resetModalProps}
  22. title="添加服务记录"
  23. getContainer={() => document.getElementById('root')}
  24. onOk={() => {
  25. setState({ ...state, loading: true })
  26. formRef
  27. ?.validateFields()
  28. .then(async values => {
  29. const newVal = { ...values }
  30. formRef.current?.resetFields()
  31. if (values.date) {
  32. newVal.date = dayjsFormat(values.date, 'YYYY-MM-DD')
  33. }
  34. if (values.remindTime) {
  35. newVal.remindTime = dayjsFormat(values.remindTime, 'YYYY-MM-DD')
  36. }
  37. const isSuccess = await onConfirm(newVal)
  38. isSuccess && resetModalProps.onCancel()
  39. setState({ ...state, loading: false })
  40. })
  41. .catch(() => {
  42. setState({ ...state, loading: false })
  43. })
  44. }}
  45. confirmLoading={state.loading}
  46. >
  47. <Form layout="vertical" form={formRef}>
  48. <Form.Item name="status" label="服务类型" rules={[{ required: true, message: '请选择类型' }]}>
  49. <Radio.Group>
  50. <Radio value={1}>上门服务</Radio>
  51. <Radio value={2}>电话拜访</Radio>
  52. <Radio value={3}>其他事项</Radio>
  53. <Radio value={4}>在线服务</Radio>
  54. </Radio.Group>
  55. </Form.Item>
  56. <Form.Item
  57. name="date"
  58. label="服务日期"
  59. initialValue={dayjs(new Date())}
  60. rules={[{ required: true, message: '请选择服务日期' }]}
  61. >
  62. <DatePicker style={{ width: '100%' }} />
  63. </Form.Item>
  64. <ProFormTextArea name="mark" label="内容" rules={[{ required: true, message: '请输入服务内容' }]} />
  65. <div className="pb-5">
  66. <Switch onChange={onChange} checked={state.showExtraItem} />
  67. <span className="ml-2">添加备忘录</span>
  68. </div>
  69. {state.showExtraItem ? (
  70. <>
  71. <Form.Item
  72. name="remindTime"
  73. label="备忘日期"
  74. rules={[{ required: true, message: '请选择备忘日期' }]}
  75. >
  76. <DatePicker style={{ width: '100%' }} disabledDate={disabledDate} />
  77. </Form.Item>
  78. <ProFormTextArea name="remarks" label="备忘内容" />
  79. </>
  80. ) : null}
  81. </Form>
  82. </Modal>
  83. )
  84. }
  85. export default AddRecord