Blame view

src/pages/identify/IdentifyAudit/components/Modal.tsx 6.34 KB
3890e142   王强   添加 认证审核,并对接接口;
1
2
3
4
  /*
   * @Author: wangqiang@feewee.cn
   * @Date: 2023-02-10 17:52:44
   * @LastEditors: wangqiang@feewee.cn
a2ca1da5   王强   优化 认证系统-认证审核 页面交互;
5
   * @LastEditTime: 2023-03-01 14:04:28
3890e142   王强   添加 认证审核,并对接接口;
6
7
8
9
10
11
12
13
14
15
16
17
18
19
   */
  import {
    Button,
    DatePicker,
    Divider,
    Form,
    Input,
    message,
    Modal,
    Spin,
  } from "antd";
  import React, { useEffect, useState } from "react";
  import { useStore } from "../index";
  import ProDescriptions from "@ant-design/pro-descriptions";
3890e142   王强   添加 认证审核,并对接接口;
20
21
22
23
  import {
    getIdentifyItemExpandInfoListApi,
    submitIdentifyAuditApi,
  } from "@/pages/identify/IdentifyAudit/api";
19e4cd34   王强   fix;
24
  import moment from "moment";
3890e142   王强   添加 认证审核,并对接接口;
25
26
27
28
29
30
31
32
  import FeeweeUploadAttachment from "@/components/FeeweeUploadAttachment";
  import DetailItem from "@/pages/ehr/Authentication/Settings/components/DetailItem";
  
  const REMARK_KEY = "fw_other_remark";
  
  export default function IdentifyAuditModal() {
    const { open, setOpen, current, setCurrent, Types, pagination, Type } =
      useStore();
3890e142   王强   添加 认证审核,并对接接口;
33
34
35
36
37
38
39
40
41
42
43
    const [editData, setEditData] = useState<IdentifyAudit.ExpandItem[]>([]);
    const [form] = Form.useForm();
    const [loading, setLoading] = useState(false);
  
    useEffect(() => {
      if (open) {
        if (current?.identifyCode && current?.extraData) {
          setLoading(true);
          getIdentifyItemExpandInfoListApi(current.identifyCode)
            .then((res) => {
              const expandListData = res.data || [];
19e4cd34   王强   fix;
44
              const _editData: IdentifyAudit.ExpandItem[] = [];
3890e142   王强   添加 认证审核,并对接接口;
45
46
47
48
49
50
51
              const extraData: { [key: string]: string } = JSON.parse(
                current.extraData!
              );
              const keys = Object.keys(extraData);
              const fields = {};
              for (let key of keys) {
                const item = expandListData.find((i) => i.name === key);
19e4cd34   王强   fix;
52
                _editData.push({
3890e142   王强   添加 认证审核,并对接接口;
53
54
55
56
57
58
59
60
61
62
63
64
                  name: key,
                  data: extraData[key],
                  ...(item || {}),
                });
                const value =
                  item?.type && Types[item.type] === "Date"
                    ? moment(extraData[key])
                    : extraData[key];
                fields[key] = value;
              }
  
              form.setFieldsValue(fields);
19e4cd34   王强   fix;
65
              setEditData(_editData);
3890e142   王强   添加 认证审核,并对接接口;
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
              setLoading(false);
            })
            .catch((error) => {
              console.error(error.message);
              message.error("初始化认证审核表单失败");
              setEditData([]);
              setLoading(false);
            });
        }
      }
    }, [open, current]);
  
    const cancel = () => {
      setCurrent(undefined);
      setOpen(false);
    };
  
    const submit = (pass: boolean) => {
      form.validateFields().then((val) => {
        const remark = val[REMARK_KEY];
        delete val[REMARK_KEY];
        for (let key of Object.keys(val)) {
          if (typeof val[key] === "object") {
            val[key] = moment(val[key]).format("YYYY-MM-DD HH:mm:ss");
          }
        }
        const auditData = JSON.stringify(val);
        setLoading(true);
        submitIdentifyAuditApi({ id: current?.id, pass, auditData, remark })
          .then((res) => {
            message.success(res.result);
            setLoading(false);
            cancel();
            pagination.setLoading(true);
          })
          .catch((error) => {
            setLoading(false);
            message.error(error.message || "保存认证审核失败");
          });
      });
    };
  
    return (
      <Modal
        title="认证审核"
        open={open}
        onCancel={cancel}
        footer={[
          <Button loading={loading} onClick={cancel}>
            取消
          </Button>,
          <Button
            loading={loading}
            type="primary"
            danger
            onClick={() => submit(false)}
          >
            拒绝
          </Button>,
          <Button loading={loading} type="primary" onClick={() => submit(true)}>
            通过
          </Button>,
        ]}
        width="50%"
        maskClosable={false}
        afterClose={() => {
          form.resetFields();
        }}
      >
        <ProDescriptions column={2}>
          <ProDescriptions.Item label="资料编码">
            {current?.identifyCode || "-"}
          </ProDescriptions.Item>
          <ProDescriptions.Item label="资料名称">
            {current?.identifyName || "-"}
          </ProDescriptions.Item>
a2ca1da5   王强   优化 认证系统-认证审核 页面交互;
142
          {pagination.innerParams?.type !== Type.员工认证 ? (
3890e142   王强   添加 认证审核,并对接接口;
143
144
145
146
            <ProDescriptions.Item label="会员ID">
              {current?.memberId || "-"}
            </ProDescriptions.Item>
          ) : null}
a2ca1da5   王强   优化 认证系统-认证审核 页面交互;
147
          {pagination.innerParams?.type !== Type.会员认证 ? (
3890e142   王强   添加 认证审核,并对接接口;
148
149
150
151
152
153
154
155
156
            <ProDescriptions.Item label="员工ID">
              {current?.staffId || "-"}
            </ProDescriptions.Item>
          ) : null}
          {pagination.innerParams?.type === Type.车辆认证 ? (
            <ProDescriptions.Item label="VIN">
              {current?.vin || "-"}
            </ProDescriptions.Item>
          ) : null}
19e4cd34   王强   fix;
157
158
159
          <ProDescriptions.Item label="审核原因">
            <span style={{ color: "red" }}>{current?.verify || "-"}</span>
          </ProDescriptions.Item>
3890e142   王强   添加 认证审核,并对接接口;
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
        </ProDescriptions>
  
        <DetailItem
          title="附件"
          desp={
            <div style={{ flex: 1, width: "85%" }}>
              <FeeweeUploadAttachment
                fidList={current?.fids?.split(",")}
                disabled
                style={{ flex: 1 }}
              />
            </div>
          }
        />
        <Divider orientation="left">可编辑审核数据如下</Divider>
        <Spin spinning={loading}>
          <Form form={form}>
            {editData.map((data) => (
              <Form.Item
                name={data.name}
19e4cd34   王强   fix;
180
181
182
183
                label={data.label || data.name}
                rules={[
                  { required: !!data.label, message: `${data.label}不能为空` },
                ]}
3890e142   王强   添加 认证审核,并对接接口;
184
185
186
187
188
189
190
              >
                {data.type && Types[data.type] === "Date" ? (
                  // @ts-ignore
                  <DatePicker
                    style={{ width: "100%" }}
                    allowClear
                    format="YYYY-MM-DD HH:mm:ss"
19e4cd34   王强   fix;
191
                    placeholder={`请选择${data.label || data.name}`}
3890e142   王强   添加 认证审核,并对接接口;
192
193
                  />
                ) : (
19e4cd34   王强   fix;
194
195
196
197
                  <Input
                    allowClear
                    placeholder={`请输入${data.label || data.name}`}
                  />
3890e142   王强   添加 认证审核,并对接接口;
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
                )}
              </Form.Item>
            ))}
            <Divider />
            <Form.Item name={REMARK_KEY} label="备注信息">
              <Input.TextArea
                allowClear
                autoSize={{ minRows: 2 }}
                placeholder="请输入备注信息"
              />
            </Form.Item>
          </Form>
        </Spin>
      </Modal>
    );
  }