"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"] = Result;
var _react = _interopRequireWildcard(require("react"));
var _Total = _interopRequireDefault(require("../_component/Total"));
var _CustomModal = _interopRequireDefault(require("../_component/CustomModal"));
var _service = _interopRequireDefault(require("../_mapUtil/service"));
var _useProps2 = _interopRequireDefault(require("@vtx/ol-map/lib/use-props"));
var _MyTabs = _interopRequireDefault(require("../_component/MyTabs"));
var _Table = _interopRequireDefault(require("../_component/Table"));
var _MyEmpty = _interopRequireDefault(require("../_component/MyEmpty"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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 _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; } /*
 * @Description:流向异常诊断
 */
function Result() {
  var _getItems;
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map,
    analysisLayer = _useProps.analysisLayer,
    onClose = _useProps.onClose,
    activeKey = _useProps.activeKey,
    setActiveKey = _useProps.setActiveKey,
    options = _useProps.options,
    highLayer = _useProps.highLayer;
  var _useState = (0, _react.useState)([]),
    _useState2 = _slicedToArray(_useState, 2),
    linesData = _useState2[0],
    setLinesData = _useState2[1];
  var _useState3 = (0, _react.useState)(false),
    _useState4 = _slicedToArray(_useState3, 2),
    loading = _useState4[0],
    setLoading = _useState4[1];
  var _useState5 = (0, _react.useState)([]),
    _useState6 = _slicedToArray(_useState5, 2),
    data = _useState6[0],
    setData = _useState6[1];
  var _useState7 = (0, _react.useState)(0),
    _useState8 = _slicedToArray(_useState7, 2),
    lineLength = _useState8[0],
    setLineLength = _useState8[1];
  (0, _react.useEffect)(function () {
    setLoading(true);
    setLinesData([]);
    setData([]);
    analysisLayer === null || analysisLayer === void 0 || analysisLayer.getData(activeKey, options, function (_ref) {
      var linesData = _ref.linesData,
        data = _ref.data,
        lineLength = _ref.lineLength;
      setLinesData(linesData);
      setData(data);
      setLineLength(lineLength);
      setLoading(false);
    });
  }, [analysisLayer, activeKey]);
  var _onClick = function onClick(code) {
    _service["default"].setFieldListClick({
      record: {
        code: code
      },
      map: map,
      activeKey: activeKey,
      highLayer: highLayer
    });
  };
  var getColumns = function getColumns() {
    var columns = [{
      title: '序号',
      dataIndex: 'num',
      width: 40,
      onCell: function onCell(r) {
        return {
          rowSpan: r.total
        };
      }
    }, {
      title: '上游管线编码',
      dataIndex: 'upCode',
      width: 100,
      onCell: function onCell(r) {
        return {
          rowSpan: r.total
        };
      },
      render: function render(text, record) {
        var _record$parent2;
        return /*#__PURE__*/_react["default"].createElement("a", {
          onClick: function onClick() {
            var _record$parent;
            return _onClick(record === null || record === void 0 || (_record$parent = record.parent) === null || _record$parent === void 0 ? void 0 : _record$parent.code);
          }
        }, record === null || record === void 0 || (_record$parent2 = record.parent) === null || _record$parent2 === void 0 ? void 0 : _record$parent2.code);
      }
    }, {
      title: '下游管线编码',
      dataIndex: 'code',
      width: 100,
      render: function render(text, record) {
        var code = text;
        if (Object.prototype.toString.call(text) === '[object Object]') {
          code = text === null || text === void 0 ? void 0 : text.code;
        }
        return /*#__PURE__*/_react["default"].createElement("a", {
          onClick: function onClick() {
            return _onClick(code);
          }
        }, code);
      }
    }];
    return columns;
  };
  var getItems = function getItems() {
    var items = [];
    options === null || options === void 0 || options.map(function (v) {
      items.push({
        label: v.label,
        key: v.key,
        codeField: v.codeField,
        children: /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_Total["default"], {
          options: [{
            label: '流向异常数',
            value: linesData === null || linesData === void 0 ? void 0 : linesData.length,
            unit: '个'
          }, {
            label: '管线数量',
            value: linesData === null || linesData === void 0 ? void 0 : linesData.length,
            unit: '条'
          }, {
            label: '管线总长',
            value: lineLength,
            unit: 'km'
          }]
        }), /*#__PURE__*/_react["default"].createElement(_Table["default"], {
          indexColumn: false,
          loading: loading,
          columns: getColumns(),
          dataSource: data || []
        }))
      });
    });
    return items;
  };
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_CustomModal["default"], {
    title: "\u6D41\u5411\u5F02\u5E38\u8BCA\u65AD",
    map: map,
    onCancel: function onCancel() {
      onClose && onClose();
    },
    visible: true
  }, (options === null || options === void 0 ? void 0 : options.length) > 1 ? /*#__PURE__*/_react["default"].createElement(_MyTabs["default"], {
    tabsList: getItems(),
    activeKey: activeKey,
    onChange: function onChange(e) {
      setActiveKey(e);
    }
  }) : (options === null || options === void 0 ? void 0 : options.length) == 1 ? (_getItems = getItems()) === null || _getItems === void 0 || (_getItems = _getItems[0]) === null || _getItems === void 0 ? void 0 : _getItems.children : /*#__PURE__*/_react["default"].createElement(_MyEmpty["default"], null)));
}
//# sourceMappingURL=Result.js.map
