| import React, { useState, useRef, useEffect } from 'react'; | 
| import { Col, Form, Input, Row, Switch, Slider, message, Drawer, Space, Button, InputNumber, Segmented } from 'antd'; | 
| import { FormattedMessage, useIntl, useModel } from '@umijs/max'; | 
| import { createStyles } from 'antd-style'; | 
| import * as Utils from '../utils' | 
| import * as PIXI from 'pixi.js'; | 
|   | 
| const useStyles = createStyles(({ token, css }) => { | 
|   | 
| }) | 
|   | 
| const MapCopySettings = (props) => { | 
|     const intl = useIntl(); | 
|     const { styles } = useStyles(); | 
|     const { curSprite } = props; | 
|     const [form] = Form.useForm(); | 
|     const [autoIncrement, setAutoIncrement] = useState(false); | 
|     const [autoIncrementError, setAutoIncrementError] = useState(null); | 
|   | 
|     useEffect(() => { | 
|         setAutoIncrement(false); | 
|         form.resetFields(); | 
|         if (curSprite && props) { | 
|             form.setFieldsValue({ | 
|                 ...props.values, | 
|             }); | 
|         } | 
|     }, [form, props]); | 
|   | 
|     useEffect(() => { | 
|         if (autoIncrement === true && curSprite) { | 
|             switch (curSprite.data?.type) { | 
|                 case Utils.SENSOR_TYPE.SHELF: | 
|                     if (!curSprite.data?.row || !curSprite.data?.bay) { | 
|                         setAutoIncrementError(intl.formatMessage({ id: 'map.settings.sub.copy.warn.config.shelf', defaultMessage: '请先设置货架参数!' })); | 
|                     } else { | 
|                         setAutoIncrementError(null); | 
|                     } | 
|                     break; | 
|                 default: | 
|                     break; | 
|             } | 
|         } else { | 
|             setAutoIncrementError(null); | 
|         } | 
|     }, [autoIncrement]) | 
|   | 
|     const handleCancel = () => { | 
|         props.onClose(); | 
|     } | 
|   | 
|     const handleOk = () => { | 
|         form.submit(); | 
|     } | 
|   | 
|     const handleFinish = (values) => { | 
|         props.submit({ | 
|             ...values | 
|             , ...props.values | 
|             , autoIncrement: autoIncrement | 
|             , type: curSprite?.data?.type | 
|         }) | 
|     } | 
|   | 
|     return ( | 
|         <> | 
|             <Drawer | 
|                 title={intl.formatMessage({ id: 'map.settings.sub.copy.rule', defaultMessage: '复制规则' })} | 
|                 width={350} | 
|                 closable={false} | 
|                 open={props.open} | 
|                 getContainer={props.refCurr} | 
|                 rootStyle={{ position: "absolute" }} | 
|                 onClose={handleCancel} | 
|                 extra={ | 
|                     <Space> | 
|                         <Button onClick={handleCancel}> | 
|                             <FormattedMessage id='common.cancel' defaultMessage='取消' /> | 
|                         </Button> | 
|                         <Button onClick={handleOk} type="primary"> | 
|                             <FormattedMessage id='common.submit' defaultMessage='确定' /> | 
|                         </Button> | 
|                     </Space> | 
|                 } | 
|             > | 
|                 <Form | 
|                     form={form} | 
|                     initialValues={{ | 
|                         copyGap: 0, | 
|                         autoIncrement: false, | 
|                         incrementMode: 'ascending', | 
|                     }} | 
|                     onFinish={handleFinish} | 
|                     autoComplete="off" | 
|                     style={{ | 
|                         maxWidth: 300, | 
|                     }} | 
|                     size='default' | 
|                     variant='filled' | 
|                     labelWrap | 
|                     disabled={false} | 
|                     layout='horizontal' | 
|                 > | 
|                     <Row gutter={[16, 0]}> | 
|   | 
|                         <Col span={24}> | 
|                             <Form.Item | 
|                                 label={intl.formatMessage({ id: 'map.settings.sub.copy.dire', defaultMessage: '方向' })} | 
|                                 labelCol={{ span: 8 }} | 
|                             > | 
|                                 <span>{props?.values?.copyDire}</span> | 
|                             </Form.Item> | 
|                         </Col> | 
|   | 
|                         <Col span={24}> | 
|                             <Form.Item | 
|                                 label={intl.formatMessage({ id: 'map.settings.sub.copy.count', defaultMessage: '数量' })} | 
|                                 labelCol={{ span: 8 }} | 
|                             > | 
|                                 <span>{props?.values?.copyCount}</span> | 
|                             </Form.Item> | 
|                         </Col> | 
|   | 
|                         <Col span={24}> | 
|                             <Form.Item | 
|                                 name='copyGap' | 
|                                 label={intl.formatMessage({ id: 'map.settings.sub.copy.gap', defaultMessage: '间距' })} | 
|                                 labelCol={{ span: 8 }} | 
|                             > | 
|                                 <InputNumber | 
|                                     style={{ | 
|                                         width: '60%', | 
|                                     }} | 
|                                 // min={0} | 
|                                 /> | 
|                             </Form.Item> | 
|                         </Col> | 
|   | 
|                         {/* switch auto increment  */} | 
|                         <Col span={24}> | 
|                             <Form.Item | 
|                                 label={intl.formatMessage({ id: 'map.settings.sub.copy.shelf.auto-increment', defaultMessage: '自增长' })} | 
|                                 labelCol={{ span: 8 }} | 
|                                 help={autoIncrementError} | 
|                                 validateStatus={autoIncrementError ? "error" : null} | 
|                             > | 
|                                 <Switch value={autoIncrement} onChange={setAutoIncrement} /> | 
|                             </Form.Item> | 
|                         </Col> | 
|   | 
|                         {autoIncrement && curSprite?.data?.type === Utils.SENSOR_TYPE.AGV && ( | 
|                             <> | 
|                                 <Col span={24}> | 
|                                     <Form.Item | 
|                                         name='incrementValue' | 
|                                         label={intl.formatMessage({ id: 'map.settings.sub.copy.shelf.increment-value', defaultMessage: '自增长值' })} | 
|                                         labelCol={{ span: 8 }} | 
|                                         initialValue='no' | 
|                                     > | 
|                                         <Segmented | 
|                                             block | 
|                                             options={[ | 
|                                                 { | 
|                                                     label: intl.formatMessage({ id: 'map.settings.no', defaultMessage: '编号' }), | 
|                                                     value: 'no' | 
|                                                 }, | 
|                                             ]} | 
|                                             onChange={(value) => { | 
|                                             }} | 
|                                         /> | 
|                                     </Form.Item> | 
|                                 </Col> | 
|                                 <Col span={24}> | 
|                                     <Form.Item | 
|                                         name='incrementMode' | 
|                                         label={intl.formatMessage({ id: 'map.settings.sub.copy.increment.mode', defaultMessage: '增长方式' })} | 
|                                         labelCol={{ span: 8 }} | 
|                                     > | 
|                                         <Segmented | 
|                                             block | 
|                                             options={[ | 
|                                                 { | 
|                                                     label: intl.formatMessage({ id: 'map.settings.sub.copy.ascend', defaultMessage: '升序' }), | 
|                                                     value: 'ascending' | 
|                                                 }, | 
|                                                 { | 
|                                                     label: intl.formatMessage({ id: 'map.settings.sub.copy.descend', defaultMessage: '降序' }), | 
|                                                     value: 'descending' | 
|                                                 }, | 
|                                             ]} | 
|                                             onChange={(value) => { | 
|                                             }} | 
|                                         /> | 
|                                     </Form.Item> | 
|                                 </Col> | 
|                             </> | 
|                         )} | 
|   | 
|                         {autoIncrement && curSprite?.data?.type === Utils.SENSOR_TYPE.SHELF && ( | 
|                             <> | 
|                                 <Col span={24}> | 
|                                     <Form.Item | 
|                                         name='incrementValue' | 
|                                         label={intl.formatMessage({ id: 'map.settings.sub.copy.shelf.increment-value', defaultMessage: '自增长值' })} | 
|                                         labelCol={{ span: 8 }} | 
|                                         initialValue='row' | 
|                                     > | 
|                                         <Segmented | 
|                                             block | 
|                                             options={[ | 
|                                                 { | 
|                                                     label: intl.formatMessage({ id: 'map.settings.shelf.row', defaultMessage: '排' }), | 
|                                                     value: 'row' | 
|                                                 }, | 
|                                                 { | 
|                                                     label: intl.formatMessage({ id: 'map.settings.shelf.bay', defaultMessage: '列' }), | 
|                                                     value: 'bay' | 
|                                                 }, | 
|                                             ]} | 
|                                             onChange={(value) => { | 
|                                             }} | 
|                                         /> | 
|                                     </Form.Item> | 
|                                 </Col> | 
|                                 <Col span={24}> | 
|                                     <Form.Item | 
|                                         name='incrementMode' | 
|                                         label={intl.formatMessage({ id: 'map.settings.sub.copy.increment.mode', defaultMessage: '增长方式' })} | 
|                                         labelCol={{ span: 8 }} | 
|                                     > | 
|                                         <Segmented | 
|                                             block | 
|                                             options={[ | 
|                                                 { | 
|                                                     label: intl.formatMessage({ id: 'map.settings.sub.copy.ascend', defaultMessage: '升序' }), | 
|                                                     value: 'ascending' | 
|                                                 }, | 
|                                                 { | 
|                                                     label: intl.formatMessage({ id: 'map.settings.sub.copy.descend', defaultMessage: '降序' }), | 
|                                                     value: 'descending' | 
|                                                 }, | 
|                                             ]} | 
|                                             onChange={(value) => { | 
|                                             }} | 
|                                         /> | 
|                                     </Form.Item> | 
|                                 </Col> | 
|                             </> | 
|                         )} | 
|   | 
|                     </Row> | 
|                 </Form> | 
|             </Drawer> | 
|         </> | 
|     ) | 
| } | 
|   | 
| export default MapCopySettings; |