|
@@ -12,10 +12,15 @@
|
|
// eslint-disable-next-line unused-imports/no-unused-imports
|
|
// eslint-disable-next-line unused-imports/no-unused-imports
|
|
import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
|
|
import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
|
|
import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
|
|
import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
|
|
|
|
+import { getConfigByCode } from '@/api/common'
|
|
|
|
+import { myFavoriteAdd, myFavoriteDel } from '@/api/mine'
|
|
import { preOrder as _preOrder } from '@/api/order'
|
|
import { preOrder as _preOrder } from '@/api/order'
|
|
import { getDetail, pinkList } from '@/api/product'
|
|
import { getDetail, pinkList } from '@/api/product'
|
|
|
|
+import { getUserInfoHook, requireLogin } from '@/hooks/usePageAuth'
|
|
|
|
+import { t } from '@/locale'
|
|
import { formatNumber } from '@/utils/index'
|
|
import { formatNumber } from '@/utils/index'
|
|
import { getPageParams, goBack, toPage } from '@/utils/page'
|
|
import { getPageParams, goBack, toPage } from '@/utils/page'
|
|
|
|
+import { toast } from '@/utils/toast'
|
|
import CustomTooltip from './components/CustomTooltip.vue'
|
|
import CustomTooltip from './components/CustomTooltip.vue'
|
|
import NotificationCarousel from './components/NotificationCarousel.vue'
|
|
import NotificationCarousel from './components/NotificationCarousel.vue'
|
|
|
|
|
|
@@ -33,7 +38,11 @@ const safeAreaInsets = systemInfo.safeAreaInsets
|
|
const paging = ref(null)
|
|
const paging = ref(null)
|
|
// 类似mixins,如果是页面滚动务必要写这一行,并传入当前ref绑定的paging,注意此处是paging,而非paging.value
|
|
// 类似mixins,如果是页面滚动务必要写这一行,并传入当前ref绑定的paging,注意此处是paging,而非paging.value
|
|
useZPaging(paging)
|
|
useZPaging(paging)
|
|
-
|
|
|
|
|
|
+function goHome() {
|
|
|
|
+ uni.switchTab({
|
|
|
|
+ url: '/pages/index/index',
|
|
|
|
+ })
|
|
|
|
+}
|
|
// 添加导航栏背景色变量
|
|
// 添加导航栏背景色变量
|
|
const navBgColor = ref('transparent')
|
|
const navBgColor = ref('transparent')
|
|
const changeNavbarThreshold = 300 // 滚动到这个高度时改变导航栏颜色
|
|
const changeNavbarThreshold = 300 // 滚动到这个高度时改变导航栏颜色
|
|
@@ -191,11 +200,14 @@ function findMatchingAttrValue(selectedSpecs) {
|
|
return selectedKeys.every(key => selectedSpecs[key] === attrValueSpecs[key])
|
|
return selectedKeys.every(key => selectedSpecs[key] === attrValueSpecs[key])
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+const rebate = ref<any>(0)
|
|
// 查询商品详情
|
|
// 查询商品详情
|
|
async function queryDetail() {
|
|
async function queryDetail() {
|
|
const res = await getDetail({ id: productId.value })
|
|
const res = await getDetail({ id: productId.value })
|
|
console.log(res)
|
|
console.log(res)
|
|
detail.value = res.data
|
|
detail.value = res.data
|
|
|
|
+ const rate = await getConfig()
|
|
|
|
+ rebate.value = formatNumber(rate * res.data.price)
|
|
// 默认选择第一个规格
|
|
// 默认选择第一个规格
|
|
setDefaultSpecs()
|
|
setDefaultSpecs()
|
|
paging.value.complete()
|
|
paging.value.complete()
|
|
@@ -208,6 +220,20 @@ async function queryPinkInfo() {
|
|
pinkInfo.value = res.data.list
|
|
pinkInfo.value = res.data.list
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+async function getConfig() {
|
|
|
|
+ try {
|
|
|
|
+ const res = await getConfigByCode({ code: 'open_red_envelope_rate' })
|
|
|
|
+ console.log(res)
|
|
|
|
+ if (res.code === '200') {
|
|
|
|
+ return res.data.valueInfo / 100
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return 0
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch {}
|
|
|
|
+}
|
|
|
|
+
|
|
// 设置默认规格选择
|
|
// 设置默认规格选择
|
|
function setDefaultSpecs() {
|
|
function setDefaultSpecs() {
|
|
if (detail.value.attr && detail.value.attr.length > 0) {
|
|
if (detail.value.attr && detail.value.attr.length > 0) {
|
|
@@ -241,6 +267,35 @@ function setDefaultSpecs() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 收藏/取消收藏
|
|
|
|
+async function toggleFavorite() {
|
|
|
|
+ if (!requireLogin()) {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ if (detail.value.isFavorite) {
|
|
|
|
+ // 取消收藏
|
|
|
|
+ const res = await myFavoriteDel({ id: productId.value })
|
|
|
|
+ if (res.code === '200') {
|
|
|
|
+ detail.value.isFavorite = false
|
|
|
|
+ toast.success(t('productDetail.unfavoriteSuccess'))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ // 添加收藏
|
|
|
|
+ const res = await myFavoriteAdd({ productIdList: [productId.value] })
|
|
|
|
+ if (res.code === '200') {
|
|
|
|
+ detail.value.isFavorite = true
|
|
|
|
+ toast.success(t('productDetail.favoriteSuccess'))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (error) {
|
|
|
|
+ console.error('收藏操作失败:', error)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
// 预下单
|
|
// 预下单
|
|
async function preOrder() {
|
|
async function preOrder() {
|
|
if (!requireLogin()) {
|
|
if (!requireLogin()) {
|
|
@@ -428,13 +483,26 @@ onShow(() => {
|
|
<view class="flex gap-32rpx bg-white/60 px-28rpx py-30rpx backdrop-blur-20">
|
|
<view class="flex gap-32rpx bg-white/60 px-28rpx py-30rpx backdrop-blur-20">
|
|
<view class="flex items-center justify-between gap-20rpx">
|
|
<view class="flex items-center justify-between gap-20rpx">
|
|
<view class="flex flex-col items-center justify-center">
|
|
<view class="flex flex-col items-center justify-center">
|
|
- <wd-icon color="#BDBDBD" name="home" size="40rpx" />
|
|
|
|
|
|
+ <image
|
|
|
|
+ src="/static/icons/go-home.png"
|
|
|
|
+ class="h-40rpx w-40rpx"
|
|
|
|
+ @click="goHome"
|
|
|
|
+ />
|
|
<text class="text-18rpx text-#757575">
|
|
<text class="text-18rpx text-#757575">
|
|
{{ $t('productDetail.home') }}
|
|
{{ $t('productDetail.home') }}
|
|
</text>
|
|
</text>
|
|
</view>
|
|
</view>
|
|
- <view class="flex flex-col items-center justify-center">
|
|
|
|
- <wd-icon color="#BDBDBD" name="heart-filled" size="40rpx" />
|
|
|
|
|
|
+ <view class="flex flex-col items-center justify-center" @click="toggleFavorite">
|
|
|
|
+ <image
|
|
|
|
+ v-if="detail.isFavorite"
|
|
|
|
+ src="/static/icons/favorite-active.png"
|
|
|
|
+ class="h-40rpx w-40rpx"
|
|
|
|
+ />
|
|
|
|
+ <image
|
|
|
|
+ v-else
|
|
|
|
+ src="/static/icons/favorite.png"
|
|
|
|
+ class="h-40rpx w-40rpx"
|
|
|
|
+ />
|
|
<text class="text-18rpx text-#757575">
|
|
<text class="text-18rpx text-#757575">
|
|
{{ $t('productDetail.favorite') }}
|
|
{{ $t('productDetail.favorite') }}
|
|
</text>
|
|
</text>
|
|
@@ -447,8 +515,8 @@ onShow(() => {
|
|
</view>
|
|
</view>
|
|
<CustomTooltip
|
|
<CustomTooltip
|
|
v-model:visible="showTip"
|
|
v-model:visible="showTip"
|
|
- :highlight-text1="`৳${detail.price}`"
|
|
|
|
- highlight-text2="$1.8"
|
|
|
|
|
|
+ :highlight-text1="`৳${formatNumber(detail.price)}`"
|
|
|
|
+ :highlight-text2="`৳${rebate}`"
|
|
/>
|
|
/>
|
|
</view>
|
|
</view>
|
|
<view class="rounded-r-full bg-[var(--wot-color-theme)] px-34rpx py-18rpx text-white" @click="openSku('join')">
|
|
<view class="rounded-r-full bg-[var(--wot-color-theme)] px-34rpx py-18rpx text-white" @click="openSku('join')">
|