完善本地生活购物车

This commit is contained in:
wangxiaowei 2024-10-30 17:31:10 +08:00
parent 88d3dc1263
commit fec652b5e7
2 changed files with 106 additions and 5 deletions

@ -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)
}

@ -107,7 +107,7 @@
</view>
<view class="footer flex row-between">
<view class="cart">
<view class="cart" @click="getCartGoods">
<u-image :src="aliOSSDomain + 'uniapp/cart.png'" width="60" height="60"></u-image>
<view class="cart-num" :style="{ transform: zoomTransform }" v-if="cartNum > 0">{{cartNum}}</view>
</view>
@ -170,6 +170,52 @@
</view>
</view>
</u-popup>
<u-popup v-model="cart.popup" mode="bottom" height="60%">
<view style="padding: 20rpx;height: 80rpx;">
<view class="flex row-between">
<view class="flex">
<view>
总价
<price-format :color="colorConfig.primary" :subscript-size="26"
:first-size="38" :second-size="26" :price="cart.total_amount" class="m-l-10">
</price-format>
</view>
</view>
<view>
<u-icon name="trash" size="32" class="m-r-10"></u-icon>
清空购物车
</view>
</view>
</view>
<scroll-view scroll-y="true" style="height: calc(100% - 80rpx);">
<view>
<view class="p-20 flex row-between" v-for="(item, index) in cart.data" :key="index">
<view class="m-r-20">
<u-image width="120" height="120" :src="item.pic"></u-image>
</view>
<view class="flex row-between flex-1">
<view>
<view class="line-2">
{{item.title}}
</view>
<view>
<price-format :color="colorConfig.primary" :subscript-size="26"
:first-size="38" :second-size="26" :price="item.price">
</price-format>
</view>
</view>
<view class="row-between">
<u-number-box :min="1" :max="spec.shop_max" :value="item.goods_num" :disabled-input="true" class="m-t-10" :index="item.id" @minus="minusCartFun" @plus="plusCartFun"/>
<view class="m-t-20 u-text-right">移除</view>
</view>
</view>
</view>
</view>
</scroll-view>
</u-popup>
</view>
</mescroll-uni>
</template>
@ -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;
}
</style>