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

// CRUD 服务器
export default {


  // 根据windowId获取windowDto
  getWindowById: function (windowNo, success, error) {
    $.ajax({
      url: Common.getApiURL('CurdWindowResource/uniqueByNoWithRole'),
      type: 'get',
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      data: {
        no: windowNo,
      },
      success: success,
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        if (error != undefined) {
          error();
        }
        Common.processException(XMLHttpRequest, textStatus, errorThrown);
      },
    });
  },
  // 根据windowId获取windowDto
  uniqueByNoWithRoleNew: function (windowNo, success, error) {
    $.ajax({
      url: Common.getApiURL('CurdWindowResource/uniqueByNoWithRoleNew'),
      type: 'get',
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      data: {
        no: windowNo,
      },
      success: success,
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        if (error != undefined) {
          error();
        }
        Common.processException(XMLHttpRequest, textStatus, errorThrown);
      },
    });
  },

  // 查询页签数据
  queryTabData: function (tabQueryParam, success, error) {
    $.ajax({
      url: Common.getApiURL('CurdWindowResource/tabData'),
      type: 'post',
      contentType: 'application/json',
      data: JSON.stringify(tabQueryParam),
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: success,
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        if (error != undefined) {
          error();
        }
        Common.processException(XMLHttpRequest, textStatus, errorThrown);
      },
    });
  },

  // 加载页签数据
  loadTabSingleData: function (tabLoadParam, success, error) {
    $.ajax({
      url: Common.getApiURL('CurdWindowResource/Load'),
      type: 'get',
      contentType: 'application/json',
      data: tabLoadParam,
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: success,
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        if (error != undefined) {
          error();
        }
        Common.processException(XMLHttpRequest, textStatus, errorThrown);
      },
    });
  },

  // 保存页签数据
  saveTabData: function (tabData, success, error) {
    $.ajax({
      type: 'post',
      url: Common.getApiURL('CurdWindowResource/saveOrUpdate'),
      contentType: 'application/json',
      data: JSON.stringify(tabData),
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: success,
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        if (error != undefined) {
          error();
        }
        Common.processException(XMLHttpRequest, textStatus, errorThrown);
      },
    });
  },

  // 批量保存页签数据
  saveTabDatas: function (tabDatas, success, error) {
    $.ajax({
      type: 'post',
      url: Common.getApiURL('CurdWindowResource/saveOrUpdateDatas'),
      contentType: 'application/json',
      data: JSON.stringify(tabDatas),
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: success,
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        if (error != undefined) {
          error();
        }
        Common.processException(XMLHttpRequest, textStatus, errorThrown);
      },
    });
  },

  deleteTabData: function (tabDeleteData, success, error) {
    $.ajax({
      type: 'post',
      url: Common.getApiURL('CurdWindowResource/delete'),
      contentType: 'application/json',
      data: JSON.stringify(tabDeleteData),
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: success,
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        if (error != undefined) {
          error();
        }
        Common.processException(XMLHttpRequest, textStatus, errorThrown);
      },
    });
  },


  // 根据windowId查询TabId
  newModelData: function (windowNo, tabIndex, modelDataCreate, success, error) {
    

    $.ajax({
      type: 'post',
      url: Common.getApiURL('TabResource/newModelData?windowNo=' + windowNo + '&tabIndex=' + tabIndex),
      contentType: 'application/json',
      data: JSON.stringify(modelDataCreate),
      beforeSend: function (request) {
        Common.addTokenToRequest(request);
      },
      success: success,
      error: function (XMLHttpRequest, textStatus, errorThrown) {
        if (error != undefined) {
          error();
        }
        Common.processException(XMLHttpRequest, textStatus, errorThrown);
      },
    });
  },
};