import apis from '../utils/request';
import { getConfigByEnv } from "../utils/index"
const { GET, POST, PUT, DELETE } = apis

// 获取电费账单列表
export const getBillList = async function(page) {
  const tenement = wx.getStorageSync('tenement')?.id || ""
  return await GET(`/wx/getBillList?tenement=${tenement}&page=${page}`);
}

// 电量查询
export const getElectricityList = async function({ meter, type, time, page }) {
  const tenement = wx.getStorageSync('tenement')?.id || ""
  return await GET(`/wx/getElectricityList?tenement=${tenement}&meter=${meter}&type=${type}&time=${time}&page=${page}`);
}

// 抄表记录列表
export const getMeterReadingList = async function({ id = '', time, page }) {
  const tenement = wx.getStorageSync('tenement')?.id || ""
  return await GET(`/wx/getMeterReadingList?tenement=${tenement}&meter=${id}&page=${page}&readAt=${time}`);
}
// 账务余额列表
export const getAccountingList = async function(meter) {
  const tenement = wx.getStorageSync('tenement')?.id || ""
  return await GET(`/wx/getAccountingList?tenement=${tenement}&meter=${meter}`);
}

// 导出电量查询
export const exportElectricityList = async function({ meter, type, time }) {
  const tenement = wx.getStorageSync('tenement')?.id || ""
  const { api } = getConfigByEnv();
  return new Promise(resolve => {
    wx.downloadFile({
      url: `${api}/wx/getElectricityList/export?tenement=${tenement}&meter=${meter}&type=${type}&time=${time}`,
      success(res) {
        console.log('请求成功结果', res)
        resolve(res)
      },
      fail(err) {
        console.log('err', err)
      }
    })
  })
}