PullUpLoadMore.ets 1.4 KB
import PageModel from '../viewmodel/PageModel';
import { RefreshConstants as Const } from './RefreshConstants';
import PageHelper from '../viewmodel/PageHelper';

export function touchMoveLoadMore(model: PageModel, event: TouchEvent) {
  // list size +1
  if (model.endIndex >= model.compList.totalCount()-3 && model.endIndex <= model.compList.totalCount()) {
    // model.offsetY = event.touches[0].y - model.downY;
    // if (Math.abs(model.offsetY) > vp2px(model.pullUpLoadHeight) / 2) {
    //   model.isCanLoadMore = true;
    //   model.isVisiblePullUpLoad = true;
    //   model.offsetY = -vp2px(model.pullUpLoadHeight) + model.offsetY * Const.Y_OFF_SET_COEFFICIENT;
    // }

    // 不用分页动画,直接预加载
    model.isCanLoadMore = true;
    model.isVisiblePullUpLoad = true;
    touchUpLoadMore(model);
  }
}

export function touchUpLoadMore(model: PageModel) {
  let self: PageModel = model;
  animateTo({
    duration: Const.ANIMATION_DURATION,
  }, () => {
    self.offsetY = 0;
  })
  if ((self.isCanLoadMore === true) && (self.hasMore === true) && (self.isLoading === false)) {
    self.isLoading = true;
    setTimeout(() => {
      closeLoadMore(model);
      PageHelper.loadMore(self)
    }, Const.DELAY_TIME);
  } else {
    closeLoadMore(self);
  }
}

export function closeLoadMore(model: PageModel) {
  model.isCanLoadMore = false;
  model.isLoading = false;
  model.isVisiblePullUpLoad = false;
}