第59讲订单数据下拉实现

bash 复制代码
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
bash 复制代码
    /**
     * 订单查询 type值 0 全部订单  1待付款  2 待收货  3 退款/退货
     * @param type
     * @return
     */
    @RequestMapping("/list")
    public R list(Integer type,Integer page,Integer pageSize){
        System.out.println("type="+type);
        List<Order> orderList=null;
        Map<String,Object> resultMap=new HashMap<String,Object>();

        Page<Order> pageOrder=new Page<>(page,pageSize);

        if(type==0){  // 全部订单查询
            // orderList=orderService.list(new QueryWrapper<Order>().orderByDesc("id"));
            Page<Order> orderResult = orderService.page(pageOrder, new QueryWrapper<Order>().orderByDesc("id"));
            System.out.println("总记录数:"+orderResult.getTotal());
            System.out.println("总页数:"+orderResult.getPages());
            System.out.println("当前页数据:"+orderResult.getRecords());
            orderList=orderResult.getRecords();
            resultMap.put("total",orderResult.getTotal());
            resultMap.put("totalPage",orderResult.getPages());
        }else{
           // orderList = orderService.list(new QueryWrapper<Order>().eq("status", type).orderByDesc("id"));
            Page<Order> orderResult = orderService.page(pageOrder, new QueryWrapper<Order>().eq("status", type).orderByDesc("id"));
            System.out.println("总记录数:"+orderResult.getTotal());
            System.out.println("总页数:"+orderResult.getPages());
            System.out.println("当前页数据:"+orderResult.getRecords());
            orderList=orderResult.getRecords();
            resultMap.put("total",orderResult.getTotal());
            resultMap.put("totalPage",orderResult.getPages());
        }
        resultMap.put("orderList",orderList);
        return R.ok(resultMap);
    }

前端定义分页参数:

bash 复制代码
 // 接口参数
  QueryParams:{
    type:0,
    page:1,// 第几页
    pageSize:10 // 每页记录数
  },

  // 总页数
  totalPage:1,

触底获取下一页数据:

bash 复制代码
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log("触底")
    if(this.QueryParams.page>=this.totalPage){
      // 没有下一页数据
      console.log("没有下一页数据");
      wx.showToast({
        title: '没有下一页数据了'
      })
    }else{
      console.log("有下一页数据");
      this.QueryParams.page++;
      this.getOrders();
    }
  },

拼接下一页数据:

bash 复制代码
  /**
   * 获取订单
   */
  async getOrders(){
    const res=await requestUtil({url:'/my/order/list',data:this.QueryParams});
    console.log(res)
    this.totalPage=res.totalPage;
    this.setData({
      orders:[...this.data.orders,...res.orderList]
    })
  },

重置请求参数:

bash 复制代码
  // 根据标题索引来激活选中的数据
  changeTitleByIndex(index){
    // 切换标题
    let {tabs}=this.data;
    tabs.forEach((v,i)=>i==index?v.isActive=true:v.isActive=false);
    this.setData({
      tabs
    })
  },

  /**
   * tab点击事件处理
   * @param {*} e 
   */
  handleItemTap(e){
    const {index}=e.currentTarget.dataset;
    this.changeTitleByIndex(index);
   // console.log("index="+index)
   
    // 获取订单列表
    this.QueryParams.type=index;
    this.QueryParams.page=1;
    this.setData({
      orders:[]
    })
    this.getOrders();

   
  },

下拉刷新实现:

开启下拉刷新:

bash 复制代码
{
  "usingComponents": {},
  "navigationBarTitleText": "订单查询",
  "enablePullDownRefresh":true,
  "backgroundTextStyle":"dark"
}

下拉刷新事件

bash 复制代码
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log("下拉刷新")
    this.QueryParams.page=1;
    this.setData({
      orders:[]
    })
    this.getOrders();
    // 手动关闭等待效果
    wx.stopPullDownRefresh({
     
    })
  }

进入页面加载信息:

bash 复制代码
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log("onShow")
    let pages=getCurrentPages();
    console.log(pages)
    let currentPage=pages[pages.length-1];
    const {type}=currentPage.options;
    this.changeTitleByIndex(type);
    this.QueryParams.type=type;
    this.QueryParams.page=1;
    this.getOrders();
  },

报错

bash 复制代码
2024-02-08 14:33:15.723  WARN 26256 --- [nio-8080-exec-2] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: "undefined"]

链接

bash 复制代码
http://localhost:8080/my/order/list?type=undefined&page=1&pageSize=10

http://localhost:8080/my/order/list?type=0&page=1&pageSize=10

相关推荐
枣把儿3 分钟前
Vercel 收购 NuxtLabs!Nuxt UI Pro 即将免费!
前端·vue.js·nuxt.js
望获linux4 分钟前
【Linux基础知识系列】第四十三篇 - 基础正则表达式与 grep/sed
linux·运维·服务器·开发语言·前端·操作系统·嵌入式软件
爱编程的喵6 分钟前
从XMLHttpRequest到Fetch:前端异步请求的演进之路
前端·javascript
喜欢吃豆9 分钟前
深入企业内部的MCP知识(三):FastMCP工具转换(Tool Transformation)全解析:从适配到增强的工具进化指南
java·前端·人工智能·大模型·github·mcp
豆苗学前端12 分钟前
手把手实现支持百万级数据量、高可用和可扩展性的穿梭框组件
前端·javascript·面试
不见_12 分钟前
不想再写周报了?来看看这个吧!
前端·命令行
yinke小琪14 分钟前
JavaScript 事件冒泡与事件捕获
前端·javascript
pany16 分钟前
写代码的节奏,正在被 AI 改写
前端·人工智能·aigc
liliangrong77719 分钟前
ES2025新特性详解
前端
gzzeason26 分钟前
Ajax:现代JS发起http通信的代名词
前端·javascript·ajax