zjj
2025-02-17 a4093814b51bba7eae9530cfa076f6242df3f5f8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import React, { useState, useRef, useEffect } from 'react';
import { Form, Modal, Space, Table, Tag, Switch, message } from 'antd';
import { FormattedMessage, useIntl } from '@umijs/max';
import moment from 'moment';
import Http from '@/utils/http';
 
const ShuttleCommand = (props) => {
    const intl = useIntl();
    const [form] = Form.useForm();
    const { } = props;
    const [commandData, setCommandData] = useState([]);
 
    const getCommands = () => {
        Http.doPost('api/task/shuttleCommand', {
            taskNo: props.values.taskNo
        }).then(resp => {
            if (resp.data != null) {
                setCommandData(resp.data.records)
            }
        })
    }
 
    const toggle = async (record) => {
        const hide = message.loading(intl.formatMessage({ id: 'page.updating', defaultMessage: '正在更新' }));
        try {
            const resp = await Http.doPost('api/task/shuttleCommand/completeSwitch', {
                taskNo: props.values.taskNo,
                index: record.index,
                complete: !record.complete
            });
            if (resp.code === 200) {
                getCommands()
                message.success(intl.formatMessage({ id: 'page.update.success', defaultMessage: '更新成功' }));
                return true;
            } else {
                message.error(resp.msg);
                return false;
            }
        } catch (error) {
            message.error(intl.formatMessage({ id: 'page.update.fail', defaultMessage: '更新失败请重试!' }));
            return false;
        } finally {
            hide();
        }
    };
 
    const commandRollback = async (record) => {
        const hide = message.loading(intl.formatMessage({ id: 'page.updating', defaultMessage: '正在更新' }));
        try {
            const resp = await Http.doPost('api/task/shuttleCommand/commandRollback', {
                taskNo: props.values.taskNo,
                index: record.index
            });
            if (resp.code === 200) {
                getCommands()
                message.success(intl.formatMessage({ id: 'page.update.success', defaultMessage: '更新成功' }));
                return true;
            } else {
                message.error(resp.msg);
                return false;
            }
        } catch (error) {
            message.error(intl.formatMessage({ id: 'page.update.fail', defaultMessage: '更新失败请重试!' }));
            return false;
        } finally {
            hide();
        }
    }
 
    const highlightRow = (record, index) => {
        const isHighlight = record.commandStep === index;
        return isHighlight ? 'highlight-row' : '';
    };
 
    const columns = [
        {
            title: '命令类型',
            dataIndex: 'mode$',
            key: 'mode$',
        },
        {
            title: '起点',
            dataIndex: 'start',
            key: 'start',
        },
        {
            title: '终点',
            dataIndex: 'target',
            key: 'target',
        },
        {
            title: '命令报文',
            dataIndex: 'body',
            key: 'body',
            ellipsis: true,
        },
        {
            title: '穿梭车ID',
            dataIndex: 'shuttleNo',
            key: 'shuttleNo',
        },
        {
            title: '是否完成',
            key: 'complete',
            dataIndex: 'complete',
            render: (_, record) => (
                <>
                    <Switch checkedChildren="完成" unCheckedChildren="未完成" checked={record.complete} onClick={async () => {
                        toggle(record)
                    }} />
                </>
            ),
        },
        {
            title: '操作',
            key: 'action',
            render: (_, record) => (
                <Space size="middle">
                    <a onClick={async () => {
                        commandRollback(record)
                    }}>
                        回退命令
                    </a>
                </Space>
            ),
        },
    ];
 
    useEffect(() => {
        form.resetFields();
        form.setFieldsValue({
            ...props.values
        })
 
        getCommands()
    }, [form, props])
 
    const handleCancel = () => {
        props.onCancel();
    };
 
    const handleOk = () => {
        form.submit();
    }
 
    const handleFinish = async (values) => {
        props.onSubmit({ ...values });
    }
 
    return (
        <>
            <Modal
                title={
                    intl.formatMessage({ id: 'page.shuttleCommand', defaultMessage: '穿梭车指令' })
                }
                width={640}
                forceRender
                destroyOnClose
                open={props.open}
                onCancel={handleCancel}
                onOk={handleOk}
            >
                <Table columns={columns} dataSource={commandData} rowClassName={highlightRow} />
            </Modal>
        </>
    )
}
 
export default ShuttleCommand;