import { getcategroylist,getmockbannerlist,getmockfloorslist } from "@/api/index";

const state = {
	categoryList: [],
	getBannerList:[],
	getfloorslist:[]
};

const mutations = {

  CATEGORYLIST(state, categoryList) {
    // categoryList是actions传递过来的 参数 值
    state.categoryList = categoryList;
	},
	GETBANNER(state,getBannerList){
		state.getBannerList=getBannerList
	},
	GETFLOORS(state,getfloorslist){
		state.getfloorslist=getfloorslist
	}
};

const actions = {
  // commit解构提交给mutations
  async categoryList({ commit }) {
		// 通过api接口函数调用，向服务器发请求
    let result = await getcategroylist();
    if (result.code == 200) {
			// 触发categoryList中CATEGORYLIST方法，并携带参数
			// 因为只有mutations才可以修改或存储state数据	
      commit("CATEGORYLIST", result.data);
      console.log(result);
    }
	},
	// 首页获取轮播图数据
	async getBanner({commit}){
		let result = await getmockbannerlist()
		if(result.code==200){
			commit("GETBANNER",result.data)
		}
	},
	// 获取floors的数据
	async getfloorslist({commit}){
		let result = await getmockfloorslist()
		if(result.code==200){
			commit("GETFLOORS",result.data)
			console.log(result.data);
		}
	}
};

const getters = {};

export default {
  state,
  mutations,
  actions,
  getters,
};
