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

export default {
  namespaced: true,
  state: {
    orgId: '1',
    CaseList: []
  },
  mutations: {
    init (state, data) { // 这里的state对应着上面这个state
      state.orgId = '2'
    },
    setCaseList (state, data) { // 设置案场信息
      state.CaseList = data
    },
  },
  actions: {
    updateLocationInfo (context) { // 这里的context和我们使用的$store拥有相同的对象和方法
      return new Promise((resolve) => {
        Ajax(api.index.cms.location.url, {
          method: api.index.cms.location.method
        }).then(res => {
          context.commit('init', res)
          resolve()
        })
      })
    },
    getCaseList (context) { // 获取案场信息
      return new Promise((resolve) => {
        Ajax(api.user.getCaseList.url, {
          method: api.user.getCaseList.method
        }).then(res => {
          context.commit('setCaseList', res.cases)
          resolve(res)
        })
      })
    }
  }
}
