diff --git a/api/local_store.js b/api/local_store.js index 94fd6bf..da3310d 100644 --- a/api/local_store.js +++ b/api/local_store.js @@ -80,3 +80,10 @@ export function cartNum(data) { return request.post("LocalStoreGoods/num", data) } +export function getCartGoods(data) { + return request.post("LocalStoreGoods/getCartGoods", data) +} + +export function modifyCart(data) { + return request.post("LocalStoreGoods/modifyCart", data) +} diff --git a/bundle_b/pages/local_shop/local_shop_detail.vue b/bundle_b/pages/local_shop/local_shop_detail.vue index 9370f6c..72200e2 100644 --- a/bundle_b/pages/local_shop/local_shop_detail.vue +++ b/bundle_b/pages/local_shop/local_shop_detail.vue @@ -107,7 +107,7 @@ - + {{cartNum}} @@ -170,6 +170,52 @@ + + + + + + + 总价 + + + + + + + 清空购物车 + + + + + + + + + + + + + + + {{item.title}} + + + + + + + + + 移除 + + + + + + @@ -188,7 +234,9 @@ getLocalGoodsList, addCart, cartNum, - } from '@/api/local_store.js'; + getCartGoods, + modifyCart + } from '@/api/local_store'; import { sortType, } from '@/utils/type'; @@ -235,6 +283,11 @@ shop_max: 999, shop_original_price: 0 }, + cart: { + popup: false, + data: [], + all: false + }, addGoodsNum: 1 // 默认添加到购物车数量 } }, @@ -253,7 +306,6 @@ }) if (code == 1) { - console.log('data', data) this.cartNum = data.num } }, @@ -344,7 +396,6 @@ add(index) { const data = this.list[index] this.data = data - console.log(this.data) if (data.is_multiple_spec == 1) { // 多规格,这里要组装默认的数据格式 this.spec = { @@ -384,6 +435,19 @@ } }, + async getCartGoods() { + this.cart.popup = true + + const {code, data} = await getCartGoods({ + lstore_id: this.id + }) + + if (code == 1) { + this.cart.data = data.list + this.cart.total_amount = data.total_amount + } + }, + async addCartFun(lstore_id, lsg_id, item_id, goods_num) { // 加入购物车 this.spec.popup = false @@ -394,12 +458,36 @@ goods_num }) - this.cartNum = this.cartNum + goods_num this.zoomValue = 1.5 setTimeout(() => { this.zoomValue = 1 }, 200) + }, + + minusCartFun(o) { + this.modifyCartFun(o.value, o.index, 'minus') + }, + + plusCartFun(o) { + this.modifyCartFun(o.value, o.index, 'plus') + }, + + async modifyCartFun(goods_num, cart_id, type) { + const {code, data} = await modifyCart({ + goods_num, + cart_id, + type + }) + + if (code == 1) { + this.cart.total_amount = data.total_amount + if (type == 'minus') { + this.cartNum-- + } else { + this.cartNum++ + } + } } }, computed: { @@ -603,4 +691,10 @@ padding: 20rpx; text-align: center; } + + .block { + background-color: #fff; + border-radius: 20rpx; + padding: 0 20rpx; + } \ No newline at end of file