Commit 437e88fb by zhanghaozhe

定金

parent 199214f8
...@@ -340,7 +340,8 @@ class FinalDepositOrder extends Component { ...@@ -340,7 +340,8 @@ class FinalDepositOrder extends Component {
} else { } else {
selectedCourses.splice(index, 1) 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 { ...@@ -352,10 +353,7 @@ class FinalDepositOrder extends Component {
moneyOffRules = this.state.moneyOffRules moneyOffRules = this.state.moneyOffRules
} = {} } = {}
) => { ) => {
let totalPrice = 0 let totalPrice = this.getOriginTotalPrice()
totalPrice += courses.reduce((accu, item) => {
return accu + parseFloat(item['sale_price'])
}, 0)
totalPrice = this.moneyOff(totalPrice, moneyOffRules) totalPrice = this.moneyOff(totalPrice, moneyOffRules)
if (useBalance) { if (useBalance) {
totalPrice -= parseFloat(this.state.user_account) totalPrice -= parseFloat(this.state.user_account)
...@@ -363,6 +361,7 @@ class FinalDepositOrder extends Component { ...@@ -363,6 +361,7 @@ class FinalDepositOrder extends Component {
return totalPrice < 0 ? 0 : totalPrice.toFixed(2) return totalPrice < 0 ? 0 : totalPrice.toFixed(2)
} }
//满减计算
moneyOff = (totalPrice, moneyOffRules = this.state.moneyOffRules) => { moneyOff = (totalPrice, moneyOffRules = this.state.moneyOffRules) => {
let rules = moneyOffRules.sort((a, b) => b.full_amount - a.full_amount) let rules = moneyOffRules.sort((a, b) => b.full_amount - a.full_amount)
let result = parseFloat(totalPrice) let result = parseFloat(totalPrice)
...@@ -382,17 +381,30 @@ class FinalDepositOrder extends Component { ...@@ -382,17 +381,30 @@ class FinalDepositOrder extends Component {
useBalance = () => { useBalance = () => {
this.setState(prevState => { this.setState(prevState => {
const useBalance = !prevState.useBalance const useBalance = !prevState.useBalance
let offset = parseFloat(this.state.user_account) - parseFloat(this.getTotalPrice()) let totalPrice = this.getTotalPrice({useBalance})
offset = offset > 0 ? this.getTotalPrice() : this.state.user_account
return { return {
useBalance, useBalance,
salePrice: this.getTotalPrice({useBalance}), salePrice: totalPrice,
offset 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() { render() {
const { const {
orderId, 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