import { getHardData, getSignUser } from '@/api/index'

const trunkIndex = {
  namespaced: true,
  state: {
    trunkIndex: {
      hardData: null,
      signUser: null
    }
  },
  mutations: {
    upDateHardData: (state, data) => {
      state.trunkIndex.hardData = data
    },
    upDateSignUser: (state, data) => {
      state.trunkIndex.signUser = data
    }
  },
  actions: {
    // 硬件数据统计
    GetHardData({ commit }) {
      return new Promise((resolve, reject) => {
        getHardData().then(response => {
          const data = response.data
          commit('upDateHardData', data)
          resolve()
        }).catch(error => {
          reject(error)
        })
      })
    },

    // 注册用户统计
    GetSignUser({ commit }) {
      return new Promise((resolve, reject) => {
        getSignUser().then(response => {
          const data = response.data
          commit('upDateSignUser', data)
          resolve(data)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default trunkIndex
