import request from '@/utils/request'

/**
 * 查询缴费明细
 * @param {Object} params 查询参数
 * @returns {Promise} 
 */
export function queryPayFeeDetail(params) {
  return new Promise((resolve, reject) => {
    request({
      url: '/reportFeeMonthStatistics/queryPayFeeDetail',
      method: 'get',
      params
    }).then(response => {
      const res = response.data
      resolve({
        data: res.data,
        total: res.total,
        records: res.records,
        sumTotal: res.sumTotal || {}
      })
    }).catch(error => {
      reject(error)
    })
  })
}

/**
 * 导出缴费明细数据
 * @param {Object} params 导出参数
 * @returns {Promise}
 */
export function exportData(params) {
  return new Promise((resolve, reject) => {
    request({
      url: '/export.exportData',
      method: 'get',
      params
    }).then(response => {
      const res = response.data
      resolve(res)
    }).catch(error => {
      reject(error)
    })
  })
}

/**
 * 查询费用项列表
 * @param {Object} params 查询参数
 * @returns {Promise}
 */
export function listFeeConfigs(params) {
  return new Promise((resolve, reject) => {
    request({
      url: '/feeConfig.listFeeConfigs',
      method: 'get',
      params
    }).then(response => {
      const res = response.data
      resolve({
        feeConfigs: res.feeConfigs || []
      })
    }).catch(error => {
      reject(error)
    })
  })
}

/**
 * 查询小区列表
 * @param {Object} params 查询参数
 * @returns {Promise}
 */
export function listMyEnteredCommunitys(params) {
  return new Promise((resolve, reject) => {
    request({
      url: '/community.listMyEnteredCommunitys',
      method: 'get',
      params
    }).then(response => {
      const res = response.data
      resolve({
        communitys: res.communitys || []
      })
    }).catch(error => {
      reject(error)
    })
  })
}