|
@@ -1,171 +0,0 @@
|
1
|
|
-import React, { useEffect, useState, useCallback, useRef, useMemo } from 'react'
|
2
|
|
-import { useModel } from 'umi'
|
3
|
|
-import { Form, Input, Button, message } from 'antd';
|
4
|
|
-import ProCard from '@ant-design/pro-card';
|
5
|
|
-import { PageHeaderWrapper } from '@ant-design/pro-layout';
|
6
|
|
-import QRCode from './components/QRCode'
|
7
|
|
-import md5 from 'md5';
|
8
|
|
-import { getDetail, saveOrg, updateOrg, saveOrgUser, getOrgAdminDetail } from '@/services/org';
|
9
|
|
-
|
10
|
|
-export default (props) => {
|
11
|
|
- const { history } = props;
|
12
|
|
- const { id } = history.location.query;
|
13
|
|
- const { initialState } = useModel('@@initialState');
|
14
|
|
-
|
15
|
|
- const [form] = Form.useForm();
|
16
|
|
- const [formData, setFormData] = useState()
|
17
|
|
- const [loading, setLoading] = useState(false)
|
18
|
|
-
|
19
|
|
- const qrcodeText = useMemo(() => initialState.report_url + '#resume-work-form?org=' + id, [id, initialState.report_url])
|
20
|
|
-
|
21
|
|
- const [adminForm] = Form.useForm();
|
22
|
|
- const [adminFormData, setAdminFormData] = useState()
|
23
|
|
- const [adminLoading, setAdminLoading] = useState(false)
|
24
|
|
-
|
25
|
|
- const onFinish = (values) => {
|
26
|
|
- setLoading(true)
|
27
|
|
- if (id) {
|
28
|
|
- updateOrg(id, values).then(() => {
|
29
|
|
- setLoading(false);
|
30
|
|
- history.go(-1);
|
31
|
|
- }).catch(() => {
|
32
|
|
- setLoading(false);
|
33
|
|
- })
|
34
|
|
- } else {
|
35
|
|
- saveOrg(values).then((res) => {
|
36
|
|
- setLoading(false);
|
37
|
|
- history.replace(`/org/edit?id=${res.orgId}`)
|
38
|
|
- }).catch(() => {
|
39
|
|
- setLoading(false);
|
40
|
|
- })
|
41
|
|
- }
|
42
|
|
- };
|
43
|
|
- const onFinishFailed = (errorInfo) => {
|
44
|
|
- console.log('Failed:', errorInfo);
|
45
|
|
- };
|
46
|
|
-
|
47
|
|
- const onAdminFinish = (values) => {
|
48
|
|
- if (!/^1[0-9]{10}$/.test(values.phone)) {
|
49
|
|
- message.warning('请输入正确的十一位手机号');
|
50
|
|
- setLoading(false);
|
51
|
|
- return false;
|
52
|
|
- }
|
53
|
|
- var data = { ...adminFormData, ...values, password: md5(values.password), isAdmin: true };
|
54
|
|
- setAdminLoading(true)
|
55
|
|
- saveOrgUser(id, data).then(res => {
|
56
|
|
- message.success('保存成功');
|
57
|
|
- history.go(-1);
|
58
|
|
- setAdminLoading(false)
|
59
|
|
- }).catch(err => {
|
60
|
|
- console.log(err);
|
61
|
|
- setAdminLoading(false)
|
62
|
|
- })
|
63
|
|
- }
|
64
|
|
-
|
65
|
|
- useEffect(() => {
|
66
|
|
- if (id) {
|
67
|
|
- getDetail(id).then(res => {
|
68
|
|
- setFormData(res);
|
69
|
|
- form.setFieldsValue(res);
|
70
|
|
- })
|
71
|
|
- getOrgAdminDetail(id).then((res) => {
|
72
|
|
- setAdminFormData(res);
|
73
|
|
- adminForm.setFieldsValue(res);
|
74
|
|
- })
|
75
|
|
- }
|
76
|
|
- }, [id, form])
|
77
|
|
-
|
78
|
|
- return (
|
79
|
|
- <PageHeaderWrapper>
|
80
|
|
- <ProCard tabs={{ type: 'card' }} style={{ minHeight: '700px' }}>
|
81
|
|
- <ProCard.TabPane key={1} tab="基本信息">
|
82
|
|
- <div style={{ maxWidth: '600px' }}>
|
83
|
|
- <Form
|
84
|
|
- name="basic"
|
85
|
|
- form={form}
|
86
|
|
- labelCol={{ span: 8 }}
|
87
|
|
- wrapperCol={{ span: 16 }}
|
88
|
|
- initialValues={formData}
|
89
|
|
- onFinish={onFinish}
|
90
|
|
- onFinishFailed={onFinishFailed}
|
91
|
|
- autoComplete="off"
|
92
|
|
- >
|
93
|
|
- <Form.Item
|
94
|
|
- label="企业名称"
|
95
|
|
- name="orgName"
|
96
|
|
- rules={[{ required: true, message: '请填写企业名称!' }]}
|
97
|
|
- >
|
98
|
|
- <Input readOnly={formData?.canEditName}/>
|
99
|
|
- </Form.Item>
|
100
|
|
- <Form.Item
|
101
|
|
- label="权重"
|
102
|
|
- name="weight"
|
103
|
|
- rules={[{ required: true, message: '请填写企业权重!' }]}
|
104
|
|
- >
|
105
|
|
- <Input type='number' min='0' />
|
106
|
|
- </Form.Item>
|
107
|
|
- {
|
108
|
|
- id && <Form.Item label='申报二维码'>
|
109
|
|
- <QRCode text={qrcodeText} title={formData?.orgName} />
|
110
|
|
- </Form.Item>
|
111
|
|
- }
|
112
|
|
- <Form.Item label=' ' colon={false} >
|
113
|
|
- <Button type="primary" htmlType="submit" loading={loading}>
|
114
|
|
- 保存
|
115
|
|
- </Button>
|
116
|
|
- <Button style={{ marginLeft: '32px' }} onClick={() => { history.go(-1); }} >返回</Button>
|
117
|
|
- </Form.Item>
|
118
|
|
- </Form>
|
119
|
|
- </div>
|
120
|
|
- </ProCard.TabPane>
|
121
|
|
- <ProCard.TabPane disabled={!id} key={2} tab='管理员'>
|
122
|
|
- <div style={{ maxWidth: '600px' }}>
|
123
|
|
- <Form
|
124
|
|
- form={adminForm}
|
125
|
|
- labelCol={{ span: 8 }}
|
126
|
|
- wrapperCol={{ span: 16 }}
|
127
|
|
- initialValues={adminFormData}
|
128
|
|
- onFinish={onAdminFinish}
|
129
|
|
- >
|
130
|
|
- <Form.Item
|
131
|
|
- label="姓名"
|
132
|
|
- name="userName"
|
133
|
|
- rules={[{ required: true, message: '请填写管理员姓名!' }]}
|
134
|
|
- >
|
135
|
|
- <Input />
|
136
|
|
- </Form.Item>
|
137
|
|
- <Form.Item
|
138
|
|
- label="手机号"
|
139
|
|
- name="phone"
|
140
|
|
- rules={[{ required: true, message: '请填写手机号!' }]}
|
141
|
|
- >
|
142
|
|
- <Input maxLength={11} />
|
143
|
|
- </Form.Item>
|
144
|
|
- <Form.Item
|
145
|
|
- label="登录账号"
|
146
|
|
- name="loginName"
|
147
|
|
- rules={[{ required: true, message: '请填写登录账号!' }]}
|
148
|
|
- >
|
149
|
|
- <Input />
|
150
|
|
- </Form.Item>
|
151
|
|
- <Form.Item
|
152
|
|
- label="密码"
|
153
|
|
- name="password"
|
154
|
|
- rules={[{ required: true, message: '请填写密码!' }]}
|
155
|
|
- >
|
156
|
|
- <Input />
|
157
|
|
- </Form.Item>
|
158
|
|
- <Form.Item label=' ' colon={false} >
|
159
|
|
- <Button type="primary" htmlType="submit" loading={adminLoading}>
|
160
|
|
- 保存
|
161
|
|
- </Button>
|
162
|
|
- <Button style={{ marginLeft: '32px' }} onClick={() => { history.go(-1); }}>返回</Button>
|
163
|
|
- </Form.Item>
|
164
|
|
- </Form>
|
165
|
|
- </div>
|
166
|
|
-
|
167
|
|
- </ProCard.TabPane>
|
168
|
|
- </ProCard>
|
169
|
|
- </PageHeaderWrapper>
|
170
|
|
- )
|
171
|
|
-}
|