import { fetchBillList, billUploadExcelAdd, updateBillStatus, deleteBillBeach, billDownloadExcel, getBillInfoBydId } from '@/api/bill'

const transaction = {
  namespaced: true,
  state: {
    total: '',
    billList: []
  },

  mutations: {
    SET_LIST: (state, list) => {
      state.billList = list
    },
    SET_TOTAL: (state, total) => {
      state.total = total
    }
  },

  actions: {
    // 获取收费组列表
    FetchBillList({ commit }, listQuery) {
      return new Promise((resolve, reject) => {
        fetchBillList(listQuery).then(response => {
          const data = response.data
          commit('SET_LIST', data.list)
          commit('SET_TOTAL', data.total)
          resolve()
        }).catch(error => {
          reject(error)
        })
      })
    },
    BillUploadExcelAdd({ commit }, data) { // 上传缴费项接口, 保存
      return new Promise((resolve, reject) => {
        billUploadExcelAdd(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    UpdateBillStatus({ commit }, data) { // 根据 id 修改缴费项状态
      return new Promise((resolve, reject) => {
        updateBillStatus(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    DeleteBillBeach({ commit }, data) { // 根据 id集合 删除缴费项
      return new Promise((resolve, reject) => {
        deleteBillBeach(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    BillDownloadExcel({ commit }) { // 下载Excel模板
      return new Promise((resolve, reject) => {
        billDownloadExcel().then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    GetBillInfoBydId({ commit }, id) { //  根据收费项ID查询,收费项详情
      return new Promise((resolve, reject) => {
        getBillInfoBydId(id).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default transaction
