CheckForm.jsx 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React from 'react';
  2. import dayjs from 'dayjs';
  3. import { EditOutlined } from '@ant-design/icons';
  4. import { Card, Tabs, Button, Form, Input, DatePicker } from 'antd';
  5. import { ModalForm } from '@ant-design/pro-components';
  6. import { postTaCheck, putTaCheck } from '@/service/tacheck';
  7. export default (props) => {
  8. const { checkInfo, onChange, onTabChange } = props;
  9. const [open, setOpen] = React.useState(false);
  10. const [form] = Form.useForm();
  11. const onEdit = () => {
  12. setOpen(true);
  13. }
  14. const title = checkInfo ? checkInfo.title : <div onClick={onEdit}>点击编辑创建</div>;
  15. const dateStr = checkInfo ? `${checkInfo.startDate} ~ ${checkInfo.endDate}` : '';
  16. const onFinish = async (values) => {
  17. const data = {
  18. ...values,
  19. startDate: dayjs(values.startDate).format('YYYY-MM-DD'),
  20. endDate: dayjs(values.endDate).format('YYYY-MM-DD'),
  21. }
  22. if (!checkInfo) {
  23. const res = await postTaCheck(data);
  24. onChange(res);
  25. } else {
  26. const res = await putTaCheck(checkInfo.checkId, data);
  27. onChange(res);
  28. }
  29. return true;
  30. }
  31. React.useEffect(() => {
  32. if (checkInfo) {
  33. form.setFieldsValue({
  34. ...checkInfo,
  35. startDate: dayjs(checkInfo.startDate),
  36. endDate: dayjs(checkInfo.endDate),
  37. });
  38. }
  39. }, [checkInfo]);
  40. return (
  41. <Card bodyStyle={{padding: 0}}>
  42. <div style={{display: 'flex', padding: '1em', alignItems: 'center'}}>
  43. <div style={{flex: 'none'}}><Button type="link" onClick={onEdit} icon={<EditOutlined />} /></div>
  44. <div style={{flex: 'none', margin: '0 1em'}}>{dateStr}</div>
  45. <div style={{flex: '1', fontSize: '1.6em'}}>{title}</div>
  46. </div>
  47. <Tabs
  48. defaultActiveKey='1'
  49. onChange={onTabChange}
  50. tabBarStyle={{margin: '0 2em'}}
  51. items={[
  52. {
  53. label: '实地测评',
  54. key: '1',
  55. },
  56. {
  57. label: '问卷调查',
  58. key: '2',
  59. }
  60. ]}
  61. />
  62. <ModalForm title="测评维护" open={open} width={480} form={form} onFinish={onFinish} onOpenChange={setOpen}>
  63. <Form.Item name="title" label="测评名称" required>
  64. <Input placeholder="请输入测评名称" />
  65. </Form.Item>
  66. <Form.Item name="startDate" label="开始时间" required>
  67. <DatePicker placeholder="请选择" style={{ width: '100%' }} />
  68. </Form.Item>
  69. <Form.Item name="endDate" label="结束时间" required>
  70. <DatePicker placeholder="请选择" style={{ width: '100%' }} />
  71. </Form.Item>
  72. </ModalForm>
  73. </Card>
  74. )
  75. }