Blame view

src/pages/finance/TradeCompany/components/CreateModal.tsx 7.17 KB
ec4e9e61   zhaolin   往来单位 业务类型改成多选
1
2
3
  import React, { useState, useEffect } from "react";
  import { Modal, Form, Input, Select, message, Radio } from "antd";
  import { useStore } from "../index";
7074fac7   zhaolin   往来单位增加字段
4
  import { CompanyBusinessTypeEnum, CompanyCategoryTypeEnum, SubjectTypeEnum } from "@/pages/finance/entitys";
ec4e9e61   zhaolin   往来单位 业务类型改成多选
5
6
7
8
  import PositionSelector from "@/components/PositionSelector";
  import Contact from "./ContactsInput";
  import Account from "./AccountsInput";
  import { createCompanyApi, updateCompanyApi, getDetailComAccountApi } from "../api";
d3cdcd80   zhaofeng   往来单位选择地址
9
  import AdressSelect from "@/pages/finance/TradeCompany/components/AdressSelect";
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
10
11
12
13
14
  
  const FormItem = Form.Item;
  const { Option } = Select;
  
  export default function CreateModal() {
7074fac7   zhaolin   往来单位增加字段
15
16
    const { visible, setVisible, current, setCurrent, setLoading, comBussinessList, comBussinessLoading, brandList } =
      useStore();
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
17
18
    const [form] = Form.useForm();
    const [savelLoading, setSavelLoading] = useState(false);
ec4e9e61   zhaolin   往来单位 业务类型改成多选
19
    const [creditCodeDesc, setCreditCodeDesc] = useState<string>("社会信用代码");
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  
    useEffect(() => {
      if (visible) {
        initData(current.id);
      }
    }, [visible, current.id]);
  
    async function initData(rowId?: number) {
      try {
        let item: TradeCompany.CompDetailVO = {};
        if (rowId) {
          const { data = {} } = await getDetailComAccountApi(rowId);
          item = data;
        }
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
34
        form.setFieldsValue({
d3cdcd80   zhaofeng   往来单位选择地址
35
          ...item,
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
36
37
38
          compName: item.compName,
          compShortName: item.compShortName,
          subjectType: item.subjectType,
ec4e9e61   zhaolin   往来单位 业务类型改成多选
39
          compType: item.compType || [],
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
40
41
42
          compCategory: item.compCategory || CompanyCategoryTypeEnum["供应商"],
          compAddress: item.compAddress,
          creditCode: item.creditCode,
7074fac7   zhaolin   往来单位增加字段
43
          brandId: item.brandId,
1fbe3df6   zhaofeng   往来单位地址回显
44
45
46
47
          location: item.compAddress
            ? {
                // address: "",
                //@ts-ignored;
d8241cee   zhaofeng   修改地址参数
48
                address: item.lonLatAddress||"",
1fbe3df6   zhaofeng   往来单位地址回显
49
50
51
52
53
54
                point: {
                  lng: item.longitude,
                  lat: item.latitude,
                },
              }
            : undefined,
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
55
56
57
          contacts: (item.contacts || []).map((it, i) => ({ ...it, key: i + 1 })),
          accounts: (item.accounts || []).map((it, i) => ({ ...it, key: i + 1 })),
        });
ec4e9e61   zhaolin   往来单位 业务类型改成多选
58
      } catch (e: any) {
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
59
60
61
62
63
64
65
66
67
        message.error(e.message);
        setVisible(false);
      }
    }
  
    function submit(item: any) {
      const param = {
        id: current.id,
        ...item,
d3cdcd80   zhaofeng   往来单位选择地址
68
69
        longitude: Number(item.longitude),
        latitude: Number(item.latitude),
fe98fc42   zhaofeng   bugfix
70
        lonLatAddress: item.location? item.location.address : "",
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
71
72
73
      };
      setSavelLoading(true);
      const saveApi = current.id ? updateCompanyApi : createCompanyApi;
ec4e9e61   zhaolin   往来单位 业务类型改成多选
74
75
76
77
78
79
80
81
82
83
84
      saveApi(param)
        .then((res) => {
          message.success("保存成功");
          setLoading(true);
          setVisible(false);
          setSavelLoading(false);
        })
        .catch((err) => {
          message.error(err.message);
          setSavelLoading(false);
        });
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
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
    }
  
    function onCancel() {
      setVisible(false);
    }
  
    function changeSubjectType(value: number) {
      if (value === 1) {
        setCreditCodeDesc("身份证号码");
      } else {
        setCreditCodeDesc("社会信用代码");
      }
    }
  
    return (
      <Modal
        title={`${current.id ? "编辑" : "新增"}往来单位`}
        visible={visible}
        onOk={form.submit}
        onCancel={onCancel}
        maskClosable={false}
        confirmLoading={savelLoading}
        afterClose={() => {
          setCurrent({});
        }}
        width="60%"
      >
d3cdcd80   zhaofeng   往来单位选择地址
112
        <Form form={form} onFinish={submit} labelCol={{ span: 4 }} wrapperCol={{ span: 18 }}>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
113
114
115
116
117
118
119
120
          <FormItem name="compName" label="往来单位名称" rules={[{ required: true, message: "请填入往来单位名称" }]}>
            <Input placeholder="请填入往来单位名称" maxLength={64} />
          </FormItem>
          <FormItem name="compShortName" label="往来单位简称" rules={[{ required: true, message: "请填入往来单位简称" }]}>
            <Input placeholder="请填入往来单位简称" maxLength={64} />
          </FormItem>
          <FormItem name="subjectType" label="单位主体类型" rules={[{ required: true, message: "请选择主体类型" }]}>
            <Select placeholder="请选择主体类型" showSearch onChange={changeSubjectType}>
c2f58366   zhaolin   增加单位主体枚举类型
121
122
123
124
125
126
              {[
                SubjectTypeEnum["个人"],
                SubjectTypeEnum["公司"],
                SubjectTypeEnum["个体工商户"],
                SubjectTypeEnum["公共组织"],
              ].map((i) => (
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
127
128
129
130
131
132
133
                <Option key={i} value={i}>
                  {SubjectTypeEnum[i]}
                </Option>
              ))}
            </Select>
          </FormItem>
          <FormItem name="compCategory" label="单位类别" rules={[{ required: true, message: "请选择类别" }]}>
84c00e13   zhaolin   往来单位设置 开放编辑修改单位类别
134
            <Radio.Group>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
135
136
137
138
              <Radio value={CompanyCategoryTypeEnum["供应商"]}>供应商</Radio>
              <Radio value={CompanyCategoryTypeEnum["服务商"]}>服务商</Radio>
            </Radio.Group>
          </FormItem>
7074fac7   zhaolin   往来单位增加字段
139
          <FormItem name="compType" label="业务类型" rules={[{ required: true, message: "请选项类型" }]}>
ec4e9e61   zhaolin   往来单位 业务类型改成多选
140
141
142
143
144
145
146
            <Select
              placeholder="请选择类型"
              mode="multiple"
              showSearch
              optionFilterProp="children"
              loading={comBussinessLoading}
            >
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
147
148
149
150
151
152
153
              {comBussinessList.map((item) => (
                <Option key={item.id} value={item.id}>
                  {item.name}
                </Option>
              ))}
            </Select>
          </FormItem>
7074fac7   zhaolin   往来单位增加字段
154
155
156
157
158
          <FormItem noStyle shouldUpdate={(prevValues, currentValues) => prevValues.compType != currentValues.compType}>
            {({ getFieldValue }): any => {
              const _compType = getFieldValue("compType");
              return _compType?.includes(CompanyBusinessTypeEnum["新车采购(主机厂)"]) ||
                _compType?.includes(CompanyBusinessTypeEnum["配件采购"]) ? (
d3cdcd80   zhaofeng   往来单位选择地址
159
160
161
162
163
164
165
166
167
168
                <FormItem name="brandId" label="品牌" rules={[{ required: true, message: "请选择品牌" }]}>
                  <Select placeholder="请选择品牌" showSearch optionFilterProp="children">
                    {brandList?.map((item) => (
                      <Option key={item.id} value={item.id}>
                        {item.name}
                      </Option>
                    ))}
                  </Select>
                </FormItem>
              ) : null;
7074fac7   zhaolin   往来单位增加字段
169
170
            }}
          </FormItem>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
171
172
173
174
175
176
177
          <FormItem
            name="creditCode"
            label={creditCodeDesc}
            rules={[{ required: true, message: "请输入" + creditCodeDesc }]}
          >
            <Input placeholder={`请输入${creditCodeDesc}`} maxLength={30} />
          </FormItem>
5f5caf9a   zhaolin   通信地址 编辑
178
          <FormItem name="compAddress" label="通信地址" rules={[{ required: true, message: "请输入地址" }]}>
f26da03a   zhaolin   通信地址
179
            <Input placeholder="请输入通信地址" />
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
180
          </FormItem>
d3cdcd80   zhaofeng   往来单位选择地址
181
182
183
184
          {/* <FormItem name="location" label="地理位置" rules={[{ required: true, message: "请配置地址" }]}> */}
          {/* <PositionSelector style={{ width: "100%" }} /> */}
          <AdressSelect form={form} />
          {/* </FormItem> */}
e03118d5   zhaolin   调整
185
          <FormItem name="contacts" label="联系方式" rules={[{ required: true }]}>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
186
187
            <Contact />
          </FormItem>
d3cdcd80   zhaofeng   往来单位选择地址
188
          <FormItem name="accounts" label="账户信息" c rules={[{ required: true }]}>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
189
190
191
192
193
194
            <Account />
          </FormItem>
        </Form>
      </Modal>
    );
  }