|
@@ -1,7 +1,7 @@
|
1
|
1
|
import React, { useState, useEffect } from 'react';
|
2
|
2
|
import { Card, Form, Button, Select, message, Modal } from 'antd';
|
3
|
3
|
import ProCard from '@ant-design/pro-card';
|
4
|
|
-import { getOrderDetail } from '@/services/order'
|
|
4
|
+import { getOrderDetail } from '@/services/order';
|
5
|
5
|
import { getMachineryList, getduty } from '@/services/machinery';
|
6
|
6
|
import { history } from 'umi';
|
7
|
7
|
import { getUserList } from '@/services/user';
|
|
@@ -18,116 +18,123 @@ export default (props) => {
|
18
|
18
|
const { id } = location.query;
|
19
|
19
|
const [dispatch, setDispatch] = useState();
|
20
|
20
|
const [loading, setLoading] = useState(false);
|
21
|
|
- const [dispatchId, setDispatchId] = useState()
|
|
21
|
+ const [dispatchId, setDispatchId] = useState();
|
22
|
22
|
const [machineryList, setMachineryList] = useState([]);
|
23
|
|
- const [userList, setUserList] = useState([])
|
|
23
|
+ const [userList, setUserList] = useState([]);
|
24
|
24
|
|
25
|
25
|
const [cancelLoading, setCancelLoading] = useState(false);
|
26
|
26
|
|
27
|
27
|
const submit = () => {
|
28
|
28
|
if (!dispatch.machineryId) {
|
29
|
29
|
message.warning('请选择调度的农机');
|
30
|
|
- return
|
|
30
|
+ return;
|
31
|
31
|
}
|
32
|
32
|
if (!dispatch.workerId) {
|
33
|
33
|
message.warning('请选择农机手');
|
34
|
|
- return
|
|
34
|
+ return;
|
35
|
35
|
}
|
36
|
|
- setLoading(true)
|
37
|
|
- addDispatch(dispatch).then(res => {
|
38
|
|
- message.success('调度成功');
|
39
|
|
- setLoading(false);
|
40
|
|
- goBack()
|
41
|
|
- }).catch((err) => {
|
42
|
|
- setLoading(false);
|
43
|
|
- message.error(err.message || err);
|
44
|
|
- });
|
|
36
|
+ setLoading(true);
|
|
37
|
+ addDispatch(dispatch)
|
|
38
|
+ .then((res) => {
|
|
39
|
+ message.success('调度成功');
|
|
40
|
+ setLoading(false);
|
|
41
|
+ goBack();
|
|
42
|
+ })
|
|
43
|
+ .catch((err) => {
|
|
44
|
+ setLoading(false);
|
|
45
|
+ message.error(err.message || err);
|
|
46
|
+ });
|
45
|
47
|
};
|
46
|
48
|
const changeMachinery = (e) => {
|
47
|
|
- getduty(e, { date: dispatch.appointmentDate.substr(0, 10) }).then((res => {
|
48
|
|
- if (res.length != 0) {
|
49
|
|
- message.info('该农机当天已有' + res.length + '条调度信息');
|
50
|
|
- }
|
51
|
|
- setDispatch({ ...dispatch, machineryId: e })
|
52
|
|
- })).catch((err) => {
|
53
|
|
- console.log(err.message)
|
54
|
|
- });
|
55
|
|
- }
|
|
49
|
+ getduty(e, { date: dispatch.appointmentDate.substr(0, 10) })
|
|
50
|
+ .then((res) => {
|
|
51
|
+ if (res.length != 0) {
|
|
52
|
+ message.info('该农机当天已有' + res.length + '条调度信息');
|
|
53
|
+ }
|
|
54
|
+ setDispatch({ ...dispatch, machineryId: e });
|
|
55
|
+ })
|
|
56
|
+ .catch((err) => {
|
|
57
|
+ console.log(err.message);
|
|
58
|
+ });
|
|
59
|
+ };
|
56
|
60
|
const changeUser = (e) => {
|
57
|
|
- setDispatch({ ...dispatch, workerId: e })
|
58
|
|
- }
|
|
61
|
+ setDispatch({ ...dispatch, workerId: e });
|
|
62
|
+ };
|
59
|
63
|
const onCancel = () => {
|
60
|
64
|
Modal.confirm({
|
61
|
65
|
title: '确认取消?',
|
62
|
66
|
okText: '确认',
|
63
|
67
|
cancelText: '取消',
|
64
|
68
|
onOk() {
|
65
|
|
- setCancelLoading(true)
|
66
|
|
- cancelDispatch(dispatchId).then(() => {
|
67
|
|
- setCancelLoading(false)
|
68
|
|
- setDispatchId()
|
69
|
|
- setDispatch({ ...dispatch, machineryId: null, workerId: null })
|
70
|
|
- message.success('取消成功');
|
71
|
|
- }).catch((err) => {
|
72
|
|
- setCancelLoading(false);
|
73
|
|
- message.error(err.message || err);
|
74
|
|
- });
|
|
69
|
+ setCancelLoading(true);
|
|
70
|
+ cancelDispatch(dispatchId)
|
|
71
|
+ .then(() => {
|
|
72
|
+ setCancelLoading(false);
|
|
73
|
+ setDispatchId();
|
|
74
|
+ setDispatch({ ...dispatch, machineryId: null, workerId: null });
|
|
75
|
+ message.success('取消成功');
|
|
76
|
+ })
|
|
77
|
+ .catch((err) => {
|
|
78
|
+ setCancelLoading(false);
|
|
79
|
+ message.error(err.message || err);
|
|
80
|
+ });
|
75
|
81
|
},
|
76
|
82
|
});
|
77
|
|
- }
|
|
83
|
+ };
|
78
|
84
|
useEffect(() => {
|
79
|
|
-
|
80
|
|
- getOrderDetail(id).then((res) => {
|
81
|
|
- res.machineryId = null
|
82
|
|
- res.typeId = res.machineryType
|
83
|
|
- setDispatch(res)
|
84
|
|
- getMachineryList({ orgId: res.orgId, status: 1, typeId: res.typeId, pageSize: 999 }).then((res2) => {
|
85
|
|
- setMachineryList(res2.records)
|
86
|
|
- }).catch((err) => {
|
87
|
|
- console.log(err.message)
|
|
85
|
+ getOrderDetail(id)
|
|
86
|
+ .then((res) => {
|
|
87
|
+ res.machineryId = null;
|
|
88
|
+ res.typeId = res.machineryType;
|
|
89
|
+ setDispatch(res);
|
|
90
|
+ getMachineryList({ orgId: res.orgId, status: 1, typeId: res.typeId, pageSize: 999 })
|
|
91
|
+ .then((res2) => {
|
|
92
|
+ setMachineryList(res2.records);
|
|
93
|
+ })
|
|
94
|
+ .catch((err) => {
|
|
95
|
+ console.log(err.message);
|
|
96
|
+ });
|
|
97
|
+ getUserList({ org_id: res.orgId, pageSize: 999 })
|
|
98
|
+ .then((res3) => {
|
|
99
|
+ setUserList(res3.records);
|
|
100
|
+ })
|
|
101
|
+ .catch((err) => {
|
|
102
|
+ console.log(err.message);
|
|
103
|
+ });
|
|
104
|
+ if (res.dispatchStatus == 1) {
|
|
105
|
+ getdispatchId(id)
|
|
106
|
+ .then((res4) => {
|
|
107
|
+ setDispatchId(res4.dispatchId);
|
|
108
|
+ setDispatch({ ...res, machineryId: res4.machineryId, workerId: res4.workerId });
|
|
109
|
+ })
|
|
110
|
+ .catch((err) => {
|
|
111
|
+ console.log(err.message);
|
|
112
|
+ });
|
|
113
|
+ }
|
|
114
|
+ })
|
|
115
|
+ .catch((err) => {
|
|
116
|
+ console.log(err.message);
|
88
|
117
|
});
|
89
|
|
- getUserList({ org_id: res.orgId, pageSize: 999 }).then(res3 => {
|
90
|
|
- setUserList(res3.records)
|
91
|
|
- }).catch((err) => {
|
92
|
|
- console.log(err.message)
|
93
|
|
- });
|
94
|
|
- if (res.dispatchStatus == 1) {
|
95
|
|
- getdispatchId(id).then(res4 => {
|
96
|
|
- setDispatchId(res4.dispatchId)
|
97
|
|
- setDispatch({ ...res, machineryId: res4.machineryId, workerId: res4.workerId })
|
98
|
|
- }).catch((err) => {
|
99
|
|
- console.log(err.message)
|
100
|
|
- });
|
101
|
|
- }
|
102
|
|
- }).catch((err) => {
|
103
|
|
- console.log(err.message)
|
104
|
|
- });
|
105
|
|
- }, [id])
|
|
118
|
+ }, [id]);
|
106
|
119
|
return (
|
107
|
120
|
<Card>
|
108
|
121
|
<ProCard tabs={{ type: 'card' }}>
|
109
|
122
|
<ProCard.TabPane key={1} tab="订单调度">
|
110
|
123
|
<Form {...formItemLayout}>
|
111
|
|
- <FormItem label="客户姓名">
|
112
|
|
- {dispatch?.personName}
|
113
|
|
- </FormItem>
|
114
|
|
- <FormItem label="联系电话">
|
115
|
|
- {dispatch?.phone}
|
116
|
|
- </FormItem>
|
117
|
|
- <FormItem label="预约地址">
|
118
|
|
- {dispatch?.address}
|
119
|
|
- </FormItem>
|
120
|
|
- <FormItem label="预约时间">
|
121
|
|
- {dispatch?.appointmentDate}
|
122
|
|
- </FormItem>
|
123
|
|
- <FormItem label="合作社名">
|
124
|
|
- {dispatch?.orgName}
|
125
|
|
- </FormItem>
|
126
|
|
- <FormItem label="农机类型">
|
127
|
|
- {dispatch?.typeName}
|
128
|
|
- </FormItem>
|
|
124
|
+ <FormItem label="农户姓名">{dispatch?.personName}</FormItem>
|
|
125
|
+ <FormItem label="联系电话">{dispatch?.phone}</FormItem>
|
|
126
|
+ <FormItem label="预约地址">{dispatch?.address}</FormItem>
|
|
127
|
+ <FormItem label="预约时间">{dispatch?.appointmentDate}</FormItem>
|
|
128
|
+ <FormItem label="合作社名">{dispatch?.orgName}</FormItem>
|
|
129
|
+ <FormItem label="农机类型">{dispatch?.typeName}</FormItem>
|
129
|
130
|
<FormItem label="农机">
|
130
|
|
- <Select placeholder="请选择" value={dispatch?.machineryId} onChange={changeMachinery} allowClear style={{ width: '350px' }}>
|
|
131
|
+ <Select
|
|
132
|
+ placeholder="请选择"
|
|
133
|
+ value={dispatch?.machineryId}
|
|
134
|
+ onChange={changeMachinery}
|
|
135
|
+ allowClear
|
|
136
|
+ style={{ width: '350px' }}
|
|
137
|
+ >
|
131
|
138
|
{machineryList.map((item) => (
|
132
|
139
|
<Option value={item.machineryId} key={item.machineryId}>
|
133
|
140
|
{item.name}
|
|
@@ -136,7 +143,13 @@ export default (props) => {
|
136
|
143
|
</Select>
|
137
|
144
|
</FormItem>
|
138
|
145
|
<FormItem label="农机手">
|
139
|
|
- <Select placeholder="请选择" value={dispatch?.workerId} onChange={changeUser} allowClear style={{ width: '350px' }}>
|
|
146
|
+ <Select
|
|
147
|
+ placeholder="请选择"
|
|
148
|
+ value={dispatch?.workerId}
|
|
149
|
+ onChange={changeUser}
|
|
150
|
+ allowClear
|
|
151
|
+ style={{ width: '350px' }}
|
|
152
|
+ >
|
140
|
153
|
{userList.map((item) => (
|
141
|
154
|
<Option value={item.userId} key={item.userId}>
|
142
|
155
|
{item.userName}
|
|
@@ -148,15 +161,20 @@ export default (props) => {
|
148
|
161
|
<Button type="default" onClick={() => goBack()}>
|
149
|
162
|
返回
|
150
|
163
|
</Button>
|
151
|
|
- {
|
152
|
|
- dispatchId ?
|
153
|
|
- <Button loading={cancelLoading} onClick={onCancel} style={{ marginLeft: '4em' }}>
|
154
|
|
- 取消调度
|
155
|
|
- </Button> :
|
156
|
|
- <Button type="primary" loading={loading} onClick={submit} style={{ marginLeft: '4em' }}>
|
157
|
|
- 保存
|
158
|
|
- </Button>
|
159
|
|
- }
|
|
164
|
+ {dispatchId ? (
|
|
165
|
+ <Button loading={cancelLoading} onClick={onCancel} style={{ marginLeft: '4em' }}>
|
|
166
|
+ 取消调度
|
|
167
|
+ </Button>
|
|
168
|
+ ) : (
|
|
169
|
+ <Button
|
|
170
|
+ type="primary"
|
|
171
|
+ loading={loading}
|
|
172
|
+ onClick={submit}
|
|
173
|
+ style={{ marginLeft: '4em' }}
|
|
174
|
+ >
|
|
175
|
+ 保存
|
|
176
|
+ </Button>
|
|
177
|
+ )}
|
160
|
178
|
</FormItem>
|
161
|
179
|
</Form>
|
162
|
180
|
</ProCard.TabPane>
|