// pages/invoiceList/components/already/index.js
import { getAlreadyInvoiceList } from "../../../../service/invoice"
import { alertInfo, loadingFunc } from "../../../../utils/index";
import request from '../../../../utils/request'
const { OK } = request;
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    page: 1,
    list: []
  },
  onRefresh() {
    this.getList();
  },
  lifetimes: {
    attached() {
      this.getList();
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    async getList() {
      const { page, list = [] } = this.data;
      const { code, message, data } = await getAlreadyInvoiceList(page);
      if (!data.length) {
        alertInfo("没有更多数据了")
        return
      }
      this.setData({
        list: [...list, ...data, ],
        page: page + 1,
      })
    },
    refresh() {
      const that = this;
      that.setData({
        page: 1,
        list: []
      }, () => {
        loadingFunc(() => that.getList())
      })
    },
    onRefresh() {
      loadingFunc(() => this.getList())
    },
    scrollToLower() {
      loadingFunc(() => this.getList())
    },
    jumpToDetail(e) {
      const { id } = e.currentTarget.dataset;
      wx.navigateTo({
        url: '/pages/invoiceDetail/index?id=' + id,
      })
    },
    jumpToDetailContent(e) {
      const { id } = e.currentTarget.dataset;
      wx.navigateTo({
        url: '/pages/invoiceDetailContent/index?id=' + id,
      })
    }
  }
})