李志伟 3 lat temu
rodzic
commit
5314e69ac3

+ 56
- 70
src/pages/org/org/Edit/components/AdminPage.jsx Wyświetl plik

@@ -1,98 +1,84 @@
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, getOrgAdminDetail } from '@/services/org';
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';
6 5
 
7
-
8
-export default (props) => {
6
+export default (props)=>{
9 7
   const { id } = props;
10
-  const { initialState } = useModel('@@initialState');
8
+  const [adminForm] = Form.useForm();
9
+  const [adminFormData, setAdminFormData] = useState()
10
+  const [adminLoading, setAdminLoading] = useState(false)
11 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
-      })
12
+  const onAdminFinish = (values) => {
13
+    if (!/^1[0-9]{10}$/.test(values.phone)) {
14
+      message.warning('请输入正确的十一位手机号');
15
+      setLoading(false);
16
+      return false;
39 17
     }
40
-  };
41
-  const onFinishFailed = (errorInfo) => {
42
-    console.log('Failed:', errorInfo);
43
-  };
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
+  }
44 29
   useEffect(() => {
45 30
     if (id) {
46
-      getDetail(id).then(res => {
47
-        setFormData(res);
48
-        form.setFieldsValue(res);
31
+      getOrgAdminDetail(id).then((res) => {
32
+        setAdminFormData(res);
33
+        adminForm.setFieldsValue(res);
49 34
       })
50 35
     }
51 36
   }, [id])
52
-  return(
37
+  return (
53 38
     <div style={{ maxWidth: '600px' }}>
54 39
             <Form
55
-              name="basic"
56
-              form={form}
40
+              form={adminForm}
57 41
               labelCol={{ span: 8 }}
58 42
               wrapperCol={{ span: 16 }}
59
-              initialValues={formData}
60
-              onFinish={onFinish}
61
-              onFinishFailed={onFinishFailed}
62
-              autoComplete="off"
43
+              initialValues={adminFormData}
44
+              onFinish={onAdminFinish}
63 45
             >
64 46
               <Form.Item
65
-                label="企业名称"
66
-                name="orgName"
67
-                rules={[{ required: true, message: '请填写企业名称!' }]}
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: '请填写登录账号!' }]}
68 64
               >
69
-                <Input  readOnly={formData?.canEditName}/>
65
+                <Input />
70 66
               </Form.Item>
71 67
               <Form.Item
72
-                label="权重"
73
-                name="weight"
74
-                rules={[{ required: true, message: '请填写企业权重!' }]}
68
+                label="密码"
69
+                name="password"
70
+                rules={[{ required: true, message: '请填写密码!' }]}
75 71
               >
76
-                <Input type='number' min='0' />
72
+                <Input />
77 73
               </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 74
               <Form.Item label=' ' colon={false} >
84
-                <Button type="primary" htmlType="submit" loading={loading}>
75
+                <Button type="primary" htmlType="submit" loading={adminLoading}>
85 76
                   保存
86 77
                 </Button>
87
-                {id &&
88
-                  <Button style={{ marginLeft: '32px' }} onClick={downloadQrcode} >
89
-                    下载二维码
90
-                  </Button>
91
-                }
92
-                <Button style={{ marginLeft: '32px' }} onClick={() => { history.go(-1); }} >返回</Button>
78
+                <Button style={{ marginLeft: '32px' }} onClick={() => { history.go(-1); }}>返回</Button>
93 79
               </Form.Item>
94 80
             </Form>
95 81
           </div>
96
-        
82
+
97 83
   )
98 84
 }

+ 71
- 57
src/pages/org/org/Edit/components/BasicPage.jsx Wyświetl plik

@@ -1,84 +1,98 @@
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';
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, getOrgAdminDetail } from '@/services/org';
5 6
 
6
-export default (props)=>{
7
+
8
+export default (props) => {
7 9
   const { id } = props;
8
-  const [adminForm] = Form.useForm();
9
-  const [adminFormData, setAdminFormData] = useState()
10
-  const [adminLoading, setAdminLoading] = useState(false)
10
+  const { initialState } = useModel('@@initialState');
11 11
 
12
-  const onAdminFinish = (values) => {
13
-    if (!/^1[0-9]{10}$/.test(values.phone)) {
14
-      message.warning('请输入正确的十一位手机号');
15
-      setLoading(false);
16
-      return false;
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
+      })
17 39
     }
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
-  }
40
+  };
41
+  const onFinishFailed = (errorInfo) => {
42
+    console.log('Failed:', errorInfo);
43
+  };
29 44
   useEffect(() => {
30 45
     if (id) {
31
-      getOrgAdminDetail(id).then((res) => {
32
-        setAdminFormData(res);
33
-        adminForm.setFieldsValue(res);
46
+      getDetail(id).then(res => {
47
+        setFormData(res);
48
+        form.setFieldsValue(res);
34 49
       })
35 50
     }
36 51
   }, [id])
37
-  return (
52
+  return(
38 53
     <div style={{ maxWidth: '600px' }}>
39 54
             <Form
40
-              form={adminForm}
55
+              name="basic"
56
+              form={form}
41 57
               labelCol={{ span: 8 }}
42 58
               wrapperCol={{ span: 16 }}
43
-              initialValues={adminFormData}
44
-              onFinish={onAdminFinish}
59
+              initialValues={formData}
60
+              onFinish={onFinish}
61
+              onFinishFailed={onFinishFailed}
62
+              autoComplete="off"
45 63
             >
46 64
               <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: '请填写登录账号!' }]}
65
+                label="企业名称"
66
+                name="orgName"
67
+                rules={[{ required: true, message: '请填写企业名称!' }]}
64 68
               >
65
-                <Input />
69
+                <Input  readOnly={formData?.canEditName}/>
66 70
               </Form.Item>
67 71
               <Form.Item
68
-                label="密码"
69
-                name="password"
70
-                rules={[{ required: true, message: '请填写密码!' }]}
72
+                label="权重"
73
+                name="weight"
74
+                rules={[{ required: true, message: '请填写企业权重!' }]}
71 75
               >
72
-                <Input />
76
+                <Input type='number' min='0' />
73 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
+              }
74 83
               <Form.Item label=' ' colon={false} >
75
-                <Button type="primary" htmlType="submit" loading={adminLoading}>
84
+                <Button type="primary" htmlType="submit" loading={loading}>
76 85
                   保存
77 86
                 </Button>
78
-                <Button style={{ marginLeft: '32px' }} onClick={() => { history.go(-1); }}>返回</Button>
87
+                {id &&
88
+                  <Button style={{ marginLeft: '32px' }} onClick={downloadQrcode} >
89
+                    下载二维码
90
+                  </Button>
91
+                }
92
+                <Button style={{ marginLeft: '32px' }} onClick={() => { history.go(-1); }} >返回</Button>
79 93
               </Form.Item>
80 94
             </Form>
81 95
           </div>
82
-
96
+        
83 97
   )
84
-}
98
+}