BaseMap.jsx 5.88 KB
Newer Older
1 2 3 4 5
/* eslint-disable prefer-promise-reject-errors */
/*
 * @Description:
 * @Author: leizhe
 * @Date: 2022-05-25 15:07:30
6
 * @LastEditTime: 2022-08-16 17:27:15
7 8 9
 * @LastEditors: leizhe
 */
import React, { useState, useEffect } from 'react';
10
import { Form, Modal, Input, Select, notification, InputNumber, Tooltip, Row, Col } from 'antd';
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
import {
  GettMaplayer,
  GetVectorService,
  SetServiceConfig,
  bindSchemeBaseMap,
  SetBaseMapschemeName,
} from '@/services/webConfig/api';
import { InfoCircleOutlined } from '@ant-design/icons';
const { Item } = Form;
const { Option } = Select;
const BaseMap = props => {
  const { visible, onCancel, keepItem, keepProject, callBackSubmit = () => {} } = props;
  const [arr, setArr] = useState([]);
  const [form] = Form.useForm();
  // 删除瓦片

  useEffect(() => {
    console.log(keepItem);
    console.log(keepProject);
    if (visible) {
      let list = [];
      keepItem.baseMapDetail.map(i => {
        list.push(i.zoom);
      });
      setArr(list);
      let aa = keepItem.baseMapDetail.find(i => i.servicename == keepProject);
37
      form.setFieldsValue({ zoom: aa.zoom, maxzoom: aa.maxzoom });
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
    } else {
      form.resetFields();
    }
  }, [visible]);

  const onSubmit = () => {
    form.validateFields().then(validate => {
      if (validate) {
        let obj = form.getFieldsValue();
        //   let aa = keepItem.baseMapDetail.find(i => i.servicename == keepProject);
        //   console.log(aa);
        //   aa.zoom = obj.zoom;
        //   let query = {
        //     schemename: keepItem.schemename,
        //     terminalType: 'baseMapscheme',
        //     isBaseMap: 'false',
        //     jsonCfg: JSON.stringify({
        //       baseMap: keepItem.baseMap,
        //       baseMapDetail: keepItem.baseMapDetail,
        //     }),
        //   };
        //   SetServiceConfig(query)
        //     .then(res => {
        //       if (res.msg === 'Ok') {
        //         form.resetFields();
        //         callBackSubmit();
        //         prompt('success', '编辑成功');
        //       } else {
        //         prompt('fail', '编辑失败');
        //       }
        //     })
        //     .catch(err => {});
        let data = {
          schemename: keepItem.schemename,
          servicename: keepProject,
          zoom: obj.zoom,
74
          maxZoom: obj.maxzoom,
75 76
        };
        SetBaseMapschemeName(data).then(res => {
77
          if (res.code == '0') {
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
            form.resetFields();
            callBackSubmit();
            prompt('success', '编辑成功');
          } else {
            prompt('fail', '编辑失败');
          }
        });
      }
    });
  };
  const prompt = (type, content) => {
    if (type == 'success') {
      notification.success({
        message: '提示',
        duration: 3,
        description: content,
      });
    } else {
      notification.error({
        message: '提示',
        duration: 3,
        description: content,
      });
    }
  };

  const layout = {
    layout: 'horizontal',
    labelCol: {
      span: 7,
    },
    wrapperCol: {
      span: 15,
    },
  };
  const title = (
    <>
      <span>编辑</span>
      <span style={{ color: 'rgb(24, 144, 255)' }}>{keepProject}</span>
117
      <span>的级别</span>
118 119 120 121 122 123 124
    </>
  );
  return (
    <Modal
      title={title}
      bodyStyle={{ width: '100%', minHeight: '100px' }}
      style={{ top: '150px' }}
125
      width="500px"
126 127 128 129 130 131
      destroyOnClose
      maskClosable={false}
      cancelText="取消"
      okText="确认"
      {...props}
      onOk={() => onSubmit()}
132
      forceRender
133 134
      getContainer={false}
    >
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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
      <Form form={form} onFinish={onSubmit}>
        <Item label="底图级别" style={{ marginTop: '20px' }} labelCol={{ span: 5 }}>
          <Row>
            <Col span={8}>
              <Item
                // label={
                //   <div>
                //     <Tooltip title="同一分级底图中的不同基础底图级别不能相同">
                //       <InfoCircleOutlined
                //         style={{
                //           color: 'rgb(24, 144, 255)',
                //           marginLeft: '0px',
                //           marginRight: '5px',
                //         }}
                //       />
                //     </Tooltip>
                //     <span>最小级别</span>
                //   </div>
                // }

                name="zoom"
                rules={[
                  { required: true, message: '请输入级别' },
                  // {
                  //   validator: (rule, value) => {
                  //     const obj = form.getFieldsValue().zoom;
                  //     console.log(obj);
                  //     if (arr.indexOf(obj) != -1) {
                  //       console.log(111);
                  //       return Promise.reject('已存在该级别的基础底图');
                  //     }
                  //     return Promise.resolve();
                  //   },
                  // },
                ]}
              >
                <InputNumber min={0} />
              </Item>
            </Col>
            <Col span={3}>
              <div style={{ marginTop: '4px' }}>~</div>
            </Col>
            <Col span={10}>
              <Item
                name="maxzoom"
                rules={[
                  {
                    validator: (rule, value) => {
                      const obj = form.getFieldsValue().zoom;
                      const objmax = form.getFieldsValue().maxzoom;
                      if (objmax < obj) {
                        return Promise.reject('最大级别不能小于最小级别');
                      }
                      return Promise.resolve();
                    },
190
                  },
191 192 193 194 195 196 197
                ]}
              >
                <InputNumber min={0} max={99} />
              </Item>
            </Col>
          </Row>
        </Item>
198 199 200 201 202
      </Form>
    </Modal>
  );
};
export default BaseMap;