"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 _datePicker = _interopRequireDefault(require("antd/lib/date-picker"));
var _button = _interopRequireDefault(require("antd/lib/button"));
var _message = _interopRequireDefault(require("antd/lib/message"));
var _moment = _interopRequireDefault(require("moment"));
var _PublicService = _interopRequireDefault(require("../_mapUtil/PublicService"));
var _classnames = _interopRequireDefault(require("classnames"));
var _request = _interopRequireDefault(require("../_mapUtil/request"));
var _config = _interopRequireDefault(require("../_mapUtil/config"));
var _dashedLine = _interopRequireDefault(require("../assets/dashedLine.png"));
var _dashedLine2 = _interopRequireDefault(require("../assets/dashedLine1.png"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _Modal = _interopRequireDefault(require("../_component/Modal"));
var _MyEmpty = _interopRequireDefault(require("../_component/MyEmpty"));
var _olMap = require("@vtx/ol-map");
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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 RangePicker = _datePicker["default"].RangePicker;
function SedimentationRisk(props) {
  var _useProps = (0, _olMap.useProps)(),
    map = _useProps.map;
  var _ref = props || {},
    onClose = _ref.onClose,
    _ref$show = _ref.show,
    show = _ref$show === void 0 ? true : _ref$show;
  var _useState = (0, _react.useState)([(0, _moment["default"])().subtract(1, 'days'), (0, _moment["default"])()]),
    _useState2 = _slicedToArray(_useState, 2),
    timeDate = _useState2[0],
    setTimeDate = _useState2[1];
  var _useState3 = (0, _react.useState)({}),
    _useState4 = _slicedToArray(_useState3, 2),
    modalData = _useState4[0],
    setModalData = _useState4[1];
  var _useState5 = (0, _react.useState)(null),
    _useState6 = _slicedToArray(_useState5, 2),
    detailFeature = _useState6[0],
    setDetailFeature = _useState6[1];
  var _useState7 = (0, _react.useState)(true),
    _useState8 = _slicedToArray(_useState7, 2),
    modalVisible = _useState8[0],
    setModalVisible = _useState8[1];
  var analysisLayer = (0, _react.useRef)();
  var _ref2 = detailFeature && (detailFeature === null || detailFeature === void 0 ? void 0 : detailFeature.getProperties()) || {},
    category = _ref2.category,
    code = _ref2.code;
  (0, _react.useEffect)(function () {
    if (show) {
      setModalVisible(true);
    } else {
      setModalVisible(false);
    }
  }, [show]);
  (0, _react.useEffect)(function () {
    analysisLayer.current = new _olMap.AnalysisLayer({
      map: map,
      layerName: 'zhsw:zhsw_manhole'
    });
    getData();
    // 地图提示
    map.showTip('请选择一个高亮窨井');
    // 地图点击事件
    map.on('click', mapClick);
    return function () {
      analysisLayer.current.destroy();

      // 地图点击事件
      map.un('click', mapClick);

      // 地图提示
      map.hideTip();
    };
  }, []);
  (0, _react.useEffect)(function () {
    code && getChartsData();
  }, [code]);

  // 地图点击
  var mapClick = function mapClick(event) {
    var feature = map.getFeaturesAtPixel(event.pixel)[0];
    var layer = analysisLayer.current.layer;
    if (layer && layer.getSource() && feature) {
      var features = layer.getSource().getFeatures();
      if (features !== null && features !== void 0 && features.length) {
        var newFeature = features.find(function (v) {
          return v.get('code') === feature.get('code');
        });
        setDetailFeature(newFeature);
      }
    }
  };

  // 获取高亮数据
  var getData = function getData() {
    _request["default"].get("".concat(_config["default"].publicUrlZNFX, "/api/gisAnalyze/getPointDeviceRelationList"), {
      body: {}
    }).then(function (res) {
      if ((res === null || res === void 0 ? void 0 : res.result) === 0 && res !== null && res !== void 0 && res.data) {
        var hasFacilityWells = [];
        res.data.map(function (item) {
          if (item.hasWaterFlow && item.hasWaterLevel) {
            // 淤积风险
            hasFacilityWells.push(_objectSpread(_objectSpread({}, item), {}, {
              junc_cat: item.type,
              yjfxType: true
            }));
          }
        });
        var codes = _PublicService["default"].getFilterParams(hasFacilityWells, 'code');
        analysisLayer.current.filter = codes ? "code in (".concat(codes, ")") : '';
      }
    });
  };

  // 获取弹框数据
  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/riskPooling"), {
      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);
      }
      setModalData(list);
    });
  };

  // 获取流速不达标的时间
  var getSpeedTimes = function getSpeedTimes() {
    var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var times = [];
    if (data !== null && data !== void 0 && data.length) {
      data.forEach(function (item) {
        if (item.value < 0.75) {
          times.push(item.time);
        }
      });
    }
    return times;
  };
  var getFullData = function getFullData() {
    var full = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var times = arguments.length > 1 ? arguments[1] : undefined;
    var data = [];
    if (times.length) {
      full.forEach(function (item) {
        if (times.includes(item.time) && item.value >= 80) {
          data.push(_objectSpread(_objectSpread({}, item), {}, {
            itemStyle: {
              color: '#ec808d'
            }
          }));
        } else {
          data.push(_objectSpread(_objectSpread({}, item), {}, {
            itemStyle: {
              color: '#a3dcc4'
            }
          }));
        }
      });
    } else {
      data = _PublicService["default"].getDataByKey(full, 'value');
    }
    return data;
  };

  // 获取series数据
  var getSeriesData = function getSeriesData() {
    var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var time = arguments.length > 1 ? arguments[1] : undefined;
    var defaultArr = [];
    if (data !== null && data !== void 0 && data.length) {
      time.length && time.forEach(function (item) {
        var dataValue = data.filter(function (val) {
          return val.time === item;
        }) || [];
        if (dataValue.length) {
          defaultArr.push({
            value: dataValue[0].value,
            time: dataValue[0].time
          });
        } else {
          defaultArr.push({
            value: null
          });
        }
      });
    }
    return defaultArr;
  };
  var renderRiskPooling = function renderRiskPooling() {
    var _ref3 = modalData || {},
      _ref3$full = _ref3.full,
      full = _ref3$full === void 0 ? [] : _ref3$full,
      _ref3$waterSpeed = _ref3.waterSpeed,
      waterSpeed = _ref3$waterSpeed === void 0 ? [] : _ref3$waterSpeed,
      _ref3$timeList = _ref3.timeList,
      timeList = _ref3$timeList === void 0 ? [] : _ref3$timeList;
    var speedDownTime = getSpeedTimes(waterSpeed);
    var timeData = _PublicService["default"].getDataByKey(timeList, 'time');
    var fullDataOld = getSeriesData(full, timeData);
    var fullData = getFullData(fullDataOld, speedDownTime);
    var waterSpeedData = getSeriesData(waterSpeed, timeData);
    var fullWarnData = new Array(timeData.length).fill(80);
    var speedWarnData = new Array(timeData.length).fill(0.75);
    var tootipColor = {
      充满度: '#a3dcc4',
      '流速(m/s)': '#0000ff',
      充满度阈值线: '#a3dcc4',
      流速阈值线: '#0000ff'
    };
    var option = {
      grid: {
        top: 60,
        left: '8%',
        right: '8%',
        bottom: 50,
        containLabel: true
      },
      legend: {
        show: true,
        itemWidth: 25,
        itemHeight: 10,
        data: [{
          name: '充满度'
        }, {
          name: '流速(m/s)'
        }, {
          name: '充满度阈值线',
          icon: "image://".concat(_dashedLine["default"])
        }, {
          name: '流速阈值线',
          icon: "image://".concat(_dashedLine2["default"])
        }]
      },
      tooltip: {
        trigger: 'axis',
        axisLine: {
          lineStyle: {
            color: '#FEFEFE'
          }
        },
        confine: true,
        formatter: function formatter(params) {
          var conformData = params.filter(function (item) {
            return item.color === '#ec808d' && item.seriesName === '充满度';
          });
          var content = null,
            subItem = '';
          if (conformData.length) {
            subItem = "\u5B58\u5728\u6DE4\u79EF\u98CE\u9669";
          } else {
            params.length && params.map(function (val, idx) {
              var htmlMarket = "<span style=\"display:inline-block;margin-right:5px;border-radius:10px;width:10px;height:10px;background-color: ".concat(tootipColor[val.seriesName], "\"></span>");
              var unit = ['充满度', '充满度阈值线'].includes(val.seriesName) ? '%' : '';
              if (idx == 0) {
                subItem += "<div>".concat(val.axisValue, "</div>");
              }
              subItem += "<div>".concat(htmlMarket, " ").concat(val.seriesName, " ").concat(val.value || '').concat(val.value ? unit : '', "</div>");
            });
          }
          content = "<div>".concat(subItem, "</div>");
          return content;
        }
      },
      xAxis: {
        type: 'category',
        data: timeData.map(function (str) {
          return str.replace(' ', '\n');
        }),
        axisTick: {
          show: false
        },
        axisLabel: {
          color: '#000'
        }
      },
      yAxis: [{
        type: 'value',
        name: '充满度',
        alignTicks: true,
        axisLine: {
          show: true
        },
        axisLabel: {
          formatter: '{value}%'
        },
        splitLine: {
          show: false
        }
      }, {
        type: 'value',
        name: '流速(m/s)',
        alignTicks: true,
        axisLine: {
          show: true
        },
        splitLine: {
          show: false
        }
      }],
      dataZoom: [{
        // 这个dataZoom组件，默认控制x轴。
        type: 'slider',
        // 这个 dataZoom 组件是 slider 型 dataZoom 组件
        // start: 0, // 左边在 10% 的位置。
        // end: 100, // 右边在 60% 的位置。
        button: '15%',
        fillerColor: 'rgba(97, 212, 225, 0.35)',
        borderColor: 'none',
        handleIcon: 'M10.7,11.9H9.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z',
        handleSize: '150%',
        height: 10,
        handleStyle: {
          color: '#fff',
          shadowBlur: 3,
          shadowColor: 'rgba(0, 0, 0, 0.4)',
          shadowOffsetX: 2,
          shadowOffsetY: 2
        },
        showDataShadow: false,
        showDetail: false,
        bottom: 14,
        realtime: true,
        // start: 0,
        // end: 100,
        startValue: timeData.length && timeData.length > 11 ? timeData.length - 12 : 0,
        endValue: timeData.length || 0
      }, {
        // 这个dataZoom组件，也控制x轴。
        type: 'inside',
        // 这个 dataZoom 组件是 inside 型 dataZoom 组件
        // start: 0, // 左边在 10% 的位置。
        // end: 100, // 右边在 60% 的位置。
        height: 10,
        bottom: 14,
        realtime: true,
        startValue: timeData.length && timeData.length > 11 ? timeData.length - 12 : 0,
        endValue: timeData.length || 0
      }],
      series: [{
        data: fullData,
        type: 'bar',
        name: '充满度',
        barMaxWidth: 25,
        barMinWidth: 12,
        itemStyle: {
          color: '#a3dcc4'
        }
      }, {
        data: waterSpeedData,
        type: 'line',
        name: '流速(m/s)',
        yAxisIndex: 1,
        connectNulls: true,
        lineStyle: {
          color: '#0000ff'
        },
        smooth: true
      }, {
        name: '充满度阈值线',
        type: 'line',
        data: fullWarnData,
        connectNulls: true,
        smooth: true,
        symbol: 'none',
        lineStyle: {
          color: '#a3dcc4',
          type: 'dashed'
        }
      }, {
        name: '流速阈值线',
        type: 'line',
        data: speedWarnData,
        connectNulls: true,
        yAxisIndex: 1,
        smooth: true,
        symbol: 'none',
        lineStyle: {
          color: '#0000ff',
          type: 'dashed'
        }
      }]
    };
    return /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
      style: {
        height: 240
      },
      option: option,
      notMerge: true,
      lazyUpdate: true
    });
  };

  // 改变时间
  var handleTimePicker = function handleTimePicker(value) {
    setTimeDate(value);
  };

  // 确定
  var ensureBtn = function ensureBtn() {
    getChartsData();
  };

  // 重置
  var resetBtn = function resetBtn() {
    setTimeDate([(0, _moment["default"])().subtract(1, 'days'), (0, _moment["default"])()]);
  };
  var _ref4 = modalData || {},
    _ref4$timeList = _ref4.timeList,
    timeList = _ref4$timeList === void 0 ? [] : _ref4$timeList;
  return /*#__PURE__*/_react["default"].createElement(_Modal["default"], {
    title: "\u6DE4\u79EF\u98CE\u9669\u5206\u6790",
    onClose: onClose,
    width: 450,
    visible: modalVisible
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])('intelligentWarp')
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])('top')
  }, /*#__PURE__*/_react["default"].createElement(RangePicker, {
    value: timeDate,
    format: 'YYYY-MM-DD',
    style: {
      width: 260
    },
    dropdownClassName: (0, _classnames["default"])('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")), /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])('contentWarp')
  }, timeList !== null && timeList !== void 0 && timeList.length ? renderRiskPooling() : /*#__PURE__*/_react["default"].createElement(_MyEmpty["default"], {
    type: "charts"
  }))));
}
var _default = exports["default"] = SedimentationRisk;
//# sourceMappingURL=index.js.map
