AddOrUpdate.tsx 2.29 KB
import { postProductCollectBillAddOrModify } from '@/services';
import { useModel } from '@@/exports';
import {
  ModalForm,
  ProFormDigit,
  ProFormSelect,
  ProFormText,
  ProFormTextArea,
} from '@ant-design/pro-components';
import { Button, Form, message } from 'antd';

export default ({ record, onFinish }) => {
  const [form] = Form.useForm();
  const { getWarehouse } = useModel('enum');
  return (
    <ModalForm
      title="新建表单"
      trigger={
        record?.id ? (
          <Button type="link">修改</Button>
        ) : (
          <Button type="primary">新建</Button>
        )
      }
      form={form}
      autoFocusFirstInput
      modalProps={{
        destroyOnClose: true,
        onCancel: () => console.log('run'),
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
        let res = await postProductCollectBillAddOrModify({
          data: values,
        });
        if (res) {
          message.success(res.message);
          onFinish();
        }
        return true;
      }}
    >
      <ProFormDigit
        label="id"
        name="id"
        initialValue={record?.id}
        width="sm"
        hidden={true}
      />
      <ProFormText
        width="md"
        initialValue={record?.productName}
        name="productName"
        label="申领物品"
        rules={[{ required: true, message: '申领物品必填' }]}
      />
      <ProFormDigit
        label="申领数量"
        name="productNumber"
        initialValue={record?.productNumber}
        width="sm"
        min={1}
        rules={[{ required: true, message: '申领数量必填' }]}
      />
      <ProFormSelect
        width="md"
        request={async () => {
          const res = await getWarehouse();
          console.log('options:' + res);
          let options = Object.entries(res).map(([value, label]) => ({
            label,
            value,
          }));
          console.log('options:' + options);
          return options;
        }}
        // initialValue={record?.warehouseCode}
        name="warehouseCode"
        label="申领仓库"
        rules={[{ required: true, message: '申领仓库为必填项' }]}
      />
      <ProFormTextArea
        initialValue={record?.applyRemarks}
        name="applyRemarks"
        label="申领备注"
      />
    </ModalForm>
  );
};