import store from '@/utils/store';

export default {
	state: {
		level: store.get('level') || {},
		category: store.get('category') || [],
		festival: store.get('festival') || [],
		usage: store.get('usage') || []
	},
	actions: {
		// 等级
		getLevel({ commit }) {
			return this.$service.level.list().then(res => {
				commit('SET_LEVEL', res);
				return res;
			});
		},
		delLevel({ commit }) {
			commit('DEL_LEVEL');
		},

		// 分类
		getCategory({ commit }) {
			return this.$service.category.list().then(res => {
				commit('SET_CATEGORY', res);
				return res;
			});
		},
		delCategory({ commit }) {
			commit('DEL_CATEGORY');
		},

		// 节日
		getFestival({ commit }) {
			return this.$service.common.fest().then(res => {
				commit('SET_FESTIVAL', res);
				return res;
			});
		},
		delFestival({ commit }) {
			commit('DEL_FESTIVAL');
		},

		// 用途
		getUsage({ commit }) {
			return this.$service.common.usage().then(res => {
				commit('SET_USAGE', res);
				return res;
			});
		},
		delUsage({ commit }) {
			commit('DEL_USAGE');
		}
	},
	mutations: {
		SET_LEVEL(state, val) {
			state.info = val;
			store.set('level', val);
		},
		DEL_LEVEL(state) {
			state.info = {};
			store.remove('level');
		},

		SET_CATEGORY(state, val) {
			state.info = val;
			store.set('category', val);
		},

		DEL_CATEGORY(state) {
			state.info = [];
			store.remove('category');
		},

		SET_FESTIVAL(state, val) {
			state.info = val;
			store.set('festival', val);
		},

		DEL_FESTIVAL(state) {
			state.info = [];
			store.remove('festival');
		},

		SET_USAGE(state, val) {
			state.usage = val;
			store.set('usage', val);
		},

		DEL_USAGE(state) {
			state.usage = [];
			store.remove('usage');
		}
	}
};
