import Common from '../../common/Common.js';

/**
 * 工具类自动生成的API，请勿做任何修改，请勿做任何修改，请勿做任何修改（重要的事情说3遍）
 * 工具作者: 杨志杰
 * 页签设计资源 
 */
export default {

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 根据tabId获取页签数据 
	 */
  getTabById: function(tabIndex, windowNo){
    var requestUrl = 'TabResource/getTabs';
    var paramCount = 0;
    if(tabIndex != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('tabIndex=' + tabIndex);
      paramCount ++;
    }
    if(windowNo != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('windowNo=' + windowNo);
      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);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 根据windowId查询TabId 
	 */
  getWindowOpenParam: function(windowNo, fieldName, recordId){
    var requestUrl = 'TabResource/windowOpenParam';
    var paramCount = 0;
    if(windowNo != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('windowNo=' + windowNo);
      paramCount ++;
    }
    if(fieldName != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('fieldName=' + fieldName);
      paramCount ++;
    }
    if(recordId != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('recordId=' + recordId);
      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);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 根据className和recordId查询基础类数据 
	 */
  loadBaseClientEntityDto: function(className, recordId){
    var requestUrl = 'TabResource/loadBaseClientEntityDto';
    var paramCount = 0;
    if(className != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('className=' + className);
      paramCount ++;
    }
    if(recordId != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('recordId=' + recordId);
      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);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 获取新的modelData 
	 */
  newModelData: function(windowNo, tabIndex, modelDataCreate){
    var requestUrl = 'TabResource/newModelData';
    var paramCount = 0;
    if(windowNo != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('windowNo=' + windowNo);
      paramCount ++;
    }
    if(tabIndex != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('tabIndex=' + tabIndex);
      paramCount ++;
    }
    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiURL(requestUrl),
        type: 'post',
        contentType: 'application/json',
        data: JSON.stringify(modelDataCreate),
				
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },
};
