Commit 437e88fb by zhanghaozhe

定金

parent 199214f8
......@@ -340,7 +340,8 @@ class FinalDepositOrder extends Component {
} else {
selectedCourses.splice(index, 1)
}
return {selectedCourses, salePrice: this.getTotalPrice(selectedCourses)}
let totalPrice = this.getTotalPrice(selectedCourses)
return {selectedCourses, salePrice: totalPrice, offset: this.getBalanceOffset(totalPrice)}
})
}
......@@ -352,10 +353,7 @@ class FinalDepositOrder extends Component {
moneyOffRules = this.state.moneyOffRules
} = {}
) => {
let totalPrice = 0
totalPrice += courses.reduce((accu, item) => {
return accu + parseFloat(item['sale_price'])
}, 0)
let totalPrice = this.getOriginTotalPrice()
totalPrice = this.moneyOff(totalPrice, moneyOffRules)
if (useBalance) {
totalPrice -= parseFloat(this.state.user_account)
......@@ -363,6 +361,7 @@ class FinalDepositOrder extends Component {
return totalPrice < 0 ? 0 : totalPrice.toFixed(2)
}
//满减计算
moneyOff = (totalPrice, moneyOffRules = this.state.moneyOffRules) => {
let rules = moneyOffRules.sort((a, b) => b.full_amount - a.full_amount)
let result = parseFloat(totalPrice)
......@@ -382,17 +381,30 @@ class FinalDepositOrder extends Component {
useBalance = () => {
this.setState(prevState => {
const useBalance = !prevState.useBalance
let offset = parseFloat(this.state.user_account) - parseFloat(this.getTotalPrice())
offset = offset > 0 ? this.getTotalPrice() : this.state.user_account
let totalPrice = this.getTotalPrice({useBalance})
return {
useBalance,
salePrice: this.getTotalPrice({useBalance}),
offset
salePrice: totalPrice,
offset: this.getBalanceOffset(totalPrice)
}
})
}
getOriginTotalPrice = ({courses = this.state.selectedCourses} = {}) => {
return courses.reduce((accu, item) => {
return accu + parseFloat(item['sale_price'])
}, 0)
}
getBalanceOffset = () => {
let originalTotalPrice = this.getOriginTotalPrice()
let offset = parseFloat(this.state.user_account) - parseFloat(originalTotalPrice)
offset = offset >= 0 ? originalTotalPrice : this.state.user_account
return offset
}
render() {
const {
orderId,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment