import { getBillList } from "../../service/accounting"
import { alertInfo, loadingFunc } from "../../utils/index";
import request from '../../utils/request'
const { OK } = request;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    list: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const that = this;
    loadingFunc(async () => {
      await that.init();
    })

  },
  async init() {
    const { page, list } = this.data;
    const { code, data, message } = await getBillList(page)
    if (code !== OK) {
      alertInfo(message)
      return;
    }
    if (!data?.length) {
      alertInfo("没有更多了")
      return;
    }
    this.setData({
      list: [...list, ...data],
      page: page + 1,
    })
  },
  jumpToDetail(e) {
    const { id: report } = e.currentTarget.dataset
    const tenement = wx.getStorageSync('tenement')?.id || ""
    wx.navigateTo({
      url: `/childPackage/pages/billDetail/index?id=${report}&tenement=${tenement}`,
    })
  },
})