"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"] = _default;
var _react = _interopRequireWildcard(require("react"));
var _MyTabs = _interopRequireDefault(require("../_component/MyTabs"));
var _CustomModal = _interopRequireDefault(require("../_component/CustomModal"));
var _useProps2 = _interopRequireDefault(require("@vtx/ol-map/lib/use-props"));
var _Table = _interopRequireDefault(require("../_component/Table"));
var _LinesChart = _interopRequireDefault(require("./LinesChart"));
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 _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 _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; }
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; } /*
 * @description: 管网统计
 */
function _default(props) {
  var _items$3;
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map,
    tableData = _useProps.tableData,
    visible = _useProps.visible,
    setVisible = _useProps.setVisible,
    loading = _useProps.loading,
    activeKey = _useProps.activeKey,
    setActiveKey = _useProps.setActiveKey,
    fieldOption = _useProps.fieldOption,
    layerOptions = _useProps.layerOptions;
  var _useState = (0, _react.useState)([]),
    _useState2 = _slicedToArray(_useState, 2),
    items = _useState2[0],
    setItems = _useState2[1];
  var getColumns = function getColumns() {
    var columns = [{
      title: fieldOption === null || fieldOption === void 0 ? void 0 : fieldOption.label,
      dataIndex: 'name'
    }, {
      title: '管长(m)',
      dataIndex: 'value',
      render: function render(text) {
        return /*#__PURE__*/_react["default"].createElement("span", null, text ? Number(text).toFixed(2) : '');
      },
      align: 'right'
    }, {
      title: '占比(%)',
      dataIndex: 'percent',
      render: function render(text) {
        return /*#__PURE__*/_react["default"].createElement("span", null, text ? (Number(text) * 100).toFixed(2) : '');
      },
      align: 'right'
    }];
    return columns;
  };
  (0, _react.useEffect)(function () {
    getItems(layerOptions);
  }, [tableData, layerOptions, fieldOption]);

  /**
   * @description: 获取表格数据
   * @return {*}
   */
  var getItems = function getItems(options) {
    var items = [];
    options === null || options === void 0 || options.map(function (v) {
      var _tableData$;
      var data = (tableData === null || tableData === void 0 || (_tableData$ = tableData[0]) === null || _tableData$ === void 0 ? void 0 : _tableData$.lineDataList) || [];
      items.push({
        label: v.label,
        key: v.value,
        codeField: v.codeField,
        children: /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_LinesChart["default"], {
          yAxisName: "m",
          yAxisName2: "%",
          data: [{
            seriesData: data === null || data === void 0 ? void 0 : data.map(function (item) {
              return item.value;
            }),
            xAxisData: data === null || data === void 0 ? void 0 : data.map(function (item) {
              return item.name;
            }),
            type: 'bar',
            name: '',
            barWidth: 18,
            itemStyle: {
              color: '#4095F9'
            }
          }, {
            seriesData: data === null || data === void 0 ? void 0 : data.map(function (item) {
              return item.percent;
            }),
            yAxisIndex: 1,
            type: 'line',
            name: ''
          }],
          boundaryGap: true
        }), /*#__PURE__*/_react["default"].createElement(_Table["default"], {
          loading: loading,
          rowKey: "code",
          columns: getColumns(v.value),
          dataSource: data,
          scroll: {
            y: map.getViewport().clientHeight - 422,
            x: 200
          }
        }))
      });
    });
    setItems(items);
    return items;
  };
  (0, _react.useEffect)(function () {
    var _items$;
    // 图层改变，改变选择tab
    var isHave = items === null || items === void 0 ? void 0 : items.find(function (it) {
      return (it === null || it === void 0 ? void 0 : it.key) == activeKey;
    });
    if (!isHave) {
      setActiveKey('');
    }
    if (items !== null && items !== void 0 && (_items$ = items[0]) !== null && _items$ !== void 0 && _items$.key && !activeKey) {
      var _items$2;
      setActiveKey(items === null || items === void 0 || (_items$2 = items[0]) === null || _items$2 === void 0 ? void 0 : _items$2.key);
    }
  }, [items]);
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_CustomModal["default"], {
    title: "\u7BA1\u7F51\u7EDF\u8BA1",
    map: map,
    onCancel: function onCancel() {
      setVisible(false);
    },
    visible: visible
  }, /*#__PURE__*/_react["default"].createElement(_MyTabs["default"], {
    tabsList: items,
    activeKey: activeKey || (items === null || items === void 0 || (_items$3 = items[0]) === null || _items$3 === void 0 ? void 0 : _items$3.key),
    onChange: function onChange(e) {
      setActiveKey(e);
    }
  })));
}
//# sourceMappingURL=Result.js.map
