Files

417 lines
10 KiB
Vue

<template>
<view
class="w100"
:class="{
'card-goods1': props.type == 1,
'card-goods2': props.type == 2,
'card-goods3': props.type == 3,
}"
>
<view
class="shrink"
@click="onCardClick"
:class="{
goodsImg1: props.type == 1,
goodsImg2: props.type == 2,
goodsImg3: props.type == 3,
}"
>
<view
v-if="isSoldOut"
class="sold-out-tag"
:class="{
sold1: props.type == 1,
sold2: props.type == 2,
sold3: props.type == 3,
}"
>已售罄</view>
<image
class=""
:src="props.data.picUrl ? sheep.$url.cdn(props.data.picUrl) : '/static/icon/null1.png'"
mode="aspectFill"
/>
</view>
<view class="goodItem" :class="{ itemBg: props.type == 1 }" @click="onCardClick">
<view class="wrap">
<view
class="title "
:class="{ lineTwo: props.type == 2, lineOne: props.type == 1 || props.type == 3, c34: props.type == 2 || props.type == 1, c34: props.type == 3 }"
>{{ props.data.name }} </view
>
<view
class="flex-center m-t-10 m-b-12"
:class="{ 'ju-between': props.data.tagSaleName, 'ju-flex-end': !props.data.tagSaleName }"
v-if="props.type == 1"
>
<view class="label" v-if="props.data.tagSaleName">{{ props.data.tagSaleName }}</view>
<view class="num" v-if="!props.memberPreferred">已售{{ props.data.salesCount }}</view>
</view>
<view v-else-if="props.type == 2">
<view class="flex-center ju-between mt10 wrap">
<view class="num size26 m-r-4">{{ props.data.categoryText }}</view>
<view class="num" v-if="!props.memberPreferred">销量:{{ props.data.salesCount }}</view>
</view>
<view class="flex-row wrap" v-if="props.data.tagSaleName">
<view
class="label mr10 mb10"
v-for="(v, i) in props.data.tagSaleName.split(',')"
:key="i"
>{{ v }}</view
>
<!-- <view class="label">标签2</view> -->
</view>
</view>
</view>
<view class="flex-center ju-between">
<view class="price"
><span class="f500" style="font-size: 24rpx;">¥</span
><span class="priceNum f500">{{ fen2yuan(props.data.price) }}</span>
<span v-if="props.type == 1 && props.data.unit">/{{ props.data.unit || '' }}</span>
<!-- <span
class="marketPrice"
v-else
style="color: 20rpx; color: #777777; text-decoration: line-through; margin-left: 8rpx"
>¥{{ fen2yuan(props.data.marketPrice) }}</span
> -->
</view>
<!-- -->
<uni-badge
v-if="!isSoldOut && props.type == 2 && props.data.cartCount"
:text="props.data.cartCount"
absolute="rightTop"
:customStyle="{background: '#FF0000'}"
>
<view
class="shopIcon"
:class="{ 'shopIcon1': props.type == 2, 'shop-icon-soldout': isSoldOut }"
@click.stop="onShopIconClick"
>
<image src="/static/index/shop.png" mode="scaleToFill" />
</view>
</uni-badge>
<view
class="shopIcon"
:class="{ 'shopIcon1': props.type == 2, 'shop-icon-soldout': isSoldOut }"
@click.stop="onShopIconClick"
v-else
>
<image v-if="!isSoldOut" src="/static/index/shop.png" mode="scaleToFill" />
<view v-else class="shop-soldout-tip">售罄</view>
</view>
</view>
</view>
<s-select-sku
v-if="showSelectSku"
:goodsInfo="state.goodsInfo"
:show="showSelectSku"
@addCart="onAddCart"
@buy="onBuy"
@change="onSkuChange"
@close="showSelectSku = false"
/>
</view>
</template>
<script setup>
import sheep from '@/sheep';
import { ref, reactive, watch, computed } from 'vue';
import SpuApi from '@/sheep/api/product/spu';
import { fen2yuan } from '@/sheep/hooks/useGoods';
const props = defineProps({
data: {
type: Object,
default() {
return {};
},
},
memberPreferred: {
type: Boolean,
default: false,
},
type: {
//1:首页 2:分类 3:搜索
type: Number,
default: 1,
},
search: {
type: String,
default: '',
},
});
watch(
() => props.data,
() => {},
{
immediate: true,
deep: true,
},
);
const isSoldOut = computed(() => {
return Number(props.data.stock || 0) <= 0;
});
let showSelectSku = ref(false);
const goDetail = () => {
sheep.$router.go('/pages/goods/info', { id: props.data.id });
};
const onCardClick = () => {
if (props.memberPreferred) return;
goDetail();
};
const buyMemberGoods = () => {
uni.navigateTo({
url: `/pages/AI/giftOrder?id=${props.data.id}`,
});
};
const onShopIconClick = () => {
if (isSoldOut.value) return;
if (props.memberPreferred) {
buyMemberGoods();
return;
}
changeSelectSku();
};
const changeSelectSku = async () => {
let res = await getData();
showSelectSku.value = true;
};
const getData = async () => {
let res = await SpuApi.getSpuDetail(props.data.id);
if (res.code !== 0 || !res.data) {
state.goodsInfo = null;
state.skeletonLoading = false;
return;
}
// 加载到商品
state.skeletonLoading = false;
state.goodsInfo = res.data;
// 获取结算信息
// getSettlementByIds(state.goodsId);
};
const state = reactive({
goodsId: 0,
skeletonLoading: true, // SPU 加载中
goodsInfo: {}, // SPU 信息
showSelectSku: false, // 是否展示 SKU 选择弹窗
selectedSku: {}, // 选中的 SKU
settlementSku: {}, // 结算的 SKU:由于 selectedSku 不进行默认选中,所以初始使用结算价格最低的 SKU 作为基础展示
showModel: false, // 是否展示 Coupon 优惠劵的弹窗
couponInfo: [], // 可领取的 Coupon 优惠劵的列表
showActivityModel: false, // 【满减送/限时折扣】是否展示 Activity 营销活动的弹窗
rewardActivity: {}, // 【满减送】活动
activityList: [], // 【秒杀/拼团/砍价】可参与的 Activity 营销活动的列表
});
// 添加购物车
function onAddCart(e) {
//console.log(e);
if (!e.id) {
sheep.$helper.toast('请选择商品规格');
return;
}
sheep.$store('cart').add(e);
showSelectSku.value = false;
}
// 立即购买
function onBuy(e) {
if (!e.id) {
sheep.$helper.toast('请选择商品规格');
return;
}
showSelectSku.value = false;
sheep.$router.go('/pages/order/confirm', {
data: JSON.stringify({
items: [
{
skuId: e.id,
count: e.goods_num,
categoryId: state.goodsInfo.categoryId,
},
],
}),
});
}
// 规格变更
function onSkuChange(e) {
state.selectedSku = e;
state.settlementSku = e;
}
</script>
<style lang="scss" scoped>
.sold-out-tag {
position: absolute;
right: 0;
top: 0;
z-index: 3;
color: #ffffff;
font-weight: 600;
background: rgba(0, 0, 0, 0.58);
border-radius: 0 0 0 8rpx;
backdrop-filter: blur(2px);
text-align: center;
}
.sold-out-tag.sold1 {
width: 108rpx;
height: 52rpx;
line-height: 52rpx;
font-size: 24rpx;
}
.sold-out-tag.sold2 {
width: 96rpx;
height: 44rpx;
line-height: 44rpx;
font-size: 22rpx;
}
.sold-out-tag.sold3 {
width: 76rpx;
height: 36rpx;
line-height: 36rpx;
font-size: 18rpx;
}
.goodItem {
padding: 20rpx 24rpx;
box-sizing: border-box;
margin-bottom: 32rpx;
border-radius: 0 0 8rpx 8rpx;
.title {
font-size: 28rpx;
line-height: 30rpx;
font-weight: 500;
color: #333333;
}
.label {
font-size: 20rpx;
color: #ff5040;
border: 1px solid #ff5040;
border-radius: 8rpx;
height: 34rpx;
line-height: 34rpx;
padding: 0 8rpx;
box-sizing: border-box;
}
.num {
color: #777777;
font-size: 24rpx;
}
.price {
color: #ee0a24;
font-size: 24rpx;
}
.priceNum {
font-size: 36rpx;
font-weight: 600;
}
.shopIcon {
width: 50rpx;
height: 50rpx;
image {
width: 100%;
height: 100%;
}
}
.shopIcon1{
width: 52rpx;
height: 52rpx;
image {
width: 100%;
height: 100%;
}
}
.shop-icon-soldout {
background: #cccccc;
filter: grayscale(100%);
border-radius: 50%;
cursor: not-allowed;
display: flex;
align-items: center;
justify-content: center;
}
.shop-soldout-tip {
font-size: 18rpx;
color: #ffffff;
font-weight: 600;
text-align: center;
line-height: 1.2;
}
}
.shrink{
border-radius: 10rpx;
overflow: hidden;
image {
width: 100%;
height: 100%;
}
}
.goodsImg2 {
width: 200rpx;
height: 200rpx;
}
.goodsImg3 {
width: 96rpx;
height: 96rpx;
}
.goodsImg1 {
// width: 100%;
// aspect-ratio: 1/1;
border-radius:10rpx 10rpx 0 0;
position: relative;
}
.goodsImg1::before{
content: '';
display: block;
padding-top: 100%;
}
.goodsImg1 image{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.card-goods1 {
display: flex;
flex-direction: column;
}
.card-goods2,
.card-goods3 {
width: 100%;
display: flex;
flex-direction: row;
margin-bottom: 36rpx;
flex-wrap: nowrap;
.goodItem {
flex: 1;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
justify-content: space-between;
padding-left: 12rpx;
box-sizing: border-box;
}
}
.card-goods3 {
.priceNum {
font-size: 28rpx;
}
.marketPrice {
font-size: 24rpx;
}
}
.itemBg{
background-color: #ffffff;
}
</style>