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

export default {
  namespaced: true,
  state: {
    projectDetailInfo: {},
    houseDetailInfo: {}
  },
  actions: {
    findDetailOnCApp({ commit, state }, payload) { //项目详情
      return api.request("get", api.getURL("Region/findDetialOnCApp"), payload).then(res => {				
				
        if(res) {
          res.data.data.imgList = res.data.data.props.filter(item => {
            if(item.propCode === "showImage") {
              return true;
            }
          });
          res.data.data.supList = res.data.data.props.filter(item => {
            if(item.propCode === "suppo") {
              return true;
            }
          });
          res.data.data.regionToggle = true;
          if(res.data.data.collectionId !== null) {
            res.data.data.regionToggle = false;
          }
          if(res.data.data.layoutListPos.length === 1) {
            res.data.data.layoutListPos.push(res.data.data.layoutListPos[0],res.data.data.layoutListPos[0]);
          }
          if(res.data.data.layoutListPos.length === 2) {
            res.data.data.layoutListPos.push(res.data.data.layoutListPos[0]);
          }
          //
          commit("SET_PROJECT_DETAIL_INFO_INFO", res.data.data);
        }
        return res;
      });
    },
    houseFindDetailOnCApp({ commit, state }, payload) { //户型详情
      return api.request("get", api.getURL("houseLayout/finddetailOnCApp"), payload).then(res => {				
				
        if(res) {
          res.data.data.imgList = res.data.data.prop.filter(item => {
            if(item.propCode === "showImg") {
              return true;
            }
          });
					
          res.data.data.supList = res.data.data.prop.filter(item => {
            if(item.propCode === "suppo") {
              return true;
            }
          });					
          //
          res.data.data.layoutToggle = true;
          if(res.data.data.collectionId !== null) {
                    	res.data.data.layoutToggle = false;
          }
          commit("SET_HOUSE_DETAIL_INFO_INFO", res.data.data);
					
        }
        return res;
      });
    }

  },
  mutations: {
    INIT_DATA_STATUS(state, data) {
			
    },
    SET_PROJECT_DETAIL_INFO_INFO(state, data) {
      Vue.set(state, "projectDetailInfo", data);
    },
    SET_HOUSE_DETAIL_INFO_INFO(state, data){
      Vue.set(state, "houseDetailInfo", data);
    }

  },
  getters: {}
};