"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _config = _interopRequireDefault(require("../../../Components/config"));
var _config2 = _interopRequireDefault(require("../../../../../_mapUtil/config"));
var _request = _interopRequireDefault(require("../../../../../_mapUtil/request"));
var _PublicService = _interopRequireDefault(require("../../../../../_mapUtil/PublicService"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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); }
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 _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 _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 _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 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); } /**
 *  内部工单按钮展示
 */
var processParams = _config["default"].processParams;
var handleUserRole = function handleUserRole() {
  var userRole = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var list = [];
  // shift_boss_role   办结角色
  // dispatch_role  派发角色
  // supervisor_role  审核角色
  // function_dept_role  处置角色
  // report  上报
  // superAdmin  超级管理员
  var orderRole = ['dispatch_role', 'supervisor_role', 'superAdmin', 'report', 'function_dept_role', 'DBR'];
  var orderRoleNames = {
    dispatch_role: 'payPeople',
    // 派发角色
    supervisor_role: 'handlePeople',
    // 审核角色
    superAdmin: 'admin',
    // 管理员、超级管理员
    report: 'report',
    // 上报者
    function_dept_role: 'dealPeople',
    // 处置角色
    DBR: 'supervisePeople' // 督办角色
  };
  if (userRole !== null && userRole !== void 0 && userRole.length) {
    userRole.map(function (val) {
      if (orderRole.includes(val === null || val === void 0 ? void 0 : val.code)) {
        list.push(_objectSpread(_objectSpread({}, val), {}, {
          value: orderRoleNames === null || orderRoleNames === void 0 ? void 0 : orderRoleNames[val === null || val === void 0 ? void 0 : val.code]
        }));
      }
    });
  }
  return list;
};

// 判断处置按钮权限
var judgeDisposeBtn = function judgeDisposeBtn(record) {
  var _record$disposeDeptLi = record.disposeDeptList,
    disposeDeptList = _record$disposeDeptLi === void 0 ? [] : _record$disposeDeptLi;
  var userId = _PublicService["default"].getQueryString('userId');
  var disposeBtn = disposeDeptList !== null && disposeDeptList !== void 0 && disposeDeptList.some(function (val) {
    return (val === null || val === void 0 ? void 0 : val.disposeDeptDutyMan) === userId;
  }) ? ['处置'] : [];
  return disposeBtn;
};

// 工单操作按钮
var getWorkOrderBtn = function getWorkOrderBtn(_ref) {
  var _ref$statusTag = _ref.statusTag,
    statusTag = _ref$statusTag === void 0 ? 'OrderEnd' : _ref$statusTag,
    _ref$userRole = _ref.userRole,
    userRole = _ref$userRole === void 0 ? ['admin'] : _ref$userRole,
    _ref$record = _ref.record,
    record = _ref$record === void 0 ? {} : _ref$record;
  var _userRole = handleUserRole(userRole); // 整理角色权限为需要的形式
  var dismissBtn = [];
  if (_userRole.some(function (val) {
    return val.value === 'report';
  }) && (record === null || record === void 0 ? void 0 : record.status) === 3 && (record === null || record === void 0 ? void 0 : record.hasWithdraw) !== true) {
    // 撤回的工单不能撤销
    dismissBtn = ['撤销'];
  }
  var disposeBtn = judgeDisposeBtn(record) || [];
  var btnList = {
    Payout: {
      // 待派发
      report: ['派发'].concat(_toConsumableArray(dismissBtn)),
      payPeople: ['派发']
    },
    Dispose: {
      // 待处置
      // dealPeople: [...disposeBtn],
      payPeople: ['催办'],
      handlePeople: ['催办'] // 审核角色
    },
    OrderCheck: {
      // 待审核
      payPeople: ['审核'],
      handlePeople: ['审核'] // 审核角色
    },
    OrderEnd: {
      // 已办结
    },
    BackOut: {
      // 已撤销
    }
  };
  var list = [],
    _btnList = (btnList === null || btnList === void 0 ? void 0 : btnList[statusTag]) || null;
  if (_userRole !== null && _userRole !== void 0 && _userRole.length && _btnList) {
    _userRole.map(function (val) {
      if (_btnList !== null && _btnList !== void 0 && _btnList[val === null || val === void 0 ? void 0 : val.value]) {
        list.push.apply(list, _toConsumableArray(_btnList === null || _btnList === void 0 ? void 0 : _btnList[val === null || val === void 0 ? void 0 : val.value]));
      }
    });
  }
  var _list = _toConsumableArray(new Set(list));
  return _list;
};

// 获取办理状态对应的标识
var getOrderStatusTag = {
  3: 'Payout',
  // 待派发
  4: 'Dispose',
  // 待处置
  7: 'OrderCheck',
  // 待审核
  9: 'OrderEnd',
  // 已办结
  10: 'BackOut' // 已撤销
};

// 获取工单流程状态标识---用于展示对应表单
var getOrderProcessTag = {
  派发: 'Payout',
  撤销: 'BackOut',
  处置: 'Dispose',
  催办: 'PressToDo',
  审核: 'OrderCheck'
};

// 操作按钮对应的提示信息
var getOperateMessage = {
  撤销: '请确认是否撤销此工单？',
  催办: '是否向责任人发一条催办提醒？'
};

// 获取操作按钮展示
var getOperateBtn = function getOperateBtn(_ref2) {
  var userRole = _ref2.userRole,
    record = _ref2.record,
    onConfirm = _ref2.onConfirm,
    onModalShow = _ref2.onModalShow,
    pageType = _ref2.pageType;
  var newList = [];
  if (!['HaveToDo'].includes(pageType)) {
    var statusTag = (getOrderStatusTag === null || getOrderStatusTag === void 0 ? void 0 : getOrderStatusTag[record === null || record === void 0 ? void 0 : record.status]) || '';
    var buttonList = getWorkOrderBtn({
      statusTag: statusTag,
      userRole: userRole,
      record: record,
      pageType: pageType
    }) || [];
    if (buttonList && buttonList.length) {
      buttonList.map(function (item) {
        if (['撤销', '催办'].includes(item)) {
          var msg = getOperateMessage === null || getOperateMessage === void 0 ? void 0 : getOperateMessage[item];
          // 二次确认框操作
          newList.push({
            name: item,
            onClick: function onClick() {
              return onConfirm(record, getOrderProcessTag === null || getOrderProcessTag === void 0 ? void 0 : getOrderProcessTag[item], msg);
            }
          });
        } else {
          newList.push({
            name: item,
            onClick: function onClick() {
              return onModalShow(record, getOrderProcessTag === null || getOrderProcessTag === void 0 ? void 0 : getOrderProcessTag[item]);
            }
          });
        }
      });
    }
  }
  return [{
    name: '详情',
    onClick: function onClick() {
      return onModalShow(record, 'Details');
    }
  }].concat(newList);
};
var _default = exports["default"] = {
  getOperateBtn: getOperateBtn,
  // 表格操作按钮
  getOperateMsg: getOperateMessage,
  getOrderProcessTagMsg: getOrderProcessTag,
  // 获取流程的上一步和下一步操作
  getProcessArgument: function getProcessArgument(_ref3, callBack) {
    var modalType = _ref3.modalType,
      _ref3$modalVal = _ref3.modalVal,
      modalVal = _ref3$modalVal === void 0 ? {} : _ref3$modalVal;
    _request["default"].get("".concat(_config2["default"].publicUrlZHXT, "/case/info/nextStepList"), {
      body: {
        processInstanceId: modalVal === null || modalVal === void 0 ? void 0 : modalVal.processInstanceId,
        id: modalVal === null || modalVal === void 0 ? void 0 : modalVal.id,
        processDefinitionKey: 'zhxt_case_main_process'
      }
    }).then(function (res) {
      var list = {},
        nextList = [];
      if (String(res === null || res === void 0 ? void 0 : res.result) === '0' && res !== null && res !== void 0 && res.data) {
        var _res$data;
        nextList = (res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.nextList) || [];
        var currentParams = (processParams === null || processParams === void 0 ? void 0 : processParams[modalType]) || {};
        list = nextList.find(function (val) {
          return (val === null || val === void 0 ? void 0 : val.name) === (currentParams === null || currentParams === void 0 ? void 0 : currentParams.status);
        }) || {};
      }
      callBack && callBack(list, nextList);
    });
  }
};
//# sourceMappingURL=OperationBtns.js.map
