Edit.jsx 3.26 KB
Newer Older
DarkForst's avatar
DarkForst committed
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
import React, {useEffect} from 'react';
import { connect } from 'umi';
import { Form, Card, Button, Row, Col, Input } from 'antd';
import { dispatchHandle } from '@/utils/publicHandle';
import { DescriptionForm } from '@/components/Customized/Description';

const isBigScreenScale = window.innerWidth / 1600 > 1;

const AddInstrument = (props) => {
  const {id} = props?.match?.params;
  const {
    dispatch,
    opsGather: {attarInfo, meterSelect, roundRobinSelect, attrSelectData}
  } = props;
  /**
   * @表单提交
   */
  const [form] = Form.useForm();

  const handleSubmit =  e => {
    e.preventDefault();
    form.validateFields().then(values => {
      console.log(values)
      // dispatchHandle(dispatch, 'opsGather/device_service_type_post', values);
    }).catch((err) => {
      console.log(err)
    });
  };

  /**
   * @页面方法
   */
  const goBack = () => {
    closeCurrentPage('/ops/gather/attar')
  }

  /**
   * @页面数据
   */

  const getSelectData = () => {
    dispatchHandle(dispatch, 'opsGather/device_service_meter_post');
    dispatchHandle(dispatch, 'opsGather/device_service_round_robin_post');
    dispatchHandle(dispatch, 'opsGather/device_service_meter_attr_data_type_get');
  }
  useEffect(() => {
    if (id) {
      dispatchHandle(dispatch, 'opsGather/device_service_type_post', {id}, res => {
        console.log(res)
      });
    }
    getSelectData()
  }, [])

  const JsonData = JSON.stringify(meterSelect)
  const newJson = JsonData
    .replace(/\bname\b/g, "label")
    .replace(/\bid\b/g, "value")
  const mSelect = JSON.parse(newJson)

  const rSelect = roundRobinSelect.map(item => ({
    label: `id: ${item.id} command: ${item.command}`,
    value: item.pollingId
  }))

  const JsonAttar = JSON.stringify(attrSelectData)
  const newAttar = JsonAttar
    .replace(/\bname\b/g, "label")
    .replace(/\bid\b/g, "value")
  const aSelect = JSON.parse(newAttar)

  const infoData = [
    { label: '属性名称', name: 'name', type: 'input'},
    { label: '偏移地址', name: 'offsetAddress', type: 'input'},
    { label: '系数', name: 'coefficient', type: 'input'},
    { label: '比特位', name: 'bit', type: 'input'},


    { label: '计量器id', name: 'meterId', type: 'select', selectData: mSelect},
    { label: '数据类型id', name: 'dataTypeId', type: 'select', selectData: rSelect},
    { label: '轮询id', name: 'pollingId', type: 'select', selectData: aSelect},

    { label: '是否是计量属性', name: 'measureIs', type: 'switch'},
    { label: '是否大端模式', name: 'bigEndianIs', type: 'switch'},

  ];
  return (
    <Card size="small">
      <Form form={form} onFinish={ handleSubmit } initialValues={{measureIs: false, bigEndianIs: false}}>
        <DescriptionForm
          columns={isBigScreenScale ? 4 : 3}
          data={infoData}
        />
        <div style={{ marginTop: 32, textAlign: 'right' }}>
          <Button style={{ width: 100, height: 30, marginRight: 20 }} onClick={goBack}>
            取消
          </Button>
          <Button style={{ width: 100, height: 30 }} type="primary" onClick={handleSubmit}>
            保存
          </Button>
        </div>
      </Form>
    </Card>
  );
};

export default connect(({ opsGather, loading }) => ({
  opsGather,
  loading: loading.models.opsGather,
}))(AddInstrument);