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

export default {
  namespaced: true,
  state: {
    sampleRoomList:[],
    imgTab: [],
    sampleRoomDetail: {
      tabMap: {
        "厨房": {
          list: []
        }
      }
    }
  },
  actions: {
    fetchSampleRoomList({ commit, state }) {
      return api.request("get", api.getURL("houseLayout/findAllModelOnCApp"), {
        pn: 1,
        pageSize: 100000
      }).then(res => {
        commit("SET_SAMPE_ROOM_LISE", res.data.data.list);
        return res;
      });
    },
    findModelDetail( { commit, state }, id) {
      return api.request("get", api.getURL("houseLayout/findModelDetail"), {
				 id
      }).then(res => {
        commit("SET_SAMPLE_ROOM_DETAIL", res.data.data);
        return res;
      });
    }
  },
  mutations: {
    INIT_DATA_STATUS(state, data) {
			
    },
    SET_SAMPE_ROOM_LISE(state, list) {
      let ListRoom = list.filter(item => {
        if(item.houselayouts) {
          return true;
        }
      });
      
      Vue.set(state, "sampleRoomList", ListRoom);
    },
    SET_SAMPLE_ROOM_DETAIL(state, data) {
      data.tabMap = {

      };
      data.prop.map(item => {
        if(item.propCode === "Sample-room") {
          item.name = item.propName.slice(4);
          if(!data.tabMap[item.name]) {
            data.tabMap[item.name] = {
              list: []
            };
            //data.tabMap[item.name].list = []
          }
          data.tabMap[item.name].list.push(item);
        }
      });
      state.imgTab = [];
      for(let key in data.tabMap) {
        state.imgTab.push({
          list: data.tabMap[key].list
        });
      }
      
      Vue.set(state, "sampleRoomDetail", data);
    }
  },
  getters: {}
};