feat: 选品广场详情添加购买按钮

This commit is contained in:
2026-06-16 11:02:02 +08:00
parent a811e42c92
commit 5124f93433
4 changed files with 61 additions and 11 deletions
+28 -5
View File
@@ -16,7 +16,7 @@
</view>
<view class="ai-button1 h_80 line80 w_200" @click="go"> 去结算 </view>
</view>
<uni-popup ref="popupRef" type="bottom" border-radius="10px 10px 0 0">
<uni-popup ref="popupRef" type="bottom" border-radius="10px 10px 0 0" @change="onPopupChange">
<view class="p-x-32 p-y-40 bg17">
<view class="flex-center ju-between p-b-44">
<view>已加购商品</view>
@@ -117,10 +117,10 @@
}
});
const popupSpacerHeight = computed(() => {
const deltaPx = uni.upx2px(30);
return Math.max(0, (Number(props.bottomOffset) || 0) - deltaPx);
});
const safeAreaBottom = Number(uni.getSystemInfoSync()?.safeAreaInsets?.bottom || 0);
const popupOpened = ref(false);
const popupBottomInsetPx = ref(0);
const popupSpacerHeight = computed(() => Math.max(0, Number(popupBottomInsetPx.value) || 0));
const cartList = ref([]);
let price = ref(0);
let num = ref(0);
@@ -155,15 +155,38 @@
getCartList();
});
let popupRef = ref(null);
const resolvePopupBottomInsetPx = () => {
return Math.max(0, (Number(props.bottomOffset) || 0) - safeAreaBottom);
};
const onPopupChange = (e: any) => {
popupOpened.value = !!e?.show;
if (popupOpened.value) {
popupBottomInsetPx.value = resolvePopupBottomInsetPx();
} else {
popupBottomInsetPx.value = 0;
}
};
const showPopup = () => {
if (!popupRef.value) return;
popupOpened.value = true;
popupBottomInsetPx.value = resolvePopupBottomInsetPx();
popupRef.value.open('bottom');
};
const hidePopup = () => {
popupOpened.value = false;
popupBottomInsetPx.value = 0;
popupRef.value.close();
};
onMounted(() => { });
watch(
() => cartList.value?.length,
(len) => {
if (popupOpened.value && (!len || len <= 0)) {
hidePopup();
}
},
);
//#region 选择规格弹窗
let showSelectSku = ref(false);
let goodsInfo = ref({});
+2 -2
View File
@@ -2,8 +2,8 @@
"name" : "优购商城",
"appid" : "__UNI__8B19741",
"description" : "",
"versionName" : "1.4.6",
"versionCode" : 146,
"versionName" : "1.4.7",
"versionCode" : 147,
"transformPx" : false,
"app-plus" : {
"privacy" : {
+30 -3
View File
@@ -68,14 +68,21 @@
<detail-content-card class="detail-content-selector" :content="state.goodsInfo.description" />
</view>
</block>
<view class="theme-ai">
<card_payment ref="paymentRef" source="orderInfo" :actionStatus="timeText" @addCar="addCar" />
<view class="theme-ai" v-if="state.goodsInfo && state.goodsInfo.id">
<card_payment ref="paymentRef" source="orderInfo" :actionStatus="timeText" :bottomOffset="paymentBottomOffset"
@addCar="addCar" @updatePrice="updatePrice" />
</view>
<su-fixed bottom placeholder bg="bg24" :zIndex="1"
v-if="state.goodsInfo && state.goodsInfo.id && !hasCartItems">
<view class="buy-now-bar bg24">
<view class="ai-button1 buy-now-btn" @tap="addCar">立即购买</view>
</view>
</su-fixed>
</view>
</s-layout>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, onUnmounted, getCurrentInstance, watch, nextTick } from 'vue';
import { computed, ref, reactive, onMounted, onUnmounted, getCurrentInstance, watch, nextTick } from 'vue';
import { onLoad, onPageScroll } from '@dcloudio/uni-app';
import sheep from '@/sheep';
// import { onPageScroll} from '@dcloudio/uni-app';
@@ -114,6 +121,7 @@ const getInfo = async () => {
};
let id = ref();
let shoppingPlazaId = ref();
const hasCartItems = ref(false);
onLoad(async (options) => {
// 滚到顶部
uni.pageScrollTo({
@@ -130,6 +138,9 @@ function onSkuChange(e) {
const onAddCart = () => { };
const onBuy = () => { };
let paymentRef = ref(null);
const updatePrice = (val) => {
hasCartItems.value = !!val;
};
const addCar = () => {
paymentRef.value.addCar({ ...state.goodsInfo, shoppingPlazaId: shoppingPlazaId.value });
};
@@ -187,6 +198,9 @@ let sysInfo = uni.getSystemInfoSync();
const windowHeight = sysInfo.windowHeight;
let height = ref(0);
height.value = sysInfo.statusBarHeight + uni.upx2px(88);
const buyBarOffset =
uni.upx2px(120) + Number(sheep?.$platform?.device?.safeAreaInsets?.bottom || 0);
const paymentBottomOffset = computed(() => (hasCartItems.value ? 0 : buyBarOffset));
</script>
<style lang="scss" scoped>
.detail-card {
@@ -457,6 +471,19 @@ height.value = sysInfo.statusBarHeight + uni.upx2px(88);
left: 0;
}
.buy-now-bar {
height: 120rpx;
padding: 20rpx 32rpx;
box-sizing: border-box;
}
.buy-now-btn {
width: 100%;
height: 80rpx;
line-height: 80rpx;
text-align: center;
}
:deep(.uni-countdown__number) {
font-size: 24rpx !important;
width: 40rpx !important;
+1 -1
View File
@@ -330,7 +330,7 @@
};
const system = uni.getSystemInfoSync();
const tabbarBottomOffset = uni.upx2px(100);
const tabbarBottomOffset = uni.upx2px(100) + Number(system.safeAreaInsets?.bottom || 0);
const paymentBarReserve = uni.upx2px(148);
const baseHeight =
system.windowHeight -