"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 _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireWildcard(require("react"));
var _vtxModal = _interopRequireDefault(require("@vtx/components/lib/vtx-modal"));
var _antd = require("antd");
var _GwDetail = _interopRequireDefault(require("../_component/GwDetail"));
var _AnalysisDetailWrap = _interopRequireDefault(require("../_component/AnalysisDetailWrap"));
var _AnalysisDetailStatistics = _interopRequireDefault(require("../_component/AnalysisDetailStatistics"));
var _config = _interopRequireDefault(require("../_mapUtil/config"));
var echarts = _interopRequireWildcard(require("echarts"));
var _useGetDeviceData2 = _interopRequireDefault(require("../_mapUtil/useGetDeviceData"));
var _moment = _interopRequireDefault(require("moment"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _ahooks = require("ahooks");
var _service = require("./service");
var _lodash = require("lodash");
var _config2 = require("./config");
var _StreamInfoWrap = _interopRequireDefault(require("../_component/StreamInfoWrap"));
var _ResultDiagnosis = _interopRequireDefault(require("../_component/ResultDiagnosis"));
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(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(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _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(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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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; }
// eslint-disable-next-line react/prop-types
var DeviceMonitor = function DeviceMonitor(_ref) {
  var _data$find;
  var _ref$config = _ref.config,
    config = _ref$config === void 0 ? {} : _ref$config,
    deviceFacilityId = _ref.deviceFacilityId,
    startDate = _ref.startDate,
    endDate = _ref.endDate;
  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_wq_ddl',
      facilityId: deviceFacilityId,
      startTime: startTime,
      endTime: endTime
    }),
    _useGetDeviceData$dat = _useGetDeviceData.data,
    data = _useGetDeviceData$dat === void 0 ? [] : _useGetDeviceData$dat;
  var ywData = ((_data$find = data.find(function (item) {
    return item.monitorItemCode === 'w_wq_ddl';
  })) === null || _data$find === void 0 ? void 0 : _data$find.values) || [];
  var option = {
    grid: {
      top: '20%',
      left: '5%',
      right: '10%',
      bottom: '20%',
      containLabel: true
    },
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      left: 'center',
      top: 30,
      itemWidth: 18,
      itemHeight: 6,
      itemGap: 32,
      textStyle: {
        color: '#222',
        fontSize: 14
      },
      data: [{
        name: '电导率'
      }, {
        name: '电导率阈值',
        itemStyle: {
          opacity: 0
        }
      }]
    },
    xAxis: {
      type: 'category',
      axisLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        show: true,
        textStyle: {
          fontSize: 12,
          color: 'rgba(0, 0, 0, 0.6)' //X轴文字颜色
        },
        formatter: function formatter(value) {
          return value.replace(' ', '\n');
        }
      }
    },
    yAxis: [{
      type: 'value',
      name: '电导率（μS/cm）',
      nameTextStyle: {
        color: 'rgba(0, 0, 0, 0.6)',
        fontSize: 12
      },
      axisLine: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: 'rgba(0, 0, 0, 0.6)',
        fontSize: 14
      },
      splitLine: {
        show: true,
        lineStyle: {
          color: 'rgba(0, 0, 0, 0.2)',
          type: 'dashed'
        }
      }
    }],
    dataZoom: [{}],
    series: [{
      name: '电导率',
      type: 'line',
      smooth: true,
      symbol: 'circle',
      //标记的图形为实心圆
      symbolSize: 6,
      //标记的大小
      itemStyle: {
        //折线拐点标志的样式
        color: 'white',
        borderWidth: '1',
        borderColor: '#FF8D2C'
      },
      areaStyle: {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
        // 折线点的阴影
        {
          offset: 0,
          color: 'rgba(255, 141, 44, 0.7)'
        }, {
          offset: 1,
          color: 'rgba(255, 141, 44, 0)'
        }])
      },
      lineStyle: {
        color: '#FF8D2C'
      },
      data: ywData.map(function (item) {
        return [(0, _moment["default"])(item.x).format('MM-DD HH:mm'), item.y];
      })
    }, {
      name: '电导率阈值',
      type: 'line',
      symbol: 'none',
      //标记的图形为实心圆
      lineStyle: {
        color: '#CB4EFF',
        type: 'dashed'
      },
      data: ywData.map(function (item) {
        return [(0, _moment["default"])(item.x).format('MM-DD HH:mm'), config.ddlThreshold];
      })
    }]
  };
  return /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    style: {
      width: '100%',
      height: 280
    },
    option: option
  });
};

// eslint-disable-next-line react/prop-types
var Analysis = function Analysis(_ref2) {
  var _info$result;
  var _ref2$info = _ref2.info,
    info = _ref2$info === void 0 ? {} : _ref2$info;
  var roadName = info.roadName,
    lineNo = info.lineNo,
    totalOccTimes = info.totalOccTimes,
    totalDurationHours = info.totalDurationHours,
    avgDdl = info.avgDdl,
    firstOccDate = info.firstOccDate,
    lastEndDate = info.lastEndDate,
    deviceFacilityId = info.deviceFacilityId;
  var list = [{
    label: '雨污混接次数',
    value: totalOccTimes,
    unit: '次',
    icon: require('./assets/ywhj.svg'),
    color: _config["default"].colorMap.red
  }, {
    label: '雨污混接时长',
    value: totalDurationHours,
    unit: 'h',
    icon: require('./assets/duration.png')
  }, {
    label: '雨污混接平均电导率',
    value: avgDdl || 0,
    unit: 'μS/cm',
    icon: require('./assets/ddl.png'),
    color: '#24a6e7'
  }];
  return /*#__PURE__*/_react["default"].createElement(_AnalysisDetailWrap["default"], {
    roadName: roadName,
    lineNo: lineNo,
    header: '雨污混接分析'
  }, /*#__PURE__*/_react["default"].createElement(_AnalysisDetailStatistics["default"], {
    list: list
  }), !(0, _lodash.isEmpty)(info) && /*#__PURE__*/_react["default"].createElement(DeviceMonitor, {
    config: info === null || info === void 0 || (_info$result = info.result) === null || _info$result === void 0 ? void 0 : _info$result.config,
    startDate: firstOccDate,
    endDate: lastEndDate,
    deviceFacilityId: deviceFacilityId
  }));
};

// eslint-disable-next-line react/prop-types
var StreamInfo = function StreamInfo(_ref3) {
  var _ref3$info = _ref3.info,
    info = _ref3$info === void 0 ? {} : _ref3$info,
    isUp = _ref3.isUp,
    _ref3$config = _ref3.config,
    config = _ref3$config === void 0 ? {} : _ref3$config;
  var sewageMixedType = info.sewageMixedType,
    deviceFacilityId = info.deviceFacilityId,
    lineNo = info.lineNo,
    firstOccDate = info.firstOccDate,
    lastEndDate = info.lastEndDate;
  var isError = sewageMixedType !== _config2.RainSewageType.ZC;
  return /*#__PURE__*/_react["default"].createElement(_StreamInfoWrap["default"], {
    isError: isError,
    isUp: isUp,
    lineNo: lineNo
  }, /*#__PURE__*/_react["default"].createElement(DeviceMonitor, {
    config: config,
    deviceFacilityId: deviceFacilityId,
    startDate: firstOccDate,
    endDate: lastEndDate
  }));
};
var DetailModal = function DetailModal(_ref4) {
  var _info$facility;
  var visible = _ref4.visible,
    info = _ref4.info,
    onCancel = _ref4.onCancel;
  var facilityId = info.facilityId,
    sewageMixedType = info.sewageMixedType,
    firstOccDate = info.firstOccDate,
    lastEndDate = info.lastEndDate,
    lineNo = info.lineNo,
    roadName = info.roadName;
  var _useRequest = (0, _ahooks.useRequest)(function () {
      if (facilityId) {
        return (0, _service.fetchQueryDataResult)({
          facilityId: facilityId
        });
      }
      return {};
    }, {
      refreshDeps: [facilityId]
    }),
    _useRequest$data = _useRequest.data,
    data = _useRequest$data === void 0 ? {} : _useRequest$data;
  var _data$result = data.result,
    result = _data$result === void 0 ? {} : _data$result;
  var upstreamItems = result.upstreamItems,
    downstreamItems = result.downstreamItems,
    _result$config = result.config,
    config = _result$config === void 0 ? {} : _result$config,
    skeletonNodes = result.skeletonNodes,
    targetItem = result.targetItem;
  var handleMeasure = config.handleMeasure,
    ddlThreshold = config.ddlThreshold;
  var _startDate = (0, _moment["default"])(firstOccDate).format('YYYY-MM-DD HH:mm:ss');
  var _endDate = (0, _moment["default"])(lastEndDate).format('YYYY-MM-DD HH:mm:ss');
  var reason = (0, _react.useMemo)(function () {
    var reason = '';
    if (sewageMixedType === _config2.RainSewageType.YWHJ && !(0, _lodash.isEmpty)(data)) {
      if ((0, _lodash.isEmpty)(upstreamItems) && (0, _lodash.isEmpty)(downstreamItems)) {
        reason = "".concat(_startDate, "\u81F3").concat(_endDate, "\u671F\u95F4\uFF0C\u7535\u5BFC\u7387\u9AD8\u4E8E").concat(ddlThreshold, "\u03BCS/cm\u6545").concat(roadName, " ").concat(lineNo, "\u53EF\u80FD\u5B58\u5728\u96E8\u6C61\u6DF7\u63A5\u98CE\u9669");
      } else {
        var getText = function getText(_ref5) {
          var roadName = _ref5.roadName,
            lineNo = _ref5.lineNo,
            sewageMixedType = _ref5.sewageMixedType;
          return "".concat(roadName, " ").concat(lineNo, "\u5728").concat(_startDate, "\u81F3").concat(_endDate, "\u671F\u95F4\uFF0C\u7535\u5BFC\u7387").concat(sewageMixedType === _config2.RainSewageType.ZC ? '低于' : '高于').concat(ddlThreshold, "\u03BCS/cm");
        };
        reason = /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", null, "1\u3001", getText({
          lineNo: lineNo,
          roadName: roadName,
          sewageMixedType: sewageMixedType
        })), [].concat(_toConsumableArray((upstreamItems || []).map(function (item) {
          return _objectSpread(_objectSpread({}, item), {}, {
            isUp: true
          });
        })), _toConsumableArray((downstreamItems || []).map(function (item) {
          return _objectSpread(_objectSpread({}, item), {}, {
            isUp: false
          });
        }))).map(function (_ref6, index) {
          var isUp = _ref6.isUp,
            lineNo = _ref6.lineNo,
            roadName = _ref6.roadName,
            sewageMixedType = _ref6.sewageMixedType;
          return /*#__PURE__*/_react["default"].createElement("div", {
            key: facilityId
          }, "".concat(index + 2, "\u3001").concat(isUp ? '上游节点' : '下游节点', "\uFF1A").concat(getText({
            lineNo: lineNo,
            roadName: roadName,
            sewageMixedType: sewageMixedType
          })));
        }), /*#__PURE__*/_react["default"].createElement("div", null, "\u6545", targetItem.roadName, " ", targetItem.lineNo, "\u7BA1\u6BB5\u53EF\u80FD\u5B58\u5728\u96E8\u6C61\u6DF7\u63A5\u98CE\u9669\u3002"));
      }
    }
    return reason;
  }, [data]);
  return /*#__PURE__*/_react["default"].createElement(_vtxModal["default"], {
    title: /*#__PURE__*/_react["default"].createElement(_vtxModal["default"].Title, {
      text: "\u96E8\u6C61\u6DF7\u63A5\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: info === null || info === void 0 || (_info$facility = info.facility) === null || _info$facility === void 0 ? void 0 : _info$facility.id
  }), /*#__PURE__*/_react["default"].createElement(Analysis, {
    info: data
  }), (0, _lodash.isEmpty)(upstreamItems) ? null : upstreamItems.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(StreamInfo, {
      info: item,
      isUp: true,
      key: item.deviceFacilityId,
      config: config
    });
  }), (0, _lodash.isEmpty)(downstreamItems) ? null : downstreamItems.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(StreamInfo, {
      info: item,
      isUp: false,
      key: item.deviceFacilityId,
      config: config
    });
  })), /*#__PURE__*/_react["default"].createElement(_antd.Col, {
    span: 8
  }, /*#__PURE__*/_react["default"].createElement(_ResultDiagnosis["default"], {
    result: sewageMixedType === _config2.RainSewageType.ZC ? "".concat(_startDate, "\u81F3").concat(_endDate, "\u671F\u95F4\uFF0C\u7535\u5BFC\u7387\u4F4E\u4E8E").concat(ddlThreshold, "\n\n                                \u6545").concat(roadName, " ").concat(lineNo, "\u4E0D\u5B58\u5728\u96E8\u6C61\u6DF7\u63A5\u98CE\u9669") : '',
    reason: reason,
    measure: handleMeasure,
    skeletonNodes: skeletonNodes
  }))));
};
DetailModal.propTypes = {
  visible: _propTypes["default"].bool,
  info: _propTypes["default"].object,
  onCancel: _propTypes["default"].func
};
var _default = exports["default"] = DetailModal;
//# sourceMappingURL=DetailModal.js.map
