"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 _Table = _interopRequireDefault(require("../_component/Table"));
var _MyTabs = _interopRequireDefault(require("../_component/MyTabs"));
var _CustomModal = _interopRequireDefault(require("../_component/CustomModal"));
var _AddModal = _interopRequireDefault(require("../_component/TaskConfig/TabPage/Temporary/AddModal"));
var _WorkOrderModal = _interopRequireDefault(require("../_component/WorkOrderSystem/Components/WorkOrderModal"));
var _request = _interopRequireDefault(require("../_mapUtil/request"));
var _config = _interopRequireDefault(require("../_mapUtil/config"));
var _service = _interopRequireDefault(require("../_mapUtil/service"));
var _useProps2 = _interopRequireDefault(require("@vtx/ol-map/lib/use-props"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _analysisLayer = require("@vtx/ol-map/lib/analysis-layer");
var _ResultTitle = _interopRequireDefault(require("../_component/ResultTitle"));
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 _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _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(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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 OPTIONS = [{
  name: '供水管线',
  type: '1'
}, {
  name: '消防栓',
  type: '2'
}, {
  name: '阀门',
  type: '3'
}];
function Result(props) {
  var _items$3;
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map,
    layerRef = _useProps.layerRef,
    drawEndDsField = _useProps.drawEndDsField,
    setTableFilter = _useProps.setTableFilter,
    tableFilter = _useProps.tableFilter,
    tableData = _useProps.tableData,
    setTableData = _useProps.setTableData,
    resultVisible = _useProps.resultVisible,
    setResultVisible = _useProps.setResultVisible,
    _useProps$activeKey = _useProps.activeKey,
    activeKey = _useProps$activeKey === void 0 ? '' : _useProps$activeKey,
    _useProps$setActiveKe = _useProps.setActiveKey,
    setActiveKey = _useProps$setActiveKe === void 0 ? function () {} : _useProps$setActiveKe,
    _useProps$loading = _useProps.loading,
    loading = _useProps$loading === void 0 ? false : _useProps$loading,
    tableActive = _useProps.tableActive,
    setTableActive = _useProps.setTableActive;
  var _useState = (0, _react.useState)(true),
    _useState2 = _slicedToArray(_useState, 2),
    visible = _useState2[0],
    setVisible = _useState2[1];
  var _useState3 = (0, _react.useState)([]),
    _useState4 = _slicedToArray(_useState3, 2),
    items = _useState4[0],
    setItems = _useState4[1];
  var _useState5 = (0, _react.useState)([]),
    _useState6 = _slicedToArray(_useState5, 2),
    businessList = _useState6[0],
    setBusinessList = _useState6[1];
  var _useState7 = (0, _react.useState)([]),
    _useState8 = _slicedToArray(_useState7, 2),
    columns = _useState8[0],
    setColumns = _useState8[1]; // 表格配置项
  var _useState9 = (0, _react.useState)(''),
    _useState10 = _slicedToArray(_useState9, 2),
    orderId = _useState10[0],
    setOrderId = _useState10[1];
  var _useState11 = (0, _react.useState)(false),
    _useState12 = _slicedToArray(_useState11, 2),
    orderVisible = _useState12[0],
    setOrderVisible = _useState12[1];
  var _useState13 = (0, _react.useState)(false),
    _useState14 = _slicedToArray(_useState13, 2),
    modalShow = _useState14[0],
    setModalShow = _useState14[1];
  var _useState15 = (0, _react.useState)(''),
    _useState16 = _slicedToArray(_useState15, 2),
    objectCode = _useState16[0],
    setObjectCode = _useState16[1];
  var _useState17 = (0, _react.useState)(true),
    _useState18 = _slicedToArray(_useState17, 2),
    isFold = _useState18[0],
    setIsFold = _useState18[1];
  var classnames = function classnames(name) {
    if (name) {
      return "ol-map-large-diameter-analysis-".concat(name);
    }
    return "ol-map-large-diameter-analysis";
  };
  (0, _react.useEffect)(function () {
    var _items$;
    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]);
  (0, _react.useEffect)(function () {
    getBusinessList();
  }, []);
  (0, _react.useEffect)(function () {
    setVisible(resultVisible);
  }, [resultVisible]);
  (0, _react.useEffect)(function () {
    if (!loading) {
      getItems();
    }
  }, [tableData, columns, loading, tableFilter]);
  var clickTableTab = function clickTableTab(current) {
    setTableActive(current);
    var filter = '';
    switch (current) {
      case 0:
        filter = 'ds >= 1000';
        break;
      case 1:
        filter = 'ds >= 800 and ds < 1000';
        break;
      case 2:
        filter = 'ds >= 600 and ds < 800';
        break;
      case 3:
        filter = 'ds >= 400 and ds < 600';
        break;
      case 4:
        filter = 'ds >= 300 and ds < 400';
        break;
      case 5:
        filter = 'ds >= 200 and ds < 300';
        break;
      case 6:
        filter = 'ds >= 100 and ds < 200';
        break;
      case 7:
        filter = 'ds < 100';
        break;
    }
    setTableFilter(filter);
  };

  /**
   * @description: 获取表格数据
   * @return {*}
   */
  var getItems = function getItems() {
    var items = [];
    OPTIONS === null || OPTIONS === void 0 || OPTIONS.map(function (v, index) {
      items.push({
        label: v.name,
        key: "".concat(v.type),
        children: /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
          className: classnames('typeWrap')
        }, drawEndDsField < 999999 && /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(classnames('item'), " ").concat(tableActive == 0 ? classnames('item_active') : null),
          onClick: function onClick() {
            clickTableTab(0);
          }
        }, "\u22651000mm"), drawEndDsField < 1000 && /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(classnames('item'), " ").concat(tableActive == 1 ? classnames('item_active') : null),
          onClick: function onClick() {
            clickTableTab(1);
          }
        }, "800~1000mm"), drawEndDsField < 800 && /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(classnames('item'), " ").concat(tableActive == 2 ? classnames('item_active') : null),
          onClick: function onClick() {
            clickTableTab(2);
          }
        }, "600~800mm"), drawEndDsField < 600 && /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(classnames('item'), " ").concat(tableActive == 3 ? classnames('item_active') : null),
          onClick: function onClick() {
            clickTableTab(3);
          }
        }, "400~600mm"), drawEndDsField < 400 && /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(classnames('item'), " ").concat(tableActive == 4 ? classnames('item_active') : null),
          onClick: function onClick() {
            clickTableTab(4);
          }
        }, "300~400mm"), drawEndDsField < 300 && /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(classnames('item'), " ").concat(tableActive == 5 ? classnames('item_active') : null),
          onClick: function onClick() {
            clickTableTab(5);
          }
        }, "200~300mm"), drawEndDsField < 200 && /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(classnames('item'), " ").concat(tableActive == 6 ? classnames('item_active') : null),
          onClick: function onClick() {
            clickTableTab(6);
          }
        }, "100~200mm"), drawEndDsField < 100 && /*#__PURE__*/_react["default"].createElement("div", {
          className: "".concat(classnames('item'), " ").concat(tableActive == 7 ? classnames('item_active') : null),
          onClick: function onClick() {
            clickTableTab(7);
          }
        }, '<100mm')), /*#__PURE__*/_react["default"].createElement(_Table["default"], {
          orderFixed: 'left',
          loading: loading,
          rowKey: "code",
          columns: getColumns(v.name),
          dataSource: tableData
        }))
      });
    });
    setItems(items);
    return items;
  };
  (0, _react.useEffect)(function () {
    var code = _service["default"].getCode(items, activeKey);
    if (activeKey && code) {
      _service["default"].getFieldList(null, {
        code: code
      }, _onClick).then(function (res) {
        setColumns(res || []);
      });
    } else {
      setColumns([]);
    }
  }, [activeKey]);
  /**
   * @description: feature居中，气泡框打开
   * @param {*} code
   * @return {*}
   */
  var _onClick = function onClick(code, record) {
    // 判断是管线
    if (activeKey == 1) {
      setIsFold(true);
    }
    if (activeKey === 'CurrentView') {
      var layer = map.getWmsVisibleLayers(record === null || record === void 0 ? void 0 : record.key);
      var filter = "code = '".concat(code, "'");
      if (layer !== null && layer !== void 0 && layer.length) {
        (0, _analysisLayer.getWFSFeatureInfoByLayers)(layer, filter).then(function (features) {
          if (features !== null && features !== void 0 && features.length) {
            map.showTemplate(features[0]);
          }
        });
      }
    } else {
      var _layerRef$current, _layerRef$current2;
      layerRef === null || layerRef === void 0 || (_layerRef$current = layerRef.current) === null || _layerRef$current === void 0 || _layerRef$current.setCenter(code);
      var selectFeature = layerRef === null || layerRef === void 0 || (_layerRef$current2 = layerRef.current) === null || _layerRef$current2 === void 0 ? void 0 : _layerRef$current2.selectFeature;
      if (selectFeature) {
        map === null || map === void 0 || map.showTemplate(selectFeature);
      }
    }
  };
  var getColumns = function getColumns(label) {
    var columns = [{
      title: '编码',
      dataIndex: 'code',
      // width: 120,
      fixed: 'left',
      render: function render(text, record) {
        return /*#__PURE__*/_react["default"].createElement("a", {
          onClick: function onClick() {
            _onClick(text, record);
          }
        }, text);
      }
    }, {
      title: '口径(mm)',
      dataIndex: 'ds'
      // width: 100,
    }].concat(_toConsumableArray(label === '消防栓' ? [{
      title: '实时压力(MPa)',
      //   dataIndex: 'w_pressure',
      dataIndex: 'pressure'
      //   width: 120,
    }] : []), [{
      title: '工单情况',
      dataIndex: 'workOrder',
      // width: 100,
      render: function render(text, record) {
        var _record$caseList;
        return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, record === null || record === void 0 || (_record$caseList = record.caseList) === null || _record$caseList === void 0 ? void 0 : _record$caseList.map(function (v, i) {
          var _record$caseList2;
          return /*#__PURE__*/_react["default"].createElement("a", {
            key: i,
            onClick: function onClick() {
              setOrderId(v.id);
              setOrderVisible(true);
            }
          }, v === null || v === void 0 ? void 0 : v.taskName, i === (record === null || record === void 0 || (_record$caseList2 = record.caseList) === null || _record$caseList2 === void 0 ? void 0 : _record$caseList2.length) - 1 ? '' : ', ');
        }));
      }
    }, {
      title: '巡检记录',
      dataIndex: 'patrolRecord'
      // width: 100,
    }, {
      title: '所在道路',
      dataIndex: 'roadName'
      // width: 200,
    }, {
      title: '操作',
      dataIndex: 'cz',
      // width: 120,
      render: function render(h, record) {
        return /*#__PURE__*/_react["default"].createElement("a", {
          onClick: function onClick() {
            setModalShow(true);
            setObjectCode(record === null || record === void 0 ? void 0 : record.code);
          }
        }, "\u65B0\u589E\u5DE1\u68C0\u4EFB\u52A1");
      }
    }]);
    return columns;
  };
  var modalProps = {
    modalTitle: '新增',
    onCancel: function onCancel() {
      setModalShow(false);
    },
    visible: modalShow,
    objectCode: objectCode
  };
  var getBusinessList = function getBusinessList() {
    _request["default"].get("".concat(_config["default"].publicUrlXCGL, "/api/businessType/list")).then(function (res) {
      if (String(res === null || res === void 0 ? void 0 : res.result) === '0') {
        var _res$data;
        if (res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && _res$data.length) {
          res.data.map(function (item) {
            item.value = item.id;
            item.label = item.name;
            item.text = item.name;
          });
          setBusinessList(_toConsumableArray(res.data));
        }
      }
    });
  };
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, map && /*#__PURE__*/_react["default"].createElement(_CustomModal["default"], {
    map: map,
    width: !isFold ? '50vw' : '',
    title: /*#__PURE__*/_react["default"].createElement(_ResultTitle["default"], {
      title: '大口径分析',
      noline: true,
      question: /*#__PURE__*/_react["default"].createElement("span", null, "\u67E5\u8BE2\u5927\u4E8E\u6307\u5B9A\u53E3\u5F84\u7684\u6D88\u9632\u6813\u3001\u9600\u95E8\u3001\u7BA1\u6BB5")
    }),
    onCancel: function onCancel() {
      setVisible(false);
      setTableData([]);
      setResultVisible(false);
    },
    visible: visible,
    isCanFold: true,
    isFold: isFold,
    setIsFold: setIsFold
  }, /*#__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);
    }
  })), /*#__PURE__*/_react["default"].createElement(_AddModal["default"], _extends({
    titleConfig: '临时任务'
  }, modalProps)), /*#__PURE__*/_react["default"].createElement(_CustomModal["default"], {
    visible: orderVisible,
    map: map,
    title: "\u5DE5\u5355\u8BE6\u60C5",
    onCancel: function onCancel() {
      setOrderVisible(false);
      setOrderId('');
    }
    // style={{ width: '100%', top: 0, left: 0 }}
    // style={{ top: 0, right: 12 }}
  }, orderVisible && /*#__PURE__*/_react["default"].createElement(_WorkOrderModal["default"], {
    modalType: 'Details',
    modalVal: {
      id: orderId
    },
    goBack: function goBack() {
      setOrderVisible(false);
      setOrderId('');
    },
    orderType: 'innerOrder',
    extraParams: {
      processDefinitionKey: 'clock_event_process'
    }
  })));
}
Result.propTypes = {
  setResult: _propTypes["default"].func,
  activeKey: _propTypes["default"].string,
  setActiveKey: _propTypes["default"].func,
  loading: _propTypes["default"].bool,
  tableData: _propTypes["default"].array,
  resultVisible: _propTypes["default"].bool
};
//# sourceMappingURL=Result.js.map
