// mine/pages/settlement/settlement.js
const Api = require("../../../utils/util")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loadStatus: 'more',   
    filterOpen: false,
    params:{
			// orderCode:'',
			// startDate:'',
      // endDate:'',
			pageNum:1,
			pageSize:10
    },
    listData: [{
      id: 1,
      totalCost: 1000,
      orderNumber: '2558001455477',
      type: 1,
      applianceProdInfo: '122121'
    }],
    //时间查询    
		isPickerShow: false,
		pickerConfig: {
		  endDate: true,
		}    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // this.getList()
  },

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

  },
  //数据列表
  getList(){
    let params = this.data.params
    let list = this.data.listData
    Api.findFactorySettlemenPage(params).then((res) => {
      if(res.code === 200){
        if (params.pageNum == 1) {
          list = []
        }
        list = list.concat(res.rows) //拼接下一页
        if (res.rows.length == params.pageSize) { //判断是否有下一页
          params.pageNum++
        }        
        this.setData({
          loadStatus: res.rows.length == params.pageSize ? "more" : "noMore",
          listData: list,
          triggered: false,
          params
        })
      }    
    })
  },
  //下拉刷新
  Pulldownrefresh(){
    this.setData({
      [`params.pageNum`]: 1,
      loadStatus: 'more'
    })    
    this.getList()
  },
  //加载更多
  more(){
    if (this.data.loadStatus != 'noMore') {
      this.getList()
    }
  },  
  /** 结算时间 **/
	pickerShow: function() {
		let now = new Date(),
			year = now.getFullYear(),
			month = now.getMonth() + 1,
			day = now.getDate(),
			initStartTime = year+ '-' + month + '-' + day;
		let pickerConfig = this.data.pickerConfig, params = this.data.params;
		pickerConfig.initStartTime = params.startDate != '' ?  params.startDate : initStartTime;
		pickerConfig.initEndTime = params.endDate != '' ? params.endDate : initStartTime;
		this.setData({
		  pickerConfig:pickerConfig,
		  isPickerShow: true
		});
	},

  pickerHide: function() {
		this.setData({
		  isPickerShow: false
		});
  },
  setPickerTime: function(val) {
		// console.log(val);
		let data = val.detail, params = this.data.params;
		params.pageNum = 1;
		params.startDate = data.startTime.substring(0,data.startTime.indexOf(' ') + 1);
		params.endDate = data.endTime.substring(0,data.endTime.indexOf(' ') + 1);
		this.setData({
      params:params,
      payTime: params.startDate + '~' + params.endDate
		});	
  },
  //打开筛选
  openWin(){
    this.setData({
      filterOpen: true
    })
  },
  //关闭筛选
  closeWin(){
    this.setData({
      filterOpen: false
    })
  }
})