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

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

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 根据tabId获取页签数据
考虑到未登陆界面可能会用，未添加AuthoriseResource注解 
	 */
  formatNumber: function(value, pattern){
    var requestUrl = 'FieldResource/formatNumber';
    var paramCount = 0;
    if(value != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('value=' + value);
      paramCount ++;
    }
    if(pattern != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('pattern=' + pattern);
      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);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 *  
	 */
  getFieldValue1: function(windowNo, tabIndex, fieldName, recordId){
    var requestUrl = 'FieldResource/getFieldValue1';
    var paramCount = 0;
    if(windowNo != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('windowNo=' + windowNo);
      paramCount ++;
    }
    if(tabIndex != null){
      requestUrl += (paramCount > 0) ? '&' : '?';
      requestUrl += ('tabIndex=' + tabIndex);
      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',
				
        dataType: 'json',
				
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 根据类名称、recordId、属性名称获取属性值 
	 */
  getFieldValue2: function(className, recordId, fieldName){
    var requestUrl = 'FieldResource/getFieldValue2';
    var formData = new FormData();
    if(className != null){
      formData.append('className', className);
    }
    if(recordId != null){
      formData.append('recordId', recordId);
    }
    if(fieldName != null){
      formData.append('fieldName', fieldName);
    }
    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiURL(requestUrl),
        type: 'post',
        contentType: 'application/x-www-form-urlencoded',
				
				
        data: formData,
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

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

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

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 刷新字段数据 
	 */
  refreshField2: function(fieldQueryParam){
    var requestUrl = 'FieldResource/refreshField2';
    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiURL(requestUrl),
        type: 'post',
        contentType: 'application/json',
        dataType: 'json',
        data: JSON.stringify(fieldQueryParam),
				
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },

  /**
	 * 工具类自动生成的方法
	 * 工具作者: 杨志杰
	 * 为指定类指定数据修改图片 
	 */
  updateStringField: function(className, recordId, fieldName, fieldValue){
    var requestUrl = 'FieldResource/updateStringField';
    var formData = new FormData();
    if(className != null){
      formData.append('className', className);
    }
    if(recordId != null){
      formData.append('recordId', recordId);
    }
    if(fieldName != null){
      formData.append('fieldName', fieldName);
    }
    if(fieldValue != null){
      formData.append('fieldValue', fieldValue);
    }
    return new Promise((resolve, reject) => {
      $.ajax({
        url: Common.getApiURL(requestUrl),
        type: 'post',
        contentType: 'application/x-www-form-urlencoded',
				
				
        data: formData,
        beforeSend: function(request) {
          Common.addTokenToRequest(request);
        },
        success: function(data) {
          resolve(data);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
          reject(XMLHttpRequest);
        },
      });
    });
  },
};
