Просмотр исходного кода

Merge branch 'dev' of http://git.ycjcjy.com/ubpa/pc-admin into dev

张延森 3 лет назад
Родитель
Сommit
31aa888ab5

+ 2
- 2
config/routes.js Просмотреть файл

@@ -48,10 +48,10 @@ export default [
48 48
         component: '@/pages/org/org/index.jsx',
49 49
       },
50 50
       {
51
-        path: '/org/edit',
51
+        path: '/org/Edit',
52 52
         name: '企业维护',
53 53
         hideInMenu: true,
54
-        component: '@/pages/org/org/Edit.jsx',
54
+        component: '@/pages/org/org/Edit',
55 55
       },
56 56
     ],
57 57
   },

+ 0
- 171
src/pages/org/org/Edit.jsx Просмотреть файл

@@ -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
-}

+ 84
- 0
src/pages/org/org/Edit/components/AdminPage.jsx Просмотреть файл

@@ -0,0 +1,84 @@
1
+import React, { useEffect, useState } from 'react'
2
+import { Form, Input, Button, message } from 'antd';
3
+import md5 from 'md5';
4
+import { saveOrgUser, getOrgAdminDetail } from '@/services/org';
5
+
6
+export default (props) => {
7
+  const { id } = props;
8
+  const [adminForm] = Form.useForm();
9
+  const [adminFormData, setAdminFormData] = useState()
10
+  const [adminLoading, setAdminLoading] = useState(false)
11
+
12
+  const onAdminFinish = (values) => {
13
+    if (!/^1[0-9]{10}$/.test(values.phone)) {
14
+      message.warning('请输入正确的十一位手机号');
15
+      setLoading(false);
16
+      return false;
17
+    }
18
+    var data = { ...adminFormData, ...values, password: md5(values.password), isAdmin: true };
19
+    setAdminLoading(true)
20
+    saveOrgUser(id, data).then(res => {
21
+      message.success('保存成功');
22
+      history.go(-1);
23
+      setAdminLoading(false)
24
+    }).catch(err => {
25
+      console.log(err);
26
+      setAdminLoading(false)
27
+    })
28
+  }
29
+  useEffect(() => {
30
+    if (id) {
31
+      getOrgAdminDetail(id).then((res) => {
32
+        setAdminFormData(res);
33
+        adminForm.setFieldsValue(res);
34
+      })
35
+    }
36
+  }, [id])
37
+  return (
38
+    <div style={{ maxWidth: '600px' }}>
39
+      <Form
40
+        form={adminForm}
41
+        labelCol={{ span: 8 }}
42
+        wrapperCol={{ span: 16 }}
43
+        initialValues={adminFormData}
44
+        onFinish={onAdminFinish}
45
+      >
46
+        <Form.Item
47
+          label="姓名"
48
+          name="userName"
49
+          rules={[{ required: true, message: '请填写管理员姓名!' }]}
50
+        >
51
+          <Input />
52
+        </Form.Item>
53
+        <Form.Item
54
+          label="手机号"
55
+          name="phone"
56
+          rules={[{ required: true, message: '请填写手机号!' }]}
57
+        >
58
+          <Input maxLength={11} />
59
+        </Form.Item>
60
+        <Form.Item
61
+          label="登录账号"
62
+          name="loginName"
63
+          rules={[{ required: true, message: '请填写登录账号!' }]}
64
+        >
65
+          <Input />
66
+        </Form.Item>
67
+        <Form.Item
68
+          label="密码"
69
+          name="password"
70
+          rules={[{ required: true, message: '请填写密码!' }]}
71
+        >
72
+          <Input />
73
+        </Form.Item>
74
+        <Form.Item label=' ' colon={false} >
75
+          <Button type="primary" htmlType="submit" loading={adminLoading}>
76
+            保存
77
+          </Button>
78
+          <Button style={{ marginLeft: '32px' }} onClick={() => { history.go(-1); }}>返回</Button>
79
+        </Form.Item>
80
+      </Form>
81
+    </div>
82
+
83
+  )
84
+}

+ 98
- 0
src/pages/org/org/Edit/components/BasicPage.jsx Просмотреть файл

@@ -0,0 +1,98 @@
1
+import { Form, Input, Button } from 'antd';
2
+import QRCode from '@/components/QRCode'
3
+import React, { useEffect, useState, useCallback, useRef, useMemo } from 'react'
4
+import { useModel } from 'umi'
5
+import { getDetail, saveOrg, updateOrg } from '@/services/org';
6
+
7
+
8
+export default (props) => {
9
+  const { id } = props;
10
+  const { initialState } = useModel('@@initialState');
11
+
12
+  const [form] = Form.useForm();
13
+  const [formData, setFormData] = useState()
14
+  const [loading, setLoading] = useState(false)
15
+  const qrcodeRef = useRef()
16
+  const qrcodeText = useMemo(() => initialState.report_url + '#resume-work-form?org=' + id, [id, initialState.report_url])
17
+  const downloadQrcode = useCallback(() => {
18
+    if (qrcodeRef.current) {
19
+      qrcodeRef.current.download();
20
+    }
21
+  }, [])
22
+
23
+  const onFinish = (values) => {
24
+    setLoading(true)
25
+    if (id) {
26
+      updateOrg(id, values).then(() => {
27
+        setLoading(false);
28
+        history.go(-1);
29
+      }).catch(() => {
30
+        setLoading(false);
31
+      })
32
+    } else {
33
+      saveOrg(values).then((res) => {
34
+        setLoading(false);
35
+        history.replace(`/org/Edit?id=${res.orgId}`)
36
+      }).catch(() => {
37
+        setLoading(false);
38
+      })
39
+    }
40
+  };
41
+  const onFinishFailed = (errorInfo) => {
42
+    console.log('Failed:', errorInfo);
43
+  };
44
+  useEffect(() => {
45
+    if (id) {
46
+      getDetail(id).then(res => {
47
+        setFormData(res);
48
+        form.setFieldsValue(res);
49
+      })
50
+    }
51
+  }, [id])
52
+  return (
53
+    <div style={{ maxWidth: '600px' }}>
54
+      <Form
55
+        name="basic"
56
+        form={form}
57
+        labelCol={{ span: 8 }}
58
+        wrapperCol={{ span: 16 }}
59
+        initialValues={formData}
60
+        onFinish={onFinish}
61
+        onFinishFailed={onFinishFailed}
62
+        autoComplete="off"
63
+      >
64
+        <Form.Item
65
+          label="企业名称"
66
+          name="orgName"
67
+          rules={[{ required: true, message: '请填写企业名称!' }]}
68
+        >
69
+          <Input readOnly={formData?.canEditName} />
70
+        </Form.Item>
71
+        <Form.Item
72
+          label="权重"
73
+          name="weight"
74
+          rules={[{ required: true, message: '请填写企业权重!' }]}
75
+        >
76
+          <Input type='number' min='0' />
77
+        </Form.Item>
78
+        {
79
+          id && <Form.Item label=' ' colon={false} wrapperCol={{ offset: 3 }}>
80
+            <QRCode ref={qrcodeRef} border width={200} content={qrcodeText} title={formData?.orgName} fileName={formData?.orgName} />
81
+          </Form.Item>
82
+        }
83
+        <Form.Item label=' ' colon={false} >
84
+          <Button type="primary" htmlType="submit" loading={loading}>
85
+            保存
86
+          </Button>
87
+          {id &&
88
+            <Button style={{ marginLeft: '32px' }} onClick={downloadQrcode} >
89
+              下载二维码
90
+            </Button>
91
+          }
92
+          <Button style={{ marginLeft: '32px' }} onClick={() => { history.go(-1); }} >返回</Button>
93
+        </Form.Item>
94
+      </Form>
95
+    </div>
96
+
97
+  )
98
+}

+ 20
- 0
src/pages/org/org/Edit/index.jsx Просмотреть файл

@@ -0,0 +1,20 @@
1
+import ProCard from '@ant-design/pro-card';
2
+import { PageHeaderWrapper } from '@ant-design/pro-layout';
3
+import AdminPage from './components/AdminPage';
4
+import BasicPage from './components/BasicPage';
5
+export default (props) => {
6
+  const { history } = props;
7
+  const { id } = history.location.query;
8
+  return (
9
+    <PageHeaderWrapper>
10
+      <ProCard tabs={{ type: 'card' }} style={{ minHeight: '700px' }}>
11
+        <ProCard.TabPane key={1} tab="基本信息">
12
+          <BasicPage id={id} />
13
+        </ProCard.TabPane>
14
+        <ProCard.TabPane disabled={!id} key={2} tab='管理员'>
15
+          <AdminPage id={id} />
16
+        </ProCard.TabPane>
17
+      </ProCard>
18
+    </PageHeaderWrapper>
19
+  )
20
+}

+ 2
- 3
src/pages/org/org/index.jsx Просмотреть файл

@@ -13,9 +13,8 @@ const formatterTime = (val) => {
13 13
 };
14 14
 
15 15
 export default (props) => {
16
-  // document.title='666'
17 16
   const handleClick = () => {
18
-    history.push('/org/edit');
17
+    history.push('/org/Edit');
19 18
   }
20 19
   const AddNew = useMemo(() => (
21 20
     <Button type="primary" icon={<PlusOutlined />} onClick={handleClick}>
@@ -43,7 +42,7 @@ export default (props) => {
43 42
       key: 'option',
44 43
       ellipsis: true,
45 44
       render: (_, record) => [
46
-        <Button type="link" key={1} onClick={() => history.push(`/org/edit?id=${record.orgId}`)}>
45
+        <Button type="link" key={1} onClick={() => history.push(`/org/Edit?id=${record.orgId}`)}>
47 46
           详情
48 47
         </Button>,
49 48
       ],