import moneySubFn from './moneySubFn'
function modifyRechargeDeduct(that,checkMoneySub = false) {
	that.list.is_use_recharge_deduct = that.use_deduct_recharge ? 'yes' : 'no';
		// 是否使用储值卡抵扣 // 储值和金豆抵扣满足一个即可
		if (that.use_deduct_recharge && that.recharge >= 0.01) {
			// 剩余要付款金额
			let allBa2Need = parseFloat(that.list.realprice - that.list.money_sub)
			// 储值余额>付款金额
			if (getApp().globalData.util.numberFloor(that.recharge) >= allBa2Need) {
				that.list.deduct_recharge = allBa2Need;
				if (that.list.deductprice <= 0) {
					// 隐藏储值抵扣,因已经全额金豆抵扣
					that.hideCreditDeduct = true;
					that.list.deductprice = 0;
				}
			} else { // 储值余额<付款金额 直接一次性用完储值余额
				that.recharge = getApp().globalData.util.numberFloor(that.recharge)
				that.list.deduct_recharge = that.recharge;
			}
			that.list.deduct_recharge = getApp().globalData.util.numberFloor(that.list.deduct_recharge)
			that.list.needpay = that.list.realprice - that.list.deduct_recharge
			if (parseInt(that.list.needpay) != that.list.needpay && that.list.needpay != 0) {
				that.list.needpay = parseFloat(that.list.needpay * 100).toFixed(0) / 100;
			}
		} else {
			that.list.deduct_recharge = 0
			that.hideCreditDeduct = false
			that.list.needpay = that.list.realprice
		}
		that.list.needpay = parseFloat(that.list.needpay)
		if (that.list.money_sub > 0) {
			that.list.needpay -= that.list.money_sub
		}
		if (that.list.deductprice > 0) {
			that.list.needpay -= that.list.deductprice
		}
		that.list.needpay = parseFloat(that.list.needpay).toFixed(2)
		if (checkMoneySub) {
			// 使用了储值抵扣的话,储值抵扣部分不赠送金豆和随机立减
			let money4CreditAdd = that.list.realprice // 送金豆的钱 
			money4CreditAdd = money4CreditAdd - that.list.deduct_recharge
			// 赠送金豆个数
			let creditaddNumber = money4CreditAdd * that.merch.credit_give / that.merch.credit_give_rate
			if (creditaddNumber >= 0.01) {
				that.$set(that.list, 'credit', getApp().globalData.util.numberFloor(creditaddNumber))
			} else {
				that.$set(that.list, 'credit', 0)
			}
			moneySubFn.modifyMoneySub(that)
			modifyRechargeDeduct(that)
		}
		that.$forceUpdate()
}
module.exports= {
	/**
	 * 处理储值抵扣方法
	 * @param {*} e 
	 */
	modifyRechargeDeduct: modifyRechargeDeduct,	
}