Commit b4c673c0 by 高淑倩

add: 购物车_商品总价

parent a289cf01
......@@ -16,7 +16,8 @@ wxService.page({
cartList: [],
outGoods: [],
checkAll: false,
checkedColor: 'rgb(203, 60, 60)'
checkedColor: 'rgb(203, 60, 60)',
shopCartTotalFee: 0, // 商品总价
},
/**
......@@ -144,23 +145,22 @@ wxService.page({
},
blurNum: function (e) {
var newNum = e.detail.value
console.log('blurNum', newNum)
var cartList = this.data.cartList
if (newNum === '') {
newNum = 1
}
// cartList[e.currentTarget.dataset.index].quantity = newNum
// this.setData({
// cartList: cartList
// }, function () {
// this.setTotalFee()
// this.editOk(cartList[e.currentTarget.dataset.index]) //调用完成
// })
cartList[e.currentTarget.dataset.index].count = newNum
this.setData({
cartList: cartList
}, function () {
this.setTotalFee()
this.editOk(cartList[e.currentTarget.dataset.index]) //调用完成
})
},
inputNum: function (e) { // 输入数量
var newNum = e.detail.value
console.log('newNum', newNum)
if (newNum) {
const { cartList } = this.data
if (newNum === '0') {
......@@ -168,41 +168,31 @@ wxService.page({
} else {
newNum = parseInt(newNum)
}
cartList[e.currentTarget.dataset.index].count = newNum
this.setData({
cartList: cartList
}, function () {
this.setTotalFee()
this.editOk(cartList[e.currentTarget.dataset.index]) //调用完成
})
}
},
setTotalFee(skipRedemption) {
var cartList = this.data.cartList
var checkProsId = [] // 选中的商品id
var totalFee = 0
// 购物车总金额
for (let i = 0; i < cartList.length; i++) {
if (cartList[i].checked) {
totalFee += cartList[i].price * (cartList[i].count ? cartList[i].count : 1)
checkProsId.push(cartList[i].skuId)
}
}
// if(newNum) {
// var cartList = this.data.cartList
// var choosePro = cartList[e.currentTarget.dataset.index]
// if (newNum === '0') {
// newNum = 1
// } else {
// newNum = parseInt(newNum)
// if (choosePro.quantityAverage == '0') {
// if (newNum > choosePro.selectSku.inventory_num) {
// newNum = choosePro.selectSku.inventory_num
// wx.showToast({
// title: '不能超过库存',
// icon: 'none'
// })
// }
// } else {
// if (newNum > choosePro.quantityAverage) {
// newNum = choosePro.quantityAverage
// wx.showToast({
// title: '每人限购' + choosePro.quantityAverage + '件',
// icon: 'none'
// })
// }
// }
// }
// cartList[e.currentTarget.dataset.index].quantity = newNum
// this.setData({
// cartList: cartList
// }, function () {
// this.setTotalFee()
// this.editOk(cartList[e.currentTarget.dataset.index]) //调用完成
// })
// }
this.setData({
shopCartTotalFee: totalFee.toFixed(2)
})
},
goBuy() {
......@@ -263,19 +253,17 @@ wxService.page({
})
},
// 调整商品 /trolley/add
editOk() {
editOk(cartPro) {
console.log('cartPro', cartPro)
// count skuId
wx.showLoading({
title: '加载中'
})
wxService.post('/sale/trolley/add').then(res => {
console.log('query', res)
wxService.post(`/sale/trolley/add?count=${cartPro.count}&skuId=${cartPro.skuId}`).then(res => {
if (res) {
const { result, data } = res.data
const { result } = res.data
if (result == 0) {
wx.hideLoading()
this.setData({
// cartList
})
} else {
wx.showToast({
title: res.data.message,
......@@ -308,7 +296,7 @@ wxService.page({
cartList: cartList,
checkAll: checkAll
}, function () {
// this.setTotalFee()
this.setTotalFee()
})
},
......@@ -324,7 +312,7 @@ wxService.page({
}),
checkAll: false
}, function () {
// this.setTotalFee()
this.setTotalFee()
})
} else {
this.setData({
......@@ -335,7 +323,7 @@ wxService.page({
}),
checkAll: true
}, function () {
// this.setTotalFee()
this.setTotalFee()
})
}
},
......
......@@ -68,7 +68,7 @@
</view>
<view class="total-amount">
<text class="total-label">合计:</text>
<text class="total-price">¥306</text>
<text class="total-price">¥{{shopCartTotalFee}}</text>
</view>
</view>
<view class="theme-color buy-btn" bindtap="goBuy">立即购买</view>
......
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