// pages/finance/detailed_incomeAndExpenditurePublic/detailed_incomeAndExpenditurePublic.js
import * as UTIL from '../../../utils/util.js';
import * as API from '../../../utils/API.js';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isIPX: app.globalData.isIPX,
    expressionOptions:[],
    // 格数据
    loading: false,
    finished: false,
    pageDataList: [],
    searchDate: {
      bookDate: "",
      templateName: '收支公开榜',
      signature: false, // 添加底部落款
    },
    // 查询参数
    queryParams: {
      // 分页
      pageNum: 1,
      pageSize: 50,
      startYyyy_MM: null,
      endYyyy_MM: null,
      title: '收支公开榜',
      combineTitle: false,
      // 查询排序
      //orderByColumn: "id",
      //isAsc: "desc",
    },

    list: [],
    accountingYear: "",
    accountingMonth: "",
    // 显示搜索条件
    visible: false,
    showPickerTime: false,

    minDate: new Date(2020, 0, 1),
    maxDate: new Date().getTime(),
    currentDate: new Date(),
    date:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    UTIL.httpRequest(API.getLoginBook,{}, {
      success: (res) => {
        if (res.code == API.SUCCESS_CODE) {
          let currentDays = res.data.currentDay;
          if (currentDays == null) {
            UTIL.showToastNoneIcon("当前账套未开启!");
            return false;
          }

          let mindate = res.data.startDay.split('-')
          let dealDays = currentDays.split("-");
          this.setData({
            accountingYear:dealDays[0],
            accountingMonth:dealDays[1],
            date: dealDays[0]+'年'+dealDays[1]+'月',
            ['searchDate.bookDate']:currentDays,
            ['queryParams.startYyyy_MM']:res.data.currentDay,
            ['queryParams.endYyyy_MM']:res.data.currentDay,
            minDate: new Date(mindate[0],mindate[1]-1).getTime(),
            ['queryParams.deptId']:JSON.parse(wx.getStorageSync('user')).loginDeptId,
            ['queryParams.bookType']:JSON.parse(wx.getStorageSync('user')).bookType,
            ['queryParams.bookId']:JSON.parse(wx.getStorageSync('user')).loginBookId,
            bookName:JSON.parse(wx.getStorageSync('user')).bookName,
          })
          this.initPage()
        }
      }
    })
  },
  initPage() {
    var that = this;
    UTIL.httpRequest(API.financialIncomeExpenditurePublic,this.data.queryParams, {
      success: (res) => {
          this.setData({
            pageDataList:res.rows,
            total:res.total
          })
      }
    });
  },
  onConfirm(time) {
    console.log(time.detail);
    let date = UTIL.formatDates(time.detail).split('-');
    this.setData({
      date:date[0] + '年' + date[1] + '月',
      ['queryParams.startDate']:UTIL.formatDates(time.detail),
      showPickerTime : false
    })
    this.getList();
  },
  back:function(){
    wx.navigateBack({
      delta: 1
    })
  },
  openPick(){
    this.setData({
      showPickerTime:true
    })
  },
  closePick(){
    this.setData({
      showPickerTime:false
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})