import store from '@/utils/store';
import service from '@/service/index';

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

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

		// 节日
		getFestival({ commit }) {
			return service.common.fest().then(res => {
				commit('SET_FESTIVAL', res);
				return res;
			});
		},
		delFestival({ commit }) {
			commit('DEL_FESTIVAL');
		}
	},
	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');
		}
	}
};
