李志伟 3 years ago
parent
commit
0d64ff93b0

+ 127
- 65
src/pages/Machinery/MachineryType/index.jsx View File

@@ -1,37 +1,99 @@
1
-import React from 'react';
2
-import { history, Link } from 'umi';
3
-import { Button, Popconfirm, Modal, Form, Input, message, Space, Tooltip } from 'antd';
1
+import { Button, Popconfirm, Modal, Form, Input, message, Select } from 'antd';
4 2
 import { PlusOutlined } from '@ant-design/icons';
5
-// import { getPersonList, exportPersonList } from '@/services/person';
6 3
 import { PageHeaderWrapper } from '@ant-design/pro-layout';
7
-import { useRef, useState, useEffect } from 'react';
4
+import React, { useRef, useState, useEffect } from 'react';
8 5
 import moment from 'moment';
9 6
 import PageTable from '@/components/PageTable';
7
+import {
8
+  getMachineryTypeList,
9
+  addMachineryType,
10
+  updateMachineryType,
11
+  deleteMachineryType,
12
+} from '@/services/machineryType';
10 13
 
11 14
 const formatterTime = (val) => {
12
-  return val ? moment(val).format('YYYY-MM-DD HH:mm:ss') : '';
15
+  return val ? moment(val).format('YYYY-MM-DD') : '';
13 16
 };
14 17
 const FormItem = Form.Item;
18
+const { Option } = Select;
19
+
15 20
 export default (props) => {
16 21
   const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
17 22
   const [loading, setLoading] = useState(false);
18 23
   const [form] = Form.useForm();
19 24
   const actionRef = useRef();
20
-  const [name, setName] = useState();
21 25
   const [selectModal, setSelectModal] = useState(false);
22
-  const [machineryTypeList, setMachineryTypeList] = useState([]);
26
+  const [typeId, setTypeId] = useState();
23 27
 
24
-  const handleName = (val) => {
25
-    setName(val);
28
+  //列表切换分类状态方法
29
+  const handleOK = (record, data) => {
30
+    const title = record.status
31
+      ? '您确定要将该分类状态变更为禁用吗? 禁用后该分类将不能登录'
32
+      : '您确定要将该分类状态变更为启用吗? 启用后该分类可以登录!';
33
+    Modal.confirm({
34
+      title: title,
35
+      okText: '确认',
36
+      cancelText: '取消',
37
+      onOk() {
38
+        updateMachineryType(record.typeId, { ...record, status: record.status === 1 ? 0 : 1 })
39
+          .then((res) => {
40
+            message.success('操作成功');
41
+            actionRef.current.reload();
42
+          })
43
+          .catch((err) => {
44
+            message.error(err);
45
+          });
46
+      },
47
+    });
26 48
   };
27
-  const changeWeight = (record) => {
49
+  const handleChange = (val) => {
28 50
     setSelectModal(true);
51
+    setTypeId(val.typeId);
52
+    form.setFieldsValue(val);
53
+  };
54
+
55
+  const handleDelete = (val) => {
56
+    deleteMachineryType(val).then(() => {
57
+      message.success('删除成功');
58
+      actionRef.current.reload();
59
+    });
60
+  };
29 61
 
30
-    // setWeight(record.weight || 0)
31
-    // setEditDetail(record)
62
+  const Submit = (data) => {
63
+    setLoading(true);
64
+    if (typeId) {
65
+      updateMachineryType(typeId, data)
66
+        .then(() => {
67
+          message.success(`修改成功`);
68
+          setLoading(false);
69
+          onCancel();
70
+          actionRef.current.reload();
71
+        })
72
+        .catch((err) => {
73
+          setLoading(false);
74
+          message.error(err.message || err);
75
+        });
76
+    } else {
77
+      addMachineryType(data)
78
+        .then(() => {
79
+          message.success(`添加成功`);
80
+          setLoading(false);
81
+          onCancel();
82
+          actionRef.current.reload();
83
+        })
84
+        .catch((err) => {
85
+          setLoading(false);
86
+          message.error(err.message || err);
87
+        });
88
+    }
89
+  };
90
+  const onCancel = () => {
91
+    form.resetFields();
92
+    setSelectModal(false);
93
+    setTypeId();
32 94
   };
33 95
   const actions = () => [
34
-    <Button key="add" type="primary" icon={<PlusOutlined />} onClick={selectModalOpen}>
96
+    <Button key="add" type="primary" icon={<PlusOutlined />} onClick={() => setSelectModal(true)}>
35 97
       新增农机分类
36 98
     </Button>,
37 99
   ];
@@ -42,68 +104,67 @@ export default (props) => {
42 104
       key: 'name',
43 105
     },
44 106
     {
45
-      title: '操作',
46
-      key: 'option',
107
+      title: '创建时间',
108
+      dataIndex: 'createDate',
109
+      key: 'createDate',
110
+      render: formatterTime,
111
+      search: false,
112
+      width: 240,
113
+    },
114
+    {
115
+      title: '状态',
116
+      dataIndex: 'status',
117
+      key: 'status',
118
+      width: 80,
119
+      search: false,
47 120
       render: (_, record) => {
48
-        return (
49
-          <Space>
50
-            <Button key={1} onClick={() => changeWeight(record)} type="link">
51
-              编辑
52
-            </Button>
53
-            <Popconfirm
54
-              key={2}
55
-              title="您是否确认删除 ?"
56
-              onConfirm={() => handleDelete(record.cooperativeId)}
57
-              okText="确定"
58
-              cancelText="取消"
59
-            >
60
-              <a href="#">删除</a>
61
-            </Popconfirm>
62
-          </Space>
63
-        );
121
+        return record.status === 1 ? '发布' : '未发布';
64 122
       },
65
-      search: false,
123
+    },
124
+    {
125
+      title: '操作',
126
+      valueType: 'option',
127
+      width: 160,
128
+      render: (_, record) => [
129
+        <Button style={{ padding: 0 }} type="link" key={1} onClick={() => handleOK(record)}>
130
+          {record.status === 0 ? '发布' : '取消发布'}
131
+        </Button>,
132
+        <Button style={{ padding: 0 }} type="link" key={2} onClick={() => handleChange(record)}>
133
+          编辑
134
+        </Button>,
135
+        <Popconfirm
136
+          key={3}
137
+          title="您是否确认删除 ?"
138
+          onConfirm={() => handleDelete(record.typeId)}
139
+          okText="确定"
140
+          cancelText="取消"
141
+        >
142
+          <Button style={{ padding: 0 }} type="link">
143
+            删除
144
+          </Button>
145
+        </Popconfirm>,
146
+      ],
66 147
     },
67 148
   ];
68
-  const handleDelete = () => { };
69
-
70
-  const Submit = () => {
71
-    setLoading(true);
72
-    editRecommend({ ...editdetail, weight }, editdetail.serialNo).then(() => {
73
-      message.success(`修改成功`);
74
-      setLoading(false);
75
-      onCancel();
76
-      setName();
77
-      actionRef.current.reload();
78
-    });
79
-  };
80
-  const selectModalOpen = () => {
81
-    setSelectModal(true);
82
-  };
83
-  const onCancel = () => {
84
-    form.resetFields();
85
-    setSelectModal(false);
86
-  };
87
-
88
-  useEffect(() => {
89
-    form.setFieldsValue({ targetName: '' });
90
-    // setPackageList();
91
-    // getResource({ pageSize: 100 }).then((res) => {
92
-    //   setMachineryTypeList(res.records || []);
93
-    // });
94
-  }, []);
95 149
   return (
96 150
     <PageHeaderWrapper>
97 151
       <Modal
98
-        title="修改"
152
+        forceRender
153
+        title="农机分类"
99 154
         visible={selectModal}
100 155
         onCancel={onCancel}
101 156
         destroyOnClose={true}
102 157
         footer={null}
103 158
       >
104 159
         <Form {...formItemLayout} onFinish={Submit} form={form}>
105
-          <FormItem label="分类名" name="name" initialValue={name}>
106
-            <Input onChange={handleName} style={{ width: '100%' }} placeholder="请输入分类名" />
160
+          <FormItem label="分类名" name="name">
161
+            <Input placeholder="请输入分类名" />
162
+          </FormItem>
163
+          <FormItem label="状态" name="status" rules={[{ required: true, message: '请选择' }]}>
164
+            <Select placeholder="请选择是否发布">
165
+              <Option value={1}>发布</Option>
166
+              <Option value={0}>未发布</Option>
167
+            </Select>
107 168
           </FormItem>
108 169
           <FormItem label=" " colon={false}>
109 170
             <Button type="default" onClick={onCancel}>
@@ -115,15 +176,16 @@ export default (props) => {
115 176
               htmlType="Submit"
116 177
               style={{ marginLeft: '4em' }}
117 178
             >
118
-              修改
179
+              确定
119 180
             </Button>
120 181
           </FormItem>
121 182
         </Form>
122 183
       </Modal>
123 184
       <PageTable
124
-        // request={getPersonList}
185
+        request={getMachineryTypeList}
125 186
         // expfunc={exportPersonList}
126 187
         toolBarRender={actions}
188
+        actionRef={actionRef}
127 189
         columns={columns}
128 190
         rowKey="typeId"
129 191
         options={false}

+ 11
- 8
src/pages/SystemManagement/Administrator/index.jsx View File

@@ -286,6 +286,7 @@ export default (props) => {
286 286
       key: 'createDate',
287 287
       render: formatterTime,
288 288
       search: false,
289
+      width: 160,
289 290
     },
290 291
     {
291 292
       title: '状态',
@@ -300,17 +301,17 @@ export default (props) => {
300 301
     {
301 302
       title: '操作',
302 303
       valueType: 'option',
303
-      width: 240,
304
+      width: 160,
304 305
       render: (_, record) => [
305
-        <a key={1} onClick={() => handleOK(record)}>
306
+        <Button style={{ padding: 0 }} type="link" key={1} onClick={() => handleOK(record)}>
306 307
           {record.status === 0 ? '启用' : '禁用'}
307
-        </a>,
308
-        <a key={2} onClick={() => handleEdit(record)}>
308
+        </Button>,
309
+        <Button style={{ padding: 0 }} type="link" key={2} onClick={() => handleEdit(record)}>
309 310
           编辑
310
-        </a>,
311
-        <a key={3} onClick={() => handleRole(record)}>
311
+        </Button>,
312
+        <Button style={{ padding: 0 }} type="link" key={3} onClick={() => handleRole(record)}>
312 313
           授权角色
313
-        </a>,
314
+        </Button>,
314 315
         <Popconfirm
315 316
           key={4}
316 317
           title="您是否确认删除 ?"
@@ -318,7 +319,9 @@ export default (props) => {
318 319
           okText="确定"
319 320
           cancelText="取消"
320 321
         >
321
-          <a href="#">删除</a>
322
+          <Button style={{ padding: 0 }} type="link">
323
+            删除
324
+          </Button>
322 325
         </Popconfirm>,
323 326
       ],
324 327
     },

+ 5
- 3
src/pages/SystemManagement/Region/index.jsx View File

@@ -92,9 +92,9 @@ export default (props) => {
92 92
       valueType: 'option',
93 93
       width: 160,
94 94
       render: (_, record) => [
95
-        <a key={1} onClick={() => handelEdit(record)}>
95
+        <Button type="link" style={{ padding: 0 }} key={1} onClick={() => handelEdit(record)}>
96 96
           编辑
97
-        </a>,
97
+        </Button>,
98 98
         <Popconfirm
99 99
           key={2}
100 100
           title="您是否确认删除 ?"
@@ -102,7 +102,9 @@ export default (props) => {
102 102
           okText="确定"
103 103
           cancelText="取消"
104 104
         >
105
-          <a href="#">删除</a>
105
+          <Button style={{ padding: 0 }} type="link">
106
+            删除
107
+          </Button>
106 108
         </Popconfirm>,
107 109
       ],
108 110
     },

+ 9
- 7
src/pages/SystemManagement/UserRights/index.jsx View File

@@ -336,16 +336,16 @@ export default (props) => {
336 336
       dataIndex: 'createDate',
337 337
       key: 'createDate',
338 338
       render: formatterTime,
339
-      width: 240,
339
+      width: 160,
340 340
     },
341 341
     {
342 342
       title: '操作',
343 343
       valueType: 'option',
344
-      width: 240,
344
+      width: 160,
345 345
       render: (_, record) => [
346
-        <a key={1} onClick={() => handelEdit(record)}>
346
+        <Button key={1} style={{ padding: 0 }} type="link" onClick={() => handelEdit(record)}>
347 347
           编辑
348
-        </a>,
348
+        </Button>,
349 349
         <Popconfirm
350 350
           key={2}
351 351
           title="您是否确认删除 ?"
@@ -353,11 +353,13 @@ export default (props) => {
353 353
           okText="确定"
354 354
           cancelText="取消"
355 355
         >
356
-          <a href="#">删除</a>
356
+          <Button style={{ padding: 0 }} type="link">
357
+            删除
358
+          </Button>
357 359
         </Popconfirm>,
358
-        <a key={3} onClick={() => handelEmpower(record)}>
360
+        <Button key={3} style={{ padding: 0 }} type="link" onClick={() => handelEmpower(record)}>
359 361
           授权菜单
360
-        </a>,
362
+        </Button>,
361 363
       ],
362 364
     },
363 365
   ];

+ 37
- 0
src/services/machineryType.js View File

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