"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 _tabs = _interopRequireDefault(require("antd/lib/tabs"));
var _Cycle = _interopRequireDefault(require("./TabPage/Cycle"));
var _Temporary = _interopRequireDefault(require("./TabPage/Temporary"));
var _config = _interopRequireDefault(require("../../_mapUtil/config"));
var _http = _interopRequireDefault(require("../../_util/http"));
var _index = _interopRequireDefault(require("./index.less"));
var _PublicService = _interopRequireDefault(require("../../_mapUtil/PublicService"));
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; }
var TabPane = _tabs["default"].TabPane;
var rateObj = {
  1: '小时',
  2: '日',
  3: '周',
  4: '季',
  5: '月',
  6: '年'
};
function TaskConfig() {
  var _useState = (0, _react.useState)('cycle'),
    _useState2 = _slicedToArray(_useState, 2),
    activeKey = _useState2[0],
    setActiveKey = _useState2[1];
  var _useState3 = (0, _react.useState)([]),
    _useState4 = _slicedToArray(_useState3, 2),
    businessList = _useState4[0],
    setBusinessList = _useState4[1];
  var _useState5 = (0, _react.useState)(null),
    _useState6 = _slicedToArray(_useState5, 2),
    dates = _useState6[0],
    setDates = _useState6[1];
  var cycleRef = (0, _react.useRef)();
  (0, _react.useEffect)(function () {
    getBusinessList();
  }, []);
  (0, _react.useEffect)(function () {
    if (activeKey === 'cycle' && _PublicService["default"].getQueryString('businessTypeCode')) {
      var _cycleRef$current;
      cycleRef === null || cycleRef === void 0 || (_cycleRef$current = cycleRef.current) === null || _cycleRef$current === void 0 || (_cycleRef$current = _cycleRef$current.tabPageRef) === null || _cycleRef$current === void 0 || _cycleRef$current.current.onSubmit();
    }
  }, [businessList]);
  var getBusinessList = function getBusinessList() {
    _http["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));
        }
      }
    });
  };
  var onTabChange = function onTabChange(val) {
    setActiveKey(val);
  };

  // 时间不可选日期
  var disabledDate = function disabledDate(current) {
    if (!dates) {
      return false;
    }
    var tooLate = dates[0] && current.diff(dates[0], 'days') >= 7;
    var tooEarly = dates[1] && dates[1].diff(current, 'days') >= 7;
    return !!tooEarly || !!tooLate;
  };
  var onOpenChange = function onOpenChange(open) {
    if (open) {
      setDates([null, null]);
    } else {
      setDates(null);
    }
  };
  var processConfig = [{
    linkName: '基本信息',
    isArrive: '1'
  }, {
    linkName: '巡检对象',
    isArrive: '0'
  }];
  var cycleConfig = {
    businessList: businessList,
    items: [{
      type: 'input',
      label: '巡查人员',
      paramName: 'userName',
      itemProps: {
        placeholder: '请输入'
      }
    }].concat(_toConsumableArray(_PublicService["default"].getQueryString('businessTypeCode') ? [] : [{
      type: 'select',
      label: '业务类型',
      paramName: 'businessTypeId',
      showAll: true,
      itemProps: {
        options: businessList,
        placeholder: '请选择'
      }
    }]), [{
      type: 'input',
      label: '关键字',
      paramName: 'keyWord',
      itemProps: {
        placeholder: '请输入任务名称/任务编号'
      }
    }, {
      type: 'rangePicker',
      label: '任务触发时间',
      paramName: 'reportTime',
      itemProps: {},
      formItemLayout: {}
    }, {
      type: 'rangePicker',
      label: '任务截止时间',
      paramName: 'time',
      itemProps: {},
      formItemLayout: {}
    }, {
      type: 'input',
      label: '创建人',
      paramName: 'createByName',
      itemProps: {
        placeholder: '请输入'
      }
    }]),
    columnsConfig: [['任务编号', 'code', {
      width: 90
    }], ['任务名称', 'name', {
      width: 100
    }], ['业务类型', 'businessTypeName', {
      width: 80
    }], ['巡查人员', 'userName', {
      width: 100,
      render: function render(text, record) {
        var staffName = [];
        if (record.staffList && record.staffList.length) {
          record.staffList.map(function (item) {
            staffName.push(item.staffName);
          });
          return staffName.join(',');
        } else {
          return '值班人员';
        }
      }
    }], ['任务触发时间', 'triggerTime', {
      width: 100,
      sorter: true,
      sortType: 'time'
    }], ['任务截止时间', 'endTime', {
      width: 100,
      sorter: true,
      sortType: 'time',
      render: function render(text) {
        return text || '--';
      }
    }], ['任务周期', 'rate', {
      width: 60,
      render: function render(text, record) {
        return /*#__PURE__*/_react["default"].createElement("div", null, record.count || '', rateObj[text] || '', "1\u6B21");
      }
    }], ['创建人', 'createByName', {
      width: 60
    }]],
    hideDeleteBtn: true,
    titleConfig: '周期任务',
    toolbarTilte: '周期任务',
    missionType: 'cycle',
    searchParam: {
      type: '1'
    },
    // 周期任务
    searchUrl: "".concat(_config["default"].publicUrlXCGL, "/api/taskConfig/page"),
    detailUrl: "".concat(_config["default"].publicUrlXCGL, "/api/taskConfig/detail"),
    searchBefore: function searchBefore(params) {
      var _newParams$time, _newParams$reportTime;
      var newParams = params;
      // 任务截止时间
      if (newParams !== null && newParams !== void 0 && (_newParams$time = newParams.time) !== null && _newParams$time !== void 0 && _newParams$time.length) {
        newParams.startTime = newParams.time[0].format('YYYY-MM-DD 00:00:00');
        newParams.endTime = newParams.time[1].format('YYYY-MM-DD 23:59:59');
        delete newParams.time;
      }
      // 任务触发时间
      if (newParams !== null && newParams !== void 0 && (_newParams$reportTime = newParams.reportTime) !== null && _newParams$reportTime !== void 0 && _newParams$reportTime.length) {
        newParams.startReportTime = newParams.reportTime[0].format('YYYY-MM-DD 00:00:00');
        newParams.endReportTime = newParams.reportTime[1].format('YYYY-MM-DD 23:59:59');
        delete newParams.reportTime;
      }
      if (_PublicService["default"].getQueryString('businessTypeCode')) {
        var _businessList$find;
        newParams.businessTypeId = (_businessList$find = businessList.find(function (item) {
          return item.patrolCode === _PublicService["default"].getQueryString('businessTypeCode');
        })) === null || _businessList$find === void 0 ? void 0 : _businessList$find.id;
      }
      return newParams;
    },
    updateBusinessList: function updateBusinessList(data) {
      if (data !== null && data !== void 0 && data.length) {
        data.map(function (item) {
          item.value = item.id;
          item.label = item.name;
          item.text = item.name;
        });
        setBusinessList(_toConsumableArray(data));
      } else {
        setBusinessList([]);
      }
    }
  };
  var temporaryConfig = {
    businessList: businessList,
    items: [{
      type: 'input',
      label: '巡查人员',
      paramName: 'userName',
      itemProps: {
        placeholder: '请输入'
      }
    }].concat(_toConsumableArray(_PublicService["default"].getQueryString('businessTypeCode') ? [] : [{
      type: 'select',
      label: '业务类型',
      paramName: 'businessTypeId',
      showAll: true,
      itemProps: {
        options: businessList,
        placeholder: '请选择'
      }
    }]), [{
      type: 'input',
      label: '关键字',
      paramName: 'keyWord',
      itemProps: {
        placeholder: '请输入任务名称/任务编号'
      }
    }, {
      type: 'rangePicker',
      label: '下派时间',
      paramName: 'factionTime',
      itemProps: {
        disabledDate: disabledDate,
        onOpenChange: onOpenChange,
        onCalendarChange: function onCalendarChange(val) {
          return setDates(val);
        }
      },
      formItemLayout: {}
    }, {
      type: 'rangePicker',
      label: '任务截止时间',
      paramName: 'time',
      itemProps: {
        disabledDate: disabledDate,
        onOpenChange: onOpenChange,
        onCalendarChange: function onCalendarChange(val) {
          return setDates(val);
        }
      },
      formItemLayout: {}
    }, {
      type: 'input',
      label: '创建人',
      paramName: 'createByName',
      itemProps: {
        placeholder: '请输入'
      }
    }]),
    columnsConfig: [['任务编号', 'code', {
      width: 150
    }], ['任务名称', 'name', {
      width: 150
    }], ['巡查人员', 'userName', {
      width: 100,
      render: function render(text, record) {
        var staffName = [];
        if (record.staffList && record.staffList.length) {
          record.staffList.map(function (item) {
            staffName.push(item.staffName);
          });
          return staffName.join(',');
        } else {
          return '值班人员';
        }
      }
    }], ['业务类型', 'businessTypeName', {
      width: 100
    }], ['任务截止时间', 'endTime', {
      width: 130,
      sorter: true,
      sortType: 'time',
      render: function render(text) {
        return text || '--';
      }
    }], ['下派时间', 'createTime', {
      width: 130,
      sorter: true,
      sortType: 'time',
      render: function render(text) {
        return text || '--';
      }
    }], ['创建人', 'createByName', {
      width: 80
    }]],
    searchBefore: function searchBefore(params) {
      var _newParams$time2, _newParams$factionTim;
      var newParams = params;
      // 任务截止时间
      if (newParams !== null && newParams !== void 0 && (_newParams$time2 = newParams.time) !== null && _newParams$time2 !== void 0 && _newParams$time2.length) {
        newParams.startTime = newParams.time[0].format('YYYY-MM-DD 00:00:00');
        newParams.endTime = newParams.time[1].format('YYYY-MM-DD 23:59:59');
        delete newParams.time;
      }
      // 下派时间
      if (newParams !== null && newParams !== void 0 && (_newParams$factionTim = newParams.factionTime) !== null && _newParams$factionTim !== void 0 && _newParams$factionTim.length) {
        newParams.startCreateTime = newParams.factionTime[0].format('YYYY-MM-DD 00:00:00');
        newParams.endCreateTime = newParams.factionTime[1].format('YYYY-MM-DD 23:59:59');
        delete newParams.factionTime;
      }
      if (_PublicService["default"].getQueryString('businessTypeCode')) {
        var _businessList$find2;
        newParams.businessTypeId = (_businessList$find2 = businessList.find(function (item) {
          return item.patrolCode === _PublicService["default"].getQueryString('businessTypeCode');
        })) === null || _businessList$find2 === void 0 ? void 0 : _businessList$find2.id;
      }
      return newParams;
    },
    hideDeleteBtn: true,
    showEdit: false,
    showStrtOrStop: false,
    titleConfig: '临时任务',
    toolbarTilte: '临时任务',
    searchParam: {
      type: '2'
    },
    // 临时任务
    missionType: 'temporary',
    searchUrl: "".concat(_config["default"].publicUrlXCGL, "/api/taskConfig/page"),
    detailUrl: "".concat(_config["default"].publicUrlXCGL, "/api/taskConfig/detail")
  };
  var tabList = [{
    tab: '周期任务',
    key: 'cycle',
    page: /*#__PURE__*/_react["default"].createElement(_Cycle["default"], _extends({}, cycleConfig, {
      processConfig: processConfig,
      ref: cycleRef
    }))
  }, {
    tab: '临时任务',
    key: 'temporary',
    page: /*#__PURE__*/_react["default"].createElement(_Temporary["default"], _extends({}, temporaryConfig, {
      processConfig: processConfig
    }))
  }];
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: _index["default"].myTab
  }, /*#__PURE__*/_react["default"].createElement(_tabs["default"], {
    activeKey: activeKey,
    onChange: onTabChange,
    destroyInactiveTabPane: true
  }, tabList.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(TabPane, {
      tab: item.tab,
      key: item.key
    }, item.page);
  })));
}
var _default = exports["default"] = TaskConfig;
//# sourceMappingURL=index.js.map
