小程序 -- 点击切换分类 分页加载 懒加载

//历史拍卖
import store from '../../store'
import create from '../../westore/create';
var utils = require("../../utils/utils.js");
var base = require("../../utils/base.js");
var log = require("../../utils/log.js");
var core = require("../../core/core.js");
var api = require("../../config/api.config.js").api;
create(store, {

  /**
   * 页面的初始数据
   */
  data: {
    getSystemInfo: {},
    localImages: {},//图片缓存
    auctionGoodsList:[],//拍品信息列表
    orderState:[],//分类
    category_id:'',//初始分类id
    page:1,//页数
    page_size:8,//每页数量
    isLoadingGoodsList: false,//正在加载
    no_more_goods: false,//没有更多了
    no_datas:false,//暂无数据

  },
  //返回上一页
  onClickLeft: function () {
    var pages = getCurrentPages();
    var page_length = pages.length;
    if (page_length == 1) {
      //如果当前是顶级路由
      wx.switchTab({
        url: '/pages/index/index'
      })
    } else {
      wx.navigateBack({
        delta: 1
      })
    }
  },
  // 点击切换分类
  bindCategroyList:function(event){
    var that = this;
    var id = event.currentTarget.dataset.id;
    that.setData({
      category_id:id,
      page:1,
      no_more_goods: false,
      isLoadingGoodsList:false,
      auctionGoodsList:[],//清空拍品列表
    })
  
    that.getAuctionList()

  },

  // 拍品信息列表
  loadAuctionList:function(options){
    var that = this;
    // 拍品列表接口
    core.Ajax({
      url: api.auctionList,
      data: {
        category_id: that.data.category_id,
        page: that.data.page,
        page_size: that.data.page_size,
      },
      success: function (res) {
        options.success && options.success(res);
  
      }
    })
  },
  //获取拍品信息列表 
  getAuctionList:function(){
    var that = this;
    that.setData({
      isLoadingGoodsList: true, //显示正在加载数据
    })
    wx.showLoading({
      title: '加载中',
    });
    this.loadAuctionList({
      success:function(res){
        console.log(res)
          var images = [];
        res.result.goods.map(function (item) {
          images.push(item.image);
        })
        base.getImagesUrlByServerIDs(store, images);
        store.update();
        if (res.result.goods.length == 0){//加载第一页的时候
          if (that.data.page == 1){//返回的数据为空的时候显示暂无数据图片
          that.setData({
            no_datas:true,
            isLoadingGoodsList:true, 
            auctionGoodsList:[]
          })
          wx.hideLoading();
          } else {//返回的数据消息page_size的时候 提示没有更多数据
            that.setData({
              no_datas: false,
              isLoadingGoodsList: false,
              no_more_goods:true,//没有更多了
            })
            wx.hideLoading();
          }
        }else{
          if (res.result.goods.length < that.data.page_size){
         
            that.data.auctionGoodsList.push(...res.result.goods);
           
            that.setData({
              no_datas: false,
              isLoadingGoodsList: false,
              no_more_goods: true,//没有更多了
              auctionGoodsList: that.data.auctionGoodsList
            })
            wx.hideLoading();
          }else{
            that.data.auctionGoodsList.push(...res.result.goods);
            that.setData({
              page: that.data.page + 1,
              no_datas: false,
              isLoadingGoodsList: false,
              no_more_goods: false,//没有更多了
              auctionGoodsList: that.data.auctionGoodsList
            })
            wx.hideLoading();
          }
     
        }
       
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    //  分类接口
    core.Ajax({
      url: api.category,
      success:function(res){
        console.log(res);
        that.setData({
          orderState: res.result.category,
          category_id: res.result.first_category_id
        })
        that.getAuctionList()
      },
      fail:function(res){
      }
    })
  },
  // 拍品信息滚动加载
  loadMoreGoods:function(){
    var that =this;
    if (this.data.isLoadingGoodsList) return;//防止多次下拉
    if (that.data.no_more_goods){
      wx.showToast({
        title: '没有更多了',
        icon:'none'
      })
       return
    }
    that.getAuctionList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
数据接口:https://api.getweapp.com/vendor/lightstao/searchkeyhttps://api.getweapp.com/vendor/lightstao/product/search微信小程序中,特效让人头疼不已,因为小程序完全没法操作dom,所以位置的操作在小程序中,变得极其的难~~先看特效:我们将其拆分为如下几个步骤进行讲解~~1)如何获取图片的位置高度先看一张图:通过上图可以知道,图片位置高度其实可以通过img.height margin值算出。js代码:arrHight[i] = Math.floor(i/2)*(img.height   margin-bottom);为何是Math.floor(i/2)呢,因为同一排两张图片高度一样,比如i=0和i=1,通过Math.floor得出值都为0,所以可以保证同一排的两张图片位置高度是同一个值。2)替换默认图片先看效果图片:wxml代码:<image src="{{arr[index] ? productArr[index].Image : 'default.jpg'}}"></image>思路很明显,一开始arr[index]中都是false,所以默认都是default图片但是随着往下移动,有些arr[index]的值变为true,所以替换默认图片js代码:for (var i = 0; i < this.data.productArr.length; i ) {   if (arrHight[i] < scrollTop) {       if (arr[i] == false) {           arr[i] = true;       }   } }思路相当清晰,无需多言~~3)中渐显特效先看效果:wxss代码:.product_image{   opacity: 0;   width: 100%;   height: 70%;   transition: opacity 1s linear 2s; } .loaded{     opacity: 1; }其实就是opacity的一个过渡动画而已,so easy~~作者:小小小是我
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值