EditModal.jsx 3.48 KB
Newer Older
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
/* eslint-disable indent */
import React, { useState, useEffect } from 'react';
import { Form, Modal, Input, Select, notification } from 'antd';
import {
  GetVectorService,
  bindSchemeBaseMap,
  UpdateSchemPipeNetwork,
} from '@/services/webConfig/api';
const { Item } = Form;
const { Option } = Select;
const EditModal = props => {
  const { callBackSubmit = () => {}, formObj, visible } = props;
  const [loading, setLoading] = useState(false);
  const [pipeArr, setPipeArr] = useState([]);

  const [form] = Form.useForm();
  // 提交
  const onSubmit = () => {
    form.validateFields().then(validate => {
      if (validate) {
        setLoading(true);
        let obj = form.getFieldsValue();
        UpdateSchemPipeNetwork({
          schemename: formObj.schemename,
          ...obj,
        }).then(res => {
          setLoading(false);
          if (res.code == '0') {
            form.resetFields();
            callBackSubmit();
            notification.success({
              message: '提示',
              duration: 3,
              description: '修改成功',
            });
          } else {
            notification.error({
              message: '提示',
              duration: 3,
              description: res.msg,
            });
          }
        });
      }
    });
  };

  useEffect(() => {
    if (visible) {
      pipeNetwork();
      form.setFieldsValue({
        servicename: formObj.servicename,
        label: formObj.label,
        url: formObj.url,
      });
    } else {
      form.resetFields();
    }
  }, [visible]);

  // 获取管网及默认底图
  const pipeNetwork = () => {
    form.resetFields();
    let pipeArr1 = [];
    GetVectorService().then(res => {
      if (res.code === 0) {
        if (res.data.VectorList.length > 0) {
          res.data.VectorList.map(item => {
            pipeArr1.push(item.ServiceName.split('.')[0]);
          });
        }
        setPipeArr(pipeArr1);
      }
    });
  };

  const layout = {
    layout: 'horizontal',
    labelCol: {
      span: 4,
    },
    wrapperCol: {
      span: 18,
    },
  };

  // 选择管网
  const handleService = value => {
    form.setFieldsValue({
      label: value,
      // url: `http://{IP}/PandaGIS/MapServer/Export?mapServerName=${value}`,
      url: `http://{IP}/PandaGIS/MapServer/${value}`,
    });
  };

  return (
    <Modal
      title="修改管网"
      bodyStyle={{ width: '100%', minHeight: '100px' }}
      style={{ top: '150px' }}
      width="700px"
      destroyOnClose
      maskClosable={false}
      cancelText="取消"
      okText="确认"
      {...props}
      onOk={() => onSubmit()}
      confirmLoading={loading}
      forceRender={true}
      getContainer={false}
    >
      {visible && (
        <Form form={form} {...layout}>
          <Item label="管网" name="servicename">
            <Select onChange={handleService} placeholder="请选择管网">
              {pipeArr.length
                ? pipeArr.map((item, index) => {
                    return (
                      <Option key={index} value={item}>
                        {item}
                      </Option>
                    );
                  })
                : ''}
            </Select>
          </Item>
          <Item label="标签" name="label">
            <Input placeholder="请输入标签" allowClear />
          </Item>
          <Item label="url" name="url">
            <Input placeholder="请输入url" allowClear />
          </Item>
        </Form>
      )}
    </Modal>
  );
};
export default EditModal;