"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"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _useProps2 = _interopRequireDefault(require("@vtx/ol-map/lib/use-props"));
var _olMap = require("@vtx/ol-map");
var _ToolsSelect = _interopRequireDefault(require("../_component/ToolsSelect"));
var _Modal = _interopRequireDefault(require("../_component/Modal"));
var _config = _interopRequireDefault(require("../_mapUtil/config"));
var _http = _interopRequireDefault(require("../_util/http"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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 && {}.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(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
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(r) { if (Array.isArray(r)) return r; } /**
 * 条件相关
 * @description: 用于展示条件查询、绘制控件等
 */
var Search = function Search(props) {
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map;
  var onClose = props.onClose,
    onChange = props.onChange,
    setLoading = props.setLoading,
    setVisible = props.setVisible;
  var _useState = (0, _react.useState)(''),
    _useState2 = _slicedToArray(_useState, 2),
    btnKey = _useState2[0],
    setBtnKey = _useState2[1];
  var _useState3 = (0, _react.useState)([]),
    _useState4 = _slicedToArray(_useState3, 2),
    gdList = _useState4[0],
    setGdList = _useState4[1];
  var _useState5 = (0, _react.useState)([]),
    _useState6 = _slicedToArray(_useState5, 2),
    sbList = _useState6[0],
    setSbList = _useState6[1];
  var btn = (0, _react.useRef)();
  var onClosefn = function onClosefn() {
    onClose && onClose();
    onChange && onChange({
      tableData: []
    });
  };
  var handleData = function handleData(data) {
    if (data !== null && data !== void 0 && data.length) {
      data.map(function (v) {
        var geoLocationDTO = v.geoLocationDTO;
        var geometryInfo = {};
        if (geoLocationDTO) {
          geometryInfo = {
            coordType: geoLocationDTO.coordinateType,
            type: geoLocationDTO.shapeType,
            lngLats: geoLocationDTO.lngLats
          };
        }
        v.geometryInfo = geometryInfo;
        v.key = 'gd';
      });
    }
    return data;
  };
  var getOrderData = function getOrderData() {
    _http["default"].get("".concat(_config["default"].publicUrlSJGD, "/api/workOrder/allCaseList"), {
      processDefinitionKey: 'clock_event_process',
      caseSourceList: "04,05,06"
    }).then(function (res) {
      var _res$data;
      var data = [];
      if ((res === null || res === void 0 ? void 0 : res.result) === 0 && res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && _res$data.length) {
        data = handleData(res.data);
      }
      setGdList(data);
    });
  };
  (0, _react.useEffect)(function () {
    getOrderData();
  }, []);
  var getData = function getData(properties) {
    setLoading(true);
    setVisible(true);
    onChange && onChange({
      tableData: []
    });
    var url = "".concat(_config["default"].publicUrlZNFX, "/api/gisAnalyze/pollutionSourceAnalysis");
    var params = {
      lineType: 2,
      lineCode: 'JSL609_JSL608'
      // geometryInfo: {
      //     type: 'point',
      //     lngLats: properties?.geometry?.flatCoordinates.join(','),
      //     coordType: 'wgs84',
      // },
    };
    _http["default"].post(url, {
      body: params
    }).then(function (res) {
      if (res && !res.result && res.data) {
        var _res$data$waterQualit = res.data.waterQualityIds,
          waterQualityIds = _res$data$waterQualit === void 0 ? [] : _res$data$waterQualit;
        getTableData(waterQualityIds);
      }
      setLoading(false);
    });
  };
  var getTableData = function getTableData(data) {
    if (data !== null && data !== void 0 && data.length) {
      var headers = {
        'content-type': 'application/x-www-form-urlencoded'
      };
      var ret = '';
      var params = {
        deviceIds: data
      };
      for (var key in params) {
        if (Object.hasOwnProperty.call(params, key)) {
          ret += encodeURIComponent(key) + '=' + encodeURIComponent(params[key].join(',')) + '&';
        }
      }
      params = ret;
      _http["default"].post("".concat(_config["default"].publicUrlJCYJ, "/api/basicDevice/list"), {
        body: params,
        headers: headers
      }).then(function (res) {
        if ((res === null || res === void 0 ? void 0 : res.result) === 0 && res !== null && res !== void 0 && res.data) {
          setSbList(res.data);
          onChange && onChange(res.data);
        }
      });
    }
  };
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Modal["default"], {
    title: "\u6C61\u67D3\u6E90\u5206\u6790",
    visible: true,
    onClose: onClosefn,
    style: {
      minWidth: '300px'
    }
  }, /*#__PURE__*/_react["default"].createElement(_ToolsSelect["default"], {
    layout: "horizontal",
    title: "",
    value: btnKey,
    onChange: function onChange(e) {
      if (e === btnKey) {
        setBtnKey('');
        map === null || map === void 0 || map.hideTip();
        btn.current = '';
        map.drawActive = false;
      } else {
        map.showTip('请单击选择水质问题工单');
        setBtnKey(e);
        btn.current = e;
        map.drawActive = true;
      }
    },
    options: [{
      label: '选择水质问题工单',
      key: 'select',
      isActive: false,
      icon: 'icon-dianxuan'
    }]
  })), /*#__PURE__*/_react["default"].createElement(_olMap.FeatureLayer, {
    data: gdList,
    style: "GD",
    zIndex: 5,
    id: "GD",
    name: "\u5185\u90E8\u5DE5\u5355",
    labelField: "taskName",
    layerControl: false,
    onClick: function onClick(values) {
      if (map.drawActive) {
        map.showTip('请单击选择水质问题工单');
        getData(values);
      }
    }
  }), /*#__PURE__*/_react["default"].createElement(_olMap.FeatureLayer, {
    data: sbList,
    style: "SZZ",
    zIndex: 5,
    id: "SZZ",
    name: "\u8BBE\u5907",
    labelField: "name",
    layerControl: false
  }));
};
var _default = exports["default"] = Search;
//# sourceMappingURL=Search.js.map
