"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 _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _Table = _interopRequireDefault(require("../_component/Table"));
var _MyEmpty = _interopRequireDefault(require("../_component/MyEmpty"));
var _getUrlParam = _interopRequireDefault(require("@vtx/utils/lib/getUrlParam"));
var _useProps2 = _interopRequireDefault(require("@vtx/ol-map/lib/use-props"));
var _CustomModal = _interopRequireDefault(require("../_component/CustomModal"));
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: 用于展示分析结果列表、结果图层等
 */
var systemCode = (0, _getUrlParam["default"])('code');
// 材质
var texture = [{
  value: '1',
  label: '混凝土管'
}, {
  value: '2',
  label: '钢筋混凝土管'
}, {
  value: '3',
  label: '陶土管'
}, {
  value: '4',
  label: 'PE(聚乙烯)管 '
}, {
  value: '5',
  label: 'HDPE(高密度聚乙烯)管'
}, {
  value: '6',
  label: 'UPVC管'
}, {
  value: '7',
  label: '铸铁管'
}, {
  value: '8',
  label: '玻璃钢夹砂管'
}, {
  value: '9',
  label: '钢管'
}, {
  value: '10',
  label: '石棉水泥管'
}, {
  value: '11',
  label: '其他'
}];
var Result = function Result(props) {
  var _props$tableData = props.tableData,
    tableData = _props$tableData === void 0 ? {} : _props$tableData,
    resultVisible = props.resultVisible,
    setResult = props.setResult;
  var _tableData$lines = tableData.lines,
    lines = _tableData$lines === void 0 ? [] : _tableData$lines,
    _tableData$spacing = tableData.spacing,
    spacing = _tableData$spacing === void 0 ? [] : _tableData$spacing;
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map,
    highLayer = _useProps.highLayer;
  var ref = (0, _react.useRef)(null);
  var _useState = (0, _react.useState)(true),
    _useState2 = _slicedToArray(_useState, 2),
    isFold = _useState2[0],
    setIsFold = _useState2[1];
  var getTextureName = function getTextureName(lineTexture) {
    var _texture$find;
    var name = ((_texture$find = texture.find(function (tItem) {
      return tItem.value === String(lineTexture);
    })) === null || _texture$find === void 0 ? void 0 : _texture$find.label) || '';
    return name;
  };

  // 管道类别
  var getTypeLine = function getTypeLine(line) {
    var list = {
      1: '雨水',
      2: '污水',
      3: '雨污合流'
    };
    var type = systemCode === 'yc' ? (list === null || list === void 0 ? void 0 : list[line === null || line === void 0 ? void 0 : line.netType]) || '' : line.netType == 4 ? '供水' : '污水';
    return type;
  };
  var getOption = function getOption() {
    var series = [];
    var totalDistance = 2;
    var yMin = 0;
    lines.forEach(function (v, i) {
      if (i === 0) {
        series.push([Number(1), Number(v.groundElevation)]);
        yMin = v.groundElevation;
      } else {
        var x = 1;
        spacing.forEach(function (item, index) {
          if (index <= i - 1) {
            x += item;
          }
        });
        series.push([Number(x), Number(v.groundElevation)]);
        if (v.groundElevation < yMin) {
          yMin = v.groundElevation;
        }
      }
    });
    spacing.forEach(function (v, i) {
      totalDistance += v;
    });
    return {
      grid: {
        left: '10%',
        right: '14%',
        top: 30,
        bottom: 60
      },
      tooltip: {
        trigger: 'item',
        axisPointer: {
          type: 'cross'
        },
        confine: true,
        backgroundColor: 'transparent',
        padding: 0,
        formatter: function formatter(_ref) {
          var dataIndex = _ref.dataIndex;
          return "<div class=\"ol-map-cross-section-analysis-corssTooltip\">\n                        <div>\u6392\u6C34\u7BA1\u6807\u8BC6\u7801\uFF1A".concat(lines[dataIndex].code || '', "</div>\n                        <div>\u7BA1\u9053\u7C7B\u522B\uFF1A").concat(getTypeLine(lines === null || lines === void 0 ? void 0 : lines[dataIndex]), "</div>\n                        <div>\u7BA1\u9053\u957F\u5EA6(m)\uFF1A").concat(lines[dataIndex].lineLength || '', "</div>\n                        <div>\u57CB\u6DF1(m)\uFF1A").concat(lines[dataIndex].startDeep || '', "</div>\n                        <div>\u5730\u9762\u9AD8\u7A0B(m)\uFF1A").concat(lines[dataIndex].groundElevation || '', "</div>\n                        <div>\u7BA1\u9876\u6807\u9AD8(m)\uFF1A").concat(lines[dataIndex].pointTopElevation || '', "</div>\n                        <div>\u89C4\u683C(mm)\uFF1A").concat(lines[dataIndex].ds || '', "</div>\n                        <div>\u6750\u8D28\uFF1A").concat(getTextureName(lines[dataIndex].lineTexture), "</div>\n                    </div>");
        }
      },
      xAxis: {
        name: '米',
        axisTick: {
          show: false
        },
        splitLine: {
          show: false
        },
        scale: true,
        axisLine: {}
      },
      yAxis: {
        name: '米',
        axisTick: {
          show: false
        },
        splitLine: {
          show: false
        },
        axisLine: {
          show: true,
          onZero: false
        }
      },
      dataZoom: [{
        // 这个dataZoom组件，默认控制x轴。
        type: 'slider',
        // 这个 dataZoom 组件是 slider 型 dataZoom 组件
        start: 0,
        // 左边在 10% 的位置。
        end: 100,
        // 右边在 60% 的位置。
        height: 25,
        bottom: 10,
        textStyle: {
          opacity: 0
        }
      }, {
        // 这个dataZoom组件，也控制x轴。
        type: 'inside',
        // 这个 dataZoom 组件是 inside 型 dataZoom 组件
        start: 0,
        // 左边在 10% 的位置。
        end: 100,
        // 右边在 60% 的位置。
        height: 25,
        bottom: 10
      }],
      series: [{
        symbolSize: 15,
        data: series,
        type: 'scatter',
        itemStyle: {
          color: function color(params) {
            return lines[params.dataIndex].netType == 4 ? '#2020ff' : '#ff8620';
          }
        },
        emphasis: {
          itemStyle: {
            color: 'red'
          }
        }
      }]
    };
  };
  var chartWrap = function chartWrap() {
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "chartWrap"
    }, /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
      option: getOption(),
      style: {
        height: 300
      }
    }));
  };
  var renderTable = function renderTable() {
    var columns = [{
      title: '管线编码',
      dataIndex: 'name',
      key: 'name',
      width: 80,
      fixed: 'left'
    }];
    // 表格展示数据
    var list = {
      type: {
        name: '管线类别'
      },
      lineLength: {
        name: '管长(m)'
      },
      groundElevation: {
        name: '起点地面高程(m)'
      },
      endGroundElevation: {
        name: '终点地面高程(m)'
      },
      startZ: {
        name: '起点管顶高程(m)'
      },
      endZ: {
        name: '终点管顶高程(m)'
      },
      startDeep: {
        name: '起点埋深(m)'
      },
      endDeep: {
        name: '终点埋深(m)'
      },
      lineTexture: {
        name: '管材'
      },
      ds: {
        name: '管径(mm)'
      },
      roadName: {
        name: '所在道路'
      },
      infoTime: {
        name: '数据获取时间'
      },
      manageUnitName: {
        name: '管理单位'
      }
    };
    lines.forEach(function (item) {
      var _item$code;
      var _item = item;
      if (_item.netType) {
        _item.type = getTypeLine(item);
      }
      columns.push({
        title: /*#__PURE__*/_react["default"].createElement("a", {
          onClick: function onClick() {
            highLayer && highLayer.setCenter(item.code);
            if (highLayer.selectFeature) {
              map.showTemplate(highLayer.selectFeature);
              setIsFold(true);
            }
          }
        }, item.code),
        key: item.code,
        dataIndex: item.code,
        width: ((_item$code = item.code) === null || _item$code === void 0 ? void 0 : _item$code.length) * 13 || 140
      });
      Object.keys(list).forEach(function (v) {
        var _data = list[v] || {};
        _data[_item.code] = _item[v];
        if (v === 'lineTexture') {
          _data[_item.code] = getTextureName(_item[v]);
        }
        if (v === 'msz') {
          var num = _item['groundElevation'] - _item['startZ'];
          if (!Number.isNaN(num)) {
            _data[_item.code] = num.toFixed(2);
          } else {
            _data[_item.code] = '';
          }
        }
      });
    });
    var dataSource = [];
    Object.keys(list).forEach(function (v) {
      dataSource.push(list[v]);
    });
    return /*#__PURE__*/_react["default"].createElement("div", {
      ref: ref,
      style: {
        flex: 1,
        display: 'flex',
        padding: '10px 0 0',
        overflow: 'hidden'
      }
    }, /*#__PURE__*/_react["default"].createElement(_Table["default"], {
      dataSource: dataSource,
      columns: columns,
      pagination: false,
      indexColumn: false,
      isList: true
    }));
  };
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_CustomModal["default"], {
    width: !isFold ? '50vw' : '',
    title: "\u6A2A\u622A\u9762\u5206\u6790",
    map: map,
    onCancel: function onCancel() {
      setResult({
        tableData: {
          lines: [],
          spacing: []
        },
        resultVisible: false
      });
    },
    visible: resultVisible,
    isCanFold: true,
    isFold: isFold,
    setIsFold: setIsFold
  }, lines !== null && lines !== void 0 && lines.length ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, chartWrap(), renderTable()) : /*#__PURE__*/_react["default"].createElement(_MyEmpty["default"], null)));
};
var _default = exports["default"] = Result;
//# sourceMappingURL=Result.js.map
