"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 _MyModal = _interopRequireDefault(require("../_component/MyModal"));
var _antd = require("antd");
var _components = require("@vtx/components");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _ahooks = require("ahooks");
var _service = require("./service");
var _GwDetail = _interopRequireDefault(require("../_component/GwDetail"));
var _DetailItems = _interopRequireDefault(require("../_component/DetailItems"));
var _MyTag = _interopRequireDefault(require("../_component/MyTag"));
var _AnalysisDetailWrap = _interopRequireDefault(require("../_component/AnalysisDetailWrap"));
var _config = require("./config");
var _LineCharts = _interopRequireDefault(require("../_component/LineCharts"));
var _moment = _interopRequireDefault(require("moment"));
var echarts = _interopRequireWildcard(require("echarts"));
var _useGetDeviceData2 = _interopRequireDefault(require("../_mapUtil/useGetDeviceData"));
var _ResultDiagnosis = _interopRequireDefault(require("../_component/ResultDiagnosis"));
var _lodash = _interopRequireWildcard(require("lodash"));
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 _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; }
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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
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; } /* eslint-disable react/prop-types */
var Option = _components.VtxSelect.Option;
var DeviceMonitor = function DeviceMonitor(_ref) {
  var _data$find;
  var deviceId = _ref.deviceId,
    startDate = _ref.startDate,
    endDate = _ref.endDate,
    event$ = _ref.event$;
  var startTime = (0, _react.useMemo)(function () {
    return (0, _moment["default"])(startDate).subtract(24, 'h').valueOf();
  }, [startDate]);
  var endTime = (0, _react.useMemo)(function () {
    return (0, _moment["default"])(endDate).add(24, 'h').valueOf();
  }, [endDate]);
  var _useGetDeviceData = (0, _useGetDeviceData2["default"])({
      monitorItemCodes: 'w_liquid_level',
      deviceId: deviceId,
      startTime: startTime,
      endTime: endTime
    }),
    _useGetDeviceData$dat = _useGetDeviceData.data,
    data = _useGetDeviceData$dat === void 0 ? [] : _useGetDeviceData$dat,
    loading = _useGetDeviceData.loading;
  var ywData = ((_data$find = data.find(function (item) {
    return item.monitorItemCode === 'w_liquid_level';
  })) === null || _data$find === void 0 ? void 0 : _data$find.values) || [];
  var echartRef = (0, _react.useRef)();
  var series = (0, _react.useMemo)(function () {
    return _toConsumableArray(['液位'].map(function (name, index) {
      var color = '#00DC77';
      var areaColor = 'rgba(0, 220, 119, 0.7)';
      var areaColor1 = 'rgba(0, 220, 119, 0)';
      var newData = ywData;
      newData = newData.map(function (item) {
        return [(0, _moment["default"])(item.x).format('MM-DD HH:mm'), item.y];
      });
      return {
        yAxisIndex: index,
        name: name,
        type: 'line',
        smooth: true,
        symbolSize: 6,
        //标记的大小
        itemStyle: {
          //折线拐点标志的样式
          color: 'white',
          borderWidth: '1',
          borderColor: color,
          normal: {
            color: color
          }
        },
        areaStyle: {
          color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
          // 折线点的阴影
          {
            offset: 0,
            color: areaColor
          }, {
            offset: 1,
            color: areaColor1
          }])
        },
        lineStyle: {
          color: color
        },
        data: newData
      };
    }));
  }, [ywData]);
  var legendData = (0, _react.useMemo)(function () {
    return [{
      name: '液位'
    }];
  }, []);
  var yAxisList = (0, _react.useMemo)(function () {
    return [{
      name: '液位（m）'
    }];
  }, []);
  event$.useSubscription(function (val) {
    echartRef.current.echartRef.getEchartsInstance().dispatchAction(_objectSpread(_objectSpread({}, val), {}, {
      type: 'showTip'
    }));
  });
  return /*#__PURE__*/_react["default"].createElement(_LineCharts["default"], {
    legendData: legendData,
    yAxisList: yAxisList,
    series: series,
    loading: loading,
    ref: echartRef,
    event$: event$
  });
};
var DetailModal = function DetailModal(_ref2) {
  var visible = _ref2.visible,
    id = _ref2.id,
    onCancel = _ref2.onCancel;
  var _useRequest = (0, _ahooks.useRequest)(function () {
      return (0, _service.queryDataDetail)({
        id: id
      });
    }, {
      ready: !!id,
      refreshDeps: [id]
    }),
    _useRequest$data = _useRequest.data,
    data = _useRequest$data === void 0 ? {} : _useRequest$data;
  var _useState = (0, _react.useState)([]),
    _useState2 = _slicedToArray(_useState, 2),
    otherIds = _useState2[0],
    setOtherIds = _useState2[1];
  var event$ = (0, _ahooks.useEventEmitter)();
  var startDate = data.startDate,
    endDate = data.endDate,
    lineNo = data.lineNo,
    roadName = data.roadName,
    deviceName = data.deviceName,
    waterLevelChangeSimilarity = data.waterLevelChangeSimilarity,
    status = data.status,
    statusName = data.statusName,
    deviceId = data.deviceId,
    upstreamPumpStationName = data.upstreamPumpStationName,
    dataStartDate = data.dataStartDate,
    dataEndDate = data.dataEndDate,
    diagnosticResults = data.diagnosticResults,
    pipeSkeletonNodes = data.pipeSkeletonNodes,
    handlingMeasures = data.handlingMeasures,
    _data$otherAnalysisTa = data.otherAnalysisTarget,
    otherAnalysisTarget = _data$otherAnalysisTa === void 0 ? [] : _data$otherAnalysisTa;
  var formList = [{
    label: '泵站名称',
    value: upstreamPumpStationName,
    span: 8
  }, {
    label: '开泵时间',
    value: startDate,
    span: 8
  }, {
    label: '关泵时间',
    value: endDate,
    span: 8
  }, {
    label: '关联设备',
    value: deviceName,
    span: 8
  }, {
    label: '液位变化相似度',
    value: waterLevelChangeSimilarity + '%',
    span: 8
  }];
  (0, _react.useEffect)(function () {
    if (!(0, _lodash.isEmpty)(otherAnalysisTarget)) {
      var _otherAnalysisTarget$;
      setOtherIds([otherAnalysisTarget === null || otherAnalysisTarget === void 0 || (_otherAnalysisTarget$ = otherAnalysisTarget[0]) === null || _otherAnalysisTarget$ === void 0 ? void 0 : _otherAnalysisTarget$.id]);
    }
  }, [otherAnalysisTarget]);
  return /*#__PURE__*/_react["default"].createElement(_MyModal["default"], {
    title: /*#__PURE__*/_react["default"].createElement(_components.VtxModal.Title, {
      text: "\u7BA1\u7F51\u5835\u585E\u5206\u6790",
      subtitle: "\u8BE6\u60C5"
    }),
    width: 1366,
    footer: /*#__PURE__*/_react["default"].createElement(_antd.Button, {
      onClick: onCancel
    }, "\u5173\u95ED"),
    visible: visible,
    onCancel: onCancel
  }, /*#__PURE__*/_react["default"].createElement(_antd.Row, {
    gutter: [24, 0]
  }, /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    span: 16
  }, /*#__PURE__*/_react["default"].createElement(_GwDetail["default"], {
    id: data === null || data === void 0 ? void 0 : data.lineId
  }), /*#__PURE__*/_react["default"].createElement(_AnalysisDetailWrap["default"], {
    header: "\u5835\u585E\u5206\u6790",
    roadName: roadName,
    lineNo: lineNo,
    extra: /*#__PURE__*/_react["default"].createElement(_MyTag["default"], {
      text: statusName,
      color: _config.StatusColor[status]
    })
  }, /*#__PURE__*/_react["default"].createElement(_DetailItems["default"], {
    items: formList
  }), /*#__PURE__*/_react["default"].createElement(DeviceMonitor, {
    deviceId: deviceId,
    startDate: dataStartDate,
    endDate: dataEndDate,
    event$: event$
  }), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      marginTop: 16
    }
  }, /*#__PURE__*/_react["default"].createElement(_DetailItems["default"].DetailItem, {
    label: '对比分析',
    value: /*#__PURE__*/_react["default"].createElement(_components.VtxSelect, {
      mode: "multiple",
      allowClear: false,
      value: otherIds,
      onChange: function onChange(e) {
        return setOtherIds(e);
      }
    }, otherAnalysisTarget.map(function (item) {
      return /*#__PURE__*/_react["default"].createElement(Option, {
        key: item.id
      }, item.roadName, " ", item.lineNo);
    })),
    hideValueTitle: true
  })), otherIds.map(function (id, index) {
    var info = _lodash["default"].find(otherAnalysisTarget, {
      id: id
    });
    var statusName = info.statusName,
      roadName = info.roadName,
      lineNo = info.lineNo,
      status = info.status,
      deviceId = info.deviceId,
      deviceName = info.deviceName;
    var list = [{
      label: "\u5BF9\u6BD4\u7BA1\u6BB5".concat(index + 1),
      value: /*#__PURE__*/_react["default"].createElement(_antd.Space, null, /*#__PURE__*/_react["default"].createElement("span", null, "".concat(roadName ? "".concat(roadName, " ") : '').concat(lineNo)), /*#__PURE__*/_react["default"].createElement(_MyTag["default"], {
        text: statusName,
        color: _config.StatusColor[status]
      })),
      hideValueTitle: true,
      span: 12
    }, {
      label: '关联设备',
      value: deviceName,
      span: 12
    }];
    return /*#__PURE__*/_react["default"].createElement("div", {
      key: id,
      style: {
        marginTop: 16
      }
    }, /*#__PURE__*/_react["default"].createElement(_DetailItems["default"], {
      items: list
    }), /*#__PURE__*/_react["default"].createElement(DeviceMonitor, {
      deviceId: deviceId,
      startDate: dataStartDate,
      endDate: dataEndDate,
      event$: event$
    }));
  }))), /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    span: 8
  }, /*#__PURE__*/_react["default"].createElement(_ResultDiagnosis["default"], {
    reason: diagnosticResults,
    reasonTitle: "\u8BCA\u65AD\u7ED3\u679C",
    measure: status === _config.StatusType.DS ? handlingMeasures : '',
    skeletonNodes: pipeSkeletonNodes,
    showMap: false
  }))));
};
DetailModal.propTypes = {
  visible: _propTypes["default"].bool,
  info: _propTypes["default"].object,
  onCancel: _propTypes["default"].func,
  id: _propTypes["default"].string
};
var _default = exports["default"] = DetailModal;
//# sourceMappingURL=DetailModal.js.map
