"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.workRelateOkr = exports.relateOkr = exports.planTableTask = void 0;

var _request = require("@titaui/request");

var _helpers = require("../../../utils/helpers");

var _getLoginUserInfo;

var dealMessage = function dealMessage(res) {
  var Code = res.Code,
      Data = res.Data;

  if (!!Code) {
    return Data;
  } else {
    return false;
  }
};

var id = (_getLoginUserInfo = (0, _helpers.getLoginUserInfo)()) === null || _getLoginUserInfo === void 0 ? void 0 : _getLoginUserInfo.Id;

var planTableTask = function planTableTask(params, pageNum, pageSize) {
  var url = "task/search";
  var _params$startDate = params.startDate,
      startDate = _params$startDate === void 0 ? '' : _params$startDate,
      _params$endDate = params.endDate,
      endDate = _params$endDate === void 0 ? '' : _params$endDate,
      _params$keyWords = params.keyWords,
      keyWords = _params$keyWords === void 0 ? '' : _params$keyWords,
      _params$status = params.status,
      status = _params$status === void 0 ? 10 : _params$status,
      _params$relation = params.relation,
      relation = _params$relation === void 0 ? 0 : _params$relation,
      _params$userIds = params.userIds,
      userIds = _params$userIds === void 0 ? id : _params$userIds;

  if (status == 10) {
    status = '0,1,2,3,4,6';
  }

  if (!relation) {
    relation = '1,2,3';
  }

  return (0, _request.rpost)('v2')(url, {
    type: 'personal',
    to_user_id: id,
    userIds: userIds,
    StartDate: startDate,
    EndDate: endDate,
    startNum: pageNum,
    count: pageSize,
    // planTableId: planTableId,
    // planTableType: planTableType,
    fromLevel: 1,
    toLevel: 1,
    RelationType: relation,
    Status: status,
    FilterKey: keyWords,
    includeCreateFailApprovalOkr: false
  }).then(function (res) {
    return dealMessage(res);
  });
};

exports.planTableTask = planTableTask;

var relateOkr = function relateOkr(selected, labelKrId, labelOId) {
  var taskRelationModel = {
    workId: labelOId,
    krId: labelKrId
  };
  var ids = [];
  selected.forEach(function (ele) {
    ids.push(ele.id);
  });
  var url = "task/relateOkrV2";
  return (0, _request.rpost)('v2')(url, {
    taskId: ids.join(','),
    taskRelationModels: [taskRelationModel]
  });
};

exports.relateOkr = relateOkr;

var workRelateOkr = function workRelateOkr(selected, labelKrId, labelOId) {
  var taskRelationModel = {
    workId: labelOId,
    krId: labelKrId
  };
  var ids = [];
  selected.forEach(function (ele) {
    ids.push(ele.id);
  });
  var url = "work/batch/relationOkr";
  return (0, _request.rpost)('v2')(url, {
    workId: ids.join(','),
    taskRelationModels: [taskRelationModel]
  });
};

exports.workRelateOkr = workRelateOkr;