|
@@ -1,121 +1,253 @@
|
1
|
|
-import React, { useRef } from 'react';
|
2
|
|
-import { history, Link } from 'umi';
|
3
|
|
-import { Button, Popconfirm, message } from 'antd';
|
4
|
|
-import { PlusOutlined } from '@ant-design/icons';
|
5
|
|
-import { getCooperativeList, deleteCooperative } from '@/services/cooperative';
|
|
1
|
+import React, { useState, useEffect } from 'react';
|
|
2
|
+import { Tree, Row, Col, Popconfirm, Card, Form, Input, Select, Button, message } from 'antd';
|
6
|
3
|
import { PageHeaderWrapper } from '@ant-design/pro-layout';
|
7
|
|
-import PageTable from '@/components/PageTable';
|
|
4
|
+import { getRegionList } from '@/services/region';
|
|
5
|
+import {
|
|
6
|
+ getCooperativeList,
|
|
7
|
+ deleteCooperative,
|
|
8
|
+ addCooperative,
|
|
9
|
+ getCooperativeDetail,
|
|
10
|
+ updateCooperative,
|
|
11
|
+} from '@/services/cooperative';
|
|
12
|
+
|
|
13
|
+import POI from '@/components/POI/POI';
|
|
14
|
+import { CloseOutlined } from '@ant-design/icons';
|
|
15
|
+import './index.less';
|
|
16
|
+
|
|
17
|
+const FormItem = Form.Item;
|
|
18
|
+const { TextArea } = Input;
|
|
19
|
+const { Option } = Select;
|
|
20
|
+const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
|
8
|
21
|
|
9
|
22
|
export default (props) => {
|
10
|
|
- const actionRef = useRef();
|
11
|
|
- const actions = () => [
|
12
|
|
- <Button key="add" type="primary" icon={<PlusOutlined />} onClick={() => gotoEdit()}>
|
13
|
|
- 新增机构
|
14
|
|
- </Button>,
|
15
|
|
- ];
|
16
|
|
- const gotoEdit = () => {
|
17
|
|
- history.push(`./Cooperative/edit.jsx`);
|
|
23
|
+ //列表数据
|
|
24
|
+ const [data, setData] = useState([]);
|
|
25
|
+
|
|
26
|
+ //机构Id
|
|
27
|
+ const [orgId, setOrgId] = useState('');
|
|
28
|
+ const [form] = Form.useForm();
|
|
29
|
+ //机构表单数据
|
|
30
|
+ const [listForm, setListForm] = useState({});
|
|
31
|
+ //确定按钮loading框防连点
|
|
32
|
+ const [loading, setLoading] = useState(false);
|
|
33
|
+ //记录定位信息
|
|
34
|
+ const [newLocName, setLocName] = useState('');
|
|
35
|
+ const [newAddress, setAddress] = useState('');
|
|
36
|
+ //机构所属区域列表
|
|
37
|
+ const [regionList, setRegionList] = useState([]);
|
|
38
|
+
|
|
39
|
+ //选中左侧列表右侧显示详情
|
|
40
|
+ const handleslect = (val) => {
|
|
41
|
+ console.log(666);
|
|
42
|
+ setOrgId(val);
|
18
|
43
|
};
|
19
|
44
|
const handleDelete = (val) => {
|
20
|
|
- deleteCooperative(val)
|
|
45
|
+ deleteCooperative(val).then(() => {
|
|
46
|
+ message.success('删除成功');
|
|
47
|
+ setOrgId();
|
|
48
|
+ handelReset();
|
|
49
|
+ });
|
|
50
|
+ };
|
|
51
|
+ // 刷新左侧列表
|
|
52
|
+ const handelReset = () => {
|
|
53
|
+ setData([]);
|
|
54
|
+ getCooperativeList()
|
21
|
55
|
.then((res) => {
|
22
|
|
- message.success('删除成功');
|
23
|
|
- actionRef.current.reload();
|
|
56
|
+ const list = res.records?.map((item) => {
|
|
57
|
+ return { title: item.name, key: item.orgId };
|
|
58
|
+ });
|
|
59
|
+ setData(list);
|
24
|
60
|
})
|
25
|
61
|
.catch((err) => {
|
26
|
|
- return {
|
27
|
|
- success: false,
|
28
|
|
- };
|
|
62
|
+ message.error(err.message || err);
|
29
|
63
|
});
|
30
|
64
|
};
|
31
|
|
- const columns = [
|
32
|
|
- {
|
33
|
|
- title: '机构名',
|
34
|
|
- dataIndex: 'name',
|
35
|
|
- key: 'name',
|
36
|
|
- },
|
37
|
|
- {
|
38
|
|
- title: '联系人',
|
39
|
|
- dataIndex: 'contactPerson',
|
40
|
|
- key: 'contactPerson',
|
41
|
|
- },
|
42
|
|
- {
|
43
|
|
- title: '联系方式',
|
44
|
|
- dataIndex: 'phone',
|
45
|
|
- key: 'phone',
|
46
|
|
- },
|
47
|
|
- {
|
48
|
|
- title: '区域',
|
49
|
|
- dataIndex: 'regionId',
|
50
|
|
- key: 'regionId',
|
51
|
|
- },
|
52
|
|
- {
|
53
|
|
- title: '地址',
|
54
|
|
- dataIndex: 'address',
|
55
|
|
- key: 'address',
|
56
|
|
- search: false,
|
57
|
|
- },
|
|
65
|
+ // 动态生成树
|
58
|
66
|
|
59
|
|
- {
|
60
|
|
- title: '农机数',
|
61
|
|
- dataIndex: 'machineryNum',
|
62
|
|
- key: 'machineryNum',
|
63
|
|
- search: false,
|
64
|
|
- render: (_, record) => record.machineryNum || 0,
|
65
|
|
- },
|
66
|
|
- {
|
67
|
|
- title: '员工数',
|
68
|
|
- dataIndex: 'employeesNum',
|
69
|
|
- key: 'employeesNum',
|
70
|
|
- search: false,
|
71
|
|
- render: (_, record) => record.employeesNum || 0,
|
72
|
|
- },
|
73
|
|
- {
|
74
|
|
- title: '完成订单数',
|
75
|
|
- dataIndex: 'orderNum',
|
76
|
|
- key: 'orderNum',
|
77
|
|
- search: false,
|
78
|
|
- render: (_, record) => record.orderNum || 0,
|
79
|
|
- },
|
80
|
|
- {
|
81
|
|
- title: '评分',
|
82
|
|
- dataIndex: 'score',
|
83
|
|
- key: 'score',
|
84
|
|
- search: false,
|
85
|
|
- render: (_, record) => record.score || 0,
|
86
|
|
- },
|
87
|
|
- {
|
88
|
|
- title: '操作',
|
89
|
|
- valueType: 'option',
|
90
|
|
- render: (_, record) => [
|
91
|
|
- <Link key={1} to={`./Cooperative/edit.jsx?id=${record.orgId}`}>
|
92
|
|
- 编辑
|
93
|
|
- </Link>,
|
|
67
|
+ const handelNode = (item) => {
|
|
68
|
+ let node = (
|
|
69
|
+ <div
|
|
70
|
+ key={item.orgId}
|
|
71
|
+ style={{ justifyContent: 'space-between', display: 'flex', width: '100%' }}
|
|
72
|
+ onClick={() => handleslect(item.key)}
|
|
73
|
+ >
|
|
74
|
+ <span>{item.title}</span>
|
94
|
75
|
<Popconfirm
|
95
|
|
- key={2}
|
96
|
76
|
title="您是否确认删除 ?"
|
97
|
|
- onConfirm={() => handleDelete(record.orgId)}
|
|
77
|
+ onConfirm={() => handleDelete(item.key)}
|
98
|
78
|
okText="确定"
|
99
|
79
|
cancelText="取消"
|
100
|
80
|
>
|
101
|
|
- <a href="#">删除</a>
|
102
|
|
- </Popconfirm>,
|
103
|
|
- ],
|
104
|
|
- },
|
105
|
|
- ];
|
|
81
|
+ <CloseOutlined style={{ color: 'red', marginTop: '6px' }} />
|
|
82
|
+ </Popconfirm>
|
|
83
|
+ </div>
|
|
84
|
+ );
|
|
85
|
+ return node;
|
|
86
|
+ };
|
|
87
|
+
|
|
88
|
+ //提交表单
|
|
89
|
+ const Submit = (data) => {
|
|
90
|
+ setLoading(true);
|
|
91
|
+ if (orgId) {
|
|
92
|
+ updateCooperative(orgId, {
|
|
93
|
+ ...listForm,
|
|
94
|
+ ...data,
|
|
95
|
+ lng: data.location.split(',')[0],
|
|
96
|
+ lat: data.location.split(',')[1],
|
|
97
|
+ })
|
|
98
|
+ .then(() => {
|
|
99
|
+ setLoading(false);
|
|
100
|
+ message.success('数据更新成功');
|
|
101
|
+ handelReset();
|
|
102
|
+ })
|
|
103
|
+ .catch((err) => {
|
|
104
|
+ setLoading(false);
|
|
105
|
+ message.error(err.message || err);
|
|
106
|
+ });
|
|
107
|
+ } else {
|
|
108
|
+ addCooperative({
|
|
109
|
+ ...data,
|
|
110
|
+ lng: data.location.split(',')[0],
|
|
111
|
+ lat: data.location.split(',')[1],
|
|
112
|
+ })
|
|
113
|
+ .then((res) => {
|
|
114
|
+ setLoading(false);
|
|
115
|
+ message.success('数据保存成功');
|
|
116
|
+ handelReset();
|
|
117
|
+ })
|
|
118
|
+ .catch((err) => {
|
|
119
|
+ setLoading(false);
|
|
120
|
+ message.error(err.message || err);
|
|
121
|
+ });
|
|
122
|
+ }
|
|
123
|
+ };
|
106
|
124
|
|
|
125
|
+ useEffect(() => {
|
|
126
|
+ handelReset();
|
|
127
|
+ getRegionList()
|
|
128
|
+ .then((res) => {
|
|
129
|
+ setRegionList(res.records || []);
|
|
130
|
+ })
|
|
131
|
+ .catch((err) => {
|
|
132
|
+ message.error(err.message || err);
|
|
133
|
+ });
|
|
134
|
+ }, []);
|
|
135
|
+ useEffect(() => {
|
|
136
|
+ if (orgId) {
|
|
137
|
+ getCooperativeDetail(orgId)
|
|
138
|
+ .then((res) => {
|
|
139
|
+ setListForm(res || []);
|
|
140
|
+ form.setFieldsValue({ ...res, location: res.lng + ',' + res.lat });
|
|
141
|
+ })
|
|
142
|
+ .catch((err) => {
|
|
143
|
+ message.error(err.message || err);
|
|
144
|
+ });
|
|
145
|
+ } else {
|
|
146
|
+ setListForm();
|
|
147
|
+ form.resetFields();
|
|
148
|
+ }
|
|
149
|
+ }, [orgId]);
|
107
|
150
|
return (
|
108
|
151
|
<PageHeaderWrapper>
|
109
|
|
- <PageTable
|
110
|
|
- request={getCooperativeList}
|
111
|
|
- // expfunc={exportPersonList}
|
112
|
|
- columns={columns}
|
113
|
|
- rowKey="orgId"
|
114
|
|
- options={false}
|
115
|
|
- toolBarRender={actions}
|
116
|
|
- actionRef={actionRef}
|
117
|
|
- scroll={{ x: 2000 }}
|
118
|
|
- />
|
|
152
|
+ <Row gutter={16}>
|
|
153
|
+ <Col span={8}>
|
|
154
|
+ <Card
|
|
155
|
+ title="列表"
|
|
156
|
+ extra={
|
|
157
|
+ <a href="#" onClick={() => setOrgId()}>
|
|
158
|
+ 添加
|
|
159
|
+ </a>
|
|
160
|
+ }
|
|
161
|
+ >
|
|
162
|
+ <Tree className="treeClass" titleRender={(data) => handelNode(data)} treeData={data} />
|
|
163
|
+ </Card>
|
|
164
|
+ </Col>
|
|
165
|
+ <Col span={16}>
|
|
166
|
+ <Card title="详情">
|
|
167
|
+ <Form {...formItemLayout} onFinish={Submit} form={form}>
|
|
168
|
+ <FormItem
|
|
169
|
+ label="机构名"
|
|
170
|
+ name="name"
|
|
171
|
+ rules={[{ required: true, message: '请输入机构名称16个字符以内' }]}
|
|
172
|
+ >
|
|
173
|
+ <Input
|
|
174
|
+ placeholder="请输入机构名称16个字符以内"
|
|
175
|
+ maxLength="16"
|
|
176
|
+ style={{ width: '350px' }}
|
|
177
|
+ />
|
|
178
|
+ </FormItem>
|
|
179
|
+ <FormItem label="信用代码" name="creditCode">
|
|
180
|
+ <Input placeholder="请输入信用代码" style={{ width: '350px' }} />
|
|
181
|
+ </FormItem>
|
|
182
|
+ <FormItem
|
|
183
|
+ label="联系人"
|
|
184
|
+ name="contactPerson"
|
|
185
|
+ rules={[{ required: true, message: '请输入联系人' }]}
|
|
186
|
+ >
|
|
187
|
+ <Input placeholder="请输入联系人" rows={4} style={{ width: '350px' }} />
|
|
188
|
+ </FormItem>
|
|
189
|
+ <FormItem
|
|
190
|
+ label="联系方式"
|
|
191
|
+ name="phone"
|
|
192
|
+ rules={[{ required: true, message: '请输入联系方式' }]}
|
|
193
|
+ >
|
|
194
|
+ <Input placeholder="请输入联系方式" style={{ width: '350px' }} />
|
|
195
|
+ </FormItem>
|
|
196
|
+ <FormItem
|
|
197
|
+ label="定位经纬"
|
|
198
|
+ name="location"
|
|
199
|
+ rules={[{ required: true, message: '请定位' }]}
|
|
200
|
+ >
|
|
201
|
+ <POI
|
|
202
|
+ placeholder="定位"
|
|
203
|
+ setLocName={setLocName}
|
|
204
|
+ setAddress={setAddress}
|
|
205
|
+ roomBoole={true}
|
|
206
|
+ />
|
|
207
|
+ </FormItem>
|
|
208
|
+ <FormItem
|
|
209
|
+ label="地址"
|
|
210
|
+ name="address"
|
|
211
|
+ rules={[{ required: true, message: '请输入地址' }]}
|
|
212
|
+ >
|
|
213
|
+ <TextArea placeholder="请输入地址" style={{ width: '350px' }} />
|
|
214
|
+ </FormItem>
|
|
215
|
+ <FormItem
|
|
216
|
+ label="区域"
|
|
217
|
+ name="regionId"
|
|
218
|
+ rules={[{ required: true, message: '请输入区域' }]}
|
|
219
|
+ >
|
|
220
|
+ <Select placeholder="请选择区域" style={{ width: '350px' }}>
|
|
221
|
+ {regionList.map((item) => (
|
|
222
|
+ <Option value={item.regionId} key={item.regionId}>
|
|
223
|
+ {item.name}
|
|
224
|
+ </Option>
|
|
225
|
+ ))}
|
|
226
|
+ </Select>
|
|
227
|
+ </FormItem>
|
|
228
|
+ <FormItem
|
|
229
|
+ label="身份"
|
|
230
|
+ name="role"
|
|
231
|
+ rules={[{ required: true, message: '请选择身份' }]}
|
|
232
|
+ >
|
|
233
|
+ <Select placeholder="请选择身份" style={{ width: '350px' }}>
|
|
234
|
+ <Option value="合作社" key="合作社" />
|
|
235
|
+ <Option value="个体户" key="个体户" />
|
|
236
|
+ </Select>
|
|
237
|
+ </FormItem>
|
|
238
|
+ <FormItem label="员工数">{listForm?.workerNum || 0}</FormItem>
|
|
239
|
+ <FormItem label="农机数">{listForm?.machineryNum || 0}</FormItem>
|
|
240
|
+ <FormItem label="订单完成数">{listForm?.orderNum || 0}</FormItem>
|
|
241
|
+ <FormItem label="评分">{listForm?.score || 0}</FormItem>
|
|
242
|
+ <FormItem label=" " colon={false}>
|
|
243
|
+ <Button type="primary" loading={loading} htmlType="submit">
|
|
244
|
+ 保存
|
|
245
|
+ </Button>
|
|
246
|
+ </FormItem>
|
|
247
|
+ </Form>
|
|
248
|
+ </Card>
|
|
249
|
+ </Col>
|
|
250
|
+ </Row>
|
119
|
251
|
</PageHeaderWrapper>
|
120
|
252
|
);
|
121
|
253
|
};
|