import { current } from '@/api/ClientInfo'
import { findCurrentAcquisitionStation } from '@/api/AcquisitionStation'

// 八分场底牌车间200立方

const company = {
  state: {
    systemTitle: 'JG-ADC工业生产监测系统',
    clientCode: '',
    companyName: '',
    factoryName: '',
    acquisitionStationId: null,
    acquisitionStation: {},
    workshop: '',
  },

  mutations: {
    SET_ACQUISITION_STATION_ID: (state, payload) => {
      state.acquisitionStationId = payload
    },
    SET_ACQUISITION_STATION: (state, payload) => {
      state.acquisitionStation = payload
    },
    SET_WORKSHOP_NAME: (state, payload) => {
      state.workshop = payload
    },
    SET_CLIENT_CODE: (state, payload) => {
      state.clientCode = payload.code
      state.companyName = payload.company
      state.factoryName = payload.desc
    },
  },

  actions: {
    getClientCode({ commit }) {
      current().then(res => {
        if (res && res.code === '200') {
          commit('SET_CLIENT_CODE', res.data)
        }
      })
      findCurrentAcquisitionStation().then(res => {
        commit('SET_ACQUISITION_STATION_ID', res.data.id)
        commit('SET_ACQUISITION_STATION', res.data)
        commit('SET_WORKSHOP_NAME', res.data.name)
      })
    },
  }
}

export default company
