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

export default {
  namespaced: true,
  state: {
    userCurrentBillInfo: {},
    userBillDetailInfo:{},
    couponPrice:0,
    allBillListInfo:[],
    // billList:{
    // 	year1:[],
    // 	year2:[]
    // },
    payForm:{
			  "actualGetMoney": 0,
			  "billId": 0,
			  "couponId": 0,
			  "mustGetMoney": 0,
			  "payMinus": 0,
			  "payWay": 0
    },
    newPayForm:{
		  "billId": 0,
		  "businessId": 0,
		  "couponId": 0,
		  "orderAmount": "",
		  "orderTitle": "",
		  "orderType": "",
		  "remark": ""
    }
  },
  actions: {
    findUserCurrentBill({ commit, state }, payload) { // 查看当前账单信息			
      return api.request("get", api.getURL("houseLive/findUserCurrentBillOnCAPP"), payload).then(res => {				
				
        if(res) {
          //
          commit("SET_CURRENT_BILL_INFO", res.data.data);
          state.payForm.billId = res.data.data.id;
          state.payForm.mustGetMoney = res.data.data.mustGetMoney;
        }else {
          //
          commit("SET_CURRENT_BILL_INFO", "");
        }
        return res;
      });
    },
    findAllBill({ commit, state }, payload) { // 查看全部账单信息			
      return api.request("get", api.getURL("houseLive/selectAllBillsOnCAPP"), payload).then(res => {				
								
        // state.billList.year1 = []
        // state.billList.year2 = []
        if(res) {
          //
          // res.data.data.filter(item => {
          // 	if(item.billEndTime.indexOf('2018') != -1) {
          // 		state.billList.year1.push(item)
          // 	}
          // 	if(item.billEndTime.indexOf('2019') != -1) {
          // 		state.billList.year2.push(item) 
          // 	}
          // })
		             //
          commit("SET_ALL_BILL_INFO", res.data.data);
        }
        return res;
      });
    },
    findUserBillDetail({ commit, state }, payload) { // 查看当前账单信息			
      return api.request("get", api.getURL("houseLive/findBillDetailOnCAPP"), 
        payload
      ).then(res => {				
        //
        if(res) {		                  
          commit("SET_USER_BILL_DETAIL_INFO", res.data.data);
          state.payForm.billId = res.data.data.id;
          state.payForm.mustGetMoney = res.data.data.mustGetMoney;					
        }else {
          //
          commit("SET_USER_BILL_DETAIL_INFO", "");
        }
        return res;
      });
    },
    payMyBill({commit,state},payForm) {  // 支付 缴费
      return api.request("post", api.getURL("houseLive/livePayBillOnCAPP"),
        state.payForm
      ).then(res => {

            	//
            	// if(res) {                     
            		
            	// }
            	return res;
      });
    },
    payBillPriceIsZero({commit,state},payForm) {  //支付 金额为0
      return api.request("post", api.getURL("houseLive/payBillOnCAPPOnZero"),
        state.payForm
      ).then(res => {

           	//
           	// if(res) {                     
           		
           	// }
           	return res;
      });
    },
    payBillNewByWx({commit,state},params) {  //新支付
      return api.request("post", api.getURL("scanningPay/newCcbOrderByWx"),
        params
      ).then(res => {

           	//
           	// if(res) {                     
           		
           	// }
           	return res;
      });
    }
		
		
  },
  mutations: {
    SET_CURRENT_BILL_INFO(state, data) {
      Vue.set(state,"userCurrentBillInfo",data);
    },
    SET_USER_BILL_DETAIL_INFO(state, data) {
      Vue.set(state,"userBillDetailInfo",data);
    },
		
    SET_COUPON_PRICE(state,data) {
      Vue.set(state,"couponPrice",data);
    },
    SET_ALL_BILL_INFO(state,data) {
      Vue.set(state,"allBillListInfo",data);
    },
    SET_COUPON_FEE(state,payMinus) {
      state.payForm.payMinus = payMinus;
    },
    SET_COUPON_ID(state,couponId) {
      state.payForm.couponId = couponId;
    },
    SET_ACTUALGETMONEY(state, actualGetMoney){
      state.payForm.actualGetMoney = actualGetMoney;
    },
    CLEAN_COUPONPRICE(state, couponPrice) {
      state.couponPrice = 0;
    },
    INTE_NEW_PAY_FORM(state,data){
		  state.newPayForm.billId = null,
		  state.newPayForm.businessId = null,
		  state.newPayForm.couponId = null,
		  state.newPayForm.orderAmount = "",
		  state.newPayForm.orderTitle = "",
		  state.newPayForm.orderType = "",
		  state.newPayForm.remark = "";
    }

		
		
		
  },
  getters: {}
};