overwrite.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import React from 'react';
  2. import { Col, Row, Form, Input, Modal, Select, message, InputNumber, Tabs } from 'antd';
  3. import { overwriteData } from '@/services/home';
  4. interface userEditPros {
  5. visible: boolean;
  6. editCallback: () => void;
  7. params: any;
  8. }
  9. /**
  10. * 下发页面
  11. * @param props
  12. * @constructor
  13. */
  14. const Overwrite: React.FC<userEditPros> = (props) => {
  15. const { visible, editCallback, params } = props;
  16. const [form] = Form.useForm();
  17. const { TabPane } = Tabs;
  18. // 下发
  19. const onOk = () => {
  20. form.validateFields().then((values) => {
  21. if (values) {
  22. const data = {
  23. gateway: params.device_code,
  24. gear: values.gear,
  25. value: values.value,
  26. };
  27. overwriteData(data)
  28. .then((res) => {
  29. if (res.code === 0) {
  30. message.success('下发成功');
  31. } else {
  32. message.error(res?.message);
  33. }
  34. })
  35. .catch((e) => {
  36. message.error(e?.message);
  37. });
  38. }
  39. });
  40. };
  41. // 取消
  42. const onCancel = () => {
  43. editCallback();
  44. };
  45. const formItemLayout = {
  46. labelCol: {
  47. span: 6,
  48. },
  49. wrapperCol: {
  50. span: 16,
  51. },
  52. };
  53. return (
  54. <Modal
  55. title="下发管理"
  56. open={visible}
  57. onOk={onOk}
  58. onCancel={onCancel}
  59. width={800}
  60. okText="下发"
  61. >
  62. <Tabs defaultActiveKey="1">
  63. <TabPane tab="档位电压" key="1">
  64. <Form form={form}>
  65. <Row>
  66. <Col span={24}>
  67. <Form.Item
  68. {...formItemLayout}
  69. name="device_code"
  70. label="设备编号"
  71. initialValue={params?.device_code}
  72. >
  73. <Input placeholder="请输入设备编号" readOnly defaultValue={params.device_code} />
  74. </Form.Item>
  75. </Col>
  76. <Col span={24}>
  77. <Form.Item
  78. {...formItemLayout}
  79. name="gear"
  80. label="档位"
  81. rules={[{ required: true, message: '请选择档位' }]}
  82. initialValue={params?.gear}
  83. >
  84. <Select placeholder="请选择档位">
  85. <Select.Option value={1}>一档</Select.Option>
  86. <Select.Option value={2}>二档</Select.Option>
  87. <Select.Option value={3}>三档</Select.Option>
  88. <Select.Option value={4}>四档</Select.Option>
  89. <Select.Option value={5}>五档</Select.Option>
  90. </Select>
  91. </Form.Item>
  92. </Col>
  93. <Col span={24}>
  94. <Form.Item
  95. {...formItemLayout}
  96. name="value"
  97. label="电压"
  98. rules={[{ required: true, message: '请输入电压' }]}
  99. initialValue={params?.value}
  100. >
  101. <InputNumber
  102. placeholder="请输入电压"
  103. style={{ width: '100%' }}
  104. min={0}
  105. max={100}
  106. />
  107. </Form.Item>
  108. </Col>
  109. </Row>
  110. </Form>
  111. </TabPane>
  112. </Tabs>
  113. </Modal>
  114. );
  115. };
  116. export default Overwrite;