Commit b4c673c0 by 高淑倩

add: 购物车_商品总价

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