
const coupon = {
  state: {
    currentCoupon: {},
    goodsInfo4Coupon: {},
    selectCouponList: [],
  },
  mutations: {
    SET_CURRENT_COUPON: (state, payload) => {
      state.currentCoupon = payload;
    },    
    SET_GOODS_INFO_COUPON: (state, payload) => {
      state.goodsInfo4Coupon = payload;
    },
    SET_SELECT_COUPON_LIST: (state, payload) => {
      state.selectCouponList = payload;
    },
  },
  actions: {
    // 设置当前选中的优惠券
    setCurrentCoupon({ commit }, currentCoupon) {
      commit("SET_CURRENT_COUPON", currentCoupon);
    },
    // 设置当前商品的信息(包括：总价格, goodsType, cardType)
    setGoodsInfo4Coupon({ commit }, goodsInfo4Coupon) {
      commit("SET_GOODS_INFO_COUPON", goodsInfo4Coupon);
    },
    // 这里只处理disabled的状态
    setSelectCouponList({ commit, state }, selectCouponList) {
      let goodsInfo4Coupon = state.goodsInfo4Coupon;
      let price = goodsInfo4Coupon.price;
      let flag = false;
      selectCouponList.forEach( item => {
        if( price > item.requiredTotalFee) {
          
        }
      })
      commit("SET_SELECT_COUPON_LIST", selectCouponList);
    },
  },
}

export default coupon;
