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

const trunkIndex = {
  namespaced: true,
  state: {
    trunkIndex: {
      hardData: null,
      signUser: null,
      IndexInfo: null,
    }
  },
  mutations: {
    upDateHardData: (state, data) => {
      state.trunkIndex.hardData = data
    },
    upDateSignUser: (state, data) => {
      state.trunkIndex.signUser = data
    },
    upDateIndexCount: (state, data) => {
      state.trunkIndex.IndexInfo = 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)
        })
      })
    },
    // 首页图表数据
    getIndexCount({ commit }) {
      return new Promise((resolve, reject) => {
        getIndexCount().then(response => {
          const data = response.data;
          commit('upDateIndexCount', data)
          resolve(data)
        }).catch(error => {
          reject(error)
        })
      })
    },

  }
}

export default trunkIndex
