import Vue from "vue";
import api from "@/api/index.js";
import store from "@/utils/store";
export default {
  namespaced : true,
  state:{
    selectionActivityInfo : [], 
    selectionActivityDetail:{},
    serviceTeamInfo:[],
    waterElectricityInfo:{},
    payMoneyRecordData:[],
    payForm:{
      "billType": "",
      "billTypeName": "",
      "meterCode": "",
      "houseId": 0,
      "payMoney": 0,
      "payStatus": 0,
      "payWay": 0,
      "regionId": 0,
      "regionName": ""
    }
  },
  actions: {
    getSelectionActivityInfo({ commit, state }, payload) { // 精选活动列表
      	return api.request("get", api.getURL("content/choiceness"), payload).then(res => {				
      		
      		if(res) {					
      			commit("SET_SELECTION_ACTIVITY_INFO",res.data.data.list);		
      		}
      		return res;
      	});
    },
    getSelectionActivityDetail({ commit, state }, payload) { // 精选活动详情
      return api.request("get", api.getURL("content/detail"), payload).then(res => {        
          
        if(res) {         
          commit("SET_SELECTION_ACTIVITY_DETAIL_INFO",res.data.data); 
          let couponList = res.data.data.contentProps;
          // 
          // couponList.map(item => {
          //     api.request("get",api.getURL("coupon/findCouponDetails"),{
          //      id:item.propValueInt
          //    }).then(res => {
          //      commit('SET_COUPON_DETAIL_INFO',res.data.data)
          //      return res;
          //    })
          // })
             
        }
        return res;
      });
    },
    getCouponDetailInfo({ commit, state }, payload) { // 优惠券获取
      return api.request("get", api.getURL("coupon/findCouponDetails"), payload).then(res => {        
          
        if(res) {         
          commit("SET_COUPON_DETAIL_INFO",res.data.data);           
        }
        return res;
      });
    },
    getServiceTeamInfo({ commit, state }, payload) { // 服务团队
      return api.request("get", api.getURL("cAPPHouse/myStewards"), payload).then(res => {        
          
        if(res) {         
          commit("SET_SERVICE_TEAM_INFO",res.data.data);           
        }
        return res;
      });
    },
    getCurrentWaterEleDataInfo({ commit, state }, payload) { // 当前水电表余量读数
      return api.request("get", api.getURL("WEGMeter/findUserHouseMeterDetail"), payload).then(res => {        
          
        if(res.data.code === 10000) { 
          // 
          commit("SET_CURRENT_ELEWATER_DATAINFO",res.data.data);
          store("payForm",res.data.data);    
        }
        return res;
      });
    },
    reflashCurrentWaterEleDataInfo({ commit, state }, payload) { // 刷新当前水电表余量读数
      return api.request("get", api.getURL("WEGMeter/findMeterReding"), payload).then(res => {                 
        //
        if(res.data.code === 10000){
          if(res.data.data.meterType === "40") { //电表
            commit("SET_CURRENT_AMMETERBALANCE_DATA",res.data.data.balance); 
            commit("SET_CURRENT_AMMETERREAD_DATA",res.data.data.thisRead); 
          }else {
            commit("SET_CURRENT_WATERMETERBALANCE_DATA",res.data.data.balance); 
            commit("SET_CURRENT_WATERMETERREAD_DATA",res.data.data.thisRead);
          }  
        }      
        //commit('SET_CURRENT_ELECTRICITY_DATA',res.data.data)    
        return res;
      });
    },
    getPayMoneyRecordData({ commit, state }, payload) { // 缴费记录
      return api.request("get", api.getURL("WEGMeter/findHistoryDetailOnCAPP"), payload).then(res => {        
          
        if(res.data.code === 10000) { 
          //
          commit("SET_PAYMONEY_RECORD_DATA",res.data.data.list);
           
        }
        return res;
      });
    },
    payAddMoneyForMeter({commit,state},payForm) { // 缴费充值支付
      return api.request("post", api.getURL("WEGMeter/payOnCAPP"),
        payForm
      ).then(res => {                 
        if(res.data.code === 10000) { 
          
          //commit('SET_PAYMONEY_RECORD_DATA',res.data.data.list)
           
        }
        return res;
      });
    }

  },
  mutations: {
    SET_SELECTION_ACTIVITY_INFO(state,data) { 
         	Vue.set(state,"selectionActivityInfo",data);
    }, 
    SET_SELECTION_ACTIVITY_DETAIL_INFO(state,data) {
         	Vue.set(state,"selectionActivityDetail",data);
    },
    SET_COUPON_DETAIL_INFO(state,data) {  
      //Vue.set(state,'selectionActivityDetail',state.selectionActivityDetail)       
      state.selectionActivityDetail.contentProps.map(item => {
        if(item.propValueInt === data.id) {
          item.getStartTime = data.getStartTime;
          item.getEndTime = data.getEndTime;
          item.couponFee = data.couponFee;
          item.couponNum  = data.couponNum;
          item.minimumFee  = data.minimumFee;             
        }
      });
                      
    },
    SET_SERVICE_TEAM_INFO(state, data) {
      Vue.set(state,"serviceTeamInfo",data);
    },
    SET_CURRENT_ELEWATER_DATAINFO(state,data) { 
      Vue.set(state,"waterElectricityInfo",data);
    },
    SET_CURRENT_AMMETERBALANCE_DATA(state,data) {
      state.waterElectricityInfo.ammeterBalance = data;
    },
    SET_CURRENT_AMMETERREAD_DATA(state,data) {
      state.waterElectricityInfo.ammeterRead = data;
    },
    SET_CURRENT_WATERMETERBALANCE_DATA(state,data) {
      state.waterElectricityInfo.watermeterBalance = data;
    },
    SET_CURRENT_WATERMETERREAD_DATA(state,data) {
      state.waterElectricityInfo.watermeterRead = data;
    },
    SET_PAYMONEY_RECORD_DATA(state,data) {
      Vue.set(state,"payMoneyRecordData",data);
    },
    CLEAR_PAY_FORM(state,data) {
      state.payForm.billType =  "";
      state.payForm.billTypeName =  "";
      state.payForm.houseCode =  "";
      state.payForm.houseId =  0;
      state.payForm.payMoney =  0;
      state.payForm.payStatus =  0;
      state.payForm.payWay =  0;
      state.payForm.regionId =  0;
      state.payForm.regionName =  "";
    }
        
  },
  getters: {

  }


};