"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 _olMap = require("@vtx/ol-map");
var _ahooks = require("ahooks");
var _antd = require("antd");
var _react = _interopRequireWildcard(require("react"));
var _service = require("./service");
var _CustomModal = _interopRequireDefault(require("../_component/CustomModal"));
var _ResultTitle = _interopRequireDefault(require("../_component/ResultTitle"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
require("echarts-liquidfill");
var _MyTag = _interopRequireDefault(require("../_component/MyTag"));
var _DistrictSelect = _interopRequireDefault(require("../_component/DistrictSelect"));
var _Filter = _interopRequireDefault(require("../_component/Filter"));
var _FilterForm = _interopRequireDefault(require("./FilterForm"));
var _ResultList = _interopRequireDefault(require("../_component/ResultList"));
var _useModal2 = _interopRequireDefault(require("../_mapUtil/useModal"));
var _DetailItems = _interopRequireDefault(require("../_component/DetailItems"));
var _moment = _interopRequireDefault(require("moment"));
var _DetailModal = _interopRequireDefault(require("./DetailModal"));
var _DateTypeChange = _interopRequireDefault(require("../_component/DateTypeChange"));
var _MapLayer = _interopRequireDefault(require("./MapLayer"));
var _vtxSelect = _interopRequireDefault(require("@vtx/components/lib/vtx-select"));
var _config = _interopRequireDefault(require("../config"));
var _excluded = ["divisionIds"];
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
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; }
var Option = _vtxSelect["default"].Option;
// eslint-disable-next-line react/prop-types
var ResultWaterPolo = function ResultWaterPolo(_ref) {
  var _ref$searchParams = _ref.searchParams,
    searchParams = _ref$searchParams === void 0 ? {} : _ref$searchParams;
  var startDate = searchParams.startDate,
    endDate = searchParams.endDate,
    level = searchParams.level;
  var _useRequest = (0, _ahooks.useRequest)(function () {
      return (0, _service.fetchTypeStatistics)({
        monitorStartDate: startDate,
        monitorEndDate: endDate,
        levels: level
      });
    }, {
      refreshDeps: [endDate, startDate, level]
    }),
    _useRequest$data = _useRequest.data,
    data = _useRequest$data === void 0 ? 0 : _useRequest$data;
  var option = {
    grid: {
      right: 0,
      top: 'center'
    },
    series: [{
      type: 'liquidFill',
      radius: '75%',
      data: [data, {
        value: data,
        phase: Math.PI
      }],
      color: ['#0263FF'],
      label: {
        show: false
      },
      outline: {
        show: true,
        borderDistance: 5,
        itemStyle: {
          borderColor: '#0263FF',
          borderWidth: 2
        }
      },
      backgroundStyle: {
        color: '#fff'
      }
    }]
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "result-water-polo-father"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "result-water-polo"
  }, /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: option,
    style: {
      width: '100%',
      height: '100%'
    }
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "result-water-polo-content"
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "result-water-polo-title"
  }, "\u6574\u4F53\u6C34\u5E73\u8861\u7CFB\u6570"), /*#__PURE__*/_react["default"].createElement("span", {
    className: "result-water-polo-value"
  }, data || 0)));
};
var Result = function Result() {
  var _useProps = (0, _olMap.useProps)(),
    map = _useProps.map,
    visible = _useProps.visible,
    setVisible = _useProps.setVisible;
  var _Form$useForm = _antd.Form.useForm(),
    _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
    form = _Form$useForm2[0];
  var _useModal = (0, _useModal2["default"])(),
    modalInfo = _useModal.modalInfo,
    onOpenModal = _useModal.onOpenModal,
    onCancel = _useModal.onCancel;
  var _useSetState = (0, _ahooks.useSetState)({
      type: 'DAY',
      level: '1',
      startDate: (0, _moment["default"])().add(-30, 'day').format('YYYY-MM-DD'),
      endDate: (0, _moment["default"])().add(-1, 'day').format('YYYY-MM-DD'),
      start: (0, _moment["default"])().add(-30, 'day').format('YYYY-MM-DD'),
      end: (0, _moment["default"])().add(-1, 'day').format('YYYY-MM-DD'),
      districtId: null
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    searchParams = _useSetState2[0],
    setSearchParams = _useSetState2[1];
  var _useRequest2 = (0, _ahooks.useRequest)(function () {
      var _form$getFieldsValue = form.getFieldsValue(),
        divisionIds = _form$getFieldsValue.divisionIds,
        rest = _objectWithoutProperties(_form$getFieldsValue, _excluded);
      return (0, _service.fetchQueryData)(_objectSpread(_objectSpread({}, rest), {}, {
        divisionIds: (divisionIds === null || divisionIds === void 0 ? void 0 : divisionIds.length) > 0 ? divisionIds.join(',') : '',
        districtIds: searchParams.districtId,
        monitorStartDate: searchParams.startDate,
        monitorEndDate: searchParams.endDate,
        levels: searchParams.level
      }));
    }, {
      refreshDeps: [searchParams.districtId, searchParams.startDate, searchParams.endDate, searchParams.level]
    }),
    _useRequest2$data = _useRequest2.data,
    data = _useRequest2$data === void 0 ? [] : _useRequest2$data,
    run = _useRequest2.run;
  // balancePercent
  (0, _react.useEffect)(function () {
    try {
      map.hideTemplate();
    } catch (err) {}
  }, [data]);
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_CustomModal["default"], {
    map: map,
    onCancel: function onCancel() {
      setVisible(false);
    },
    visible: visible,
    isShowHidden: true
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "result-header"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    className: "result-header-img",
    src: require('./assets/level.png'),
    alt: ""
  }), /*#__PURE__*/_react["default"].createElement(_vtxSelect["default"], {
    bordered: false,
    allowClear: false,
    value: searchParams.level,
    onChange: function onChange(v) {
      setSearchParams({
        level: v,
        districtId: null
      });
    },
    style: {
      width: '80px',
      marginRight: '8px'
    }
  }, _config["default"].districtLevelList.map(function (v) {
    return /*#__PURE__*/_react["default"].createElement(Option, {
      key: v.key
    }, v.value);
  })), /*#__PURE__*/_react["default"].createElement(_DateTypeChange["default"], {
    dateType: searchParams.type,
    onChange: function onChange(v) {
      setSearchParams(_objectSpread({}, v));
    }
  })), /*#__PURE__*/_react["default"].createElement(_ResultTitle["default"], {
    title: '分析结果统计',
    question: /*#__PURE__*/_react["default"].createElement("span", null, "\u901A\u8FC7\u7247\u533A\u6392\u6C34\u91CF\u4E0E\u7247\u533A\u4F9B\u6C34\u91CF\u6570\u636E\u5206\u6790\u7247\u533A\u7684\u6C34\u5E73\u8861\u7CFB\u6570")
  }), /*#__PURE__*/_react["default"].createElement(ResultWaterPolo, {
    searchParams: searchParams
    // date={date}
  }), /*#__PURE__*/_react["default"].createElement(_ResultTitle["default"], {
    title: '水平衡系数明细',
    rightContent: /*#__PURE__*/_react["default"].createElement(_antd.Space, {
      size: 13
    }, /*#__PURE__*/_react["default"].createElement(_DistrictSelect["default"], {
      value: searchParams.districtId,
      level: searchParams.level,
      onChange: function onChange(v) {
        return setSearchParams({
          districtId: v
        });
      }
    }), /*#__PURE__*/_react["default"].createElement(_Filter["default"], {
      onOk: function onOk() {
        run();
      },
      onReset: function onReset() {
        form.resetFields();
      }
    }, /*#__PURE__*/_react["default"].createElement(_FilterForm["default"], {
      form: form
    })))
  }), /*#__PURE__*/_react["default"].createElement(_ResultList["default"], {
    list: data,
    idKey: 'facilityId',
    onTitleClick: function onTitleClick(info) {
      map.showTemplateByFilter("WATER_BALANCE_ANALYSIS_DISTRICT_".concat(info.districtLevel), 'facilityId', info.facilityId);
    },
    onItemClick: function onItemClick(info) {
      onOpenModal(info);
    },
    titleKey: "districtName",
    getDetailContent: function getDetailContent(info) {
      var divisionNames = info.divisionNames,
        supplyWater = info.supplyWater,
        drainageWater = info.drainageWater,
        balanceRate = info.balanceRate;
      var items = [{
        label: '行政区划',
        value: divisionNames,
        span: 12
      }, {
        label: '供水量',
        value: "".concat(supplyWater || 0, "m\xB3"),
        span: 12
      }, {
        label: '排水量',
        value: "".concat(drainageWater || 0, "m\xB3"),
        span: 12
      }, {
        label: '水平衡系数',
        value: balanceRate,
        span: 12
      }];
      return /*#__PURE__*/_react["default"].createElement(_DetailItems["default"], {
        items: items
      });
    },
    getOtherTitle: function getOtherTitle(info) {
      var name = info.name,
        colorVal = info.colorVal;
      return name ? /*#__PURE__*/_react["default"].createElement(_MyTag["default"], {
        text: name,
        color: colorVal
      }) : null;
    }
  })), visible && /*#__PURE__*/_react["default"].createElement(_MapLayer["default"], {
    data: data,
    openModal: onOpenModal,
    searchParams: searchParams
  }), modalInfo.visible && /*#__PURE__*/_react["default"].createElement(_DetailModal["default"], _extends({}, modalInfo, {
    onCancel: onCancel,
    defaultProps: searchParams
  })));
};
var _default = exports["default"] = Result;
//# sourceMappingURL=Result.js.map
