|  | @@ -5,6 +5,7 @@
 | 
	
		
			
				|  |  |  /*var rationChapterSpread, sectionRationsSpread;*/
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  var rationLibObj = {
 | 
	
		
			
				|  |  | +    searchLimit: 50,
 | 
	
		
			
				|  |  |      libType: {complementary: 0, std: 1},
 | 
	
		
			
				|  |  |      compleRationLibId: 'compleRationLib',
 | 
	
		
			
				|  |  |      doAfterGetRationTree: null, //获取章节树回调
 | 
	
	
		
			
				|  | @@ -214,6 +215,19 @@ var rationLibObj = {
 | 
	
		
			
				|  |  |              });
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  | +    //滚动条到底部加载
 | 
	
		
			
				|  |  | +    onRationSpreadTopRowChanged: function (sender, args) {
 | 
	
		
			
				|  |  | +        let me = rationLibObj;
 | 
	
		
			
				|  |  | +        if(me.searching) {
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        let bottomRow = args.sheet.getViewportBottomRow(1),
 | 
	
		
			
				|  |  | +            rowCount = args.sheet.getRowCount();
 | 
	
		
			
				|  |  | +        //滚到了底部
 | 
	
		
			
				|  |  | +        if (bottomRow + 1 - me.sectionRationsSetting.emptyRows === rowCount - me.sectionRationsSetting.emptyRows) {
 | 
	
		
			
				|  |  | +            seachRation();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  |      loadStdRationContextMenu: function () {
 | 
	
		
			
				|  |  |          let rationSpread = rationLibObj.sectionRationsSpread, rationSheet = rationSpread.getActiveSheet(),  rationModel = projectObj.project.Ration;;
 | 
	
		
			
				|  |  |          $.contextMenu({
 | 
	
	
		
			
				|  | @@ -449,6 +463,25 @@ var rationLibObj = {
 | 
	
		
			
				|  |  |          let defaultLib = _.find(ration_lib,{'isDefault':true});
 | 
	
		
			
				|  |  |          let libID = defaultLib?defaultLib.id:ration_lib[0].id;
 | 
	
		
			
				|  |  |          return parseInt(libID);
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    //@param {Array}datas(resultCache) @return {Object}
 | 
	
		
			
				|  |  | +    //搜索skip信息,不能被每页搜索数整除,则说明上次搜索已经搜索完整
 | 
	
		
			
				|  |  | +    getSearchSkip: function (datas) {
 | 
	
		
			
				|  |  | +        if (datas.length % this.searchLimit !== 0) {
 | 
	
		
			
				|  |  | +            return null;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        let skip = {std: 0, comple: 0};
 | 
	
		
			
				|  |  | +        if (!datas || !Array.isArray(datas) || datas.length === 0) {
 | 
	
		
			
				|  |  | +            return skip;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        for (let data of datas) {
 | 
	
		
			
				|  |  | +            if (data.type === 'std') {
 | 
	
		
			
				|  |  | +                skip.std++;
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                skip.comple++;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return skip;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  };
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -489,7 +522,7 @@ $('#rationSearchKeyword').keyup(function () {
 | 
	
		
			
				|  |  |      let keyword = $('#rationSearchKeyword').val();
 | 
	
		
			
				|  |  |      if(keyword === ''){
 | 
	
		
			
				|  |  |          if($('#rationSearchResult').is(':visible')){
 | 
	
		
			
				|  |  | -            rationLibObj.resultCache = null;
 | 
	
		
			
				|  |  | +            rationLibObj.resultCache = [];
 | 
	
		
			
				|  |  |              $('#rationSearchResult').hide();
 | 
	
		
			
				|  |  |              $(".main-data-side-search", $('#rationSearchResult')).height(0);
 | 
	
		
			
				|  |  |              switchRationSearchMode(0);
 | 
	
	
		
			
				|  | @@ -501,6 +534,7 @@ $('#rationSearchKeyword').keyup(function () {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  //变换搜索本定额、全部定额状态
 | 
	
		
			
				|  |  |  function switchRationSearchMode(mode) {
 | 
	
		
			
				|  |  | +    rationLibObj.resultCache = [];
 | 
	
		
			
				|  |  |      //搜索本定额
 | 
	
		
			
				|  |  |      if(mode === 0){
 | 
	
		
			
				|  |  |          $('#curRationLib').removeClass('btn-light');
 | 
	
	
		
			
				|  | @@ -534,11 +568,16 @@ $('#allRationLibs').click(function () {
 | 
	
		
			
				|  |  |  });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  //搜索
 | 
	
		
			
				|  |  | -$('#rationSearch').click(function () {
 | 
	
		
			
				|  |  | +function seachRation(){
 | 
	
		
			
				|  |  | +    let skip = rationLibObj.getSearchSkip(rationLibObj.resultCache);
 | 
	
		
			
				|  |  | +    if (!skip) {
 | 
	
		
			
				|  |  | +        return;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    rationLibObj.searching = true;
 | 
	
		
			
				|  |  |      var keyword = $('#rationSearchKeyword').val();
 | 
	
		
			
				|  |  |      if(keyword === ''){
 | 
	
		
			
				|  |  |          if($('#rationSearchResult').is(':visible')){
 | 
	
		
			
				|  |  | -            rationLibObj.resultCache = null;
 | 
	
		
			
				|  |  | +            rationLibObj.resultCache = [];
 | 
	
		
			
				|  |  |              $('#rationSearchResult').hide();
 | 
	
		
			
				|  |  |              $(".main-data-side-search", $('#rationSearchResult')).height(0);
 | 
	
		
			
				|  |  |              autoFlashHeight();
 | 
	
	
		
			
				|  | @@ -610,33 +649,29 @@ $('#rationSearch').click(function () {
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |      };
 | 
	
		
			
				|  |  |      var showResult = function (result) {
 | 
	
		
			
				|  |  | -        rationLibObj.resultCache = result;
 | 
	
		
			
				|  |  |          if(!rationLibObj.resultSpread){
 | 
	
		
			
				|  |  |              let resultSpread = SheetDataHelper.createNewSpread($('.main-data-side-search')[0]);
 | 
	
		
			
				|  |  |              rationLibObj.resultSpread = resultSpread;
 | 
	
		
			
				|  |  |              bindContextmenuOpr(resultSpread.getActiveSheet());
 | 
	
		
			
				|  |  |              SheetDataHelper.loadSheetHeader(rationLibObj.sectionRationsSetting, resultSpread.getActiveSheet());
 | 
	
		
			
				|  |  |              resultSpread.bind(GC.Spread.Sheets.Events.CellDoubleClick, rationLibObj.onRationSpreadCellDoubleClick);
 | 
	
		
			
				|  |  | +            resultSpread.bind(GC.Spread.Sheets.Events.TopRowChanged, rationLibObj.onRationSpreadTopRowChanged);
 | 
	
		
			
				|  |  |          }else {
 | 
	
		
			
				|  |  |              rationLibObj.resultSpread.refresh();
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          SheetDataHelper.loadSheetData(rationLibObj.sectionRationsSetting, rationLibObj.resultSpread.getActiveSheet(), result);
 | 
	
		
			
				|  |  |          rationLibObj.setTagForHint(rationLibObj.resultSpread.getActiveSheet(), result);
 | 
	
		
			
				|  |  | +        rationLibObj.resultCache = result;
 | 
	
		
			
				|  |  |      };
 | 
	
		
			
				|  |  |      $.bootstrapLoading.start();
 | 
	
		
			
				|  |  | -    CommonAjax.post('/complementaryRation/api/findRation', {'user_id': userID, 'rationRepId': rationLibIDs, 'keyword': keyword}, function (result) {
 | 
	
		
			
				|  |  | -        //sort
 | 
	
		
			
				|  |  | -        result.sort(function (a, b) {
 | 
	
		
			
				|  |  | -            let rst = 0;
 | 
	
		
			
				|  |  | -            if(a.code > b.code) rst = 1;
 | 
	
		
			
				|  |  | -            else if(a.code < b.code) rst = -1;
 | 
	
		
			
				|  |  | -            return rst;
 | 
	
		
			
				|  |  | -        });
 | 
	
		
			
				|  |  | +    CommonAjax.post('/complementaryRation/api/findRation', {'user_id': userID, 'rationRepId': rationLibIDs, 'keyword': keyword, skip: skip}, function (result) {
 | 
	
		
			
				|  |  |          var resultObj = $('#rationSearchResult');
 | 
	
		
			
				|  |  | -        $('#rationSearchCount').text(`搜索结果:${result.length.toString()}`);
 | 
	
		
			
				|  |  | -        $('a', result).unbind('click');
 | 
	
		
			
				|  |  | +        if (result.count !== null) {
 | 
	
		
			
				|  |  | +            $('#rationSearchCount').text(`搜索结果:${result.count}`);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        $('a', resultObj).unbind('click');
 | 
	
		
			
				|  |  |          $('a', resultObj).bind('click', function () {
 | 
	
		
			
				|  |  | -            rationLibObj.resultCache = null;
 | 
	
		
			
				|  |  | +            rationLibObj.resultCache = [];
 | 
	
		
			
				|  |  |              switchRationSearchMode(0);
 | 
	
		
			
				|  |  |              resultObj.hide();
 | 
	
		
			
				|  |  |              $(".main-data-side-search", resultObj).height(0);
 | 
	
	
		
			
				|  | @@ -645,9 +680,19 @@ $('#rationSearch').click(function () {
 | 
	
		
			
				|  |  |          });
 | 
	
		
			
				|  |  |          resultObj.show();
 | 
	
		
			
				|  |  |          $(".main-data-side-search", resultObj).height($(window).height() - $(".header").height() - $(".toolsbar").height() - 64);
 | 
	
		
			
				|  |  | -        showResult(result);
 | 
	
		
			
				|  |  | +        showResult(rationLibObj.resultCache.concat(result.data));
 | 
	
		
			
				|  |  | +        rationLibObj.searching = false;
 | 
	
		
			
				|  |  | +        //以防一开始就需要加载后面的分页数据
 | 
	
		
			
				|  |  | +        if (result.data.length > 0) {
 | 
	
		
			
				|  |  | +            rationLibObj.onRationSpreadTopRowChanged({}, {sheet: rationLibObj.resultSpread.getActiveSheet()});
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          $.bootstrapLoading.end();
 | 
	
		
			
				|  |  |      }, function () {
 | 
	
		
			
				|  |  | +        rationLibObj.searching = false;
 | 
	
		
			
				|  |  |          $.bootstrapLoading.end();
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +$('#rationSearch').click(function () {
 | 
	
		
			
				|  |  | +    rationLibObj.resultCache = [];
 | 
	
		
			
				|  |  | +    seachRation();
 | 
	
		
			
				|  |  |  });
 |