"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 _button = _interopRequireDefault(require("antd/lib/button"));
var _datePicker = _interopRequireDefault(require("antd/lib/date-picker"));
var _select = _interopRequireDefault(require("antd/lib/select"));
var _message = _interopRequireDefault(require("antd/lib/message"));
var _moment = _interopRequireDefault(require("moment"));
var _analysisLayer = require("@vtx/ol-map/lib/analysis-layer");
var _request = _interopRequireDefault(require("../_mapUtil/request"));
var _config = _interopRequireDefault(require("../_mapUtil/config"));
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 Option = _select["default"].Option;
var RangePicker = _datePicker["default"].RangePicker;
var Search = function Search() {
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map,
    setTableData = _useProps.setTableData,
    onClose = _useProps.onClose,
    classnames = _useProps.classnames,
    hasFacilityWell = _useProps.hasFacilityWell,
    selectOptions = _useProps.selectOptions,
    facilityType = _useProps.facilityType,
    setFacilityType = _useProps.setFacilityType,
    selectValue = _useProps.selectValue,
    setSelectValue = _useProps.setSelectValue;
  var _useState = (0, _react.useState)([]),
    _useState2 = _slicedToArray(_useState, 2),
    selectOption = _useState2[0],
    setSelectOption = _useState2[1];
  var _useState3 = (0, _react.useState)([(0, _moment["default"])().subtract(1, 'days'), (0, _moment["default"])()]),
    _useState4 = _slicedToArray(_useState3, 2),
    timeDate = _useState4[0],
    setTimeDate = _useState4[1];
  // 图层数据
  var _useState5 = (0, _react.useState)(null),
    _useState6 = _slicedToArray(_useState5, 2),
    detailFeature = _useState6[0],
    setDetailFeature = _useState6[1];
  var _ref = detailFeature && detailFeature.getProperties() || {},
    category = _ref.category,
    code = _ref.code;

  // 点击地图
  var mapClick = function mapClick(event) {
    var layers = map.layers.getAllLayers().filter(function (_layer) {
      return _layer === null || _layer === void 0 ? void 0 : _layer.show;
    });
    (0, _analysisLayer.getWMSFeatureInfoByLayers)(event, map, layers).then(function (features) {
      if (features !== null && features !== void 0 && features.length) {
        setDetailFeature(features === null || features === void 0 ? void 0 : features[0]);
        // 液位
        setSelectValue('1');
      }
    });
  };
  (0, _react.useEffect)(function () {
    // btn.current = 'Point';
    // map.drawActive = true;
    map.on('loadstart', function () {});
    // if (show) {
    map.on('click', mapClick);
    return function () {
      map.un('click', mapClick);
      map.hideTip();
    };
    // }
  }, [
  // show,
  map]);
  (0, _react.useEffect)(function () {
    getDefaultValue();
  }, [facilityType]);
  (0, _react.useEffect)(function () {
    var facilityArr = hasFacilityWell.length && hasFacilityWell.filter(function (item) {
      return item.code === code && item.rlrsType;
    }) || [];
    if (facilityArr.length) {
      setFacilityType(facilityArr[0].rlrsType);
    }
  }, [code]);
  (0, _react.useEffect)(function () {
    if (code && category) {
      getChartsData();
    }
  }, [code, category]);
  // 下拉选修改
  var handleSelect = function handleSelect(value) {
    setSelectValue(value);
  };

  // 改变时间
  var handleTimePicker = function handleTimePicker(value) {
    setTimeDate(value);
  };
  // 确定
  var ensureBtn = function ensureBtn() {
    getChartsData();
  };
  // 重置
  var resetBtn = function resetBtn() {
    getDefaultValue();
  };
  var onClosefn = function onClosefn() {
    onClose && onClose();
    // setTableData([]);
  };

  // 获取弹框数据（查询结果）
  var getChartsData = function getChartsData() {
    if (!code || !category) {
      _message["default"].warning('请先选择高亮点位！', 2);
      return false;
    }
    var params = {
      startTime: (0, _moment["default"])(timeDate[0]).format('YYYY-MM-DD 00:00:00'),
      endTime: (0, _moment["default"])(timeDate[1]).format('YYYY-MM-DD 23:59:59'),
      pointCode: code,
      type: category
    };
    _request["default"].post("".concat(_config["default"].publicUrlZNFX, "/api/gisAnalyze/infiltration"), {
      body: params
    }).then(function (res) {
      var list = [];
      if ((res === null || res === void 0 ? void 0 : res.result) === 0 && res !== null && res !== void 0 && res.data) {
        list = res.data || {};
      } else {
        _message["default"].error(res === null || res === void 0 ? void 0 : res.message, 2);
      }
      setTableData(list);
    });
  };
  var getDefaultValue = function getDefaultValue() {
    var options = [];
    if (facilityType) {
      var _selectOptions$facili;
      options = ((_selectOptions$facili = selectOptions[facilityType]) === null || _selectOptions$facili === void 0 ? void 0 : _selectOptions$facili.options) || [];
    }
    setSelectOption(options);
    // 用于重置
    setTimeDate([(0, _moment["default"])().subtract(1, 'days'), (0, _moment["default"])()]);
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('top')
  }, /*#__PURE__*/_react["default"].createElement(_select["default"], {
    value: selectValue,
    style: {
      width: 120
    },
    onChange: handleSelect,
    dropdownClassName: classnames('intelligentSelect')
  }, selectOption && selectOption.length && selectOption.map(function (item, idx) {
    return /*#__PURE__*/_react["default"].createElement(Option, {
      key: idx,
      value: item.value
    }, item.label);
  })), /*#__PURE__*/_react["default"].createElement(RangePicker, {
    value: timeDate,
    format: 'YYYY-MM-DD',
    style: {
      width: 260
    },
    dropdownClassName: classnames('intelligentTimePicker'),
    allowClear: false,
    onChange: handleTimePicker
  }), /*#__PURE__*/_react["default"].createElement(_button["default"], {
    type: "primary",
    onClick: ensureBtn
  }, "\u786E\u5B9A"), /*#__PURE__*/_react["default"].createElement(_button["default"], {
    onClick: resetBtn
  }, "\u91CD\u7F6E"));
};
var _default = exports["default"] = Search;
//# sourceMappingURL=Search.js.map
