"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 _request = _interopRequireDefault(require("../../../_mapUtil/request"));
var _config = _interopRequireDefault(require("../../../_mapUtil/config"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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 _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 formatUserData(list) {
  list.map(function (item) {
    var _item$children;
    item.title = item.name;
    item.label = item.name;
    item.disabled = item.type !== 'Staff' ? true : false;
    item.value = item.attributes.id || item.key;
    delete item.key;
    if (item !== null && item !== void 0 && (_item$children = item.children) !== null && _item$children !== void 0 && _item$children.length) {
      formatUserData(item.children);
    }
  });
  return list;
}

// 获取已经选中的下拉选数据
var getDeleteList = function getDeleteList(_ref) {
  var _ref$tableData = _ref.tableData,
    tableData = _ref$tableData === void 0 ? [] : _ref$tableData,
    jobObjectTypeId = _ref.jobObjectTypeId,
    type = _ref.type;
  var list = tableData.length && tableData.filter(function (val) {
    return val.jobObjectTypeId === jobObjectTypeId;
  }) || [];
  var jobObjectIdList = [];
  list && list.length && list.map(function (item) {
    if (item !== null && item !== void 0 && item[type]) {
      jobObjectIdList.push.apply(jobObjectIdList, _toConsumableArray(item === null || item === void 0 ? void 0 : item[type]));
    }
  });
  return jobObjectIdList;
};

// 获取表格下拉选数据
var getObjOption = function getObjOption(_ref2) {
  var _ref2$data = _ref2.data,
    data = _ref2$data === void 0 ? [] : _ref2$data,
    name = _ref2.name,
    value = _ref2.value,
    subName = _ref2.subName,
    _ref2$tableData = _ref2.tableData,
    tableData = _ref2$tableData === void 0 ? [] : _ref2$tableData,
    jobObjectTypeId = _ref2.jobObjectTypeId,
    type = _ref2.type,
    _ref2$currentList = _ref2.currentList,
    currentList = _ref2$currentList === void 0 ? [] : _ref2$currentList;
  var deleteList = [];
  if (jobObjectTypeId && type) {
    deleteList = getDeleteList({
      tableData: tableData,
      jobObjectTypeId: jobObjectTypeId,
      type: type
    }) || [];
  }
  if (currentList && currentList.length) {
    deleteList = deleteList.filter(function (val) {
      return !currentList.includes(val);
    });
  }
  var list = [];
  data.length && data.map(function (item) {
    if (!deleteList.includes(item === null || item === void 0 ? void 0 : item[value])) {
      if (item !== null && item !== void 0 && item[name] && item !== null && item !== void 0 && item[value] && item !== null && item !== void 0 && item[subName]) {
        list.push(_objectSpread(_objectSpread({}, item), {}, {
          label: "".concat(item === null || item === void 0 ? void 0 : item[name], "(").concat(item === null || item === void 0 ? void 0 : item[subName], ")"),
          value: item === null || item === void 0 ? void 0 : item[value]
        }));
      } else if (item !== null && item !== void 0 && item[name] && item !== null && item !== void 0 && item[value]) {
        list.push(_objectSpread(_objectSpread({}, item), {}, {
          label: "".concat(item === null || item === void 0 ? void 0 : item[name]),
          value: item === null || item === void 0 ? void 0 : item[value]
        }));
      }
    }
  });
  return list;
};
var _default = exports["default"] = {
  // 获取其他人员下拉树
  getStaffUserTree: function getStaffUserTree(callBack) {
    _request["default"].get("/cloud/management/rest/np/tree/loadStaffTree", {
      body: {
        isControlPermission: true
      }
    }).then(function (res) {
      var list = [];
      if (String(res === null || res === void 0 ? void 0 : res.result) === '0' && res !== null && res !== void 0 && res.data) {
        var _res$data$children = res.data.children,
          children = _res$data$children === void 0 ? [] : _res$data$children;
        list = formatUserData(children);
      }
      callBack && callBack(list);
    });
  },
  // 获取人员对应的联系方式
  getUserToPhone: function getUserToPhone() {
    var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    var callBack = arguments.length > 1 ? arguments[1] : undefined;
    _request["default"].get("".concat(_config["default"].publicUrlXCGL, "/api/patrolUser/getPhoneByStaffId"), {
      body: params
    }).then(function (res) {
      var data;
      if (String(res === null || res === void 0 ? void 0 : res.result) === '0' && res !== null && res !== void 0 && res.data) {
        data = res.data;
      }
      callBack && callBack(data);
    });
  },
  // 根据业务类型获取关联对象类型及表单信息
  getObjectAndForm: function getObjectAndForm() {
    var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    var callBack = arguments.length > 1 ? arguments[1] : undefined;
    _request["default"].get("".concat(_config["default"].publicUrlXCGL, "/api/jobObjectTypeForm/getTypeInfoByBussinessTypeId"), {
      body: params
    }).then(function (res) {
      var data;
      if (String(res === null || res === void 0 ? void 0 : res.result) === '0' && res !== null && res !== void 0 && res.data) {
        data = res.data;
      }
      callBack && callBack(data);
    });
  },
  // 任务类型名称默认值
  taskDefaultName: {
    HDXC: "\u6CB3\u9053\u5DE1\u67E5\u4EFB\u52A101",
    SBXC: "\u8BBE\u5907\u5DE1\u67E5\u4EFB\u52A101",
    DLXC: "\u9053\u8DEF\u5DE1\u67E5\u4EFB\u52A101"
  },
  getSelectList: function getSelectList(jobObjectTypeId, status) {
    var params = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
    var objList = (params === null || params === void 0 ? void 0 : params.objectAndForm.find(function (item) {
      return item.jobObjectTypeId === jobObjectTypeId;
    })) || {};
    var list = getObjOption(_objectSpread(_objectSpread({}, params), {}, {
      data: objList === null || objList === void 0 ? void 0 : objList[status]
    }));
    return list;
  },
  getObjOption: getObjOption
};
//# sourceMappingURL=config.js.map
