import request from '@/utils/request'

// 保存业主发票信息
export function saveOwnerInvoice(data) {
  return new Promise((resolve, reject) => {
    request({
      url: '/invoice.saveOwnerInvoice',
      method: 'post',
      data
    }).then(response => {
      const res = response.data
      if (res.code === 0) {
        resolve(res)
      } else {
        reject(new Error(res.msg || '保存发票信息失败'))
      }
    }).catch(error => {
      reject(error)
    })
  })
}

// 查询业主列表
export function queryOwners(params) {
  return new Promise((resolve, reject) => {
    request({
      url: '/owner.queryOwners',
      method: 'get',
      params
    }).then(response => {
      const res = response.data
      if (res.code === 0) {
        resolve({
          data: res.data,
          total: res.total
        })
      } else {
        reject(new Error(res.msg || '查询业主失败'))
      }
    }).catch(error => {
      reject(error)
    })
  })
}