card.jsx 12 KB
Newer Older
1 2
/* eslint-disable indent */
/* eslint-disable object-shorthand */
shaoan123's avatar
shaoan123 committed
3
import React, { useState, useEffect } from 'react';
4
import classnames from 'classnames';
5
import { Popconfirm, notification, Card, Button, message, Tooltip } from 'antd';
6
import {
7 8 9 10
  unbindSchemeBaseMap,
  GettMaplayer,
  SetServiceConfig,
  deleteConfig,
11
  GetbaseMapschemeName,
12
} from '@/services/webConfig/api';
13 14 15 16 17 18 19
import {
  CloseOutlined,
  PlusOutlined,
  GlobalOutlined,
  BlockOutlined,
  FormOutlined,
} from '@ant-design/icons';
20
import AddModal from '../AddModal';
21
import EditModal from '../EditModal';
22 23
import MapScope from '@/components/MapScope';
import { createGuid } from '@/utils/transformUtil';
24 25
import AddModalBase from '../AddModalBase';
import styles from '../../SchemeConfig.less';
26
const CardData = props => {
27
  const { deletebaseMaps = () => {}, item, cardFlag, keepData, nameData } = props;
28
  const [visible, setVisible] = useState(false); // 弹窗
29
  const [basevisible, setBaseVisible] = useState(false); // 弹窗
30 31 32 33 34
  const [flag, setFlag] = useState(0); // 状态更新
  const [type, setType] = useState(''); // 弹窗类型
  const [formObj, setFormObj] = useState({});
  const [serviceList, setServiceList] = useState([]);
  const [mapScopeVisible, setMapScopeVisible] = useState(false);
35
  const [cardData, setCardData] = useState([]);
36
  const [editVisible, setEditVisible] = useState(false);
37
  // 删除瓦片
38

39
  useEffect(() => {
40 41 42 43 44 45 46 47 48
    // GettMaplayer({ terminalType: 'base', isBaseMap: true }).then(res => {
    //   if (res.msg === 'Ok') {
    //     let arr = [];
    //     res.data.general.baseMap.layers.map(i => {
    //       arr.push(i.servicename);
    //     });
    //   }
    // });
    setCardData(keepData);
49
    console.log(props.item);
50
  }, [cardFlag]);
51

52
  const deletebaseMap = (item, baseMapItem) => {
53
    console.log(item);
54
    console.log(props.item.defaultOldBaseMap);
55
    console.log(baseMapItem);
56 57 58 59
    let j = props.item.defaultOldBaseMap.indexOf(baseMapItem);
    let i = props.item.defaultBaseMap;
    console.log(j);
    console.log(i);
60 61 62
    if (item.baseMap.length > 1) {
      unbindSchemeBaseMap({ schemename: item.schemename, basemapName: baseMapItem }).then(res => {
        if (res.code == '0') {
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
          if (j == i) {
            SetServiceConfig({
              schemename: props.item.schemename,
              terminalType: 'scheme',
              isBaseMap: false,
              jsonCfg: JSON.stringify({
                defaultBaseMap: 0,
              }),
            }).then(resdata => {
              if (resdata.code == '0') {
                deletebaseMaps();
              }
            });
          } else if (j < i) {
            SetServiceConfig({
              schemename: props.item.schemename,
              terminalType: 'scheme',
              isBaseMap: false,
              jsonCfg: JSON.stringify({
                defaultBaseMap: i - 1,
              }),
            }).then(resdata => {
              if (resdata.code == '0') {
                deletebaseMaps();
              }
            });
          } else {
            deletebaseMaps();
          }
92 93 94 95 96 97 98 99 100 101 102 103 104 105
          notification.success({
            message: '提示',
            duration: 3,
            description: '底图方案删除成功',
          });
        } else {
          notification.error({
            message: '提示',
            duration: 3,
            description: '底图方案删除失败',
          });
        }
      });
    } else {
106
      message.warning('方案至少需要一张底图');
107
    }
108 109 110 111 112 113 114 115
  };
  // 删除方案
  const deleteTile = item => {
    deleteConfig({
      schemename: item.schemename,
      terminalType: 'scheme',
      isBaseMap: false,
    }).then(res => {
116
      if (res.code == '0') {
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
        notification.success({
          message: '提示',
          duration: 3,
          description: '方案删除成功',
        });
        deletebaseMaps();
      } else {
        notification.error({
          message: '提示',
          duration: 3,
          description: '方案删除失败',
        });
      }
    });
  };
  const onSubmit = prop => {
    setVisible(false);
    deletebaseMaps();
135
    setBaseVisible(false);
136
  };
137

138 139
  // 增加瓦片
  const addTile = value => {
140 141 142 143
    let serverList = [];
    setFormObj(value);
    if (JSON.stringify(value) != '{}') {
      GettMaplayer({ terminalType: 'base', isBaseMap: true }).then(res => {
144
        if (res.code == '0') {
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
          res.data.general.baseMap.layers.map(item => {
            if (value.baseMap.indexOf(item.servicename) == -1) {
              serverList.push(item.servicename);
            }
          });
        }
        let arr = [];
        GetbaseMapschemeName().then(resdata => {
          if (resdata.data.length) {
            resdata.data.map(i => {
              if (value.baseMap.indexOf(i) == -1) {
                arr.push(i);
              }
            });
            if (arr.length) {
              setServiceList(arr);
              setType('add');
              setVisible(true);
            } else {
              notification.warning({
                message: '提示',
                duration: 3,
                description: '请先在底图配置-配置底图分级显示方案',
              });
            }
          } else {
            notification.warning({
              message: '提示',
              duration: 3,
              description: '请先在底图配置-配置底图分级显示方案',
            });
          }
        });
      });
    }
  };

  const addTileBase = value => {
183 184 185 186
    let serverList = [];
    setFormObj(value);
    if (JSON.stringify(value) != '{}') {
      GettMaplayer({ terminalType: 'base', isBaseMap: true }).then(res => {
187
        if (res.code == '0') {
188 189 190
          res.data.general.baseMap.layers.map(item => {
            if (value.baseMap.indexOf(item.servicename) == -1) {
              serverList.push(item.servicename);
shaoan123's avatar
shaoan123 committed
191
            }
192
          });
193
        }
194 195 196
        if (serverList.length) {
          setServiceList(serverList);
          setType('add');
197
          setBaseVisible(true);
198 199 200 201 202 203
        } else {
          notification.warning({
            message: '提示',
            duration: 3,
            description: '请先在基础配置-配置底图',
          });
mayongxin's avatar
mayongxin committed
204
        }
205
      });
shaoan123's avatar
shaoan123 committed
206
    }
207
  };
208 209 210 211 212 213

  const editTile = value => {
    setFormObj(value);
    setEditVisible(true);
  };

214 215 216 217 218 219 220
  const submitExtent = (extent, areaName, flag) => {
    if (flag === 0) {
      notification.warn({
        message: '提交失败',
        description: '请框选范围',
      });
      return;
shaoan123's avatar
shaoan123 committed
221
    }
222 223 224 225 226 227 228 229 230 231 232 233 234 235
    const jsConfig = {
      extent: extent,
      areaName: areaName,
      boundColor: '#86c8f8',
      boundWidth: '10px',
      backgroundColor: '#000000',
      backgroundOpacity: '0.6',
    };
    SetServiceConfig({
      schemename: item.schemename,
      terminalType: 'web',
      isBaseMap: false,
      jsonCfg: JSON.stringify(jsConfig),
    }).then(res => {
236
      if (res.code == '0') {
237 238 239 240 241
        setMapScopeVisible(false);
        message.info('范围设置成功');
      }
    });
  };
242

243
  const pick = (schemename, baseMapItem) => {
244
    console.log(schemename);
245 246 247
    console.log(props.item.defaultOldBaseMap);
    let i = props.item.defaultOldBaseMap.indexOf(baseMapItem);
    console.log(i);
248 249 250 251 252
    SetServiceConfig({
      schemename: schemename,
      terminalType: 'scheme',
      isBaseMap: false,
      jsonCfg: JSON.stringify({
253
        defaultBaseMap: i,
254 255
      }),
    }).then(res => {
256
      if (res.code == '0') {
257
        deletebaseMaps();
258
        message.success('设置成功');
259 260 261 262 263
      } else {
        message.warning(res.msg);
      }
    });
  };
264 265 266 267 268 269

  const onEditSubmit = () => {
    setEditVisible(false);
    deletebaseMaps();
  };

270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
  return (
    <>
      <Card
        title={
          <div>
            <span className={styles.schemeName}>方案名</span>
            {props.item.schemename}
          </div>
        }
        extra={
          <a href="#">
            <Popconfirm
              title="是否删除该方案?"
              okText="确认"
              cancelText="取消"
              onConfirm={() => {
                deleteTile(props.item);
              }}
            >
              <CloseOutlined />
            </Popconfirm>{' '}
          </a>
        }
293
        style={{ width: 360 }}
294
      >
295 296 297 298 299 300 301 302 303 304 305 306
        <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: '13px' }}>
          <div>
            <span className={styles.schemeName}>管网</span> {props.item.servicename}
          </div>
          <div>
            <FormOutlined
              style={{ marginRight: '10px', color: '#1890ff' }}
              onClick={() => editTile(props.item)}
            />
          </div>
        </div>

307
        {/* <div>
308 309 310 311 312 313 314
          <span className={styles.schemeName}>范围</span>
          <Button
            style={{ width: '12rem', marginBottom: '0.5rem' }}
            onClick={() => setMapScopeVisible(true)}
          >
            选择范围
          </Button>
315
        </div> */}
316
        <div className={styles.schemeItem}>
317 318 319 320
          {/* <span className={styles.schemeName}>底图方案</span> */}
          <Button className={styles.schemeBtn} onClick={() => addTileBase(props.item)}>
            {' '}
            <GlobalOutlined />
321 322 323 324 325 326
            添加基础底图
          </Button>
          <Button className={styles.schemeBtn} onClick={() => addTile(props.item)}>
            {' '}
            <BlockOutlined />
            添加分级底图
327 328
          </Button>
        </div>
329
        <div style={{ overflowY: 'scroll', height: '11.4rem' }}>
330
          {props.item.baseMap && props.item.baseMap.length
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
            ? props.item.baseMap.map((baseMapItem, baseindex) => (
                <div className={styles.mapItem} key={baseindex}>
                  <div
                    onClick={() => pick(props.item.schemename, baseMapItem)}
                    className={classnames({
                      [styles.defaultTile]: true,
                      [styles.activeTile]: baseindex == props.item.defaultBaseMap,
                    })}
                  >
                    默认
                    {cardData.indexOf(baseMapItem) == -1 ? (
                      <BlockOutlined style={{ marginTop: '5px' }} />
                    ) : (
                      <GlobalOutlined style={{ marginTop: '5px' }} />
                    )}
                  </div>
                  <div className={styles.mapText}>
                    <Tooltip title={baseMapItem}>{baseMapItem}</Tooltip>
                  </div>
                  <div className={styles.mapIcon}>
                    <Popconfirm
                      title={
                        cardData.indexOf(baseMapItem) == -1 ? (
                          <span>是否删除该分级底图?</span>
                        ) : (
                          <span>是否删除该底图?</span>
                        )
                      }
                      okText="确认"
                      cancelText="取消"
                      onConfirm={() => {
                        deletebaseMap(props.item, baseMapItem);
                      }}
364
                    >
365 366
                      <CloseOutlined />
                    </Popconfirm>{' '}
367
                  </div>
368 369
                </div>
              ))
370 371 372 373 374 375 376 377 378 379
            : ''}
        </div>
      </Card>
      <AddModal
        visible={visible}
        onCancel={() => setVisible(false)}
        callBackSubmit={onSubmit}
        type={type}
        serviceList={serviceList}
        formObj={formObj}
380 381 382 383 384 385 386
        nameData={nameData}
      />
      <EditModal
        visible={editVisible}
        onCancel={() => setEditVisible(false)}
        callBackSubmit={onEditSubmit}
        formObj={formObj}
387
      />
388 389 390 391 392 393 394
      <AddModalBase
        visible={basevisible}
        onCancel={() => setBaseVisible(false)}
        callBackSubmit={onSubmit}
        type={type}
        serviceList={serviceList}
        formObj={formObj}
395
        nameData={nameData}
396
      />
397 398 399 400 401 402 403 404 405 406 407 408
      <MapScope
        mapId={createGuid()}
        visible={mapScopeVisible}
        onCancel={() => setMapScopeVisible(false)}
        confirmModal={submitExtent}
        schemename={props.item.schemename}
        title={props.item.schemename}
      />
    </>
  );
};
export default CardData;