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: {
    
    val: false,
    color: "",
    details: [], //数据
    isBind: true, //控制清空时间日期的按钮
    isBinds: true,
    select: false, //下拉框控制器
    grade_name: '全部', //下拉框参数
    grades: [
      "全部",
      '支出',
      '收入',
    ],
    datet: "",
    dates: "",
    result: [],
    money: 0,
    oddNumbers: "",
    pageSize: 10,
    page: 1,
    current_page: 0,
    //is_no_more: 0,
  },


  /**
      * 生命周期函数--监听页面显示
      */
  onShow: function (options) {
    wx.setNavigationBarTitle({
      title: "积分明细",
    })
    this.init();
  },
  //监听输入框显示清空按钮
  watchPassWord: function(event) {
    console.log("监听输入框显示清空按钮");
    var val = event.detail.value;
    console.log("是什么", val);
    if (val != "" && val != null) {
      var isBind = false;
      this.setData({
        isBind: isBind
      });

    }
  },
  /**
   *  点击下拉框
   */
  bindShowMsg() {
    console.log(!this.data.select);
    this.setData({
      select: !this.data.select
    })
  },
  /**
   * 已选下拉框
   */
  mySelect(e) {
    console.log(e)
    var name = e.currentTarget.dataset.name
    this.setData({
      grade_name: name,
      select: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    
  },
  //明细查询
  Gettime: function (e) {
    var page = 0;
    //开始获取时间
    var th = this;
    var datet= th.data.datet;
    var dates= th.data.dates;
    console.log(datet, "开始结束", dates);
    //删除字符中的——
    var datatk = datet.replace(/[-]/g, "");
    //转换类型
    var datak = parseInt(datatk);
    //删除字符中的——
    var dataj = dates.replace(/[-]/g, "");
    //转换类型
    var dataj = parseInt(dataj);
    
    // if (typeof(BeginDate)!="undefined"){
    //     //删除字符中的——
    //   var datatk = BeginDate.replace(/[-]/g, "");
    //   //转换类型
    //    datak = parseInt(datatk);
    //   console.log(typeof datak, "开始数据类型", datak)
    // }

    // if (typeof(EndDate)!="undefined") {
    //   //删除字符中的——
    //   var dataj = EndDate.replace(/[-]/g, "");
    //   //转换类型
    //   dataj = parseInt(dataj);
    //   console.log(typeof dataj, "结束据类型", dataj)
    // }
    console.log("开始", datak, "结束", dataj);
    //判断初始时间小于结束时间
    if (datak > dataj) {
      console.log("开始时间", datak, '结束时间', dataj, "时间判断");
      getApp().showWarning("结束时间错误");
      this.setData({ details: [] });
    } else {
      this.setData({ details: [] });
      console.log(datak, dataj, "时间判断2");
      console.log("有进来吗", datet, dates);
      this.setData({ current_page: 0 });
      this.init();
    }
   
  },

  async init() {
   // if (this.data.is_no_more) return;
    this.data.current_page++;
    var BeginDate = this.data.datet;
    var EndDate = this.data.dates;
    var user_id = getApp().globalData.user_id;
    var store_id = os.stoid;
    var tpye = this.data.grade_name;
    console.log("是是啊", tpye);
    var e = this,
      details = "";
    var get_data = {
      user_id: user_id, store_id: store_id,
      pageSize: 10, page: e.data.current_page
    };
    // 判断下拉框，添加类型
    if (tpye == "全部") {
      console.log("全部", tpye);
      get_data.FInregral = null;
    } else if (tpye == "支出") {
      console.log("支出");
      get_data.FInregral = 0;
    } else {
      console.log("收入");
      get_data.FInregral = 1;
    }
    if (EndDate != "" && EndDate != null) {
      get_data.EndDate = EndDate;
    }

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

        var details = res.data;




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

       var details = details.data.pageData;


        details.forEach(function (val, ind) {
          big_arr.push(val);
        })
        setTimeout(() => {
          this.setData({
            details: big_arr
          });
        }, 1500)


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

  // },

  //起始时间
  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
    })
  }

})