import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    name: '这里是全局的',
    equipmentAll: [],
    projectArr: [
      { projId: 'Pj1101080001', secret: '123', projLocalName: '新华创新大厦' },
      { projId: 'Pj1101080001', secret: '123', projLocalName: '广联达二期' },
      { projId: 'Pj1101010001', secret: '123', projLocalName: '北京中海地产广场' },
      { projId: 'Pj1101020001', secret: 'saga123456', projLocalName: '广电国际酒店' }
    ],
    projId: 'Pj4419000005',
    secret: "",
    baseUrl: "http://api.sagacloud.cn/dp-auxiliary"
  },
  getters: {
    projectArr: state => state.projectArr
  },
  mutations: {
    setProId (state, projectId) {
      state.projId = projectId
    },
    setSecret (state, secret) {
      state.secret = secret
    },
    setEquipmentAll (state, {equipmentAll}) {
      state.equipmentAll = equipmentAll
    }
  },
  actions: {
    loadEquipmentAll (context) {
      axios.get(`/data-platform-3/dict/query/equipment_all`).then(res => {
        let data = res.data
        if (data.Result === 'success') {
          // context.state.equipmentAll = data.Content
          context.commit('setEquipmentAll', {equipmentAll: data.Content})
        }
      })
    }
  },
  modules: {
  }
})

export default store
