init
This commit is contained in:
@@ -0,0 +1,315 @@
|
||||
<template>
|
||||
<view
|
||||
class="w100"
|
||||
:class="{
|
||||
'card-goods1': props.type == 1,
|
||||
'card-goods2': props.type == 2,
|
||||
'card-goods3': props.type == 3,
|
||||
}"
|
||||
>
|
||||
<view
|
||||
class="shrink"
|
||||
@click="utils.go('/pages/goods/info', { id: props.data.id })"
|
||||
:class="{
|
||||
goodsImg1: props.type == 1,
|
||||
goodsImg2: props.type == 2,
|
||||
goodsImg3: props.type == 3,
|
||||
}"
|
||||
>
|
||||
<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="utils.go('/pages/goods/info', { id: props.data.id })">
|
||||
<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">已售{{ 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">销量:{{ 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 :text="props.data.cartCount" v-if="props.type == 2 && props.data.cartCount" absolute="rightTop" :customStyle="{background: '#FF0000'}">
|
||||
<view class="shopIcon" :class="{ 'shopIcon1': props.type == 2 }" @click.stop="changeSelectSku">
|
||||
<image src="/static/index/shop.png" mode="scaleToFill" />
|
||||
</view>
|
||||
</uni-badge>
|
||||
<view class="shopIcon" :class="{ 'shopIcon1': props.type == 2 }" @click.stop="changeSelectSku" v-else>
|
||||
<image src="/static/index/shop.png" mode="scaleToFill" />
|
||||
</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 } from 'vue';
|
||||
import SpuApi from '@/sheep/api/product/spu';
|
||||
import { fen2yuan } from '@/sheep/hooks/useGoods';
|
||||
|
||||
const props = defineProps({
|
||||
data: {
|
||||
type: Object,
|
||||
default() {
|
||||
return {};
|
||||
},
|
||||
},
|
||||
type: {
|
||||
//1:首页 2:分类 3:搜索
|
||||
type: Number,
|
||||
default: 1,
|
||||
},
|
||||
search: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
});
|
||||
watch(
|
||||
() => props.data,
|
||||
() => {},
|
||||
{
|
||||
immediate: true,
|
||||
deep: true,
|
||||
},
|
||||
);
|
||||
let showSelectSku = ref(false);
|
||||
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>
|
||||
.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%;
|
||||
}
|
||||
}
|
||||
}
|
||||
.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>
|
||||
Reference in New Issue
Block a user