"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 = _interopRequireWildcard(require("react"));
var _ahooks = require("ahooks");
var _Left = _interopRequireDefault(require("./Left"));
var _vmTable = _interopRequireDefault(require("../../../vm-table"));
var _config = require("../../config");
var _vmSubTabs = require("../../../vm-sub-tabs");
var _vmInfoCollection = _interopRequireDefault(require("../../../vm-info-collection"));
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _mapIcon = require("@vtx/map-icon");
var _api = require("../../api");
require("./index.less");
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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _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 _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
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; }
var OverView = function OverView(_ref) {
  var _ref$classPrefix = _ref.classPrefix,
    classPrefix = _ref$classPrefix === void 0 ? '' : _ref$classPrefix,
    id = _ref.id,
    basicInfo = _ref.basicInfo,
    customMapInfo = _ref.customMapInfo;
  var _a, _b;
  var _useSetState = (0, _ahooks.useSetState)({
      tabKey: 'all',
      rows: [],
      mapLayers: [],
      currentLayer: {},
      layer: [],
      mapPoints: []
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var tabKey = state.tabKey,
    rows = state.rows;
  var prefix = "".concat(classPrefix, "-overview");
  var common = {
    classPrefix: prefix,
    id: id
  };
  // 关联对象
  var linkedObject = _api.overViewService.getChildWorkInfo({
    id: id
  }) || {};
  (0, _react.useEffect)(function () {
    var _a, _b;
    if (!(linkedObject === null || linkedObject === void 0 ? void 0 : linkedObject.count)) return;
    var result = [];
    var layerData = [];
    // 获取所有图层数据
    linkedObject.count.forEach(function (item) {
      var _a, _b;
      layerData.push.apply(layerData, _toConsumableArray(((_b = (_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.rows) === null || _b === void 0 ? void 0 : _b.map(function (ele) {
        return Object.assign(Object.assign({}, ele), {
          typeCode: item.typeCode
        });
      })) || []));
    });
    var list = [],
      layers = [];
    layerData.forEach(function (item) {
      var _a, _b, _c, _d;
      if (item.geometryInfo.type === 'point') {
        var _ref2 = (_a = item.geometryInfo.lngLats) === null || _a === void 0 ? void 0 : _a.split(','),
          _ref3 = _slicedToArray(_ref2, 2),
          lng = _ref3[0],
          lat = _ref3[1];
        list.push({
          id: item.id,
          name: item.name,
          lng: lng,
          lat: lat,
          url: ((_c = (_b = _mapIcon.MapIcon === null || _mapIcon.MapIcon === void 0 ? void 0 : _mapIcon.MapIcon.icon) === null || _b === void 0 ? void 0 : _b[item === null || item === void 0 ? void 0 : item.typeIcon]) === null || _c === void 0 ? void 0 : _c.type) && (item === null || item === void 0 ? void 0 : item.icon) ? new _mapIcon.MapIcon.Icon({
            canvasIcon: item.icon,
            color: item.iconColor
          }).getImgUrl() : require('../../imgs/default.png'),
          width: 32,
          height: 45
        });
      } else {
        layers.push(Object.assign(Object.assign({}, item), {
          rings: (_d = item === null || item === void 0 ? void 0 : item.geometryInfo) === null || _d === void 0 ? void 0 : _d.lngLats,
          config: {
            color: (0, _config.getColor)((item === null || item === void 0 ? void 0 : item.typeCode) || ''),
            lineColor: '#fff',
            lineWidth: 1
          }
        }));
      }
    });
    setState({
      mapLayers: layers,
      mapPoints: list
    });
    // 区分页签
    if (tabKey === 'all') {
      var _layer = [];
      linkedObject.count.forEach(function (item) {
        var _result;
        var _a;
        (_result = result).push.apply(_result, _toConsumableArray(((_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.rows) || []));
        _layer.push({
          typeCode: item.typeCode,
          typeName: item.typeName
        });
      });
      setState({
        rows: result,
        layer: _layer
      });
    } else {
      result = linkedObject.count.filter(function (item) {
        return item.typeCode === tabKey;
      });
      setState({
        rows: (_b = (_a = result[0]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.rows
      });
    }
  }, [JSON.stringify(linkedObject), tabKey]);
  // 若当前设施为主次干道（TR）或为绿化带/河道（LHDorHD）
  // 基本信息数据
  var fieldsData = _toConsumableArray((basicInfo === null || basicInfo === void 0 ? void 0 : basicInfo.typeCode) === 'tr' ? _config.OverViewTRFields : _config.OverViewLHDorHDFields).map(function (item) {
    return Object.assign(Object.assign({}, item), {
      value: basicInfo === null || basicInfo === void 0 ? void 0 : basicInfo[item.key]
    });
  });
  // 作业对象
  var workObjectData = [];
  // 资源投入
  var resourceInput = [];
  var planNumOfCar = 0;
  var actualNumOfCar = 0;
  var planNumOfPeople = 0;
  var actualNumOfPeople = 0;
  // 存在作业对象时，获取相关数据
  workObjectData = ((_a = _api.overViewService.workObject({
    id: id
  })) === null || _a === void 0 ? void 0 : _a.filter(function (item) {
    return (item === null || item === void 0 ? void 0 : item.details) && item.details.length > 0;
  }).map(function (ele, index) {
    return {
      label: "".concat(ele === null || ele === void 0 ? void 0 : ele.workTypeStr, "(").concat(ele.unitStr, ")"),
      value: ele === null || ele === void 0 ? void 0 : ele.dataValue,
      key: index.toString()
    };
  })) || [];
  resourceInput = _api.overViewService.resourceInput({
    id: id
  }) || [];
  planNumOfCar = resourceInput === null || resourceInput === void 0 ? void 0 : resourceInput.reduce(function (pre, next) {
    return pre + (next.planNumOfCar || 0);
  }, 0);
  actualNumOfCar = resourceInput === null || resourceInput === void 0 ? void 0 : resourceInput.reduce(function (pre, next) {
    return pre + (next.actualNumOfCar || 0);
  }, 0);
  planNumOfPeople = resourceInput === null || resourceInput === void 0 ? void 0 : resourceInput.reduce(function (pre, next) {
    return pre + (next.planNumOfPeople || 0);
  }, 0);
  actualNumOfPeople = resourceInput === null || resourceInput === void 0 ? void 0 : resourceInput.reduce(function (pre, next) {
    return pre + (next.actualNumOfPeople || 0);
  }, 0);
  var columns = [{
    title: '名称',
    dataIndex: 'name',
    key: 'name'
  }, {
    title: '长度（m）',
    dataIndex: 'facilityLength',
    key: 'facilityLength'
  }, {
    title: '宽度（m）',
    dataIndex: 'facilityWidth',
    key: 'facilityWidth'
  }, {
    title: '面积（k㎡）',
    dataIndex: 'facilityArea',
    key: 'facilityArea'
  }];
  var tableProps = {
    height: 320,
    dataSource: rows || [],
    isIndex: false,
    currentLayer: state.currentLayer,
    onRowCallBack: function onRowCallBack(record) {
      setState({
        currentLayer: record
      });
    }
  };
  // 地图点击事件
  var clickGraphic = function clickGraphic(obj) {
    setState({
      currentLayer: obj.item,
      tabKey: obj.item.typeCode
    });
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: prefix
  }, /*#__PURE__*/_react["default"].createElement(_Left["default"], Object.assign({}, common, {
    mapPoints: state.mapPoints,
    mapLayers: state.mapLayers,
    currentLayer: state.currentLayer,
    legend: state.layer,
    clickGraphic: clickGraphic,
    customMapInfo: customMapInfo
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right-base")
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u57FA\u672C\u4FE1\u606F"
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right-basic")
  }, /*#__PURE__*/_react["default"].createElement(_vmInfoCollection["default"], {
    data: fieldsData,
    gap: 16,
    horizontal: true
  }))), (basicInfo === null || basicInfo === void 0 ? void 0 : basicInfo.workTypeId) && (/*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right-work")
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u4F5C\u4E1A\u91CF"
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right-item")
  }, (workObjectData === null || workObjectData === void 0 ? void 0 : workObjectData.length) ? (/*#__PURE__*/_react["default"].createElement(_vmInfoCollection["default"], {
    data: workObjectData,
    gap: 16,
    horizontal: true
  })) : null, /*#__PURE__*/_react["default"].createElement("span", {
    className: "label"
  }, "\u8D44\u6E90\u6295\u5165\uFF1A"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right-list")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right-listItem")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right-bottom")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right-bottomItem")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right-img")
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: require('../../imgs/car.png')
  })), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-right-title")
  }, "\u5EFA\u8BAE\u914D\u5907(\u8F86)\uFF1A"), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-right-num")
  }, planNumOfCar || '--')), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right-bottomItem")
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-right-title")
  }, "\u5B9E\u9645\u6295\u5165(\u8F86)\uFF1A"), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-right-num")
  }, actualNumOfCar || '--'))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right-bottom")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right-bottomItem")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right-img")
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: require('../../imgs/user.png')
  })), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-right-title")
  }, "\u5EFA\u8BAE\u914D\u5907(\u4EBA)\uFF1A"), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-right-num")
  }, planNumOfPeople || '--')), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right-bottomItem")
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-right-title")
  }, "\u5B9E\u9645\u6295\u5165(\u4EBA)\uFF1A"), /*#__PURE__*/_react["default"].createElement("span", {
    className: "".concat(prefix, "-right-num")
  }, actualNumOfPeople || '--')))))))), ((_b = linkedObject === null || linkedObject === void 0 ? void 0 : linkedObject.count) === null || _b === void 0 ? void 0 : _b.length) ? (/*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(prefix, "-right-table")
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u4F5C\u4E1A\u5BF9\u8C61"
  }), /*#__PURE__*/_react["default"].createElement(_vmSubTabs.SubTabsLine, {
    items: [{
      key: 'all',
      label: "\u5168\u90E8(".concat((linkedObject === null || linkedObject === void 0 ? void 0 : linkedObject.allNums) || 0, ")")
    }].concat(_toConsumableArray(linkedObject.count.map(function (item) {
      return {
        key: item.typeCode,
        label: "".concat(item.typeName, "(").concat(item.count, ")")
      };
    }))),
    activeKey: tabKey,
    onChange: function onChange(key) {
      setState({
        tabKey: key
      });
    }
  }), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_vmTable["default"], Object.assign({
    columns: columns,
    rowKey: "id"
  }, tableProps))))) : null));
};
var _default = exports["default"] = OverView;
//# sourceMappingURL=index.js.map
