"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _request = _interopRequireDefault(require("../../../../../../_mapUtil/request"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var _renderTree = function renderTree(data, params, isFilter) {
  var _data$attributes;
  var _params$labelFile = params.labelFile,
    labelFile = _params$labelFile === void 0 ? 'name' : _params$labelFile,
    _params$valueFile = params.valueFile,
    valueFile = _params$valueFile === void 0 ? 'id' : _params$valueFile,
    depType = params.depType,
    disabled = params.disabled,
    filterId = params.filterId;
  var isRenderChild = true;
  data.label = data === null || data === void 0 ? void 0 : data[labelFile];
  data.value = data === null || data === void 0 ? void 0 : data[valueFile];
  if ((data === null || data === void 0 || (_data$attributes = data.attributes) === null || _data$attributes === void 0 ? void 0 : _data$attributes.depType) === depType) {
    data.disabled = false;
    isRenderChild = false;
  } else {
    data.disabled = true;
  }
  if (isRenderChild) {
    var _data$children;
    if (data !== null && data !== void 0 && (_data$children = data.children) !== null && _data$children !== void 0 && _data$children.length) {
      if (isFilter) {
        data.children = depType === 'gs' ? data.children : data.children.filter(function (v) {
          return (v === null || v === void 0 ? void 0 : v.id) === filterId;
        }) || [];
      }
      isFilter = false;
      data.children.map(function (val) {
        _renderTree(val, {
          labelFile: labelFile,
          valueFile: valueFile,
          depType: depType,
          disabled: false
        }, isFilter);
      });
    }
  } else {
    delete data.children;
  }
  return data;
};
var _default = exports["default"] = {
  // 获取组织机构对应下的id
  getOrganizationId: function getOrganizationId(callBack) {
    var data = new FormData();
    data.append('depName', '水务集团');
    data.append('page', 0);
    data.append('size', 10);
    _request["default"].post('/cloud/management/api/v101/department/page', {
      body: data
    }).then(function (res) {
      var _res$data;
      var list = {};
      if (String(res === null || res === void 0 ? void 0 : res.result) === '0' && res !== null && res !== void 0 && (_res$data = res.data) !== null && _res$data !== void 0 && (_res$data = _res$data.rows) !== null && _res$data !== void 0 && _res$data.length) {
        var _res$data2;
        list = res === null || res === void 0 || (_res$data2 = res.data) === null || _res$data2 === void 0 || (_res$data2 = _res$data2.rows) === null || _res$data2 === void 0 ? void 0 : _res$data2[0];
      }
      callBack && callBack(list);
    });
  },
  // 获取办理单位下拉树
  getUnitData: function getUnitData(_ref, callBack) {
    var params = _ref.params,
      depType = _ref.depType,
      filterId = _ref.filterId;
    _request["default"].post('/cloud/management/org/loadTree.sa', {
      body: params
    }).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 _JSON$parse, _list;
        list = ((_JSON$parse = JSON.parse(res === null || res === void 0 ? void 0 : res.data)) === null || _JSON$parse === void 0 ? void 0 : _JSON$parse.items) || [];
        ((_list = list) === null || _list === void 0 ? void 0 : _list.length) && list.map(function (item) {
          _renderTree(item, {
            labelFile: 'name',
            valueFile: 'id',
            depType: depType,
            filterId: filterId
          }, true);
        });
      }
      callBack && callBack(list);
    });
  }
};
//# sourceMappingURL=service.js.map
