"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"] = _default;
var _react = _interopRequireWildcard(require("react"));
var _message = _interopRequireDefault(require("antd/lib/message"));
var _button = _interopRequireDefault(require("antd/lib/button"));
var _index = _interopRequireDefault(require("./index.less"));
var _PayoutForm = _interopRequireDefault(require("./PayoutForm"));
var _DisposeForm = _interopRequireDefault(require("./DisposeForm"));
var _TimeOutApplyForm = _interopRequireDefault(require("./TimeOutApplyForm"));
var _TimeOutCheckForm = _interopRequireDefault(require("./TimeOutCheckForm"));
var _OrderCheckForm = _interopRequireDefault(require("./OrderCheckForm"));
var _OrderTwoManageForm = _interopRequireDefault(require("./OrderTwoManageForm"));
var _PayReturnForm = _interopRequireDefault(require("./PayReturnForm"));
var _WrittenForm = _interopRequireDefault(require("./WrittenForm"));
var _RecallForm = _interopRequireDefault(require("./RecallForm"));
var _RedeployForm = _interopRequireDefault(require("./RedeployForm"));
var _BackForm = _interopRequireDefault(require("./BackForm"));
var _config = _interopRequireDefault(require("../../config"));
var _request = _interopRequireDefault(require("../../../../../_mapUtil/request"));
var _DetailsPage = _interopRequireDefault(require("../DetailsPage"));
var _OperationBtns = _interopRequireDefault(require("../../ServiceComponents/PublicPage/OperationBtns"));
var _dayjs = _interopRequireDefault(require("dayjs"));
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 _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; } /**
 * 客服工单流程操作入口
 */
var getAddModalValue = _config["default"].getAddModalValue,
  serviceProcessParams = _config["default"].serviceProcessParams,
  changeUrlParams = _config["default"].changeUrlParams;
var getProcessArgument = _OperationBtns["default"].getProcessArgument;
function _default(props) {
  var modalType = props.modalType,
    goBack = props.goBack,
    _props$modalVal = props.modalVal,
    modalVal = _props$modalVal === void 0 ? {} : _props$modalVal,
    sortClick = props.sortClick,
    sortType = props.sortType,
    importData = props.importData;
  var myOrderForm = (0, _react.useRef)();
  var _useState = (0, _react.useState)(false),
    _useState2 = _slicedToArray(_useState, 2),
    modalBtnLoading = _useState2[0],
    setModalBtnLoading = _useState2[1];
  var processConfig = (serviceProcessParams === null || serviceProcessParams === void 0 ? void 0 : serviceProcessParams[modalType]) || {};

  // 保存
  function onSave() {
    var _formList$myForm;
    var formList = (myOrderForm === null || myOrderForm === void 0 ? void 0 : myOrderForm.current) || {};
    (formList === null || formList === void 0 || (_formList$myForm = formList.myForm) === null || _formList$myForm === void 0 || (_formList$myForm = _formList$myForm.current) === null || _formList$myForm === void 0 || (_formList$myForm = _formList$myForm.form) === null || _formList$myForm === void 0 ? void 0 : _formList$myForm.validateFields) && formList.myForm.current.form.validateFields().then(function (val) {
      // if (
      //   modalType === 'unitBack' &&
      //   dayjs(dayjs().format('YYYY-MM-DD HH:mm:ss')).diff(modalVal?.dispatchTime, 'minute') > 45
      // ) {
      //   return message.warning('已经超过限制时间，不可退回！', 2);
      // }
      var formItems = (formList === null || formList === void 0 ? void 0 : formList.items) || [];
      val.processDefinitionKey = modalVal === null || modalVal === void 0 ? void 0 : modalVal.processDefinitionKey;
      val.processInstanceId = modalVal === null || modalVal === void 0 ? void 0 : modalVal.processInstanceId;
      val.id = modalVal === null || modalVal === void 0 ? void 0 : modalVal.id;
      // 获取表单中对应的值
      val = getAddModalValue({
        formItems: formItems,
        formValue: val
      });
      var costomParams = (formList === null || formList === void 0 ? void 0 : formList.costomParams) || null;
      if (costomParams) {
        // 派发部门数据调整
        val = formList === null || formList === void 0 ? void 0 : formList.costomParams(val);
      }
      var url = (processConfig === null || processConfig === void 0 ? void 0 : processConfig.orderUrl) || '';
      var isParams = (processConfig === null || processConfig === void 0 ? void 0 : processConfig.isParams) || ''; // 接口请求传参方式

      var deptForm = (formList === null || formList === void 0 ? void 0 : formList.deptForm) || null;
      if (deptForm !== null && deptForm !== void 0 && deptForm.current) {
        var _deptForm$current;
        // 办理部门校验
        (deptForm === null || deptForm === void 0 || (_deptForm$current = deptForm.current) === null || _deptForm$current === void 0 || (_deptForm$current = _deptForm$current.myForm) === null || _deptForm$current === void 0 || (_deptForm$current = _deptForm$current.current) === null || _deptForm$current === void 0 || (_deptForm$current = _deptForm$current.form) === null || _deptForm$current === void 0 ? void 0 : _deptForm$current.validateFields) && deptForm.current.myForm.current.form.validateFields().then(function (_val) {
          setModalBtnLoading(true);
          getReauest(url, val, isParams);
        });
      } else {
        setModalBtnLoading(true);
        getReauest(url, val, isParams);
      }
    });
  }
  var getReauest = function getReauest(url) {
    var val = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
    var isParams = arguments.length > 2 ? arguments[2] : undefined;
    if (isParams) {
      val = changeUrlParams(val);
    }
    if (url) {
      var req = isParams ? _request["default"].post(url + val, {
        headers: {
          ticket: true
        }
      }) : _request["default"].post(url, {
        body: val,
        headers: {
          ticket: true
        }
      });
      req.then(function (res) {
        if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
          _message["default"].success('操作成功');
          onCancel();
        }
        setModalBtnLoading(false);
      });
    }
  };

  // 关闭弹框
  var onCancel = function onCancel() {
    goBack && goBack();
  };

  // 渲染工单流程
  var renderProcess = function renderProcess() {
    var ProcessForm = {
      Payout: _PayoutForm["default"],
      // 信息中心派发
      Redeploy: _RedeployForm["default"],
      // 子公司转派
      Dispose: _DisposeForm["default"],
      // 部门处置
      UnitDispose: _DisposeForm["default"],
      // 子公司直接处置
      UnitFeedback: _DisposeForm["default"],
      // 子公司反馈
      OrderCheck: _OrderCheckForm["default"],
      // 子公司审核
      InfoOrderCheck: _OrderCheckForm["default"],
      // 信息中心审核
      OrderTwoManage: _OrderTwoManageForm["default"],
      // 工单二次办理(再次办理)
      OrderCheckBack: _OrderCheckForm["default"],
      // 工单审核退回
      PayReturn: _PayReturnForm["default"],
      // 回访
      Recall: _RecallForm["default"],
      // 子公司撤回
      InfoRecall: _RecallForm["default"],
      // 信息中心撤回
      Back: _BackForm["default"],
      // 子公司部门退回
      unitBack: _BackForm["default"],
      // 子公司退回
      // RePayout: PayoutForm, // 重新派发
      // ReRedeploy: RedeployForm, // 重新转派
      Written: _WrittenForm["default"],
      // 批示
      TimeOutApply: _TimeOutApplyForm["default"],
      // 延期申请
      TimeOutCheck: _TimeOutCheckForm["default"] // 延期审核
    };
    var CurrentFrom = (ProcessForm === null || ProcessForm === void 0 ? void 0 : ProcessForm[modalType]) || '';
    if (CurrentFrom) {
      return /*#__PURE__*/_react["default"].createElement(CurrentFrom, _extends({}, props, {
        ref: myOrderForm
      }));
    } else {
      return /*#__PURE__*/_react["default"].createElement("div", null, "\u6682\u65E0\u6570\u636E");
    }
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: _index["default"].orderProcessWrap
  }, /*#__PURE__*/_react["default"].createElement(_DetailsPage["default"], {
    modalType: "Details",
    modalVal: modalVal,
    isProcess: true,
    sortClick: sortClick,
    sortType: sortType,
    importData: importData
  }), renderProcess(), /*#__PURE__*/_react["default"].createElement("div", {
    className: _index["default"].orderButton
  }, /*#__PURE__*/_react["default"].createElement(_button["default"], {
    onClick: onCancel,
    loading: modalBtnLoading
  }, "\u53D6\u6D88"), /*#__PURE__*/_react["default"].createElement(_button["default"], {
    type: "primary",
    onClick: onSave,
    loading: modalBtnLoading
  }, "\u786E\u5B9A")));
}
//# sourceMappingURL=index.js.map
