import Ajax from '../../util/ajax'
import api from '../../util/api'

// 请求数据
export default {
  namespaced: true,
  state: {
    caseTotal: {},
    caseConf: {},
    choosedCase: {}
  },
  mutations: {
    setCaseTotal (state, data) { // 获取案场下单数量信息
      state.caseTotal = data
    },
    setCaseConf (state, data) { // 获取案场下单数量信息
      state.caseConf = data
    },
    setChoosedCase (state, data) { // 获取案场下单数量信息
      state.choosedCase = data
    },
  },
  actions: {
    getCaseTotal ({ commit }, { caseid }) {
      return new Promise((resolve, reject) => {
        Ajax(api.case.total.url, {
          method: api.case.total.method,
          urlData: {
            caseid
          }
        }).then(res => {
          commit("setCaseTotal", res)
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    },
    getCaseConf ({ commit }, { caseid }) {
      return new Promise((resolve, reject) => {
        Ajax(api.case.conf.url, {
          method: api.case.conf.method,
          urlData: {
            caseid
          }
        }).then(res => {
          commit("setCaseConf", res)
          resolve(res)
        }).catch((err) => {
          reject(err)
        })
      })
    },
    changeChoosedCase ({ commit }, data) {
      commit("setChoosedCase", data)
    }
  }
}