import request from '@/utils/request'

// 获取费用配置列表
export function listFeeConfigs(params) {
  return new Promise((resolve, reject) => {
    request({
      url: '/feeConfig.listFeeConfigs',
      method: 'get',
      params
    }).then(response => {
      const res = response.data
        resolve(res)
    }).catch(error => {
      reject(error)
    })
  })
}

// 添加费用配置
export function saveFeeConfig(data) {
  return new Promise((resolve, reject) => {
    request({
      url: '/feeConfig.saveFeeConfig',
      method: 'post',
      data
    }).then(response => {
      const res = response.data
        resolve(res)
    }).catch(error => {
      reject(error)
    })
  })
}

// 更新费用配置
export function updateFeeConfig(data) {
  return new Promise((resolve, reject) => {
    request({
      url: '/feeConfig.updateFeeConfig',
      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 deleteFeeConfig(data) {
  return new Promise((resolve, reject) => {
    request({
      url: '/feeConfig.deleteFeeConfig',
      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)
    })
  })
}