const app = getApp()
const navigationBarHeight = (getApp().statusBarHeight + 50) + "px"
const Http = require("../../utils/HttpBasics");
let config = require("../../config/config.js");
const util = require("../../utils/util")
Page({
  data: {
    navigationBarHeight,
    boatLsit:[
      {
        name:"全部",
        value:"all"
      },
      {
        name:"待付款",
        value:"0"
      },
      {
        name:"已完成",
        value:"1"
      },
    ],
    boatFlag:"all",
    content:"",
    loading: false, //"上拉加载"的变量，默认false，隐藏
    pageNum:1,
    allow_load: true,
    list:[]
  },
  setBoatFlag(e){
    let index = e.currentTarget.dataset.index
    console.log(index);
    this.setData({
      boatFlag:index,
      pageNum:1,
      allow_load: true,
    })
    this.getList()
  },
  getList(){
    let that = this
    if (that.data.allow_load) {
      that.setData({
        loading: true,
        content: '小主,我在玩命加载中...'
      })

      Http.get({
        url:config.api.orderList,
        data:{
          pageNum:that.data.pageNum,
          pageSize: 10,
          orderStatus:that.data.boatFlag=="all"?"":that.data.boatFlag,
          paymentType: 0,
          
        }
      }).then(res=>{
        if(that.data.pageNum==1){
          that.setData({
            list: []
          })
        }
        
        let tempArr= that.data.list
        tempArr.map(item=>{
          item.createDate = util.formatTime(item.createDate, "yyyy-MM-dd hh:mm:ss");
        })
        if(that.data.pageNum>=res.data.pages){
          that.setData({
            allow_load: false
          })
        }
        
        if(that.data.pageNum>1){//分页
          that.setData({
            list:[...tempArr ,...res.data.list],
            loading:false
          })
        }else{
          let tempLsit = res.data.list
          tempLsit.map(item=>{
            item.createDate = util.formatTime(item.createDate, "yyyy-MM-dd hh:mm:ss");
          })

          that.setData({
            list: tempLsit,
            loading:false
          })
        }
      }).catch(err => {
        that.setData({
          loading:false
        })
        tt.showToast({
          title: err.message ? err.message : err.data, // 内容
          icon: "none"
        });
      })
    }else {
      that.setData({
        loading: true,
        content: "——— 再拉裤子就掉了啦 ———"
      })
      setTimeout(function () {
        that.setData({
          loading: false,
        })
      }, 1400)
    }
    
  },
  onLoad: function (options) {
    // this.getList()
  },
  onReachBottom(){//触底
    console.log(111);
    this.setData({
      pageNum:this.data.pageNum+1
    })
    this.getList()
   },
   onShow:function(){
     this.getList()
   }
})