|
@@ -118,6 +118,11 @@
|
|
|
</view>
|
|
|
</template>
|
|
|
<script>
|
|
|
+ import {
|
|
|
+ getCartList,
|
|
|
+ deleteGoodsFormCart,
|
|
|
+ updateGoodsBuyQty
|
|
|
+ } from '@/api/shoppingCart.js'
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
@@ -136,6 +141,7 @@
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
+ // 用户信息
|
|
|
userData(){
|
|
|
return this.$store.state.vuex_userData
|
|
|
},
|
|
@@ -173,24 +179,28 @@
|
|
|
return total
|
|
|
},
|
|
|
},
|
|
|
- onUnload() {
|
|
|
- uni.$off('getCarListSuccess')
|
|
|
- },
|
|
|
onLoad() {
|
|
|
+ // 获取购物车数据
|
|
|
this.loading = true
|
|
|
- uni.$emit('getCartList')
|
|
|
- // 刷新列表成功
|
|
|
- uni.$on('getCarListSuccess',item => {
|
|
|
- this.cartList = JSON.parse(JSON.stringify(this.$store.state.vuex_cartList))
|
|
|
- this.loading = false
|
|
|
- console.log(this.isEdit,'this.isEdit')
|
|
|
- // 默认全选
|
|
|
- if(!this.isEdit){
|
|
|
- this.checkAllChange()
|
|
|
- }
|
|
|
- })
|
|
|
+ this.getCartList()
|
|
|
},
|
|
|
methods: {
|
|
|
+ // 查询购物车
|
|
|
+ getCartList(){
|
|
|
+ getCartList({}).then(res => {
|
|
|
+ if(res.status == 200){
|
|
|
+ this.$u.vuex('vuex_cartList', res.data)
|
|
|
+ this.cartList = JSON.parse(JSON.stringify(res.data))
|
|
|
+ uni.$emit('getCarCount')
|
|
|
+ // 默认全选
|
|
|
+ if(!this.isEdit){
|
|
|
+ this.checkAllChange()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.loading = false
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 去选商品
|
|
|
toBuy(){
|
|
|
uni.switchTab({
|
|
|
url:"/pages/goods/index"
|
|
@@ -320,7 +330,7 @@
|
|
|
if(a.length==0){
|
|
|
this.$u.vuex("vuex_toOrderList",goods)
|
|
|
uni.redirectTo({
|
|
|
- url:"/pages/toOrder/index"
|
|
|
+ url:"/pages/toOrder/index?orderForm=SHOPPING_CAR"
|
|
|
})
|
|
|
}else{
|
|
|
this.showMsg = true
|
|
@@ -339,11 +349,25 @@
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
+ // 删除购物车商品
|
|
|
+ delGoodFormCart(ids){
|
|
|
+ uni.showLoading({
|
|
|
+ mask: true,
|
|
|
+ title: "正在删除..."
|
|
|
+ })
|
|
|
+ deleteGoodsFormCart({idList:ids}).then(res => {
|
|
|
+ if(res.status == 200){
|
|
|
+ // 刷新购物车
|
|
|
+ this.getCartList()
|
|
|
+ }
|
|
|
+ uni.hideLoading()
|
|
|
+ })
|
|
|
+ },
|
|
|
// 删除商品
|
|
|
delGoods(){
|
|
|
let ids = this.getCheckGoods(0)
|
|
|
if(ids.length){
|
|
|
- uni.$emit("delCartGood", ids)
|
|
|
+ this.delGoodFormCart(ids)
|
|
|
}else{
|
|
|
uni.showToast({
|
|
|
title:"请选择要删除的商品",
|
|
@@ -351,6 +375,16 @@
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
+ // 更新商品数量
|
|
|
+ updateGoodsBuyQty(item){
|
|
|
+ uni.showLoading({
|
|
|
+ mask: true,
|
|
|
+ title: "更新数量中..."
|
|
|
+ })
|
|
|
+ updateGoodsBuyQty(item).then(res => {
|
|
|
+ uni.hideLoading()
|
|
|
+ })
|
|
|
+ },
|
|
|
// 更改商品数量
|
|
|
goodsNumsChange(val,id){
|
|
|
console.log(val,id)
|
|
@@ -359,7 +393,7 @@
|
|
|
let item = this.cartList[cindex]
|
|
|
let row = item.shoppingCartGoodsList[index]
|
|
|
row.buyQty = val
|
|
|
- uni.$emit("updateGoodsBuyQty",{id:row.id,buyQty:row.buyQty})
|
|
|
+ this.updateGoodsBuyQty({id:row.id,buyQty:row.buyQty})
|
|
|
}
|
|
|
},
|
|
|
}
|