"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
exports.getFramePageURL = getFramePageURL;
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireWildcard(require("react"));
var _ResultTitle = _interopRequireDefault(require("../ResultTitle"));
require("./index.less");
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _lodash = require("lodash");
var _current = _interopRequireDefault(require("./assets/current.svg"));
var _up = _interopRequireDefault(require("./assets/up.svg"));
var _down = _interopRequireDefault(require("./assets/down.svg"));
var _space = _interopRequireDefault(require("antd/lib/space"));
var _request = _interopRequireDefault(require("../../_mapUtil/request"));
var _utils = require("@vtx/utils");
var _PublicService = _interopRequireDefault(require("../../_mapUtil/PublicService"));
var _vtxModal = _interopRequireDefault(require("@vtx/components/lib/vtx-modal"));
var _antd = require("antd");
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 _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); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(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 _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; }
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(arr) { if (Array.isArray(arr)) return arr; }
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); }
var prefixCls = 'ol-map-analysis-result-diagnosis';
// 给子页面添加参数
function getFramePageURL(origin) {
  if (!origin || typeof origin != 'string') return '';
  var originParams = (0, _utils.getUrlParam)(null, origin);
  var token = (0, _utils.getUrlParam)('token') || _PublicService["default"].getToken();
  var newParams = _objectSpread(_objectSpread({}, originParams), {}, {
    tenantId: _PublicService["default"].getQueryString('tenantId') || _PublicService["default"].getSystemInfo('tenantId') || '',
    userId: _PublicService["default"].getQueryString('userId') || _PublicService["default"].getSystemInfo('userId') || '',
    token: (0, _utils.getUrlParam)('token') || _PublicService["default"].getToken(),
    access_token: token
  });
  return decodeURIComponent("".concat(origin.split('?')[0], "?").concat(_PublicService["default"].paramSerializer(newParams)));
}
var symbolMap = {
  '-1': _up["default"],
  '0': _current["default"],
  1: _down["default"]
};
var ResultDiagnosis = function ResultDiagnosis(_ref) {
  var result = _ref.result,
    reason = _ref.reason,
    measure = _ref.measure,
    _ref$skeletonNodes = _ref.skeletonNodes,
    skeletonNodes = _ref$skeletonNodes === void 0 ? [] : _ref$skeletonNodes;
  var links = [];
  skeletonNodes.forEach(function (_ref2) {
    var childFacilityIds = _ref2.childFacilityIds,
      parentFacilityIds = _ref2.parentFacilityIds,
      diameter = _ref2.diameter,
      facilityId = _ref2.facilityId;
    (childFacilityIds || []).forEach(function (id) {
      if (!links.find(function (item) {
        return item.target === id && item.source === facilityId;
      })) {
        links.push({
          target: id,
          source: facilityId,
          value: diameter
        });
      }
    });
    (parentFacilityIds || []).forEach(function (id) {
      if (!links.find(function (item) {
        return item.source === id && item.target === facilityId;
      })) {
        links.push({
          target: facilityId,
          source: id,
          value: diameter
        });
      }
    });
  });
  var _useState = (0, _react.useState)(''),
    _useState2 = _slicedToArray(_useState, 2),
    eventUrl = _useState2[0],
    setEventUrl = _useState2[1];
  var _useState3 = (0, _react.useState)(false),
    _useState4 = _slicedToArray(_useState3, 2),
    visible = _useState4[0],
    setVisible = _useState4[1];
  (0, _react.useEffect)(function () {
    if (reason) {
      _request["default"].get('/cloud/zhsw-znfx/api/gisAnalyze/getBusinessConfig', {
        body: {
          businessCode: 'EVENT_REPORT_URL'
        }
      }).then(function (res) {
        var _res$data;
        setEventUrl(getFramePageURL(res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.configJson));
      });
    }
  }, [reason]);
  // 递归处理
  var option = {
    tooltip: {},
    legend: {
      icon: 'circle',
      textStyle: {
        color: '#2D2D2D',
        fontSize: 14
      },
      data: [{
        name: '上游设备',
        itemStyle: {
          color: '#308BFA',
          borderWidth: 0
        }
      }, {
        name: '下游设备',
        itemStyle: {
          color: '#00B5B4',
          borderWidth: 0
        }
      }, {
        name: '当前设备',
        itemStyle: {
          color: '#F7984C',
          borderWidth: 0
        }
      }],
      top: '5%',
      left: 'center',
      show: true
    },
    series: [{
      categories: [{
        name: '上游设备'
      }, {
        name: '下游设备'
      }, {
        name: '当前设备'
      }],
      type: 'graph',
      layout: 'force',
      force: {
        repulsion: 1500,
        edgeLength: 120,
        layoutAnimation: true
      },
      symbolSize: 30,
      nodeScaleRatio: 1,
      //图标大小是否随鼠标滚动而变
      roam: true,
      //缩放
      draggable: true,
      //节点是否可以拖拽
      edgeSymbol: ['none', 'arrow'],
      //线2头标记

      label: {
        show: false
      },
      emphasis: {
        label: {
          show: false
        }
      },
      edgeLabel: {
        normal: {
          show: true,
          width: 58,
          height: 22,
          borderRadius: 12,
          backgroundColor: '#E1E5EA',
          align: 'center',
          verticalAlign: 'middle',
          textStyle: {
            fontSize: 12,
            color: '#2D2D2D'
          },
          formatter: '{c}mm'
        }
      },
      symbolKeepAspect: false,
      focusNodeAdjacency: false,
      // 指定的节点以及其所有邻接节点高亮
      itemStyle: {
        normal: {
          borderColor: '#29ACFC',
          borderWidth: 2,
          shadowColor: '#29ACFC',
          color: '#29ACFC',
          curveness: 0.08
        }
      },
      tooltip: {
        formatter: function formatter() {
          return '';
        }
      },
      lineStyle: {
        normal: {
          width: 2,
          curveness: 0.15,
          color: '#9DA9BA'
        }
      },
      data: skeletonNodes.map(function (_ref3) {
        var lineNo = _ref3.lineNo,
          target = _ref3.target,
          facilityId = _ref3.facilityId,
          roadName = _ref3.roadName;
        return {
          name: facilityId,
          symbol: "image://".concat(symbolMap[target]),
          tooltip: {
            formatter: "".concat(roadName || '').concat(lineNo)
          }
        };
      }),
      links: links
    }]
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefixCls, "-wrap")
  }, !(0, _lodash.isEmpty)(skeletonNodes) && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_ResultTitle["default"], {
    title: '拓扑结构'
  }), /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: option,
    style: {
      height: 400
    }
  })), /*#__PURE__*/_react["default"].createElement(_ResultTitle["default"], {
    title: '结果诊断'
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefixCls, "-content")
  }, result && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefixCls, "-subtitle")
  }, "\u8BCA\u65AD\u7ED3\u679C"), /*#__PURE__*/_react["default"].createElement("div", null, result)), reason && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefixCls, "-subtitle")
  }, /*#__PURE__*/_react["default"].createElement("span", null, "\u8BCA\u65AD\u539F\u56E0"), /*#__PURE__*/_react["default"].createElement("a", {
    onClick: function onClick() {
      if (!eventUrl) {
        return _antd.message.warn('请配置对应的上报页面');
      }
      setVisible(true);
    }
  }, /*#__PURE__*/_react["default"].createElement(_space["default"], {
    align: "center"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: require('./assets/report.svg'),
    width: 16,
    height: 16
  }), "\u4E0A\u62A5"))), /*#__PURE__*/_react["default"].createElement("div", null, reason)), measure && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefixCls, "-subtitle")
  }, "\u5904\u7406\u63AA\u65BD"), /*#__PURE__*/_react["default"].createElement("div", null, measure))), /*#__PURE__*/_react["default"].createElement(_vtxModal["default"], {
    title: '事件上报',
    visible: visible,
    footer: null,
    width: '100vw',
    maximize: true,
    defaultIsFull: true,
    onCancel: function onCancel() {
      return setVisible(false);
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      height: '100%',
      minHeight: 600,
      display: 'flex'
    }
  }, /*#__PURE__*/_react["default"].createElement("iframe", {
    src: "".concat(window.location.origin).concat(eventUrl),
    style: {
      width: '100%',
      border: '1px solid #d9d9d9'
    }
  }))));
};
ResultDiagnosis.propTypes = {
  result: _propTypes["default"].string,
  reason: _propTypes["default"].string,
  measure: _propTypes["default"].string,
  skeletonNodes: _propTypes["default"].array
};
var _default = exports["default"] = ResultDiagnosis;
//# sourceMappingURL=index.js.map
