"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 = _interopRequireDefault(require("react"));
var _vtxModal = _interopRequireDefault(require("@vtx/components/lib/vtx-modal"));
var _button = _interopRequireDefault(require("antd/lib/button"));
var _ahooks = require("ahooks");
var _service = require("./service");
var _row = _interopRequireDefault(require("antd/lib/row"));
var _col = _interopRequireDefault(require("antd/lib/col"));
var _MyCollapse = _interopRequireDefault(require("../_component/MyCollapse"));
var _DetailItems = _interopRequireDefault(require("../_component/DetailItems"));
var _useGetFacility2 = _interopRequireDefault(require("../_mapUtil/useGetFacility"));
var _moment = _interopRequireDefault(require("moment"));
var _lodash = _interopRequireWildcard(require("lodash"));
var _ResultDiagnosis = _interopRequireDefault(require("../_component/ResultDiagnosis"));
var _LineCharts = _interopRequireDefault(require("../_component/LineCharts"));
var _antd = require("antd");
var _icons = require("@ant-design/icons");
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 _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/* eslint-disable react/prop-types */

var prefix = 'ol-analysis-water-quality';
var Panel = _MyCollapse["default"].Panel;
var colors = ['#1677FF', '#00BD47'];
var DetailInfo = function DetailInfo(_ref) {
  var _ref$id = _ref.id,
    id = _ref$id === void 0 ? '' : _ref$id;
  var _useGetFacility = (0, _useGetFacility2["default"])(id),
    data = _useGetFacility.data;
  var code = data.code,
    divisionName = data.divisionName,
    _data$dataJson = data.dataJson,
    dataJson = _data$dataJson === void 0 ? {} : _data$dataJson,
    typeCode = data.typeCode,
    manageUnitName = data.manageUnitName,
    name = data.name;
  var ds = dataJson.ds,
    lineLength = dataJson.lineLength,
    startDeep = dataJson.startDeep,
    endDeep = dataJson.endDeep,
    lineTextureName = dataJson.lineTextureName,
    layWayName = dataJson.layWayName,
    flowDirectionName = dataJson.flowDirectionName,
    roadName = dataJson.roadName,
    level = dataJson.level,
    groundElevation = dataJson.groundElevation,
    bottomElevation = dataJson.bottomElevation,
    wellDeep = dataJson.wellDeep,
    wellShapeName = dataJson.wellShapeName,
    wellTextureName = dataJson.wellTextureName,
    typeName = dataJson.typeName,
    wellSize = dataJson.wellSize,
    totalRatedFlow = dataJson.totalRatedFlow,
    levelName = dataJson.levelName,
    waterCompanyName = dataJson.waterCompanyName,
    supplyCapacity = dataJson.supplyCapacity,
    sewageTreatmentProcessName = dataJson.sewageTreatmentProcessName,
    sewageTreatmentLevelName = dataJson.sewageTreatmentLevelName,
    manageStaffName = dataJson.manageStaffName;
  var lineList = [{
    label: '编码',
    value: code,
    span: 8
  }, {
    label: '等级',
    value: level,
    span: 8
  }, {
    label: '行政区划',
    value: divisionName,
    span: 8
  }, {
    label: '所在道路',
    value: roadName,
    span: 8
  }, {
    label: '管长',
    value: lineLength ? lineLength + 'm' : null,
    span: 8
  }, {
    label: '管径',
    value: ds ? ds + 'mm' : '',
    span: 8
  }, {
    label: '起点埋深',
    value: startDeep ? startDeep + 'm' : null,
    span: 8
  }, {
    label: '终点埋深',
    value: endDeep ? endDeep + 'm' : null,
    span: 8
  }, {
    label: '材质',
    value: lineTextureName || null,
    span: 8
  }, {
    label: '埋设方式',
    value: layWayName,
    span: 8
  }, {
    label: '流向',
    value: flowDirectionName,
    span: 8
  }];
  var manholeList = [{
    label: '编码',
    value: code,
    span: 8
  }, {
    label: '行政区划',
    value: divisionName,
    span: 8
  }, {
    label: '所在道路',
    value: roadName,
    span: 8
  }, {
    label: '地面高程',
    value: groundElevation + 'm',
    span: 8
  }, {
    label: '井底标高',
    value: bottomElevation + 'm',
    span: 8
  }, {
    label: '窨井井深',
    value: wellDeep ? wellDeep + 'm' : null,
    span: 8
  }, {
    label: '井盖形状',
    value: wellShapeName,
    span: 8
  }, {
    label: '井盖规格',
    value: wellSize + 'mm',
    span: 8
  }, {
    label: '井盖材质',
    value: wellTextureName,
    span: 8
  }, {
    label: '窨井类型',
    value: typeName,
    span: 8
  },
  // {
  //     label: '窨井形式',
  //     value: roadName,
  //     span: 8,
  // },
  {
    label: '管理单位',
    value: manageUnitName,
    span: 8
  }];
  var pumpStationList = [{
    label: '设施编码',
    value: code,
    span: 8
  }, {
    label: '设施名称',
    value: name,
    span: 8
  }, {
    label: '行政区划',
    value: divisionName,
    span: 8
  }, {
    label: '管理单位',
    value: manageUnitName,
    span: 8
  }, {
    label: '责任人',
    value: manageStaffName,
    span: 8
  }, {
    label: '总额定流量',
    value: totalRatedFlow ? totalRatedFlow + 'm³/s ' : null,
    span: 8
  }, {
    label: '级别',
    value: levelName,
    span: 8
  }];
  var sewagePlantList = [{
    label: '设施编码',
    value: code,
    span: 8
  }, {
    label: '设施名称',
    value: name,
    span: 8
  }, {
    label: '行政区划',
    value: divisionName,
    span: 8
  }, {
    label: '所属公司',
    value: waterCompanyName,
    span: 8
  }, {
    label: '责任人',
    value: manageStaffName,
    span: 8
  }, {
    label: '日处理能力',
    value: supplyCapacity + '万吨',
    span: 8
  }, {
    label: '污水厂类型',
    value: typeName,
    span: 8
  }, {
    label: '污水处理级别',
    value: sewageTreatmentLevelName,
    span: 8
  }, {
    label: '污水处理工艺',
    value: sewageTreatmentProcessName,
    span: 8
  }];
  var listMap = {
    line: lineList,
    manhole: manholeList,
    pump_station: pumpStationList,
    bz: pumpStationList,
    sewage_plant: sewagePlantList
  };
  return /*#__PURE__*/_react["default"].createElement(_MyCollapse["default"], {
    defaultActiveKey: ['1']
  }, /*#__PURE__*/_react["default"].createElement(Panel, {
    header: "\u57FA\u672C\u4FE1\u606F",
    key: '1'
  }, /*#__PURE__*/_react["default"].createElement(_DetailItems["default"], {
    items: listMap[typeCode] || []
  })));
};
var HistoryLine = function HistoryLine(_ref2) {
  var historyMonitorData = _ref2.historyMonitorData,
    historyPredictData = _ref2.historyPredictData;
  if ((0, _lodash.isEmpty)(historyMonitorData)) {
    return null;
  }
  var monitorListObject = _lodash["default"].groupBy(historyMonitorData, 'monitorItemCode');
  var predictKeyByTime = _lodash["default"].keyBy(historyPredictData, 'timeDesc');
  var yAxisList = [];
  var xData = _lodash["default"].uniq(_lodash["default"].map(historyMonitorData, 'timeDesc')).sort();
  var series = [];
  var legendData = [];
  Object.keys(monitorListObject).forEach(function (key, index) {
    var monitorList = monitorListObject[key];
    var item = monitorList[0];
    var monitorKeyByTime = _lodash["default"].keyBy(monitorList, 'timeDesc');
    var monitorItemName = item.monitorItemName,
      unit = item.unit,
      monitorItemCode = item.monitorItemCode;
    yAxisList.push({
      name: unit ? "(".concat(unit, ")") : '',
      offset: 15
    });
    ["\u5B9E\u9645 ".concat(monitorItemName), "\u9884\u6D4B ".concat(monitorItemName)].forEach(function (name) {
      var data = xData.map(function (time) {
        if (name.includes('实际')) {
          var _monitorKeyByTime$tim;
          return ((_monitorKeyByTime$tim = monitorKeyByTime[time]) === null || _monitorKeyByTime$tim === void 0 ? void 0 : _monitorKeyByTime$tim.value) || 0;
        } else {
          var _predictKeyByTime$tim;
          return ((_predictKeyByTime$tim = predictKeyByTime[time]) === null || _predictKeyByTime$tim === void 0 || (_predictKeyByTime$tim = _predictKeyByTime$tim.monitorsValue) === null || _predictKeyByTime$tim === void 0 ? void 0 : _predictKeyByTime$tim[monitorItemCode]) || 0;
        }
      });
      var color = colors[index % 2];
      legendData.push({
        name: name,
        itemStyle: {
          opacity: 0
        }
      });
      series.push({
        yAxisIndex: index,
        name: name,
        type: 'line',
        smooth: name.includes('预测'),
        symbolSize: name.includes('预测') ? 6 : 0,
        //标记的大小
        itemStyle: {
          //折线拐点标志的样式
          color: 'white',
          borderWidth: '1',
          borderColor: color,
          normal: {
            color: color
          }
        },
        data: data,
        lineStyle: {
          type: name.includes('实际') ? 'solid' : 'dashed'
        }
      });
    });
  });
  return /*#__PURE__*/_react["default"].createElement(_LineCharts["default"], {
    yAxisList: yAxisList,
    series: series,
    xAxisData: xData.map(function (x) {
      return (0, _moment["default"])(x).format('MM-DD HH:mm');
    }),
    legendData: legendData,
    legendOption: {
      width: '60%'
    }
  });
};
var PredictLine = function PredictLine(_ref3) {
  var predictStatisticsData = _ref3.predictStatisticsData,
    predictData = _ref3.predictData;
  if ((0, _lodash.isEmpty)(predictStatisticsData)) {
    return null;
  }
  var yAxisList = [];
  var xData = _lodash["default"].map(predictData, 'timeDesc');
  var series = [];
  var legendData = [];
  predictStatisticsData.forEach(function (item, index) {
    var monitorItemName = item.monitorItemName,
      monitorCode = item.monitorCode,
      unit = item.unit;
    var name = "\u9884\u6D4B ".concat(monitorItemName);
    var color = colors[index % 2];
    var data = predictData.map(function (data) {
      var _data$monitorsValue;
      return (data === null || data === void 0 || (_data$monitorsValue = data.monitorsValue) === null || _data$monitorsValue === void 0 ? void 0 : _data$monitorsValue[monitorCode]) || 0;
    });
    yAxisList.push({
      name: unit ? "(".concat(unit, ")") : '',
      offset: 15
    });
    legendData.push({
      name: name,
      itemStyle: {
        opacity: 0
      }
    });
    series.push({
      yAxisIndex: index,
      name: name,
      type: 'line',
      smooth: true,
      symbolSize: 6,
      //标记的大小
      itemStyle: {
        //折线拐点标志的样式
        color: 'white',
        borderWidth: '1',
        borderColor: color,
        normal: {
          color: color
        }
      },
      data: data,
      lineStyle: {
        type: 'dashed'
      }
    });
  });
  return /*#__PURE__*/_react["default"].createElement(_LineCharts["default"], {
    yAxisList: yAxisList,
    series: series,
    xAxisData: xData.map(function (x) {
      return (0, _moment["default"])(x).format('MM-DD HH:mm');
    }),
    legendData: legendData,
    legendOption: {
      width: '60%'
    }
  });
};
var DetailModal = function DetailModal(props) {
  var onCancel = props.onCancel,
    visible = props.visible,
    facilityId = props.facilityId,
    queryTime = props.queryTime,
    queryTimeStr = props.queryTimeStr,
    facilityName = props.facilityName;
  var _useRequest = (0, _ahooks.useRequest)(function () {
      return (0, _service.queryDataDetail)({
        facilityId: facilityId,
        queryTime: queryTime
      });
    }, {
      refreshDeps: [facilityId, queryTime]
    }),
    _useRequest$data = _useRequest.data,
    data = _useRequest$data === void 0 ? {} : _useRequest$data;
  var _data$historyMonitorD = data.historyMonitorData,
    historyMonitorData = _data$historyMonitorD === void 0 ? [] : _data$historyMonitorD,
    _data$historyPredictD = data.historyPredictData,
    historyPredictData = _data$historyPredictD === void 0 ? [] : _data$historyPredictD,
    _data$predictData = data.predictData,
    predictData = _data$predictData === void 0 ? [] : _data$predictData,
    _data$predictStatisti = data.predictStatisticsData,
    predictStatisticsData = _data$predictStatisti === void 0 ? [] : _data$predictStatisti,
    analyseResult = data.analyseResult,
    historyStatisticsData = data.historyStatisticsData;
  var getColumns = function getColumns(history) {
    return [{
      title: history ? '指标' : '预测指标',
      dataIndex: 'monitorItemName',
      render: function render(text, record) {
        return "".concat(text).concat(record.unit ? "(".concat(record.unit, ")") : '');
      }
    }, {
      title: history ? '谷值' : '预测谷值',
      dataIndex: 'minAmount',
      width: 90,
      align: 'right'
    }, {
      title: history ? '峰值' : '预测峰值',
      dataIndex: 'maxAmount',
      width: 90,
      align: 'right'
    }, {
      title: history ? '结果' : '预测结果',
      dataIndex: 'alarmCount',
      width: 90,
      render: function render(text) {
        return /*#__PURE__*/_react["default"].createElement(_antd.Space, {
          style: {
            color: text > 0 ? '#FF3333' : '#00B052'
          },
          size: 5
        }, text > 0 ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_icons.ExclamationCircleFilled, null), "\u5F02\u5E38") : /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_icons.CheckCircleFilled, null), "\u6B63\u5E38"));
      }
    }];
  };
  return /*#__PURE__*/_react["default"].createElement(_vtxModal["default"], {
    title: /*#__PURE__*/_react["default"].createElement(_vtxModal["default"].Title, {
      text: "\u6C34\u8D28\u9884\u6D4B",
      subtitle: "".concat(facilityName).concat(queryTimeStr, "\u9884\u6D4B\u8BE6\u60C5")
    }),
    width: 1366,
    footer: /*#__PURE__*/_react["default"].createElement(_button["default"], {
      onClick: onCancel
    }, "\u5173\u95ED"),
    visible: visible,
    onCancel: onCancel
  }, /*#__PURE__*/_react["default"].createElement(_row["default"], {
    gutter: [24, 0]
  }, /*#__PURE__*/_react["default"].createElement(_col["default"], {
    span: 16
  }, /*#__PURE__*/_react["default"].createElement(DetailInfo, {
    id: facilityId
  }), /*#__PURE__*/_react["default"].createElement(_MyCollapse["default"], {
    defaultActiveKey: ['1'],
    style: {
      marginTop: 20
    }
  }, /*#__PURE__*/_react["default"].createElement(Panel, {
    header: "\u9884\u6D4B\u8BE6\u60C5",
    key: '1'
  }, /*#__PURE__*/_react["default"].createElement(_row["default"], {
    gutter: [30, 0]
  }, /*#__PURE__*/_react["default"].createElement(_col["default"], {
    span: 12
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-detail-modal-history-title")
  }, "\u8FC7\u53BB24\u5C0F\u65F6"), /*#__PURE__*/_react["default"].createElement(HistoryLine, {
    historyMonitorData: historyMonitorData,
    historyPredictData: historyPredictData
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "ol-analysis-water-quality-table"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Table, {
    bordered: true,
    columns: getColumns(true),
    dataSource: historyStatisticsData,
    pagination: false
  }))), /*#__PURE__*/_react["default"].createElement(_col["default"], {
    span: 12
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-detail-modal-predict-title")
  }, queryTimeStr), /*#__PURE__*/_react["default"].createElement(PredictLine, {
    predictData: predictData,
    predictStatisticsData: predictStatisticsData
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "ol-analysis-water-quality-table"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Table, {
    bordered: true,
    columns: getColumns(),
    dataSource: predictStatisticsData,
    pagination: false
  }))))))), /*#__PURE__*/_react["default"].createElement(_col["default"], {
    span: 8
  }, /*#__PURE__*/_react["default"].createElement(_ResultDiagnosis["default"], {
    reason: analyseResult,
    showReport: false,
    reasonTitle: "\u9884\u6D4B\u5206\u6790",
    showTitle: false
  }))));
};
var _default = exports["default"] = DetailModal;
//# sourceMappingURL=DetailModal.js.map
