index.jsx 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { addDish, updataDish, getDishById, getDishList } from '@/services/api/dish';
  2. import { queryTable } from '@/utils/request';
  3. import { PageContainer, ProForm, ProFormDigit, ProFormText, ModalForm, Select, Option } from '@ant-design/pro-components';
  4. import { history, useSearchParams } from '@umijs/max';
  5. import { Card, Col, message, Row, Space, Image } from 'antd';
  6. import { values } from 'lodash';
  7. import { useEffect, useRef, useState } from 'react';
  8. export default (props) => {
  9. const [searchParams, setSearchParams] = useSearchParams();
  10. const id = searchParams.get('id');
  11. const [data, setData] = useState({});
  12. const formRef = useRef();
  13. useEffect(() => {
  14. if (id) {
  15. getDishById(id).then((res) => {
  16. setData(res);
  17. formRef.current.setFieldsValue(res);
  18. });
  19. }
  20. }, [id]);
  21. const onFinish = async (values) => {
  22. console.log(values)
  23. if (id) {
  24. // 修改
  25. updataDish(id, { ...values }).then((res) => {
  26. message.success('修改成功');
  27. history.back();
  28. });
  29. } else {
  30. // 新增
  31. addDish({ ...values }).then((res) => {
  32. message.success('添加成功');
  33. history.back();
  34. });
  35. }
  36. return false;
  37. };
  38. return (
  39. <PageContainer>
  40. <Card>
  41. <ProForm
  42. formRef={formRef}
  43. layout={'horizontal'}
  44. labelCol={{ span: 8 }}
  45. wrapperCol={{ span: 16 }}
  46. onFinish={onFinish}
  47. initialValues={{ type: '1', state: '1' }}
  48. submitter={{
  49. searchConfig: {
  50. resetText: '返回',
  51. },
  52. onReset: () => history.back(),
  53. render: (props, doms) => {
  54. return (
  55. <Row>
  56. <Col span={8} offset={8}>
  57. <Space>{doms}</Space>
  58. </Col>
  59. </Row>
  60. );
  61. },
  62. }}
  63. >
  64. <ProFormText name="name" label="菜肴名称" placeholder="请输入菜肴名称" width={460} />
  65. <ProFormText name="unit" label="菜肴单位" placeholder="请输入菜肴单位" width={460} />
  66. {/* <Select label="包含食材" mode="multiple" >
  67. <Option></Option>
  68. <Option></Option>
  69. </Select> */}
  70. </ProForm>
  71. </Card>
  72. </PageContainer>
  73. );
  74. };