import { createStore } from 'vuex'

export default createStore({
  state: {
    stateTagsList: [],
    user: {},
    menuList: [],
    token: '',
    verifier: '',
    stand: {},
    kittingWork: {
      workOrder: '',
      productId: '',
      singleProduct: '',
      boxNo: ''
    },
  },
  getters: {
    getStateTagsList(state) {
      return state.stateTagsList
    },
    getUser(state) {
      return state.user
    },
    getUserName(state) {
      return state.user.userName
    },
    getMenuList(state) {
      return state.menuList
    },
    getToken(state) {
      return state.token
    },
    getVerify(state) {
      return state.verifier
    },
    getStand(state) {
      return state.stand
    },
    getStandId(state) {
      return state.stand.standId
    },
    getKittingWork(state) {
      return state.kittingWork
    },
  },
  mutations: {
    /**
   * 选择tag标签
   */
    mutationSelectTags(state, data) {
      let result = false
      for (let i = 0; i < state.stateTagsList.length; i++) {
        if (state.stateTagsList[i].path == data.path) {
          return result = true
        }
      }
      result === false ? state.stateTagsList.push(data) : ''
    },

    /**
     * 关闭tag标签
     */
    mutationCloseTag(state, data) {
      let result = state.stateTagsList.findIndex(item => item.path === data.path)
      state.stateTagsList.splice(result, 1)
    },

    /**
     * 存储用户信息
     */
    mutationUser(state, data) {
      state.user = data
      sessionStorage.setItem("user", state.user)
    },

    /**
     * 存储菜单信息
     */
    mutationMenu(state, data) {
      state.menuList = data
      // sessionStorage.setItem("menuList", state.menuList)
    },

    /**
     * 存储站台信息
     */
    mutationStand(state, data) {
      state.stand = data
      // sessionStorage.setItem("stand", state.stand)
    },

    /**
     * 存储站台配料信息
     */
    mutationKittingWork(state, data) {
      state.kittingWork = data
      // sessionStorage.setItem("kittingWork", state.kittingWork)
    },

    /**
     * 存储认证
     */
    mutationAddVerify(state, data) {
      state.verifier = data
    },

    mutationClearVerify(state) {
      state.verifier = ''
    },
  },
  actions: {
  },
  modules: {
  }
})
