淘先锋技术网

首页 1 2 3 4 5 6 7
var pageList = function (url) {
  var params = {
    pageSize: 6,
    offset: 0
  };
  var model = {
    items: [], //集合列表
    totalCount: 0, //总条数
    currentNumber: 0, //当前加载条数
    pageSize: params.pageSize, //每次请求条数
    isMore: true, //是否还可以加载更多
    params: params, //请求的参数
    loadMore: function () {
      if (onlineNetwork.isOnline) {
        if (this.isMore) {
          init();
        }
      }
      $scope.$broadcast('scroll.infiniteScrollComplete');
    }
  };

  function init(reload) {
    model.isMore = false;
    params.offset = model.currentNumber;
    $http.get(url + "?" + $.param(model.params)).success(function (response) {
      if (response.status == 200) {
        var result = response.resultObject;

        model.totalCount = result.totalCount;
        model.currentNumber = result.currentNumber; //当前加载条数
        model.pageSize = result.pageSize; //每次请求条数
        model.isMore = result.totalCount > result.currentNumber; //是否还可以加载更多
        if (reload) {
          model.items = result.items;
        } else {
          model.items = model.items.concat(result.items);
        }
      } else if (response.status == 511) {
        $window.localStorage.clear();
        $state.go('login');
        wpf.notice(response ? response.errorMessage : '请重新登录');
      }

    }).error(function (data, status) {
      onlineNetwork.isOnline = false;
      if (!onlineNetwork.hasTips) {
        wpf.notice(onlineNetwork.tips);

      }
      model.isMore = true;
    });
  }

  return model;
};
$scope.model = pageList(wpfConfig.getCurrentExamSubjectUrl);
console.log("==========================================");
console.log($scope.model);
console.log("==========================================");