import { fetchList, transactionById, updateTransactionById, transactionsList, transactionsAdd, transactionsEdit, transactionsDelete, transactionReplyList, deleteReply, transactionReplyAdd, transactionReportList } from '@/api/transaction'

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

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

  actions: {
    // fetchList,获取社区列表
    FetchTransactionList({ commit }, listQuery) {
      return new Promise((resolve, reject) => {
        fetchList(listQuery).then(response => {
          const data = response.data
          commit('SET_LIST', data.list)
          commit('SET_TOTAL', data.total)
          resolve()
        }).catch(error => {
          reject(error)
        })
      })
    },
    TransactionById({ commit, state }, id) { // 查询二手租赁详情
      return new Promise((resolve, reject) => {
        transactionById(id).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    UpdateTransactionById({ commit, state }, id) {
      return new Promise((resolve, reject) => {
        updateTransactionById(id).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    TransactionsList({ commit }, data) {
      return new Promise((resolve, reject) => {
        transactionsList(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    TransactionsAdd({ commit }, data) {
      return new Promise((resolve, reject) => {
        transactionsAdd(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    TransactionsEdit({ commit }, data) {
      return new Promise((resolve, reject) => {
        transactionsEdit(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    TransactionsDelete({ commit }, data) {
      return new Promise((resolve, reject) => {
        transactionsDelete(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    TransactionReplyList({ commit }, data) {
      return new Promise((resolve, reject) => {
        transactionReplyList(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    DeleteReply({ commit }, data) {
      return new Promise((resolve, reject) => {
        deleteReply(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    TransactionReplyAdd({ commit }, data) {
      return new Promise((resolve, reject) => {
        transactionReplyAdd(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    TransactionReportList({ commit }, data) {
      return new Promise((resolve, reject) => {
        transactionReportList(data).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default transaction
