Преглед на файлове

Merge branch 'master' of http://git.ycjcjy.com/nanyang/machinery-admin

张延森 преди 3 години
родител
ревизия
8b41fd5f23

+ 2
- 2
config/routes.js Целия файл

@@ -240,10 +240,10 @@ export default [
240 240
     component: '../layouts/BasicLayout',
241 241
     routes: [
242 242
       {
243
-        path: '/SystemManagement/MapExtent',
243
+        path: '/SystemManagement/Region',
244 244
         name: '区域设置',
245 245
         access: 'region',
246
-        component: './SystemManagement/MapExtent',
246
+        component: './SystemManagement/Region',
247 247
         // hideInMenu: true
248 248
       },
249 249
       {

+ 77
- 68
src/pages/SystemManagement/Cooperative/edit.jsx Целия файл

@@ -1,11 +1,11 @@
1
-import { Form, Input, Card, InputNumber, Select, message, Button } from 'antd';
1
+import { Form, Input, Card, Select, message, Button } from 'antd';
2 2
 import { history } from 'umi';
3 3
 import ProCard from '@ant-design/pro-card';
4 4
 import { useState, useEffect } from 'react';
5 5
 import POI from '@/components/POI/POI';
6 6
 
7
-// import { getTagList } from '@/services/tag';
8
-// import { addAttaList, gettaTouristForm, EditaddAttaList } from '@/services/AttaList'
7
+import { getRegionList } from '@/services/region';
8
+import { addCooperative, getCooperativeDetail, updateCooperative } from '@/services/cooperative';
9 9
 
10 10
 const { TextArea } = Input;
11 11
 const { Option } = Select;
@@ -21,74 +21,65 @@ export default (props) => {
21 21
   const [form] = Form.useForm();
22 22
   const [listForm, setListForm] = useState({});
23 23
   const [loading, setLoading] = useState(false);
24
-  const [imageList, setImageList] = useState([]);
25
-  //地址--占位
26 24
   const [newLocName, setLocName] = useState('');
27 25
   const [newAddress, setAddress] = useState('');
26
+  const [regionList, setRegionList] = useState([]);
27
+
28 28
   const Submit = (data) => {
29
-    const typeList = (data.typeList || []).map((x) => {
30
-      return { ...x, targetId: id, targetType: 'tourist' };
31
-    });
32
-    // setLoading(true);
33 29
     console.log(data);
34
-    console.log(newLocName);
35
-    console.log(newAddress);
36
-    // if (id) {
37
-    //   EditaddAttaList(id, { ...listForm, ...data, imageList, typeList }).then(() => {
38
-    //     setLoading(false);
39
-    //     message.success('数据更新成功');
40
-    //     goBack();
41
-    //   })
42
-    //     .catch(err => {
43
-    //       setLoading(false);
44
-    //       message.error(err.message || err);
45
-    //     });
46
-    // } else {
47
-    //   addAttaList({ ...data, imageList, typeList }).then((res) => {
48
-    //     setLoading(false);
49
-    //     message.success('数据保存成功');
50
-    //     history.replace(`/Attractions/Edit?id=${res.touristId}`)
51
-    //   })
52
-    //     .catch(err => {
53
-    //       setLoading(false);
54
-    //       message.error(err.message || err);
55
-    //     });
56
-    // }
57
-  };
58
-
59
-  const selectTagList = (params) => {
60
-    // return getTagList({
61
-    // }).then((res) => {
62
-    // }).catch((err) => {
63
-    //   return {
64
-    //     success: false,
65
-    //   }
66
-    // })
67
-  };
68
-
69
-  const imageInput = (image) => {
70
-    return {
71
-      uid: image.imageId,
72
-      url: image.url,
73
-    };
30
+    setLoading(true);
31
+    if (id) {
32
+      updateCooperative(id, {
33
+        ...listForm,
34
+        ...data,
35
+        lng: data.location.split(',')[0],
36
+        lat: data.location.split(',')[1],
37
+      })
38
+        .then(() => {
39
+          setLoading(false);
40
+          message.success('数据更新成功');
41
+          goBack();
42
+        })
43
+        .catch((err) => {
44
+          setLoading(false);
45
+          message.error(err.message || err);
46
+        });
47
+    } else {
48
+      addCooperative({
49
+        ...data,
50
+        lng: data.location.split(',')[0],
51
+        lat: data.location.split(',')[1],
52
+      })
53
+        .then((res) => {
54
+          setLoading(false);
55
+          message.success('数据保存成功');
56
+          history.goBack();
57
+        })
58
+        .catch((err) => {
59
+          setLoading(false);
60
+          message.error(err.message || err);
61
+        });
62
+    }
74 63
   };
75 64
 
76
-  const imageOutput = (image) => {
77
-    return {
78
-      imageId: image?.raw?.imageId,
79
-      shopId: id,
80
-      url: image.url,
81
-    };
82
-  };
83 65
   useEffect(() => {
84
-    selectTagList();
85
-    // if (id) {
86
-    //   gettaTouristForm(id).then((res) => {
87
-    //     setListForm(res)
88
-    //     form.setFieldsValue(res)
89
-    //     setImageList(res?.imageList || [])
90
-    //   })
91
-    // }
66
+    getRegionList()
67
+      .then((res) => {
68
+        setRegionList(res.records || []);
69
+      })
70
+      .catch((err) => {});
71
+  }, []);
72
+  useEffect(() => {
73
+    if (id) {
74
+      getCooperativeDetail(id)
75
+        .then((res) => {
76
+          setListForm(res || []);
77
+          form.setFieldsValue({ ...res, location: res.lng + ',' + res.lat });
78
+        })
79
+        .catch((err) => {
80
+          message.error(err.message || err);
81
+        });
82
+    }
92 83
   }, [id]);
93 84
 
94 85
   return (
@@ -97,7 +88,7 @@ export default (props) => {
97 88
         <ProCard.TabPane key={1} tab="合作社编辑">
98 89
           <Form {...formItemLayout} onFinish={Submit} form={form}>
99 90
             <FormItem
100
-              label="机构名"
91
+              label="机构名"
101 92
               name="name"
102 93
               rules={[{ required: true, message: '请输入机构名称16个字符以内' }]}
103 94
             >
@@ -126,11 +117,11 @@ export default (props) => {
126 117
               name="phone"
127 118
               rules={[{ required: true, message: '请输入联系方式' }]}
128 119
             >
129
-              <Input placeholder="请输入联系方式" rows={4} style={{ width: '350px' }} />
120
+              <Input placeholder="请输入联系方式" style={{ width: '350px' }} />
130 121
             </FormItem>
131 122
             <FormItem
132 123
               label="定位经纬"
133
-              name="locaton"
124
+              name="location"
134 125
               rules={[{ required: true, message: '请定位' }]}
135 126
             >
136 127
               <POI
@@ -151,7 +142,25 @@ export default (props) => {
151 142
               label="区域"
152 143
               name="regionId"
153 144
               rules={[{ required: true, message: '请输入区域' }]}
154
-            />
145
+            >
146
+              <Select placeholder="请选择区域" style={{ width: '350px' }}>
147
+                {regionList.map((item) => (
148
+                  <Option value={item.regionId} key={item.regionId}>
149
+                    {item.name}
150
+                  </Option>
151
+                ))}
152
+              </Select>
153
+            </FormItem>
154
+            <FormItem label="身份" name="role" rules={[{ required: true, message: '请选择身份' }]}>
155
+              <Select placeholder="请选择身份" style={{ width: '350px' }}>
156
+                <Option value="合作社" key="合作社" />
157
+                <Option value="个体户" key="个体户" />
158
+              </Select>
159
+            </FormItem>
160
+            <FormItem label="员工数">{listForm?.workerNum || 0}</FormItem>
161
+            <FormItem label="农机数">{listForm?.machineryNum || 0}</FormItem>
162
+            <FormItem label="订单完成数">{listForm?.orderNum || 0}</FormItem>
163
+            <FormItem label="评分">{listForm?.score || 0}</FormItem>
155 164
             <FormItem label=" " colon={false}>
156 165
               <Button type="default" onClick={() => goBack()}>
157 166
                 返回

+ 237
- 93
src/pages/SystemManagement/Cooperative/index.jsx Целия файл

@@ -1,109 +1,253 @@
1
-import React from 'react';
2
-import { history, Link } from 'umi';
3
-import { Button, Popconfirm, message, Tooltip } from 'antd';
4
-import { PlusOutlined } from '@ant-design/icons';
5
-import { getList } 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 moment from 'moment';
8
-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';
9 12
 
10
-const formatterTime = (val) => {
11
-  return val ? moment(val).format('YYYY-MM-DD HH:mm:ss') : '';
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 } };
13 21
 
14 22
 export default (props) => {
15
-  const actions = () => [
16
-    <Button key="add" type="primary" icon={<PlusOutlined />} onClick={() => gotoEdit()}>
17
-      新增机构
18
-    </Button>,
19
-  ];
20
-  const gotoEdit = (id) => {
21
-    const queryStr = id ? `?id=${id}` : '';
22
-    history.push(`./Cooperative/edit.jsx${queryStr}`);
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);
43
+  };
44
+  const handleDelete = (val) => {
45
+    deleteCooperative(val).then(() => {
46
+      message.success('删除成功');
47
+      setOrgId();
48
+      handelReset();
49
+    });
23 50
   };
24
-  const columns = [
25
-    {
26
-      title: '机构名',
27
-      dataIndex: 'name',
28
-      key: 'name',
29
-    },
30
-    {
31
-      title: '联系人',
32
-      dataIndex: 'contactPerson',
33
-      key: 'contactPerson',
34
-    },
35
-    {
36
-      title: '联系方式',
37
-      dataIndex: 'phone',
38
-      key: 'phone',
39
-    },
40
-    {
41
-      title: '区域',
42
-      dataIndex: 'regionId',
43
-      key: 'regionId',
44
-    },
45
-    {
46
-      title: '地址',
47
-      dataIndex: 'address',
48
-      key: 'address',
49
-      search: false,
50
-    },
51
+  // 刷新左侧列表
52
+  const handelReset = () => {
53
+    setData([]);
54
+    getCooperativeList()
55
+      .then((res) => {
56
+        const list = res.records?.map((item) => {
57
+          return { title: item.name, key: item.orgId };
58
+        });
59
+        setData(list);
60
+      })
61
+      .catch((err) => {
62
+        message.error(err.message || err);
63
+      });
64
+  };
65
+  // 动态生成树
51 66
 
52
-    {
53
-      title: '农机数',
54
-      dataIndex: 'machineryNum',
55
-      key: 'machineryNum',
56
-      search: false,
57
-    },
58
-    {
59
-      title: '员工数',
60
-      dataIndex: 'employeesNum',
61
-      key: 'employeesNum',
62
-      search: false,
63
-    },
64
-    {
65
-      title: '完成订单数',
66
-      dataIndex: 'orderNum',
67
-      key: 'orderNum',
68
-      search: false,
69
-    },
70
-    {
71
-      title: '评分',
72
-      dataIndex: 'score',
73
-      key: 'score',
74
-      search: false,
75
-    },
76
-    {
77
-      title: '操作',
78
-      valueType: 'option',
79
-      render: (_, record) => [
80
-        <Link key={1} to={`./edit.jsx`}>
81
-          编辑
82
-        </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>
83 75
         <Popconfirm
84
-          key={2}
85 76
           title="您是否确认删除 ?"
86
-          onConfirm={() => handleDelete(record.cooperativeId)}
77
+          onConfirm={() => handleDelete(item.key)}
87 78
           okText="确定"
88 79
           cancelText="取消"
89 80
         >
90
-          <a href="#">删除</a>
91
-        </Popconfirm>,
92
-      ],
93
-    },
94
-  ];
95
-  const handleDelete = () => {};
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
+  };
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]);
96 150
   return (
97 151
     <PageHeaderWrapper>
98
-      <PageTable
99
-        request={getList}
100
-        // expfunc={exportPersonList}
101
-        columns={columns}
102
-        rowKey="cooperativeId"
103
-        options={false}
104
-        toolBarRender={actions}
105
-        scroll={{ x: 1000 }}
106
-      />
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>
107 251
     </PageHeaderWrapper>
108 252
   );
109 253
 };

+ 15
- 0
src/pages/SystemManagement/Cooperative/index.less Целия файл

@@ -0,0 +1,15 @@
1
+@import (reference) '~antd/es/style/themes/index';
2
+
3
+.treeClass {
4
+  .ant-tree-list {
5
+    & div {
6
+      width: 100% !important;
7
+      .ant-tree-switcher-noop {
8
+        display: none !important;
9
+      }
10
+      span:nth-child(3) {
11
+        width: 100%;
12
+      }
13
+    }
14
+  }
15
+}

+ 0
- 111
src/pages/SystemManagement/MapExtent/index.jsx Целия файл

@@ -1,111 +0,0 @@
1
-import React, { useState } from 'react';
2
-import { Tag, Space, Button, Popconfirm, Form, Modal, Input, message } from 'antd';
3
-import { PageHeaderWrapper } from '@ant-design/pro-layout';
4
-import { PlusOutlined, QuestionCircleOutlined } from '@ant-design/icons';
5
-
6
-import ProList from '@ant-design/pro-list';
7
-import './index.less'
8
-const FormItem = Form.Item
9
-const defaultData = [
10
-  {
11
-    id: '1',
12
-    name: '赵村',
13
-    desc: '赵村较大,多人协作',
14
-  },
15
-
16
-];
17
-export default () => {
18
-  const [form2] = Form.useForm()
19
-  const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 }, };
20
-  const [dataSource, setDataSource] = useState(defaultData);
21
-  const [editModal, setEditModal] = useState(false)
22
-  const [editdetail, setEditDetail] = useState()
23
-
24
-  const changeWeight = (record) => {
25
-    setEditDetail(record)
26
-    setEditModal(true)
27
-  }
28
-  const Submit = (values) => {
29
-    console.log('editdetail', editdetail, values);
30
-    message.success(`修改成功`);
31
-    setDataSource([...dataSource, values])
32
-    // setLoading2(false)
33
-    onCancel()
34
-
35
-  }
36
-
37
-  const onCancel = () => {
38
-    form2.resetFields()
39
-    setEditModal(false)
40
-  }
41
-  const actions = () => [
42
-    <Button key='add' type="primary" icon={<PlusOutlined />} onClick={() => setEditModal(true)}>新增</Button>,
43
-  ]
44
-  return (
45
-    <PageHeaderWrapper>
46
-      <ProList
47
-
48
-        toolBarRender={actions}
49
-        rowKey="id"
50
-        headerTitle="区域范围"
51
-        dataSource={dataSource}
52
-        showActions="hover"
53
-        editable={{
54
-          onSave: async (key, record, originRow) => {
55
-            console.log('修改后的', key, record, originRow);
56
-            return true;
57
-          },
58
-        }}
59
-        onDataSourceChange={setDataSource}
60
-        metas={{
61
-          title: {//标题
62
-            dataIndex: 'name',
63
-          },
64
-
65
-          description: {//简介
66
-            dataIndex: 'desc',
67
-          },
68
-          subTitle: {
69
-            editable: false,
70
-            render: () => {
71
-              return (<Space size={0}>
72
-                {/* <Tag color="blue"></Tag> */}
73
-                <Tag color="#5BD8A6">区域名称</Tag>
74
-              </Space>);
75
-            },
76
-          },
77
-          actions: {
78
-            render: (text, row, index, action) => [
79
-              <a onClick={() => {
80
-                action === null || action === void 0 ? void 0 : action.startEditable(row.id);
81
-              }} key="link">
82
-                编辑
83
-              </a>,
84
-              <Popconfirm
85
-                key={3}
86
-                title="您是否确认删除 ?"
87
-                onConfirm={() => handleDelete(record)}
88
-                okText="确定"
89
-                cancelText="取消"
90
-              >
91
-                <a href="#"  >删除</a>
92
-              </Popconfirm>,
93
-            ],
94
-          },
95
-        }} />
96
-      <Modal title="套餐权重修改" visible={editModal} onCancel={onCancel} keyboard={false} maskClosable={false} destroyOnClose={true} footer={null}>
97
-        < Form {...formItemLayout} onFinish={Submit} form={form2} >
98
-          <FormItem label="范围名称" name="name" rules={[{ required: true, message: '请输入' }]}>
99
-            <Input placeholder="请输入" style={{ width: '350px' }} />
100
-          </FormItem>
101
-          <FormItem label="备注" name="desc" >
102
-            <Input placeholder="请输入" style={{ width: '350px' }} />
103
-          </FormItem>
104
-          <FormItem label=" " colon={false} >
105
-            <Button type='default' onClick={onCancel} >取消</Button>
106
-            <Button type='primary' htmlType="Submit" style={{ marginLeft: '4em' }}>修改</Button>
107
-          </FormItem>
108
-        </Form>
109
-      </Modal>
110
-    </PageHeaderWrapper>);
111
-};

+ 0
- 3
src/pages/SystemManagement/MapExtent/index.less Целия файл

@@ -1,3 +0,0 @@
1
-// .ant-form-item-control {
2
-//   display: none;
3
-// }

+ 152
- 0
src/pages/SystemManagement/Region/index.jsx Целия файл

@@ -0,0 +1,152 @@
1
+import React, { useState, useEffect, useRef } from 'react';
2
+import { history, Link } from 'umi';
3
+import { Button, Popconfirm, Modal, Form, Input, message, Tooltip } from 'antd';
4
+import { PlusOutlined } from '@ant-design/icons';
5
+import { getRegionList, addRegion, deleteRegion, updateRegion } from '@/services/region';
6
+import { PageHeaderWrapper } from '@ant-design/pro-layout';
7
+import moment from 'moment';
8
+import PageTable from '@/components/PageTable';
9
+
10
+const formatterTime = (val) => {
11
+  return val && val !== '-' ? moment(val).format('YYYY-MM-DD') : '-';
12
+};
13
+const FormItem = Form.Item;
14
+
15
+export default (props) => {
16
+  const actions = () => [
17
+    <Button key="add" type="primary" icon={<PlusOutlined />} onClick={() => setEditModal(true)}>
18
+      新增
19
+    </Button>,
20
+  ];
21
+  const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
22
+  const [form] = Form.useForm();
23
+  const [editModal, setEditModal] = useState(false);
24
+  const [loading, setLoading] = useState(false);
25
+  const [regionId, setRegionId] = useState();
26
+  const actionRef = useRef();
27
+
28
+  const Submit = (values) => {
29
+    setLoading(true);
30
+    if (regionId) {
31
+      updateRegion(regionId, values).then(() => {
32
+        setLoading(false);
33
+        message.success(`修改成功`);
34
+        onCancel();
35
+        actionRef.current.reload();
36
+      });
37
+    } else {
38
+      addRegion(values)
39
+        .then(() => {
40
+          setLoading(false);
41
+          message.success(`保存成功`);
42
+          onCancel();
43
+          actionRef.current.reload();
44
+        })
45
+        .catch((err) => {
46
+          setLoading(false);
47
+          message.error(err.message || err);
48
+        });
49
+    }
50
+  };
51
+  const handelEdit = (val) => {
52
+    setRegionId(val.regionId);
53
+    form.setFieldsValue(val);
54
+    setEditModal(true);
55
+  };
56
+  const onCancel = () => {
57
+    setRegionId();
58
+    form.resetFields();
59
+    setEditModal(false);
60
+  };
61
+  const handleDelete = (id) => {
62
+    deleteRegion(id)
63
+      .then(() => {
64
+        message.success('删除成功');
65
+        actionRef.current.reload();
66
+      })
67
+      .catch((err) => {
68
+        message.error(err);
69
+      });
70
+  };
71
+  useEffect(() => {
72
+    if (regionId) {
73
+    } else {
74
+      form.resetFields();
75
+    }
76
+  }, [regionId]);
77
+  const columns = [
78
+    {
79
+      title: '区域名',
80
+      dataIndex: 'name',
81
+      key: 'name',
82
+    },
83
+    {
84
+      title: '创建时间',
85
+      dataIndex: 'createDate',
86
+      key: 'createDate',
87
+      render: formatterTime,
88
+      search: false,
89
+    },
90
+    {
91
+      title: '操作',
92
+      valueType: 'option',
93
+      render: (_, record) => [
94
+        <a key={1} onClick={() => handelEdit(record)}>
95
+          编辑
96
+        </a>,
97
+        <Popconfirm
98
+          key={2}
99
+          title="您是否确认删除 ?"
100
+          onConfirm={() => handleDelete(record.regionId)}
101
+          okText="确定"
102
+          cancelText="取消"
103
+        >
104
+          <a href="#">删除</a>
105
+        </Popconfirm>,
106
+      ],
107
+    },
108
+  ];
109
+
110
+  return (
111
+    <PageHeaderWrapper>
112
+      <PageTable
113
+        request={getRegionList}
114
+        // expfunc={exportPersonList}
115
+        columns={columns}
116
+        actionRef={actionRef}
117
+        rowKey="regionId"
118
+        options={false}
119
+        toolBarRender={actions}
120
+        scroll={{ x: 1000 }}
121
+      />
122
+      <Modal
123
+        title="区域新增"
124
+        visible={editModal}
125
+        onCancel={onCancel}
126
+        keyboard={false}
127
+        maskClosable={false}
128
+        destroyOnClose={true}
129
+        footer={null}
130
+      >
131
+        <Form {...formItemLayout} onFinish={Submit} form={form}>
132
+          <FormItem label="区域名" name="name" rules={[{ required: true, message: '请输入' }]}>
133
+            <Input placeholder="请输入" />
134
+          </FormItem>
135
+          <FormItem label=" " colon={false}>
136
+            <Button type="default" onClick={onCancel}>
137
+              取消
138
+            </Button>
139
+            <Button
140
+              type="primary"
141
+              loading={loading}
142
+              htmlType="Submit"
143
+              style={{ marginLeft: '4em' }}
144
+            >
145
+              确认
146
+            </Button>
147
+          </FormItem>
148
+        </Form>
149
+      </Modal>
150
+    </PageHeaderWrapper>
151
+  );
152
+};

+ 1
- 0
src/pages/Welcome.jsx Целия файл

@@ -7,6 +7,7 @@ import styles from './Welcome.less';
7 7
 const CodePreview = ({ children }) => (
8 8
   <pre className={styles.pre}>
9 9
     <code>
10
+      66666
10 11
       <Typography.Text copyable>{children}</Typography.Text>
11 12
     </code>
12 13
   </pre>

+ 10
- 10
src/services/cooperative.js Целия файл

@@ -1,36 +1,36 @@
1 1
 import request from '@/utils/request';
2 2
 
3 3
 /**
4
- * 保存扩展内容
4
+ * 保存组织机构
5 5
  * @param {*} data
6 6
  * @returns
7 7
  */
8
-export const save = (data) => request('/org', { method: 'post', data });
8
+export const addCooperative = (data) => request('/org', { method: 'post', data });
9 9
 
10 10
 /**
11
- * 修改扩展内容
11
+ * 修改组织机构
12 12
  * @param {*} data
13 13
  * @returns
14 14
  */
15
-export const update = (id, data) => request(`/org/${id}`, { method: 'put', data });
15
+export const updateCooperative = (id, data) => request(`/org/${id}`, { method: 'put', data });
16 16
 
17 17
 /**
18
- * 查询扩展内容列表
18
+ * 查询组织机构列表
19 19
  * @param {*} params
20 20
  * @returns
21 21
  */
22
-export const getList = (params) => request('/org', { params });
22
+export const getCooperativeList = (params) => request('/org', { params });
23 23
 
24 24
 /**
25
- * 删除扩展内容
25
+ * 删除组织机构
26 26
  * @param {*} data
27 27
  * @returns
28 28
  */
29
-export const remove = (id) => request(`/org/${id}`, { method: 'delete' });
29
+export const deleteCooperative = (id) => request(`/org/${id}`, { method: 'delete' });
30 30
 
31 31
 /**
32
- * 查询扩展内容详情
32
+ * 查询组织机构详情
33 33
  * @param {*} params
34 34
  * @returns
35 35
  */
36
-export const getDetail = (id) => request(`/org/${id}`);
36
+export const getCooperativeDetail = (id) => request(`/org/${id}`);

+ 36
- 0
src/services/region.js Целия файл

@@ -0,0 +1,36 @@
1
+import request from '@/utils/request';
2
+
3
+/**
4
+ * 保存区域
5
+ * @param {*} data
6
+ * @returns
7
+ */
8
+export const addRegion = (data) => request('/region', { method: 'post', data });
9
+
10
+/**
11
+ * 修改区域
12
+ * @param {*} data
13
+ * @returns
14
+ */
15
+export const updateRegion = (id, data) => request(`/region/${id}`, { method: 'put', data });
16
+
17
+/**
18
+ * 查询区域列表
19
+ * @param {*} params
20
+ * @returns
21
+ */
22
+export const getRegionList = (params) => request('/region', { params });
23
+
24
+/**
25
+ * 删除区域
26
+ * @param {*} data
27
+ * @returns
28
+ */
29
+export const deleteRegion = (id) => request(`/region/${id}`, { method: 'delete' });
30
+
31
+/**
32
+ * 查询区域详情
33
+ * @param {*} params
34
+ * @returns
35
+ */
36
+export const getRegionDetail = (id) => request(`/region/${id}`);