var t = getApp(),
  a = t.request,
  o = t.globalData.setting,
  os = o,
  i = require("../../../../../utils/util.js"),
  ut = i,
  s = require("../../../../../utils/common.js");
var regeneratorRuntime = require('../../../../../utils/runtime.js');
Page({
  data: {
    details:[],//数据
    isBind:true,//控制清空时间日期的按钮
    isBinds: true,
    height: '',
    pageSize: 10, 
    page: 1,
    height: '',
    datet:"",
    dates:"",
    current_page:0, 
    is_no_more:0,
  },
  //监听输入框显示清空按钮
  watchPassWord: function (event) {
    console.log("监听输入框显示清空按钮");
    var val = event.detail.value;
    console.log("是什么", val);
    if (val != "" && val != null) {
      var isBind = false;
      this.setData({ isBind: isBind });

    }
  },
 
   /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },
  //明细查询
  Gettime:function(e){
    var page= 0;
    //开始获取时间
    var th=this;
    var stime = th.data.datet;
    var etime = th.data.dates;
   
    console.log(stime, "开始结束" + etime );
     //开始获取时间结束
    console.log(stime, "结束开始", etime);
    //删除字符中的——
    var datatk = stime.replace(/[-]/g,"");
    console.log("aaa", datak);
    var dataj = etime.replace(/[-]/g, "");
    console.log("开始", datatk, "结束", dataj);
    //转换类型
    var datak = parseInt(datatk);
    var dataj = parseInt(dataj);
    console.log("sk", datak, "js", dataj);
    //判断初始时间小于结束时间
    if(datak>dataj){
      console.log("开始时间",datak,'结束时间',dataj,"时间判断",);
      getApp().showWarning("结束时间错误");
    }else{
      console.log(datak, dataj, "时间判断2");
      console.log("有进来吗", stime, etime);
      this.setData({ details: []});
      console.log("页数",this.data.page);
      this.setData({ current_page: 0 });
      this.lsmx();
    }

  },
  //流水明细
  async lsmx() {
   //if(this.data.is_no_more) return;
    this.data.current_page++;
    var stime = this.data.datet;
    var etime = this.data.dates;
    var user_id = getApp().globalData.user_id;
    var store_id = os.stoid;
    var e = this,
      details = ""; 
    var get_data = {
      user_id: user_id, store_id: store_id,
      pageSize:10, page: e.data.current_page
    };

    if (etime != "" && etime != null) {
      get_data.etime = etime;
    }

    if (stime != "" && stime != null) {
      get_data.stime = stime;
    }
    var big_arr=this.data.details;
  
    await getApp().request.promiseGet("/api/weshop/users/pageLiuDonGreCord", {
      data: get_data, isShowLoading:1
    }).then(res => {
      var details = res.data;

      if (!details || !details.data ||  !details.data.pageData ||  details.data.pageData.length== 0){
          this.data.is_no_more=1;
          getApp().showWarning("未找更多数据");
      
          return false;
      }

    var details=details.data.pageData;
        // console.log("不空", details);    
        //  console.log("长度", details.length);
        details.forEach(function(val,ind){
          big_arr.push(val);
        })
          setTimeout(() => {
            this.setData({
              details: big_arr
            });           
          }, 1500)
        
      
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },
  onShow: function () {
    
    this.lsmx();
    wx.setNavigationBarTitle({
      title: "流动资金明细 ",
    });
    wx.getSystemInfo({
      success: (details) => {
        this.setData({
          height: details.windowHeight
        })
      }
    })

  },
  // //---加载更多是靠这个函数----
  // onReachBottom: function () {
  
  //   this.lsmx();

  // },


  //起始时间
  bindDateChenge: function(e) {
    console.log("是什么", e.detail.value);
    var isBind = false;
    this.setData({
      datet: e.detail.value, isBind: isBind 
    });
  },
  // 结束时间
  bindDateChenges: function(e) {
    console.log("是什么", e.detail.value);
    var isBinds = false;
    this.setData({
      dates: e.detail.value, isBinds: isBinds 
    });
  },
  //catchtap阻止冒泡，点击清除开始时间的按钮
  eliminate:function(){
    console.log("试试");
    var isBind= true;
    var data="";
    this.setData({ datet: data, isBind: isBind})
  },
   //catchtap阻止冒泡，点击清除结束时间的按钮
  eliminates: function () {
    console.log("试试");
    var isBinds = true;
    var dates = "";
    this.setData({ dates: dates, isBinds: isBinds })
  },
})