feat: 实现秒杀商品和分类商品的一键加购。

This commit is contained in:
mixtan 2025-07-23 14:40:17 +08:00
parent 28ae2b34b1
commit 8aa7027bf6
3 changed files with 75 additions and 7 deletions

View File

@ -281,10 +281,36 @@
</view>
<view class="m-product-price1">
<view class="money">
<block v-if="item.product_unit_price_range != '0.00'">
<view
v-if="item.product_unit_price_range != '0.00'"
class="goods_name"
>
<label>{{ __("¥") }}</label
>{{ item.product_unit_price_range }}
</block>
</view>
<view
v-if="item.product_quantity != 0"
:data-stock="chooseItem.available_quantity"
:data-num="chooseItem.user_cart_quantity"
:data-step="1"
:data-spuid="
chooseItem.product_id ? chooseItem.product_id : 0
"
:data-pname="
chooseItem.item_name ? chooseItem.item_name : ''
"
:data-skuid="item.item_id"
:data-index="chooseIndex"
@click.stop="addCart"
class="btn_addcard"
></view>
<view
v-if="item.product_quantity == 0"
@click.stop="addCart2"
class="btn_addcard disabled"
></view>
<block v-if="item.product_unit_points">
<label
@ -767,7 +793,6 @@
</view>
</template>
<script>
import uniDrawer from "@/components/uni-drawer.vue";
import uniTag from "@/components/uni-tag/uni-tag.vue";
@ -1853,6 +1878,14 @@ export default {
this.onFilter();
this.onCloseFilter();
},
addCart2(){
uni.showToast({
icon: 'error',
title: this.$.__("亲~商品没有库存啦!")
});
},
//
addCart: async function (e) {
let that = this;
@ -1860,11 +1893,14 @@ export default {
let step = parseInt(e.currentTarget.dataset.step);
let user_cart_quantity = parseInt(e.currentTarget.dataset.num);
console.log(`sku${e.currentTarget.dataset.skuid}`);
let params = {
item_id: e.currentTarget.dataset.skuid,
cart_quantity: step,
activity_id: 0,
chain_id: 0,
SKU_Id: e.currentTarget.dataset.skuid,
};
if (e.currentTarget.dataset.stock == user_cart_quantity) {
@ -1896,6 +1932,12 @@ export default {
// that.pdlist[index].user_cart_quantity = that.pdlist[index].user_cart_quantity + step
//that.$.alert(that.$.__(''));
console.log(1001);
if (data?.item_quantity != 0) {
that.$.alert(that.__("添加购物车成功"), function () {}, 400);
}
that.$set(that.pdlist[index], "cart_id", data.cart_id);
that.$set(
that.pdlist[index],
@ -2109,7 +2151,6 @@ export default {
};
</script>
<style lang="scss" scoped>
@import "../styles/_variables.scss";
@import "../styles/store_tpl.scss";
@ -2745,5 +2786,17 @@ export default {
border-left: 1rpx solid #d9d9d9;
}
/*Grid*/
</style>
.btn_addcard {
position: absolute;
right: 0;
bottom: 12rpx;
width: 40rpx;
height: 40rpx;
background: url(https://media-mall-prod-1259811287.cos.ap-guangzhou.myqcloud.com/static/xcxfile/appicon/pc1.png)
center no-repeat;
background-size: cover;
&.disabled {
filter: grayscale(1);
}
}
</style>

View File

@ -576,6 +576,7 @@
<view class="activity-desc" v-if="item.eltm16.isShowNum">
{{ __("已有") }}{{ items.OrderCount }} {{ __("人参加") }}
</view>
<view class="btn_addcard" @click.stop="addCart(items)"></view>
</view>
</navigator>
<button v-else class="activity-item" :data-pid="items.did" :data-Mid="items.mid || ''"
@ -1495,4 +1496,18 @@ uni-page-body {
.diyPage {
padding-bottom: 60rpx;
}
.activity-info{
position: relative;
}
.btn_addcard{
position: absolute;
right: 0;
bottom: 14rpx;
width: 40rpx;
height: 40rpx;
background: url(https://media-mall-prod-1259811287.cos.ap-guangzhou.myqcloud.com/static/xcxfile/appicon/pc1.png) center no-repeat;
background-size: cover;
}
</style>

View File

@ -1,6 +1,6 @@
<template name="shoptheme1">
<view>
<view class="m-supermarket-ad">11111
<view class="m-supermarket-ad">
<view v-if="(commonTPL.AdContent.F1ProductContents.length>0)">
<view class="m-supermarket-tip-list">
<navigator :url="'/pages/product/list?is_store_flag=' + (commonTPL.isStoreFlag) + '&store_category_id=' + (item.store_product_cat_id) + '&cname=' + (item.name)"