Blame view

src/pages/Order/components/ProcureCheckModal.tsx 3.7 KB
zhongnanhuang authored
1
2
3
import { RESPONSE_CODE } from '@/constants/enum';
import {
  postServiceOrderProcureCheckOrder,
zhongnanhuang authored
4
  postServiceOrderProcureConvertWarehouseKeeper,
zhongnanhuang authored
5
6
7
  postServiceOrderQuerySupplier,
} from '@/services';
import { ModalForm, ProFormSelect } from '@ant-design/pro-components';
zhongnanhuang authored
8
9
import { Button, Form, Input, Popconfirm, message } from 'antd';
import { useState } from 'react';
zhongnanhuang authored
10
11
export default ({ setCheckVisible, data, subOrders, onClose }) => {
  const [form] = Form.useForm<{ name: string; company: string }>();
zhongnanhuang authored
12
13
14

  const [checkNotes, setCheckNotes] = useState<string>('');
zhongnanhuang authored
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  let subOrderIds: any[] = [];
  //是单条子订单审核
  if (subOrders === undefined) {
    subOrderIds = [data.id];
  } else {
    subOrderIds = subOrders.map((subOrder) => subOrder.id);
  }
  async function doCheck(body: object) {
    const data = await postServiceOrderProcureCheckOrder({
      data: body,
    });
    if (data.result === RESPONSE_CODE.SUCCESS) {
      message.success(data.message);
      onClose();
    }
  }

  return (
    <ModalForm<{
      name: string;
      company: string;
    }>
      width={500}
      open
zhongnanhuang authored
39
      title="采购审核"
zhongnanhuang authored
40
41
42
43
44
45
46
47
48
49
50
51
      form={form}
      autoFocusFirstInput
      modalProps={{
        okText: '确认',
        cancelText: '取消',
        destroyOnClose: true,
        onCancel: () => {
          setCheckVisible(false);
        },
      }}
      submitter={{
        render: (props, defaultDoms) => {
zhongnanhuang authored
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
          return [
            defaultDoms[0],
            <>
              <Popconfirm
                title="是否转回仓库"
                description={
                  <div>
                    <div className="py-2">
                      <span>转回仓库后将由仓库管理员进行打印、发货</span>
                    </div>
                    <Input.TextArea
                      placeholder="请填写备注"
                      onChange={(e: any) => {
                        setCheckNotes(e.target.value);
                      }}
                      rows={4}
                    ></Input.TextArea>
                  </div>
                }
                onConfirm={async () => {
                  const res =
                    await postServiceOrderProcureConvertWarehouseKeeper({
                      data: {
                        subIds: subOrderIds,
                        checkNotes: checkNotes,
                      },
                    });

                  if (res?.result === RESPONSE_CODE.SUCCESS) {
                    message.success(res.message);
                    onClose();
                    return true;
                  }
                }}
                okText="确定"
                cancelText="取消"
              >
                <Button type="primary">转回仓库</Button>
              </Popconfirm>
            </>,
            defaultDoms[1],
          ];
zhongnanhuang authored
94
95
96
97
        },
      }}
      submitTimeout={2000}
      onFinish={async (values) => {
zhongnanhuang authored
98
99
100
101
        let procureIsPrintAndSend = false;
        if (values.name === '采购自行发货') {
          procureIsPrintAndSend = true;
        }
zhongnanhuang authored
102
103
104
        return doCheck({
          ids: subOrderIds,
          supplier: values.name,
zhongnanhuang authored
105
          procureIsPrintAndSend: procureIsPrintAndSend,
zhongnanhuang authored
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
        });
      }}
      onOpenChange={setCheckVisible}
    >
      <ProFormSelect
        key="key"
        label="供应商名称"
        width="lg"
        name="name"
        // options={options}
        placeholder="请选择供应商"
        rules={[{ required: true, message: '供应商必填' }]}
        request={async () => {
          const res = await postServiceOrderQuerySupplier();
          return res.data?.map((item) => {
            return { label: item, value: item };
          });
        }}
      />
    </ModalForm>
  );
};