分页tab 小程序

2023-05-28  本文已影响0人  糖醋里脊120625

import { requestOrderList,requestOrderPrint } from '../../http/orderListApi'
import { centToYuan } from '../../unit/priceUtil'
import Toast from '@vant/weapp/toast/toast';
import Dialog from '@vant/weapp/dialog/dialog';
Page({
  data: {
    LoadingMore: false,
    noDataMore:true,
    page:1,
    size:10,
    tabTop: '0',
    navInfo:{},
    customerList: [],
    current: 1,
    autoplay: true,
    valueKey: "",
    interval: 5000,
    navigation: { type: 'dots' },
    activeSeled:0,
    orderStatus:"",
    fatherList: [
          {
            tabsName: '全部',
            orderState:'',
            ordersList: []
          },
          {
            tabsName: '待发货',
            orderState:15,
            ordersList: []
          }
    ],
   
    layout: 1,
  },

  goodListPagination: {
    index: 1,
    num: 20,
  },




  
  privateData: {
    tabIndex: 0,
  },
  
  
  goTop(){
    if (wx.pageScrollTo) {
      wx.pageScrollTo({
        scrollTop: 0
      })
    } 
  },
  // loadOrderData(){
  //   console.log(this.data.activeSeled)
  // },\


  onLoad() {
    return
    this.setData({
      page:1,
      fatherList:[  {
        tabsName: '全部',
        orderState:'',
        ordersList: []
      },
      {
        tabsName: '待发货',
        orderState:15,
        ordersList: []
      }]
    })
    this.getDataFun("");
  },

  onShow() {
    
    const tabBar = this.getTabBar()
    tabBar.setData({
      TabBarActive: 1
    })
    this.setData({
      page:1,
      fatherList:[  {
        tabsName: '全部',
        orderState:'',
        ordersList: []
      },
      {
        tabsName: '待发货',
        orderState:15,
        ordersList: []
      }]
    })
    this.getDataFun("");
  },

  ChangeTab(event){
    let indexSeled =Number(event.detail.index)
    this.setData({
      page:1, 
      activeSeled: indexSeled, 
      orderStatus:this.data.fatherList[indexSeled].orderState,
      fatherList:[  {
        tabsName: '全部',
        orderState:'',
        ordersList: []
      },
      {
        tabsName: '待发货',
        orderState:15,
        ordersList: []
      }]
    });
    this.getDataFun()
    this.goTop()
  },

  getDataFun(){
    console.log(this.data.activeSeled)
    var that =this;
    let postdata= {
      orderStatus: that.data.orderStatus,
        pageNum: that.data.page,
        pageSize: 10,
    }
    requestOrderList(postdata,).then((res) => {
      let resultData= res.data.list.map((item) => {
        return {
          ...item,
          orderAmount:centToYuan(item.orderAmount),
        };
      });
      setTimeout(() => {
        if(resultData.length < that.data.pageSize){
          this.setData({
              LoadingMore:true,
              noDataMore:false,
          })
        }




        that.data.fatherList[that.data.activeSeled].ordersList= that.data.fatherList[that.data.activeSeled].ordersList.concat(resultData)
        
        that.setData({ 
          fatherList: that.data.fatherList 
        });
        console.log(that.data.fatherList)
      }, 100);
    })
  },


  onReachBottom() {

    var that = this;
    if(that.data.noDataMore==true){
        this.setData({
          page: that.data.page + 1
        })

      this.getDataFun('')
    }
},
  

 



  goDetail(event){
    let itemData= event.currentTarget.dataset.bean;
    console.log(itemData)
    const BuildData = JSON.stringify(itemData);
    wx.navigateTo({ url: `/pages/editOrder/editOrder?detInfo=`+ encodeURIComponent(BuildData) });
  },
 

//   DelItemCustomer(event){
//     let that =this;
//     let itemData = event.currentTarget.dataset.bean
//     Dialog.confirm({
//         title: '',
//         message: '确定删除此条数据吗?',
//       })
//     .then(() => {
//         that.delItemFun(itemData)
//     })
//     .catch(() => {
//         wx.showToast({
//             icon: 'none',
//             title: '已取消',
//         })
//     });
// },

delItemFun(itemData){
  requestDelCustomer(itemData.id).then((res) => {
      wx.showToast({
          icon: 'none',
          title: '删除成功',
      })
      this.setData({
        page:1,
        customerList:[]
      })
      this.getDataFun()
  })
},

  // goEditCustomer(event){
  //   const itemData = event.currentTarget.dataset.bean;
  //   wx.navigateTo({ url: `/pages/editCustomer/editCustomer?detInfo=${JSON.stringify(itemData)}` });
  // },
  
  // // 点击单个商品
  // goAdd(e) {
  //   wx.navigateTo({ url: `/pages/editCustomer/editCustomer` });
  // },



 


});

上一篇下一篇

猜你喜欢

热点阅读