2023-11-14 17:21:03 +08:00
|
|
|
|
<!--
|
|
|
|
|
@name: 上哦
|
|
|
|
|
@author: kahu4
|
|
|
|
|
@date: 2023-11-02 18:30
|
|
|
|
|
@description:Goods
|
|
|
|
|
@update: 2023-11-02 18:30
|
|
|
|
|
-->
|
|
|
|
|
<script setup>
|
|
|
|
|
import { toRefs } from "vue";
|
|
|
|
|
import { GOODS_ITEM_TYPE } from "@/components/goodsComponents/utils/index.type";
|
|
|
|
|
import { useRouter } from "@/hooks/useRouter";
|
2023-11-15 19:59:37 +08:00
|
|
|
|
import { getRandom } from "@/utils/utils";
|
2023-11-14 17:21:03 +08:00
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
goods: {
|
|
|
|
|
type: Object,
|
|
|
|
|
default: () => ({})
|
|
|
|
|
},
|
|
|
|
|
imgWidth: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: '100%'
|
|
|
|
|
},
|
|
|
|
|
/** 图片比例 */
|
|
|
|
|
ratio: {
|
2023-11-15 19:59:37 +08:00
|
|
|
|
type: [String,Boolean],
|
|
|
|
|
default: () => '1/1'
|
2023-11-14 17:21:03 +08:00
|
|
|
|
},
|
|
|
|
|
infoPadding: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: () => "0 0"
|
|
|
|
|
},
|
|
|
|
|
/** title是否换行 */
|
2023-11-15 19:59:37 +08:00
|
|
|
|
titleWrap: {
|
2023-11-14 17:21:03 +08:00
|
|
|
|
type: Boolean,
|
2023-11-15 19:59:37 +08:00
|
|
|
|
default: () => false
|
2023-11-14 17:21:03 +08:00
|
|
|
|
},
|
|
|
|
|
/** title 文字大小 rpx */
|
|
|
|
|
titleSize: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: () => 28
|
|
|
|
|
},
|
|
|
|
|
type: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: () => GOODS_ITEM_TYPE.NEW
|
|
|
|
|
},
|
|
|
|
|
row: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
goods,
|
|
|
|
|
imgWidth,
|
|
|
|
|
ratio,
|
|
|
|
|
infoPadding,
|
2023-11-15 19:59:37 +08:00
|
|
|
|
titleWrap,
|
2023-11-14 17:21:03 +08:00
|
|
|
|
titleSize,
|
|
|
|
|
row,
|
|
|
|
|
} = toRefs(props)
|
|
|
|
|
|
|
|
|
|
const {push} = useRouter()
|
|
|
|
|
|
|
|
|
|
function toDetail() {
|
|
|
|
|
push({url: '/pages/goodsDetail/goodsDetail'}, {data: {id: goods.value.id}})
|
|
|
|
|
}
|
2023-11-15 19:59:37 +08:00
|
|
|
|
|
2023-11-14 17:21:03 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<view
|
|
|
|
|
:class="{'goods':true,'row':row}"
|
|
|
|
|
@click="toDetail"
|
|
|
|
|
>
|
|
|
|
|
<!-- goods image -->
|
|
|
|
|
<view
|
|
|
|
|
class="goods-image"
|
|
|
|
|
:style="{
|
|
|
|
|
'width':imgWidth,
|
2023-11-15 19:59:37 +08:00
|
|
|
|
'aspect-ratio': ratio===true?`${1/getRandom(1,1.3)}`:ratio
|
2023-11-14 17:21:03 +08:00
|
|
|
|
}"
|
|
|
|
|
>
|
|
|
|
|
<image
|
|
|
|
|
:src="goods.image"
|
|
|
|
|
class="image"
|
2023-11-15 19:59:37 +08:00
|
|
|
|
:mode="ratio===true?'aspectFit':'aspectFill'"
|
2023-11-14 17:21:03 +08:00
|
|
|
|
/>
|
|
|
|
|
</view>
|
|
|
|
|
<!-- good info -->
|
|
|
|
|
<view
|
|
|
|
|
class="goods-info"
|
|
|
|
|
:style="{
|
|
|
|
|
'padding':infoPadding,
|
|
|
|
|
'width':row?`calc( 100% - ${imgWidth} )`:'100%',
|
|
|
|
|
'height':row?`${imgWidth}`:'auto'
|
|
|
|
|
}"
|
|
|
|
|
>
|
|
|
|
|
<view
|
|
|
|
|
:class="{
|
|
|
|
|
'title-row':true,
|
2023-11-15 19:59:37 +08:00
|
|
|
|
'nowrap': !titleWrap
|
2023-11-14 17:21:03 +08:00
|
|
|
|
}"
|
|
|
|
|
:style="{
|
|
|
|
|
'font-size':`${titleSize}rpx`
|
|
|
|
|
}"
|
|
|
|
|
>
|
|
|
|
|
{{ goods.storeName }}
|
|
|
|
|
</view>
|
|
|
|
|
<slot
|
|
|
|
|
name="options"
|
|
|
|
|
:goods="goods"
|
|
|
|
|
></slot>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style
|
|
|
|
|
scoped
|
|
|
|
|
lang="scss"
|
|
|
|
|
>
|
|
|
|
|
.goods {
|
|
|
|
|
position: relative;
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
|
|
|
|
&-image {
|
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
|
|
|
|
|
.image {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
&-info {
|
|
|
|
|
width: 100%;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
|
|
|
|
.title-row {
|
|
|
|
|
user-select: none;
|
|
|
|
|
width: 100%;
|
2023-11-15 19:59:37 +08:00
|
|
|
|
padding-bottom: 15rpx;
|
2023-11-14 17:21:03 +08:00
|
|
|
|
font-size: 28rpx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.nowrap {
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.row {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
|
|
|
|
.goods-image {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.goods-info {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
align-items: flex-start;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</style>
|