|
@@ -5,7 +5,7 @@ import { getOrderDetail } from '@/services/order'
|
5
|
5
|
import { getMachineryList } from '@/services/machinery';
|
6
|
6
|
import { history } from 'umi';
|
7
|
7
|
import { getUserList } from '@/services/user';
|
8
|
|
-import { addDispatch } from '@/services/dispatch';
|
|
8
|
+import { addDispatch, getdispatchId, cancelDispatch } from '@/services/dispatch';
|
9
|
9
|
|
10
|
10
|
const FormItem = Form.Item;
|
11
|
11
|
const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 14 } };
|
|
@@ -16,21 +16,25 @@ const goBack = () => {
|
16
|
16
|
export default (props) => {
|
17
|
17
|
const { location } = props;
|
18
|
18
|
const { id } = location.query;
|
19
|
|
- const [order, setOrder] = useState();
|
|
19
|
+ const [dispatch, setDispatch] = useState();
|
20
|
20
|
const [loading, setLoading] = useState(false);
|
|
21
|
+ const [dispatchId, setDispatchId] = useState()
|
21
|
22
|
const [machineryList, setMachineryList] = useState([]);
|
22
|
23
|
const [userList, setUserList] = useState([])
|
|
24
|
+
|
|
25
|
+ const [cancelLoading, setCancelLoading] = useState(false);
|
|
26
|
+
|
23
|
27
|
const submit = () => {
|
24
|
|
- if (!order.machineryId) {
|
|
28
|
+ if (!dispatch.machineryId) {
|
25
|
29
|
message.warning('请选择调度的农机');
|
26
|
30
|
return
|
27
|
31
|
}
|
28
|
|
- if (!order.workerId) {
|
|
32
|
+ if (!dispatch.workerId) {
|
29
|
33
|
message.warning('请选择农机手');
|
30
|
34
|
return
|
31
|
35
|
}
|
32
|
36
|
setLoading(true)
|
33
|
|
- addDispatch(order).then(res => {
|
|
37
|
+ addDispatch(dispatch).then(res => {
|
34
|
38
|
message.success('调度成功');
|
35
|
39
|
setLoading(false);
|
36
|
40
|
goBack()
|
|
@@ -40,47 +44,67 @@ export default (props) => {
|
40
|
44
|
});
|
41
|
45
|
};
|
42
|
46
|
const changeMachinery = (e) => {
|
43
|
|
- setOrder({ ...order, machineryId: e })
|
|
47
|
+ setDispatch({ ...dispatch, machineryId: e })
|
44
|
48
|
}
|
45
|
49
|
const changeUser = (e) => {
|
46
|
|
- setOrder({ ...order, workerId: e })
|
|
50
|
+ setDispatch({ ...dispatch, workerId: e })
|
|
51
|
+ }
|
|
52
|
+ const onCancel = () => {
|
|
53
|
+ setCancelLoading(true)
|
|
54
|
+ cancelDispatch(dispatchId).then(() => {
|
|
55
|
+ setCancelLoading(false)
|
|
56
|
+ setDispatchId()
|
|
57
|
+ setDispatch({ ...dispatch, machineryId: null, workerId: null })
|
|
58
|
+ message.success('取消成功');
|
|
59
|
+ }).catch((err) => {
|
|
60
|
+ setCancelLoading(false);
|
|
61
|
+ message.error(err.message || err);
|
|
62
|
+ });
|
47
|
63
|
}
|
48
|
64
|
useEffect(() => {
|
49
|
65
|
getOrderDetail(id).then((res) => {
|
50
|
|
- setOrder(res)
|
51
|
|
- getMachineryList({ orgId: res.orgId, pageSize: 999 }).then((res2) => {
|
|
66
|
+ res.machineryId = null
|
|
67
|
+ res.typeId = res.machineryType
|
|
68
|
+ setDispatch(res)
|
|
69
|
+ getMachineryList({ orgId: res.orgId, typeId: res.typeId, pageSize: 999 }).then((res2) => {
|
52
|
70
|
setMachineryList(res2.records)
|
53
|
71
|
})
|
54
|
72
|
getUserList({ org_id: res.orgId, pageSize: 999 }).then(res3 => {
|
55
|
73
|
setUserList(res3.records)
|
56
|
74
|
})
|
|
75
|
+ if (res.dispatchStatus == 1) {
|
|
76
|
+ getdispatchId(id).then(res4 => {
|
|
77
|
+ setDispatchId(res4.dispatchId)
|
|
78
|
+ setDispatch({ ...res, machineryId: res4.machineryId, workerId: res4.workerId })
|
|
79
|
+ })
|
|
80
|
+ }
|
57
|
81
|
})
|
58
|
|
- }, [])
|
|
82
|
+ }, [id])
|
59
|
83
|
return (
|
60
|
84
|
<Card>
|
61
|
85
|
<ProCard tabs={{ type: 'card' }}>
|
62
|
86
|
<ProCard.TabPane key={1} tab="订单调度">
|
63
|
87
|
<Form {...formItemLayout}>
|
64
|
88
|
<FormItem label="客户姓名">
|
65
|
|
- {order?.personName}
|
|
89
|
+ {dispatch?.personName}
|
66
|
90
|
</FormItem>
|
67
|
91
|
<FormItem label="联系电话">
|
68
|
|
- {order?.phone}
|
|
92
|
+ {dispatch?.phone}
|
69
|
93
|
</FormItem>
|
70
|
94
|
<FormItem label="预约地址">
|
71
|
|
- {order?.address}
|
|
95
|
+ {dispatch?.address}
|
72
|
96
|
</FormItem>
|
73
|
97
|
<FormItem label="预约时间">
|
74
|
|
- {order?.appointmentDate}
|
|
98
|
+ {dispatch?.appointmentDate}
|
75
|
99
|
</FormItem>
|
76
|
100
|
<FormItem label="机构名">
|
77
|
|
- {order?.orgName}
|
|
101
|
+ {dispatch?.orgName}
|
78
|
102
|
</FormItem>
|
79
|
103
|
<FormItem label="农机类型">
|
80
|
|
- {order?.typeName}
|
|
104
|
+ {dispatch?.typeName}
|
81
|
105
|
</FormItem>
|
82
|
106
|
<FormItem label="农机">
|
83
|
|
- <Select placeholder="请选择" value={order?.machineryId} onChange={changeMachinery} allowClear style={{ width: '350px' }}>
|
|
107
|
+ <Select placeholder="请选择" value={dispatch?.machineryId} onChange={changeMachinery} allowClear style={{ width: '350px' }}>
|
84
|
108
|
{machineryList.map((item) => (
|
85
|
109
|
<Option value={item.machineryId} key={item.machineryId}>
|
86
|
110
|
{item.name}
|
|
@@ -89,7 +113,7 @@ export default (props) => {
|
89
|
113
|
</Select>
|
90
|
114
|
</FormItem>
|
91
|
115
|
<FormItem label="农机手">
|
92
|
|
- <Select placeholder="请选择" value={order?.workerId} onChange={changeUser} allowClear style={{ width: '350px' }}>
|
|
116
|
+ <Select placeholder="请选择" value={dispatch?.workerId} onChange={changeUser} allowClear style={{ width: '350px' }}>
|
93
|
117
|
{userList.map((item) => (
|
94
|
118
|
<Option value={item.userId} key={item.userId}>
|
95
|
119
|
{item.userName}
|
|
@@ -101,9 +125,15 @@ export default (props) => {
|
101
|
125
|
<Button type="default" onClick={() => goBack()}>
|
102
|
126
|
返回
|
103
|
127
|
</Button>
|
104
|
|
- <Button type="primary" loading={loading} onClick={submit} style={{ marginLeft: '4em' }}>
|
105
|
|
- 保存
|
106
|
|
- </Button>
|
|
128
|
+ {
|
|
129
|
+ dispatchId ?
|
|
130
|
+ <Button loading={cancelLoading} onClick={onCancel} style={{ marginLeft: '4em' }}>
|
|
131
|
+ 取消
|
|
132
|
+ </Button> :
|
|
133
|
+ <Button type="primary" loading={loading} onClick={submit} style={{ marginLeft: '4em' }}>
|
|
134
|
+ 保存
|
|
135
|
+ </Button>
|
|
136
|
+ }
|
107
|
137
|
</FormItem>
|
108
|
138
|
</Form>
|
109
|
139
|
</ProCard.TabPane>
|