|
|
@@ -1,13 +1,110 @@
|
|
|
-<!--Lab2新增-->
|
|
|
-<!--商品列表父组件中的单个商品子组件-->
|
|
|
<script setup lang="ts">
|
|
|
+import {ref} from "vue"
|
|
|
+import {getProductById} from "../api/product.ts"
|
|
|
|
|
|
+// 使用props接收父界面传来的数据
|
|
|
+const props = defineProps({
|
|
|
+ productId: {
|
|
|
+ type: Number,
|
|
|
+ required: true
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+const storeId = ref(0)
|
|
|
+const name = ref('')
|
|
|
+const photoUrlList = ref([])
|
|
|
+const rating = ref(0)
|
|
|
+const number = ref(0)
|
|
|
+const salesAmount = ref(0)
|
|
|
+const stock = ref(0)
|
|
|
+const category = ref()
|
|
|
+const price = ref()
|
|
|
+const photoUrl = ref('')
|
|
|
+
|
|
|
+getProductById(props.productId).then(res => {
|
|
|
+ storeId.value = res.result.storeId
|
|
|
+ name.value = res.result.name
|
|
|
+ photoUrlList.value = res.result.photoUrlList
|
|
|
+ rating.value = res.result.rating
|
|
|
+ number.value = res.result.number
|
|
|
+ salesAmount.value = res.result.salesAmount
|
|
|
+ stock.value = res.result.stock
|
|
|
+ category.value = res.result.category
|
|
|
+ price.value = res.result.price
|
|
|
+
|
|
|
+ photoUrl.value = photoUrlList.value[0]
|
|
|
+})
|
|
|
+
|
|
|
+function parseCategory(category) {
|
|
|
+ if (category === 'FOOD') {
|
|
|
+ return "食品"
|
|
|
+ } else if (category === 'CLOTHES') {
|
|
|
+ return "服饰"
|
|
|
+ } else if (category === 'FURNITURE') {
|
|
|
+ return "家具"
|
|
|
+ } else if (category === 'ELECTRONICS') {
|
|
|
+ return "电子产品"
|
|
|
+ } else if (category === 'ENTERTAINMENT') {
|
|
|
+ return "娱乐"
|
|
|
+ } else if (category === 'SPORTS') {
|
|
|
+ return "体育产品"
|
|
|
+ } else if (category === 'LUXURY') {
|
|
|
+ return "奢侈品"
|
|
|
+ }
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
-<template>
|
|
|
|
|
|
+<template>
|
|
|
+ <el-card class="product-item-card" shadow="hover">
|
|
|
+ <div class="photo-div">
|
|
|
+ <el-image class="photo-image" :src="photoUrl"/>
|
|
|
+ </div>
|
|
|
+ <div style="padding: 14px">
|
|
|
+ <h1> {{ name }} </h1>
|
|
|
+ <el-descriptions :column="1">
|
|
|
+ <el-descriptions-item style="font-size: 10px" label="品类">
|
|
|
+ {{ parseCategory(category) }}
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item style="font-size: 10px" label="价格">
|
|
|
+ {{ price }} 元
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item style="font-size: 10px" label="评分">
|
|
|
+ <el-rate
|
|
|
+ v-model="rating"
|
|
|
+ disabled
|
|
|
+ show-score
|
|
|
+ text-color="#ff9900"
|
|
|
+ score-template="{value} 分"
|
|
|
+ size="small"
|
|
|
+ />
|
|
|
+ (共 {{ number }} 人打分)
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item style="font-size: 10px" label="销量">
|
|
|
+ {{ salesAmount }} 件
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item style="font-size: 10px" label="库存">
|
|
|
+ {{ stock }} 件
|
|
|
+ </el-descriptions-item>
|
|
|
+ </el-descriptions>
|
|
|
+ </div>
|
|
|
+ </el-card>
|
|
|
</template>
|
|
|
|
|
|
+
|
|
|
<style scoped>
|
|
|
+.product-item-card {
|
|
|
+ margin: 8px;
|
|
|
+ border-radius: 8px;
|
|
|
+ min-width: 31%;
|
|
|
+}
|
|
|
+
|
|
|
+.photo-div {
|
|
|
+ display: flex;
|
|
|
+ justify-content: center;
|
|
|
+}
|
|
|
|
|
|
+.photo-image {
|
|
|
+ height: 200px;
|
|
|
+}
|
|
|
</style>
|