StatusTransitionModal.tsx 2.34 KB
import { RESPONSE_CODE } from '@/constants/enum';
import {
  postProcureReturnBillAudit,
  postProcureReturnBillSend,
} from '@/services';
import { ModalForm, ProFormTextArea } from '@ant-design/pro-components';
import { Button, Form, message } from 'antd';

export default ({ type, ids, reloadTable }) => {
  const transitionTypes = {
    audit: {
      title: '审核',
      notesLabel: '驳回原因',
      notesPlaceholder: '请输入驳回原因',
      submitText: '通过',
      resetText: '驳回',
      onfinish: async (values) => {
        const res = await postProcureReturnBillAudit({
          data: {
            ids: ids,
            transitionNotes: values.transitionNotes,
          },
        });
        if (res.result === RESPONSE_CODE.SUCCESS) {
          message.success('操作成功');
          reloadTable();
          return true;
        } else {
          message.error('操作失败');
        }
      },
    },
    send: {
      title: '发货',
      notesLabel: '发货信息',
      notesPlaceholder: '请输入发货信息(如:顺丰快递,SF24070802324)',
      submitText: '发货',
      resetText: '取消',
      onfinish: async (values) => {
        const res = await postProcureReturnBillSend({
          data: {
            ids: ids,
            transitionNotes: values.transitionNotes,
          },
        });
        if (res.result === RESPONSE_CODE.SUCCESS) {
          message.success('操作成功');
          reloadTable();
          return true;
        } else {
          message.error('操作失败');
        }
      },
    },
  };
  const [form] = Form.useForm();
  return (
    <ModalForm
      title={transitionTypes[type].title}
      trigger={
        <Button size={'small'} type="link">
          {transitionTypes[type].title}
        </Button>
      }
      form={form}
      autoFocusFirstInput
      modalProps={{
        destroyOnClose: true,
        onCancel: () => console.log('run'),
      }}
      submitter={{
        searchConfig: {
          submitText: transitionTypes[type].submitText,
          resetText: transitionTypes[type].resetText,
        },
      }}
      onFinish={transitionTypes[type].onfinish}
    >
      <ProFormTextArea
        name="transitionNotes"
        label={transitionTypes[type].notesLabel}
        placeholder={transitionTypes[type].notesPlaceholder}
      />
    </ModalForm>
  );
};