import Vue from 'vue'
import Vuex from 'vuex'
// [ seedSheedSource, seedSheedLevel, seedSheedStatus ]
import publicType from './publicType.js' // 公共的类型 
import { reqWorkerList, reqBuildList } from "@/api/fileInfo.js";
import { reqBasicsInfoList} from "@/api/material.js";

Vue.use(Vuex)

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