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

export default {
  namespaced: true,
  state: {
    info: store("bindHouseInfo"),
    houseInfo: store("houseInfo"),
    myInfo: {
			
    }
  },
  actions: {
    checkLiveWith( { commit, state }, id) {
      return api.request("get", api.getURL("cAPPHouse/checkLiveWith"), {
				 id
      }).then(res => {
        return res;
      });
    },
    deleteLiveWith( { commit, state }, id) {
      return api.request("get", api.getURL("cAPPHouse/deleteLiveWith"), {
				 id,
      }).then(res => {
        return res;
      });
    },
    outBindHouse( { commit, state }, params) {
      return api.request("get", api.getURL("customer/outBindHouse")).then(res => {
        return res;
      });
    },
    bindHouseFirst({ commit, state }, userInfo) {
      return api.request("post", api.getURL("customer/bindHouseFirst"), userInfo).then(res => {
        return res;
      });
    },
    bindHouseSecond({ commit, state }, userInfo) {
      return api.request("post", api.getURL("customer/bindHouseSecond"), {
        cardCode: state.info.cardCode,
        userName: state.info.userName,
      }).then(res => {
        //commit('INIT_BIND_HOUSE_INFO', res.data.data)
        return res;
      });
    },
    viewHouseInfo( { commit, state, rootState }, params) {
      return api.request("get", api.getURL("customer/myHouseInfo")).then(res => {
        if(res) {
          commit("INIT_SELF_INFO", res.data.data);
          rootState.loginModule.loginInfo.cappUserInfo = res.data.data;
        }
        return res;
      });
    }
  },
  mutations: {
    INIT_DATA_STATUS(state, data) {
			
    },
    INIT_BIND_HOUSE_INFO(state, data) {
      data.houseInfo.normalStartTime = new Date(data.houseInfo.liveStartTime).Format("yyyy/MM/dd");
      data.houseInfo.normalEndTime = new Date(data.houseInfo.liveEndTime).Format("yyyy/MM/dd");
      //
      data.houseInfo.outputDate = data.houseInfo.normalStartTime + " -  " + data.houseInfo.normalEndTime;

      data.houseInfo.fullName = `${data.houseInfo.regionName} ${data.houseInfo.houseCode.slice(0, 2)}栋 ${data.houseInfo.houseCode.slice(2)}`;
      Vue.set(state, "info", data);
      Vue.set(state, "houseInfo", data.houseInfo);
      store("houseInfo", data.houseInfo);
      store("bindHouseInfo", data);
    },
    INIT_SELF_INFO(state, data) {
      Vue.set(state, "myInfo", data);
    }
  },
  getters: {}
};