"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"));
require("echarts-liquidfill");
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 _excluded = ["divisionIds"];
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 _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, 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(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : 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(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
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; }
// eslint-disable-next-line react/prop-types
var ResultProgress = function ResultProgress(_ref) {
  var _ref$searchParams = _ref.searchParams,
    searchParams = _ref$searchParams === void 0 ? {} : _ref$searchParams;
  var startDate = searchParams.startDate,
    endDate = searchParams.endDate;
  var _useRequest = (0, _ahooks.useRequest)(function () {
      return (0, _service.fetchTypeStatistics)({
        monitorStartDate: startDate,
        monitorEndDate: endDate
      });
    }, {
      refreshDeps: [endDate, startDate]
    }),
    _useRequest$data = _useRequest.data,
    data = _useRequest$data === void 0 ? 0 : _useRequest$data;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "result-progress-father"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "result-progress"
  }, /*#__PURE__*/_react["default"].createElement(_antd.Progress, {
    width: 74,
    strokeLinecap: "butt",
    type: "circle",
    percent: data,
    showInfo: false,
    strokeColor: "#0263FF"
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "result-progress-content"
  }, /*#__PURE__*/_react["default"].createElement("span", {
    className: "result-progress-title"
  }, "\u6574\u4F53\u6C61\u6C34\u6536\u96C6\u7387"), /*#__PURE__*/_react["default"].createElement("span", {
    className: "result-progress-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',
      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(',') : '',
        districtId: searchParams.districtId,
        monitorStartDate: searchParams.startDate,
        monitorEndDate: searchParams.endDate
      }));
    }, {
      refreshDeps: [searchParams.districtId, searchParams.startDate, searchParams.endDate]
    }),
    _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(_DateTypeChange["default"], {
    style: {
      paddingTop: '15px',
      paddingBottom: '32px'
    },
    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\u6C61\u6C34\u6536\u96C6\u7247\u533A\u6C61\u6C34\u5904\u7406\u91CF\u4E0E\u6C61\u6C34\u6392\u653E\u91CF\u6570\u636E\u5206\u6790\u7247\u533A\u7684\u6C61\u6C34\u6536\u96C6\u7387")
  }), /*#__PURE__*/_react["default"].createElement(ResultProgress, {
    searchParams: searchParams
  }), /*#__PURE__*/_react["default"].createElement(_ResultTitle["default"], {
    title: '污水收集率明细',
    rightContent: /*#__PURE__*/_react["default"].createElement(_antd.Space, {
      size: 13
    }, /*#__PURE__*/_react["default"].createElement(_DistrictSelect["default"], {
      level: 1,
      value: searchParams.districtId,
      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("SEWAGE_COLLECTION_RATE_ANALYSIS_DISTRICT", 'facilityId', info.facilityId);
    },
    onItemClick: function onItemClick(info) {
      onOpenModal(info);
    },
    titleKey: "districtName",
    getDetailContent: function getDetailContent(info) {
      var divisionNames = info.divisionNames,
        process = info.process,
        pollution = info.pollution,
        collectionRate = info.collectionRate,
        beyondLimitFlag = info.beyondLimitFlag;
      var items = [{
        label: '行政区划',
        value: divisionNames
      }, {
        label: '污水处理量',
        value: "".concat(process || 0, "\u5428"),
        span: 12
      }, {
        label: '污染物排放量',
        value: "".concat(pollution || 0, "\u5428"),
        span: 12
      }, {
        label: '污水收集率',
        value: /*#__PURE__*/_react["default"].createElement(_antd.Space, null, /*#__PURE__*/_react["default"].createElement(_antd.Progress, {
          percent: collectionRate,
          strokeColor: beyondLimitFlag ? '#FF2626' : '#1990FA',
          showInfo: false,
          style: {
            width: 260
          }
        }), /*#__PURE__*/_react["default"].createElement("span", {
          style: {
            color: beyondLimitFlag ? '#FF2626' : '#1990FA'
          }
        }, collectionRate || 0, "%"))
      }];
      return /*#__PURE__*/_react["default"].createElement(_DetailItems["default"], {
        items: items
      });
    }
  })), 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
