let util = require('../../../../utils/util')
let apiArr = require('../../../../api/water_filter')
// packages/partner/pages/income/income.js
const __staticUrl = require('../../../../config/env.js').static_url
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabIndex:0,
    SelectDate:[],
    page_size:10,
    page_num:1,
    flag:false,
    orderList:[],
  },

  getBanlance(){
    let that = this
    wx.showLoading({
      title: '加载中...',
      mask:true
    })
    util.postUrl(apiArr.getOrderBuyList,{
        pay_time:that.data.SelectDate,
        dealer_id:wx.getStorageSync('dealer_id'),
        page_size:that.data.page_size,
        page_num:that.data.page_num
    },res=>{
        wx.hideLoading()
        console.log(res);
        let flag = false
        if(!res.rows){
            return
        }
        if(that.data.page_size == res.rows.length){
            flag = true
        }else{
            flag = false
        }
        that.setData({
            orderList:that.data.orderList.concat(res.rows || []),
            page_num:that.data.page_num + 1,
            flag,
        })
    })
  },

  changeIndex(e){
    let that = this
    let SelectDate
    if(e.currentTarget.dataset.index == '0'){
        if(wx.getStorageSync('SelectDate')){
            SelectDate = wx.getStorageSync('SelectDate')
        }else{
            SelectDate = []
        }
    }else{
        SelectDate = []
    }
    that.setData({
        tabIndex:e.currentTarget.dataset.index,
        SelectDate,
        page_num:1,
        flag:false,
        orderList:[]
    })
    that.getBanlance()
  },
  detail(){
      wx.navigateTo({
        url: '../incomeDetail/incomeDetail',
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this
    let SelectDate = wx.getStorageSync('SelectDate')
    if(SelectDate){
        that.setData({
            SelectDate
        })
    }

    that.getBanlance()
    wx.showShareMenu({
        withShareTicket: true,
        menus: ['shareAppMessage', 'shareTimeline']
    })
  },

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

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    console.log(123);
    let that = this
    if(that.data.flag){
        that.getBanlance()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage(){
    return {
        title: '人人爱净水',  // 分享卡片标题（必填）
        path: '/pages/water_filter/water_filter',  // 用户点击后跳转的路径（可选，默认当前页）
        imageUrl: (__staticUrl + '/share.png')  // 自定义图片（可选，比例建议 5:4）
      }
},
onShareTimeline() {
    return {
        title: '人人爱净水', // 自定义标题
        query: '', // 自定义页面路径中的参数
        imageUrl: (__staticUrl + '/share.png') // 自定义分享图片路径
    }
},
})