|
@@ -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}
|