import { Common } from 'pc-component-v3';

/**
 * 工具类自动生成的API，请勿做任何修改，请勿做任何修改，请勿做任何修改（重要的事情说3遍）
 * 工具作者: 杨志杰
 * 权限编辑:角色-部门Resource 
 */
export default {

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 获取集团公司所有部门 
	 */
  getClientOrganization: function(roleId){
    var requestUrl = 'roleOrganizationResource/getClientOrganization';
    var paramCount = 0;
    if(roleId != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('roleId=' + roleId);
      paramCount ++;
    }


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiURL(requestUrl),
        type: 'get',
				
        dataType: 'json',
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 查询单位及部门 
	 */
  getClientOrganizations: function(isClient){
    var requestUrl = 'roleOrganizationResource/getClientOrganizations';
    var paramCount = 0;
    if(isClient != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('isClient=' + isClient);
      paramCount ++;
    }


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiURL(requestUrl),
        type: 'get',
				
        dataType: 'json',
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 根据角色获取部门访问权限 
	 */
  getRoleOrganizationDtoListByRoleId: function(roleId){
    var requestUrl = 'roleOrganizationResource/getRoleOrganizationDtoListByRoleId';
    var paramCount = 0;
    if(roleId != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('roleId=' + roleId);
      paramCount ++;
    }


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiURL(requestUrl),
        type: 'get',
				
        dataType: 'json',
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 *  
	 */
  initRoleOrganization: function(clientId){
    var requestUrl = 'roleOrganizationResource/initRoleOrganization';
    var paramCount = 0;
    if(clientId != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('clientId=' + clientId);
      paramCount ++;
    }


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiURL(requestUrl),
        type: 'get',
				
				
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 保存部门权限 
	 */
  saveRoleOrganization: function(roleOrganizationDtoList){
    var requestUrl = 'roleOrganizationResource/saveRoleOrganization';


    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiURL(requestUrl),
        type: 'post',
        contentType: 'application/json',
				
				
        data: JSON.stringify(roleOrganizationDtoList),
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },
};
