import Vue from "vue";
import api from "@/api/index.js";

export default {
  namespaced: true,
  state: {
    homeProjectListInfo: [],
    homeAddList:[],
    homeLayoutListInfo: []
  },
  actions: {
    findMoreRegions({ commit, state }, payload) { //热门项目
      if(state.homeProjectListInfo.length > 0 && !payload.cache) {
        return;
      }
      return api.request("get", api.getURL("Region/findMoreRegions"), payload).then(res => {				
        //
        if(res) {
          commit("SET_HOME_PROJECT_LIST_INFO", res.data.data.list);
        }
        return res;
      });
    },
    findAllOnCApp({ commit, state }, payload) { // 热门户型
      if(state.homeLayoutListInfo.length > 0) {
        return;
      }
      return api.request("get", api.getURL("houseLayout/findAllOnCApp"), payload).then(res => {				
        //
        if(res) {
          //
          if(res.data.data.list.length === 1) {
            res.data.data.list.push(res.data.data.list[0],res.data.data.list[0]);
          }
          if(res.data.data.list.length === 2) {
            res.data.data.list.push(res.data.data.list[0]);
          }
          commit("SET_HOME_LAYOUT_LIST_INFO", res.data.data.list);
        }
        return res;
      });
    },
  },
  mutations: {
    INIT_DATA_STATUS(state, data) {
			
    },
    SET_HOME_PROJECT_LIST_ADD_INFO(state, data) {
      data.map(item => {
        state.homeAddList.push(item);
      });
      //state.homeProjectListInfo = state.homeProjectListInfo.concat(data)
      
      //state.homeProjectListInfo = [...state.homeProjectListInfo, ...data]
    },
    SET_HOME_PROJECT_LIST_INFO(state, data) {
      //[1,2,3] = [4,5,6]
      Vue.set(state, "homeProjectListInfo", data);
    },
    SET_HOME_LAYOUT_LIST_INFO(state, data) {
      Vue.set(state, "homeLayoutListInfo", data);
    }
		
  },
  getters: {}
};