acdr/acdr-ui/src/pages/mall/goods/components/detail/detail-navbar.vue

261 lines
5.8 KiB
Vue
Raw Normal View History

2024-09-05 14:05:15 +08:00
<!-- 商品详情商品/评价/详情的 nav -->
<template>
<su-fixed alway :bgStyles="{ background: '#fff' }" :val="0" noNav opacity :placeholder="false">
<su-status-bar />
<view
class="ui-bar ss-flex ss-col-center ss-row-between ss-p-x-20"
:style="[{ height: sys_navBar - sys_statusBar + 'px' }]"
>
<!-- -->
<view class="icon-box ss-flex">
<view class="icon-button icon-button-left ss-flex ss-row-center" @tap="onClickLeft">
<text class="sicon-back" v-if="hasHistory" />
<text class="sicon-home" v-else />
</view>
<view class="line"></view>
<view class="icon-button icon-button-right ss-flex ss-row-center" @tap="onClickRight">
<text class="sicon-more" />
</view>
</view>
<!-- -->
<view class="detail-tab-card ss-flex-1" :style="[{ opacity: state.tabOpacityVal }]">
<view class="tab-box ss-flex ss-col-center ss-row-around">
<view
class="tab-item ss-flex-1 ss-flex ss-row-center ss-col-center"
v-for="item in state.tabList"
:key="item.value"
@tap="onTab(item)"
>
<view class="tab-title" :class="state.curTab === item.value ? 'cur-tab-title' : ''">
{{ item.label }}
</view>
<view v-show="state.curTab === item.value" class="tab-line"></view>
</view>
</view>
</view>
<!-- #ifdef MP -->
<view :style="[capsuleStyle]"></view>
<!-- #endif -->
</view>
</su-fixed>
</template>
<script setup>
2024-09-08 14:01:29 +08:00
import { reactive } from 'vue'
import { onPageScroll } from '@dcloudio/uni-app'
import sheep from '@/sheep'
import throttle from '@/sheep/helper/throttle.js'
import { showMenuTools, closeMenuTools } from '@/sheep/hooks/useModal'
2024-09-05 14:05:15 +08:00
2024-09-08 14:01:29 +08:00
const sys_statusBar = sheep.$platform.device.statusBarHeight
const sys_navBar = sheep.$platform.navbar
const capsuleStyle = {
width: sheep.$platform.capsule.width + 'px',
height: sheep.$platform.capsule.height + 'px',
}
2024-09-05 14:05:15 +08:00
2024-09-08 14:01:29 +08:00
const state = reactive({
tabOpacityVal: 0,
curTab: 'goods',
tabList: [
{
label: '商品',
value: 'goods',
to: 'detail-swiper-selector',
},
{
label: '评价',
value: 'comment',
to: 'detail-comment-selector',
},
{
label: '详情',
value: 'detail',
to: 'detail-content-selector',
},
],
})
const emits = defineEmits(['clickLeft'])
const hasHistory = sheep.$router.hasHistory()
2024-09-05 14:05:15 +08:00
2024-09-08 14:01:29 +08:00
function onClickLeft() {
if (hasHistory) {
sheep.$router.back()
} else {
sheep.$router.go('/pages/mall/index/index')
2024-09-05 14:05:15 +08:00
}
2024-09-08 14:01:29 +08:00
emits('clickLeft')
}
2024-09-05 14:05:15 +08:00
2024-09-08 14:01:29 +08:00
function onClickRight() {
showMenuTools()
}
2024-09-05 14:05:15 +08:00
2024-09-08 14:01:29 +08:00
const commentCard = {
top: 0,
bottom: 0,
}
2024-09-05 14:05:15 +08:00
2024-09-08 14:01:29 +08:00
function getCommentCardNode() {
return new Promise((res, rej) => {
uni
.createSelectorQuery()
.select('.detail-comment-selector')
.boundingClientRect((data) => {
if (data) {
commentCard.top = data.top
commentCard.bottom = data.top + data.height
res(data)
} else {
res(null)
}
})
.exec()
})
}
2024-09-05 14:05:15 +08:00
2024-09-08 14:01:29 +08:00
function onTab(tab) {
let scrollTop = 0
if (tab.value === 'comment') {
scrollTop = commentCard.top - sys_navBar + 1
} else if (tab.value === 'detail') {
scrollTop = commentCard.bottom - sys_navBar + 1
2024-09-05 14:05:15 +08:00
}
2024-09-08 14:01:29 +08:00
uni.pageScrollTo({
scrollTop,
duration: 200,
})
}
2024-09-05 14:05:15 +08:00
2024-09-08 14:01:29 +08:00
onPageScroll((e) => {
state.tabOpacityVal = e.scrollTop > sheep.$platform.navbar ? 1 : e.scrollTop * 0.01
if (commentCard.top === 0) {
throttle(() => {
getCommentCardNode()
}, 50)
}
2024-09-05 14:05:15 +08:00
2024-09-08 14:01:29 +08:00
if (e.scrollTop < commentCard.top - sys_navBar) {
state.curTab = 'goods'
} else if (
e.scrollTop >= commentCard.top - sys_navBar &&
e.scrollTop <= commentCard.bottom - sys_navBar
) {
state.curTab = 'comment'
} else {
state.curTab = 'detail'
}
})
2024-09-05 14:05:15 +08:00
</script>
<style lang="scss" scoped>
2024-09-08 14:01:29 +08:00
@import '@/scss/index.scss';
.icon-box {
box-shadow:
0px 0px 4rpx rgba(51, 51, 51, 0.08),
0px 4rpx 6rpx 2rpx rgba(102, 102, 102, 0.12);
border-radius: 30rpx;
width: 134rpx;
height: 56rpx;
margin-left: 8rpx;
border: 1px solid rgba(#fff, 0.4);
.line {
width: 2rpx;
height: 24rpx;
background: #e5e5e7;
}
.sicon-back {
font-size: 32rpx;
color: #000;
}
.sicon-home {
font-size: 32rpx;
color: #000;
}
.sicon-more {
font-size: 32rpx;
color: #000;
}
.icon-button {
width: 67rpx;
2024-09-05 14:05:15 +08:00
height: 56rpx;
2024-09-08 14:01:29 +08:00
&-left:hover {
background: rgba(0, 0, 0, 0.16);
border-radius: 30rpx 0px 0px 30rpx;
2024-09-05 14:05:15 +08:00
}
2024-09-08 14:01:29 +08:00
&-right:hover {
background: rgba(0, 0, 0, 0.16);
border-radius: 0px 30rpx 30rpx 0px;
2024-09-05 14:05:15 +08:00
}
}
2024-09-08 14:01:29 +08:00
}
.left-box {
position: relative;
width: 60rpx;
height: 60rpx;
display: flex;
justify-content: center;
align-items: center;
.circle {
position: absolute;
left: 0;
top: 0;
2024-09-05 14:05:15 +08:00
width: 60rpx;
height: 60rpx;
2024-09-08 14:01:29 +08:00
background: rgba(#fff, 0.6);
border: 1rpx solid #ebebeb;
border-radius: 50%;
box-sizing: border-box;
z-index: -1;
2024-09-05 14:05:15 +08:00
}
2024-09-08 14:01:29 +08:00
}
.right {
position: relative;
width: 60rpx;
height: 60rpx;
display: flex;
justify-content: center;
align-items: center;
.circle {
position: absolute;
left: 0;
top: 0;
2024-09-05 14:05:15 +08:00
width: 60rpx;
height: 60rpx;
2024-09-08 14:01:29 +08:00
background: rgba(#ffffff, 0.6);
border: 1rpx solid #ebebeb;
box-sizing: border-box;
border-radius: 50%;
z-index: -1;
2024-09-05 14:05:15 +08:00
}
2024-09-08 14:01:29 +08:00
}
.detail-tab-card {
width: 50%;
.tab-item {
height: 80rpx;
position: relative;
z-index: 11;
2024-09-05 14:05:15 +08:00
2024-09-08 14:01:29 +08:00
.tab-title {
font-size: 30rpx;
}
2024-09-05 14:05:15 +08:00
2024-09-08 14:01:29 +08:00
.cur-tab-title {
font-weight: $font-weight-bold;
}
2024-09-05 14:05:15 +08:00
2024-09-08 14:01:29 +08:00
.tab-line {
width: 60rpx;
height: 6rpx;
border-radius: 6rpx;
position: absolute;
left: 50%;
transform: translateX(-50%);
bottom: 10rpx;
background-color: var(--ui-BG-Main);
z-index: 12;
2024-09-05 14:05:15 +08:00
}
}
2024-09-08 14:01:29 +08:00
}
2024-09-05 14:05:15 +08:00
</style>