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

export default {
  namespaced: true,
  state: {
    homeLayoutListInfo: [],
    selectListRegionInfo: [],
    selectListAreaInfo: [],
    selectListHouseTypeInfo: [],
    selectListPriceInfo: [
		   {
		       price_id:0,
		       name:"不限"
		   },
		   {
		       price_id:1,
		       name:"500元以下"
		   },
		   {
		       price_id:2,
		       name:"500-1000元"
		   },
		   {
		       price_id:3,
		       name:"1000-1500元"
		   },
		   {
		       price_id:4,
		       name:"1500-2000元"
		   },
		   {
		       price_id:5,
		       name:"2000-2500元"
		   },
		   {
		       price_id:6,
		       name:"2500-3000元"
		   },
		   {
		       price_id:7,
		       name:"3000-3500元"
		   },
		   {
		       price_id:8,
		       name:"3500-4000元"
		   }
    ],
  },
  actions: {
    selectListRegion({ commit, state }, payload) { // 项目下拉
      return api.request("get", api.getURL("Region/selectListRegion"), payload).then(res => {				
				
        if(res) {					
          //
          commit("SET_LAYOUT_REGION_SELECT_INFO", res.data.data);
        }
        return res;
      });
    },
    selectListArea({ commit, state }, payload) { // 地区下拉
      return api.request("get", api.getURL("area/findAllCounty"), payload).then(res => {				
				
        if(res) {					
          //
          commit("SET_LAYOUT_AREA_SELECT_INFO", res.data.data);
        }
        return res;
      });
    },
    selectListHouseType({ commit, state }, payload) { // 户型下拉
      return api.request("get", api.getURL("houseLayout/listSelect"), payload).then(res => {				
				
        if(res) {					
          //
          commit("SET_LAYOUT_HOUSE_TYPE_SELECT_INFO", res.data.data);
        }
        return res;
      });
    },
    findAllLayoutHouse({ commit, state }, payload) { // 热门户型			
      return api.request("get", api.getURL("houseLayout/findAllOnCApp"), payload).then(res => {				
        //
        if(res) {
          commit("SET_HOME_LAYOUT_LIST_INFO", res.data.data.list);
        }
        return res;
      });
    },
		

  },
  mutations: {
    INIT_DATA_STATUS(state, data) {
			
    },
    SET_LAYOUT_REGION_SELECT_INFO(state, data) { //项目下拉数据
      Vue.set(state,"selectListRegionInfo",data);
    },
    SET_LAYOUT_AREA_SELECT_INFO(state,data) { //地区下拉数据
      Vue.set(state,"selectListAreaInfo",data);
    },
    SET_LAYOUT_HOUSE_TYPE_SELECT_INFO(state,data) { //户型下拉数据
      Vue.set(state,"selectListHouseTypeInfo",data);
    },
    REGION_MARK_SELECTED_ITEM(state, curIndex) { //先清空选中状态，后设置选中状态
      state.selectListRegionInfo.map(item => {
        item.selected = false;
      });
      state.selectListRegionInfo[curIndex].selected = true;
    },		
    PRICE_MARK_SELECTED_ITEM(state, curIndex) {
      state.selectListPriceInfo.map(item => {
        item.selected = false;
      });
      state.selectListPriceInfo[curIndex].selected = true;
    },
    AREA_MARK_SELECTED_ITEM(state, curIndex) {
      state.selectListAreaInfo.map(item => {
        item.selected = false;
      });
      state.selectListAreaInfo[curIndex].selected = true;
    },
    HOUSE_MARK_SELECTED_ITEM(state, curIndex) {
      state.selectListHouseTypeInfo.map(item => {
        item.selected = false;
      });
      state.selectListHouseTypeInfo[curIndex].selected = true;
    },
    SET_HOME_LAYOUT_LIST_INFO(state, data) {
      Vue.set(state, "homeLayoutListInfo", data);
    }
		

  },
  getters: {}
};