美文网首页
2023-05-31

2023-05-31

作者: 糖醋里脊120625 | 来源:发表于2023-05-30 17:24 被阅读0次
    
    import { requestOrderList,requestDeliveryList, requestCancelOrder,requestOrderPrint } from '../../http/orderListApi'
    
    import { centToYuan } from '../../unit/priceUtil'
    import Toast from '@vant/weapp/toast/toast';
    import Dialog from '@vant/weapp/dialog/dialog';
    var dayjs = require('dayjs')
    Page({
      data: {
        LoadingMore: true,
        noDataMore:false,
        page:1,
        size:10,
        tabTop: '0',
        navInfo:{},
        customerList: [],
        current: 1,
        autoplay: true,
        valueKey: "",
        interval: 5000,
        navigation: { type: 'dots' },
        activeSeled:0,
        orderStatus:15,
        fatherList: [
              {
                tabsName: '待发货',
                orderState:15,
                ordersList: []
              },
              {
                tabsName: '已发货',
                orderState:'hasSend',
                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({
          
          fatherList:[  {
            tabsName: '待发货',
            orderState:15,
            ordersList: []
          },
          {
            tabsName: '已发货',
            orderState:'hasSend',
            ordersList: []
          }]
        })
        this.getDataFun("");
      },
    
      ChangeTab(event){
        
        let indexSeled =Number(event.detail.index)
        this.setData({
          page:1, 
          LoadingMore:true,
          noDataMore:false,
          activeSeled: indexSeled, 
          orderStatus:this.data.fatherList[indexSeled].orderState,
          fatherList:[  {
            tabsName: '待发货',
            orderState:15,
            ordersList: []
          },
          {
            tabsName: '已发货',
            orderState:'hasSend',
            ordersList: []
          }]
        });
    
        
        this.getDataFun()
        this.goTop()
      },
    
      getDataFun(){
        console.log(this.data.activeSeled)
        var that =this;
        let postdata= {
            pageNum: that.data.page,
            pageSize: 10,
        }
    
        let PromiseReault;
        if(this.data.fatherList[that.data.activeSeled].orderState==15){
          PromiseReault = requestOrderList({...postdata,orderStatus: that.data.orderStatus,});
        }
        if(this.data.fatherList[that.data.activeSeled].orderState=='hasSend'){
          
          PromiseReault = requestDeliveryList({...postdata});
        }
        PromiseReault.then(res => {
          console.log(res)
          let resultData= res.data.list.map((item) => {
            return changeItem(item)
            
          });
    
          function changeItem(item){
            var objItem={};
            if(that.data.fatherList[that.data.activeSeled].orderState==15){
              objItem={
                ...item,
                orderAmount:centToYuan(item.orderAmount),
                goodsName:item.details.map((item) => {
                  return item.productName
              }).join(", "),
              }
            }else{
              objItem={
                goodsName:item.details.map((item) => {
                  return item.productName
              }).join(", "),
                orderNo:item.orderNo,
                ordSupplyDate:dayjs(item.delSupplyDate).format('YYYY-MM-DD'),
                ordSupplierName:item.enterpriseName, 
                orderAmount:centToYuan(item.delAmount),
              }
            }
            return objItem;
          }
          setTimeout(() => {
            console.log(resultData.length)
            if(resultData.length < 10){
              that.setData({
                  LoadingMore:false,
                  noDataMore:true,
              })
    
            }
            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);
          
        }).finally(() => {
         // this.editSaveLoading = false;
        });
      },
    
    
      onReachBottom() {
        
        var that = this;
        console.log(that.data.noDataMore)
        if(that.data.noDataMore==false){
            this.setData({
              page: that.data.page + 1
            })
    
          this.getDataFun('')
        }
    },
      
    
     
    
    goRemove(event){
      let itemData= event.currentTarget.dataset.bean;
      let that =this;
      console.log(itemData)
      Dialog.confirm({
        title: '提示',
        message: '确定取消此订单吗',
      })
      .then(() => {
        that.ClearOrder(itemData)
      })
      .catch(() => {
        // on cancel
      });
    },
    
    ClearOrder(itemData){
      let that =this;
      requestCancelOrder(itemData.ordId).then((res) => {
    
        if(res.status=="success"){
            Toast('提交成功!');
            this.setData({
              page:1, 
              LoadingMore:true,
              noDataMore:false,
              activeSeled: that.data.activeSeled, 
              orderStatus:this.data.fatherList[that.data.activeSeled].orderState,
              fatherList:[  {
                tabsName: '待发货',
                orderState:15,
                ordersList: []
              },
              {
                tabsName: '已发货',
                orderState:'hasSend',
                ordersList: []
              }]
            });
        
            
            that.getDataFun()
            that.goTop()
        }
    
    })
    },
    
      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) });
      },
     
    
    
    
      // 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` });
      // },
    
    
    
     
    
    
    });
    
    

    相关文章

      网友评论

          本文标题:2023-05-31

          本文链接:https://www.haomeiwen.com/subject/bdleedtx.html