import Vue from 'vue'
import Vuex from 'vuex'
// [ seedSheedSource, seedSheedLevel, seedSheedStatus ]
import publicType from './publicType.js' // 公共的类型 

import { reqWorkerList, reqBuildList } from "@/api/fileInfo.js";


Vue.use(Vuex)

export default new Vuex.Store({
	strict: true,
	state: {
		token: localStorage.getItem("token"),
		workerList: [{id:1}], // 员工列表 (加{id:1} 是为了防止刷新时报错，因为设置默认值时用到过)
		areaList: [{id:1}],
		...publicType
	},
	getters: {},
	mutations: {
		
		setWorkerList(state, workerList) {
			state.workerList = workerList
		},
		setAreaList(state, areaList) {
			state.areaList = areaList
		}
	},
	actions: {
		/* 获取员工列表 登录后再 home、workerInfo时调用了*/
		getWorkerList({ commit }) {
			reqWorkerList({
				searchStr: '',
				pageSize: 1000,
				pageNum: 1
			}).then(res => {
				commit('setWorkerList', res.content)
			})
		},
		/* 获取栋舍列表 登录后再 home、workerInfo时调用了*/
		getAreaList({ commit }) {
			reqBuildList({
				searchStr: '',
				pageSize: 1000,
				pageNum: 1
			}).then(res => {
				commit('setAreaList', res.content)
			})
		}
	}
})
