AfterSalesDrawer.tsx 2.69 KB
import { RESPONSE_CODE } from '@/constants/enum';
import { postServiceOrderApplyAfterSales } from '@/services';
import { enumToSelect } from '@/utils';
import {
  DrawerForm,
  ProFormDigit,
  ProFormSelect,
  ProFormTextArea,
  ProFormUploadDragger,
} from '@ant-design/pro-components';
import { Form, message } from 'antd';
import { AFTE_SALES_PLAN_OPTIONS } from '../../constant';
export default ({ setVisible, mainOrder, subOrders, onClose }) => {
  let subOrderIds = subOrders?.map((item: { id: any }) => {
    return item.id;
  });

  let mainOrderId = mainOrder.id;
  const [form] = Form.useForm<{
    afterSalesNotes: string;
    afterSalesPlan: string;
    ids: [];
    totalPayment: number;
    filePaths: any[];
  }>();

  return (
    <DrawerForm<{
      afterSalesNotes: string;
      afterSalesPlan: string;
      subOrderIds: [];
      totalPayment: number;
      mainId: number;
      filePaths: any[];
    }>
      title="申请售后"
      open
      resize={{
        onResize() {
          console.log('resize!');
        },
        maxWidth: window.innerWidth * 0.8,
        minWidth: 500,
      }}
      form={form}
      autoFocusFirstInput
      drawerProps={{
        destroyOnClose: true,
        onClose: () => {
          setVisible(false);
        },
      }}
      onFinish={async (values) => {
        values.subOrderIds = subOrderIds;
        values.mainId = mainOrderId;
        values.filePaths = values.filePaths?.map((file) => {
          return { url: file.response.data[0] };
        });
        let res = await postServiceOrderApplyAfterSales({ data: values });
        if (res?.result === RESPONSE_CODE.SUCCESS) {
          message.success(res.message);
          onClose();
        }
      }}
    >
      <ProFormSelect
        key="key"
        label="售后方案"
        width="lg"
        showSearch
        name="afterSalesPlan"
        options={enumToSelect(AFTE_SALES_PLAN_OPTIONS)}
        placeholder="请搜索"
        rules={[{ required: true, message: '售后方案必填' }]}
      ></ProFormSelect>
      <ProFormDigit
        width="lg"
        name="totalPayment"
        label="总金额调整"
        min={0}
        initialValue={mainOrder.totalPayment}
        rules={[{ required: true, message: '总金额必填' }]}
      />
      <ProFormTextArea
        width="lg"
        label="售后原因"
        name="afterSalesNotes"
        rules={[{ required: true, message: '售后原因必填' }]}
      />
      <ProFormUploadDragger
        key="filePaths"
        label="附件"
        name="filePaths"
        action="/api/service/order/fileProcess"
        fieldProps={{
          headers: { Authorization: localStorage.getItem('token') },
        }}
      />
    </DrawerForm>
  );
};