Blame view

src/pages/approval/ApprovalSetting/components/CreateItem.tsx 7.61 KB
60c0e139   赵凤   审批
1
  import React, { useState, useEffect } from "react";
87e1b4f2   赵凤   审批角色添加顺序
2
3
4
5
6
7
8
9
10
11
12
  import {
    Input,
    Select,
    Modal,
    Form,
    message,
    Tooltip,
    Tag,
    Button,
    Space,
  } from "antd";
cf310b97   赵凤   审批角色展示
13
  import { DeleteOutlined, PlusOutlined } from "@ant-design/icons";
60c0e139   赵凤   审批
14
15
16
17
18
19
  import {
    ApprovalType,
    Approval_Status,
    transformDTO,
    transformFormData,
  } from "../entity";
1fcd2cfd   赵凤   审批列表
20
  import _ from "lodash";
60c0e139   赵凤   审批
21
22
  import { systemListApi } from "@/pages/admin/Privilege/api";
  import usePagination from "@/hooks/usePagination";
32a827a0   赵凤   新增审批配置
23
  import { getAllRoleCodeApi } from "@/common/api";
60c0e139   赵凤   审批
24
  import useInitial from "@/hooks/useInitail";
f844ec2f   赵凤   删除审批配置
25
  import { saveApproveConfig } from "../api";
cf310b97   赵凤   审批角色展示
26
  import toChineseBig from "@/utils/toChinease";
1fcd2cfd   赵凤   审批列表
27
28
  
  const { Option } = Select;
24463ce3   赵凤   新增审批配置
29
  const layout = {
60c0e139   赵凤   审批
30
31
    labelCol: { span: 6 },
    wrapperCol: { span: 18 },
24463ce3   赵凤   新增审批配置
32
  };
1fcd2cfd   赵凤   审批列表
33
  interface Props {
60c0e139   赵凤   审批
34
35
36
    item: { visible: boolean; currentItem?: ApprovalSetteing.ApprovalListItems };
    setItem: any;
    setParams: any;
1fcd2cfd   赵凤   审批列表
37
38
  }
  
cf310b97   赵凤   审批角色展示
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  const formItemLayout = {
    labelCol: {
      xs: { span: 24 },
      sm: { span: 4 },
    },
    wrapperCol: {
      xs: { span: 24 },
      sm: { span: 20 },
    },
  };
  const formItemLayoutWithOutLabel = {
    wrapperCol: {
      xs: { span: 24, offset: 0 },
      sm: { span: 20, offset: 4 },
    },
  };
f844ec2f   赵凤   删除审批配置
55
  export default function CreateItem({ item, setItem, setParams }: Props) {
3d9288d2   赵凤   编辑审批配置
56
    const [form] = Form.useForm();
cf310b97   赵凤   审批角色展示
57
    const { list } = usePagination(systemListApi, { current: 1, pageSize: 500 });
3d9288d2   赵凤   编辑审批配置
58
    const { data, setData } = useInitial(getAllRoleCodeApi, [], {});
f844ec2f   赵凤   删除审批配置
59
    const [loading, setLoading] = useState(false);
3d9288d2   赵凤   编辑审批配置
60
    const { visible, currentItem } = item;
3d9288d2   赵凤   编辑审批配置
61
    useEffect(() => {
60c0e139   赵凤   审批
62
      setData(data.filter((item) => item.useType === 3 || item.useType === 4));
3d9288d2   赵凤   编辑审批配置
63
      if (visible && currentItem) {
3d9288d2   赵凤   编辑审批配置
64
        const result = transformFormData(currentItem);
3d9288d2   赵凤   编辑审批配置
65
66
67
        form.setFieldsValue({ ...result });
      }
    }, [visible]);
1fcd2cfd   赵凤   审批列表
68
  
24463ce3   赵凤   新增审批配置
69
    const onFinish = () => {
60c0e139   赵凤   审批
70
71
72
73
74
      form
        .validateFields()
        .then((fileds) => {
          const pa = {
            ...fileds,
87e1b4f2   赵凤   审批角色添加顺序
75
            id: currentItem ? currentItem.id : undefined,
60c0e139   赵凤   审批
76
77
78
          };
  
          const result = transformDTO(pa);
d0fae3ad   赵凤   审批角色顺序
79
          // return;
60c0e139   赵凤   审批
80
81
82
83
84
          setLoading(true);
          saveApproveConfig(result)
            .then((res) => {
              message.success("保存成功");
              setParams({ current: 1 }, true);
b1d46fda   赵凤   budfix
85
              setItem({ visible: false });
60c0e139   赵凤   审批
86
87
88
89
            })
            .catch((err) => message.error(err.message))
            .finally(() => {
              setLoading(false);
60c0e139   赵凤   审批
90
91
            });
        })
87e1b4f2   赵凤   审批角色添加顺序
92
        .catch((err) => message.error(err.message));
24463ce3   赵凤   新增审批配置
93
    };
87e1b4f2   赵凤   审批角色添加顺序
94
  
1fcd2cfd   赵凤   审批列表
95
    return (
32a827a0   赵凤   新增审批配置
96
      <Modal
60c0e139   赵凤   审批
97
        // title="新增"
e2c1272a   赵凤   审批角色筛选
98
        title={`${currentItem ? "编辑" : "新增"}审批配置`}
32a827a0   赵凤   新增审批配置
99
100
101
        visible={visible}
        onCancel={() => setItem({ visible: false })}
        onOk={() => form.submit()}
f844ec2f   赵凤   删除审批配置
102
103
        confirmLoading={loading}
        afterClose={() => form.resetFields()}
d0fae3ad   赵凤   审批角色顺序
104
105
        labelCol={{ span: 8 }}
        wrapperCol={{ span: 16 }}
32a827a0   赵凤   新增审批配置
106
      >
87e1b4f2   赵凤   审批角色添加顺序
107
108
109
110
111
        <Form
          {...layout}
          form={form}
          name="control-hooks"
          onFinish={onFinish}
d0fae3ad   赵凤   审批角色顺序
112
          initialValues={{ approvalRoles: [{}] }}
87e1b4f2   赵凤   审批角色添加顺序
113
        >
60c0e139   赵凤   审批
114
115
116
117
118
          <Form.Item
            name="approvalName"
            label="审批名称"
            rules={[{ required: true }]}
          >
32a827a0   赵凤   新增审批配置
119
            <Input placeholder="请输入审批名称" maxLength={16} />
24463ce3   赵凤   新增审批配置
120
          </Form.Item>
60c0e139   赵凤   审批
121
122
123
124
125
126
127
128
129
130
131
          <Form.Item
            name="approvalType"
            label="审批类型"
            rules={[{ required: true }]}
          >
            <Select placeholder="请选择审批类型">
              {ApprovalType.map((item) => (
                <Option value={item.value} key={item.value}>
                  {item.label}
                </Option>
              ))}
24463ce3   赵凤   新增审批配置
132
133
            </Select>
          </Form.Item>
6676800a   赵凤   角色拖动排序
134
135
136
137
138
139
140
141
142
          <Form.Item
            noStyle
            shouldUpdate={(prevValues, currentValues) => prevValues.approvalType !== currentValues.approvalType}
          >
            {({ getFieldValue }) => (getFieldValue("approvalType") === 1 ? (
              <Form.List name="approvalRoles">
                {(fields, { add, remove }) => (
                  <div style={{ paddingLeft: 47 }}>
                    {fields.map(({ key, name, ...restField }, index) => (
cf310b97   赵凤   审批角色展示
143
                      <Form.Item
6676800a   赵凤   角色拖动排序
144
                        label={index === 0 ? "审批角色" : ""}
cf310b97   赵凤   审批角色展示
145
                        key={key}
6676800a   赵凤   角色拖动排序
146
147
148
149
                        {...(index === 0
                            ? formItemLayout
                            : formItemLayoutWithOutLabel)}
                        style={{ height: 55 }}
87e1b4f2   赵凤   审批角色添加顺序
150
                      >
6676800a   赵凤   角色拖动排序
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
                        <div>
                          <span style={{ fontSize: 14 }}>
                            {toChineseBig(index + 1)}级审批
                          </span>
                          {index !== 0 && (
                          <DeleteOutlined
                            style={{ marginLeft: 5, color: "red" }}
                            onClick={() => remove(name)}
                          />
                            )}
                          <Form.Item
                            key={key}
                            style={{ width: "100%" }}
                            {...restField}
                            name={[name, "roleObj"]}
                            rules={[
                                { required: true, message: "请选择审批角色" },
                              ]}
                          >
                            <Select
                              style={{ width: "100%" }}
                              placeholder="请选择审批角色"
                              labelInValue
                              showSearch
                              showArrow
                              allowClear
                              optionFilterProp="children"
                            >
                              {data.map((item) => (
                                <Option
                                    value={item.roleCode}
                                    key={item.roleCode}
                                  >
                                    {item.roleName}
                                  </Option>
                                ))}
                            </Select>
                          </Form.Item>
                        </div>
cf310b97   赵凤   审批角色展示
190
                      </Form.Item>
6676800a   赵凤   角色拖动排序
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
                      ))}
                    <Form.Item style={{ width: "100%" }}>
                      <Button
                        type="dashed"
                        onClick={() => add()}
                        block
                        style={{ marginLeft: 67, width: 358 }}
                        icon={<PlusOutlined />}
                      >
                        增加角色
                      </Button>
                    </Form.Item>
                  </div>
                  )}
              </Form.List>
              ) : null)}
          </Form.Item>
  
60c0e139   赵凤   审批
209
210
211
          <Form.Item
            name="path"
            label="业务详情路径"
ef82232e   赵凤   业务详情路径不是必传
212
            // rules={[{ required: true }]}
60c0e139   赵凤   审批
213
214
215
216
217
218
219
220
          >
            <Input placeholder="请输入业务详情路径" />
          </Form.Item>
          <Form.Item
            name="gateName"
            label="归属系统"
            rules={[{ required: true }]}
          >
87e1b4f2   赵凤   审批角色添加顺序
221
222
223
224
225
226
            <Select
              placeholder="请选择归属系统"
              showSearch
              allowClear
              optionFilterProp="children"
            >
60c0e139   赵凤   审批
227
228
              {list.map((item) => (
                <Option value={item.sysPrefix} key={item.sysPrefix}>
cf310b97   赵凤   审批角色展示
229
                  {/* <Option value={item.id} key={item.sysPrefix}> */}
60c0e139   赵凤   审批
230
231
232
                  {item.sysName}
                </Option>
              ))}
32a827a0   赵凤   新增审批配置
233
234
            </Select>
          </Form.Item>
32a827a0   赵凤   新增审批配置
235
          <Form.Item name="status" label="状态" rules={[{ required: true }]}>
60c0e139   赵凤   审批
236
237
238
239
240
241
            <Select placeholder="请选择状态">
              {Approval_Status.map((item) => (
                <Option value={item.value} key={item.value}>
                  {item.label}
                </Option>
              ))}
24463ce3   赵凤   新增审批配置
242
243
244
            </Select>
          </Form.Item>
        </Form>
1fcd2cfd   赵凤   审批列表
245
246
247
      </Modal>
    );
  }