|
@@ -0,0 +1,139 @@
|
|
1
|
+import React, { useState, useEffect } from 'react';
|
|
2
|
+import { Form, Checkbox, Card, Button, notification, Modal, Input, Upload } from 'antd';
|
|
3
|
+import { fetch, apis } from '../../../utils/request';
|
|
4
|
+import ImageUpload from '../../../components/uploadImage/ImageUpload';
|
|
5
|
+
|
|
6
|
+const getAdvanced = fetch(apis.member.advanced);
|
|
7
|
+const authorizeAdvanced = fetch(apis.member.saveAdvanced);
|
|
8
|
+
|
|
9
|
+const gridStyle = {
|
|
10
|
+ width: '50%',
|
|
11
|
+ textAlign: 'center',
|
|
12
|
+};
|
|
13
|
+
|
|
14
|
+const formItemLayout = {
|
|
15
|
+ labelCol: {
|
|
16
|
+ xs: { span: 24 },
|
|
17
|
+ sm: { span: 2 },
|
|
18
|
+ },
|
|
19
|
+ wrapperCol: {
|
|
20
|
+ xs: { span: 24 },
|
|
21
|
+ sm: { span: 16 },
|
|
22
|
+ },
|
|
23
|
+};
|
|
24
|
+
|
|
25
|
+const Advanced = (props) => {
|
|
26
|
+ const { getFieldDecorator } = props.form;
|
|
27
|
+ const [menus, setMenus] = useState([])
|
|
28
|
+ const [checkOpts, setCheckOptions] = useState({checkedList: [], indeterminate: true, checkAll: false})
|
|
29
|
+
|
|
30
|
+ const user = props.data || {}
|
|
31
|
+
|
|
32
|
+ useEffect(() => {
|
|
33
|
+ if (user && user.userId) {
|
|
34
|
+ getAdvanced({ params: {orgId: user.orgId} }).then((data) => {
|
|
35
|
+ let checkedList = []
|
|
36
|
+ const modules = (data.list || []).map(item => {
|
|
37
|
+ if (item.hasRights) {
|
|
38
|
+ checkedList.push(item.advancedConfigId)
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ return {
|
|
42
|
+ label: item.advancedConfigName,
|
|
43
|
+ value: item.advancedConfigId,
|
|
44
|
+ }
|
|
45
|
+ })
|
|
46
|
+ props.form.setFieldsValue(data.taWxPayConfig)
|
|
47
|
+ setMenus(modules);
|
|
48
|
+ setCheckOptions({
|
|
49
|
+ checkedList,
|
|
50
|
+ indeterminate: !!checkedList.length && checkedList.length < modules.length,
|
|
51
|
+ checkAll: checkedList.length === modules.length
|
|
52
|
+ })
|
|
53
|
+ }).catch(x => x)
|
|
54
|
+ }
|
|
55
|
+ }, [user.userId])
|
|
56
|
+
|
|
57
|
+ const handleChange = (checkedList) => {
|
|
58
|
+ setCheckOptions({
|
|
59
|
+ checkedList,
|
|
60
|
+ indeterminate: !!checkedList.length && checkedList.length < menus.length,
|
|
61
|
+ checkAll: checkedList.length === menus.length
|
|
62
|
+ })
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ const checkAllChange = (e) => {
|
|
66
|
+ setCheckOptions({
|
|
67
|
+ checkedList: e.target.checked ? menus.map(x => x.value) : [],
|
|
68
|
+ indeterminate: false,
|
|
69
|
+ checkAll: e.target.checked,
|
|
70
|
+ })
|
|
71
|
+ }
|
|
72
|
+
|
|
73
|
+ const CheckAll = (
|
|
74
|
+ <Checkbox
|
|
75
|
+ indeterminate={checkOpts.indeterminate}
|
|
76
|
+ onChange={checkAllChange}
|
|
77
|
+ checked={checkOpts.checkAll}
|
|
78
|
+ > 全选 </Checkbox>
|
|
79
|
+ )
|
|
80
|
+
|
|
81
|
+ const handleSubmit = () => {
|
|
82
|
+ const data = {
|
|
83
|
+ orgId: user.orgId,
|
|
84
|
+ menus: checkOpts.checkedList,
|
|
85
|
+ wxPayData: props.form.getFieldsValue()
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ authorizeAdvanced({ data }).then(() => {
|
|
89
|
+ notification.success({ message: '更新高级配置成功' })
|
|
90
|
+ }).catch(x => x)
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ const handleCancel = () => {
|
|
94
|
+ if (typeof props.onCancel === 'function') {
|
|
95
|
+ props.onCancel()
|
|
96
|
+ }
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ return (
|
|
100
|
+ <div>
|
|
101
|
+ <Card title="功能开放" extra={CheckAll} bordered={false}>
|
|
102
|
+ <Checkbox.Group
|
|
103
|
+ value={checkOpts.checkedList}
|
|
104
|
+ onChange={handleChange}
|
|
105
|
+ >
|
|
106
|
+ {menus.map((menu, inx) => {
|
|
107
|
+ return (
|
|
108
|
+ <Card.Grid hoverable={false} style={gridStyle} key={inx}>
|
|
109
|
+ <Checkbox value={menu.value}>{menu.label}</Checkbox>
|
|
110
|
+ </Card.Grid>
|
|
111
|
+ )
|
|
112
|
+ })}
|
|
113
|
+ </Checkbox.Group>
|
|
114
|
+ </Card>
|
|
115
|
+ <Card title="支付配置" bordered={false}>
|
|
116
|
+ <Form {...formItemLayout} >
|
|
117
|
+ <Form.Item label="商户号">
|
|
118
|
+ {getFieldDecorator('mchId')(<Input />)}
|
|
119
|
+ </Form.Item>
|
|
120
|
+ <Form.Item label="appid">
|
|
121
|
+ {getFieldDecorator('appid')(<Input />)}
|
|
122
|
+ </Form.Item>
|
|
123
|
+ <Form.Item label="key">
|
|
124
|
+ {getFieldDecorator('mchKey')(<Input />)}
|
|
125
|
+ </Form.Item>
|
|
126
|
+ <Form.Item label="API密钥">
|
|
127
|
+ {getFieldDecorator('apiPath')(<ImageUpload />)}
|
|
128
|
+ </Form.Item>
|
|
129
|
+ </Form>
|
|
130
|
+ </Card>
|
|
131
|
+ <div style={{ padding: '36px 100px' }}>
|
|
132
|
+ <Button type="primary" onClick={handleSubmit}>提交</Button>
|
|
133
|
+ <Button style={{ marginLeft: '36px' }} onClick={handleCancel}>取消</Button>
|
|
134
|
+ </div>
|
|
135
|
+ </div>
|
|
136
|
+ );
|
|
137
|
+}
|
|
138
|
+const WrappedAdvancedForm = Form.create({ name: 'Advanced' })(Advanced);
|
|
139
|
+export default WrappedAdvancedForm;
|