"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = _default;
var _react = _interopRequireWildcard(require("react"));
var _service = _interopRequireDefault(require("../_mapUtil/service"));
var _Modal = _interopRequireDefault(require("../_component/Modal"));
var _Select = _interopRequireDefault(require("../_component/Select"));
var _ToolsSelect = _interopRequireDefault(require("../_component/ToolsSelect"));
var _featureDraw = _interopRequireDefault(require("@vtx/ol-map/lib/feature-draw"));
var _useProps2 = _interopRequireDefault(require("@vtx/ol-map/lib/use-props"));
var _request = _interopRequireDefault(require("../_mapUtil/request"));
var _config = _interopRequireDefault(require("../_mapUtil/config"));
var _lodash = _interopRequireDefault(require("lodash"));
var _index = _interopRequireDefault(require("../_mapUtil/GetData/index"));
var _Observable = require("ol/Observable");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /*
 * @description: 管网统计
 */
//统计字段下拉
var fieldOptions = [{
  value: 1,
  label: '管径',
  key: 'ds'
}, {
  value: 2,
  label: '管材',
  key: 'lineTextureName'
}, {
  value: 3,
  label: '埋深',
  key: 'startDeep'
}, {
  value: 4,
  label: '管龄',
  key: 'age'
}, {
  value: 5,
  label: '权属单位',
  key: 'orgName'
}];
function _default(props) {
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map,
    highLayer = _useProps.highLayer,
    analysisLayer = _useProps.analysisLayer,
    setVisible = _useProps.setVisible,
    setTableData = _useProps.setTableData,
    setLoading = _useProps.setLoading,
    setFieldOption = _useProps.setFieldOption,
    setLayerOptions = _useProps.setLayerOptions,
    onClose = _useProps.onClose,
    layerKeys = _useProps.layerKeys,
    setLayerKeys = _useProps.setLayerKeys,
    layerOptions = _useProps.layerOptions,
    activeKey = _useProps.activeKey;
  var moveKey = (0, _react.useRef)();
  var _useState = (0, _react.useState)(''),
    _useState2 = _slicedToArray(_useState, 2),
    drawType = _useState2[0],
    setDrawType = _useState2[1];
  var _useState3 = (0, _react.useState)(null),
    _useState4 = _slicedToArray(_useState3, 2),
    feature = _useState4[0],
    setFeature = _useState4[1]; // 框选绘制feature
  var _useState5 = (0, _react.useState)('DragBox'),
    _useState6 = _slicedToArray(_useState5, 2),
    activeBtn = _useState6[0],
    setActiveBtn = _useState6[1]; // 框选选择
  var _useState7 = (0, _react.useState)(1),
    _useState8 = _slicedToArray(_useState7, 2),
    fieldKey = _useState8[0],
    setFieldKey = _useState8[1]; // 统计字段
  var _useState9 = (0, _react.useState)([]),
    _useState10 = _slicedToArray(_useState9, 2),
    flatCoordinates = _useState10[0],
    setFlatCoordinates = _useState10[1];
  var onClosefn = function onClosefn() {
    moveKey.current && (0, _Observable.unByKey)(moveKey.current);
    onClose();
    analysisLayer.current.filter = '';
    setTableData([]);
  };
  var onDrawEnd = function onDrawEnd(feature) {
    setFeature(feature);
  };
  (0, _react.useEffect)(function () {
    setDrawType('');
    if (activeBtn && activeBtn !== 'CurrentView') {
      setDrawType(activeBtn);
    }
  }, [activeBtn]);
  var onToolsChange = function onToolsChange(key) {
    moveKey.current && (0, _Observable.unByKey)(moveKey.current);
    setTableData([]);
    setActiveBtn(key);
    if (key === 'CurrentView') {
      setFeature(null);
      highLayer.current.clearFeatures();
      setFlatCoordinates(_service["default"].getExtend(map));
    }
  };
  (0, _react.useEffect)(function () {
    if ((layerKeys === null || layerKeys === void 0 ? void 0 : layerKeys.length) > 0) {
      getData();
    } else {
      var _highLayer$current;
      setTableData([]);
      highLayer === null || highLayer === void 0 || (_highLayer$current = highLayer.current) === null || _highLayer$current === void 0 || _highLayer$current.clearFeatures();
    }
  }, [feature, layerKeys, fieldKey, activeKey, flatCoordinates]);
  /**
   * @description: 图层高亮
   * @param {*} features
   * @return {*}
   */
  var highLayerFn = function highLayerFn(features) {
    if (activeBtn !== 'CurrentView') highLayer.current.setHighlight(features);
  };
  var getData = function getData() {
    if (feature || flatCoordinates !== null && flatCoordinates !== void 0 && flatCoordinates.length) {
      setVisible(true);
      setLoading(true);
      setTableData([]);
      (0, _index["default"])({
        feature: feature,
        map: map,
        highLayerFn: highLayerFn,
        drawType: activeBtn,
        keys: layerKeys,
        flatCoordinates: flatCoordinates
      }).then(function (res) {
        var _res$features;
        setLoading(false);
        if (res !== null && res !== void 0 && (_res$features = res.features) !== null && _res$features !== void 0 && _res$features.length) {
          _service["default"].getSimpleList({
            layerOptions: layerOptions,
            tableData: res.data.filter(function (item) {
              return item.key == activeKey;
            }),
            activeKey: activeKey
          }).then(function (_ref) {
            var dataSource = _ref.dataSource;
            if (dataSource !== null && dataSource !== void 0 && dataSource.length) {
              getDatas(dataSource);
            } else {
              setTableData([]);
            }
          });
        }
      });
    }
  };
  var layerChange = function layerChange(e, option) {
    setLayerKeys(e);
    setLayerOptions(option);
  };
  // 获取表格数据
  var getDatas = function getDatas(dataSource) {
    var _dataSource$;
    var codes = dataSource === null || dataSource === void 0 ? void 0 : dataSource.map(function (it) {
      return it === null || it === void 0 ? void 0 : it.code;
    });
    var networkTypes = [(_dataSource$ = dataSource[0]) === null || _dataSource$ === void 0 ? void 0 : _dataSource$.network_type];
    _request["default"].post("".concat(_config["default"].publicUrlZNFX, "/api/gisAnalyze/getStatisticByType"), {
      body: {
        networkTypes: networkTypes,
        statisticType: fieldKey,
        codes: codes
      }
    }).then(function (res) {
      var _data = [];
      if ((res === null || res === void 0 ? void 0 : res.result) === 0 && res !== null && res !== void 0 && res.data) {
        _data = res === null || res === void 0 ? void 0 : res.data;
      }
      setTableData(_data);
    });
  };
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Modal["default"], {
    title: "\u7BA1\u7F51\u7EDF\u8BA1",
    onClose: onClosefn,
    width: 500
  }, /*#__PURE__*/_react["default"].createElement(_ToolsSelect["default"], {
    title: "",
    value: activeBtn,
    onChange: onToolsChange,
    options: _service["default"].btnList || []
  }), /*#__PURE__*/_react["default"].createElement(_Select["default"], {
    mode: "multiple",
    options: _service["default"].getLayerOption(map, map.layers.getShowKeys()) || [],
    title: "\u7BA1\u7F51\u7C7B\u578B",
    onChange: layerChange,
    value: layerKeys,
    width: 300,
    layout: "horizontal"
  }), /*#__PURE__*/_react["default"].createElement(_Select["default"], {
    options: fieldOptions,
    value: fieldKey,
    title: "\u7EDF\u8BA1\u5B57\u6BB5",
    onChange: function onChange(e, option) {
      setFieldKey(e);
      setFieldOption(option);
    },
    width: 300,
    layout: "horizontal"
  }), /*#__PURE__*/_react["default"].createElement(_featureDraw["default"], {
    drawType: drawType,
    onDrawEnd: onDrawEnd
  })));
}
//# sourceMappingURL=Search.js.map
