|
@@ -3,27 +3,54 @@ import {ref, computed} from "vue"
|
|
|
import {router} from '../../router'
|
|
import {router} from '../../router'
|
|
|
import {Back} from "@element-plus/icons-vue"
|
|
import {Back} from "@element-plus/icons-vue"
|
|
|
import {addStock, getProductById} from "../../api/product.ts"
|
|
import {addStock, getProductById} from "../../api/product.ts"
|
|
|
-import {parseCategory} from "../../utils"
|
|
|
|
|
|
|
+import {createOrder, payOrder} from "../../api/order.ts"
|
|
|
|
|
+import {getCommentsById} from "../../api/product.ts"
|
|
|
|
|
+import CommentItem from "../../components/CommentItem.vue"
|
|
|
|
|
+import {parseCategory, parseOrderType} from "../../utils"
|
|
|
|
|
|
|
|
const role = sessionStorage.getItem("role")
|
|
const role = sessionStorage.getItem("role")
|
|
|
|
|
|
|
|
const productId = Number(router.currentRoute.value.params.productId)
|
|
const productId = Number(router.currentRoute.value.params.productId)
|
|
|
-const actualStoreId = Number(sessionStorage.getItem("storeId"))
|
|
|
|
|
const productVO = ref()
|
|
const productVO = ref()
|
|
|
const storeId = ref(0)
|
|
const storeId = ref(0)
|
|
|
const name = ref('')
|
|
const name = ref('')
|
|
|
const photoUrlList = ref([])
|
|
const photoUrlList = ref([])
|
|
|
|
|
+const rating = ref(0)
|
|
|
|
|
+const number = ref(0)
|
|
|
|
|
+const salesAmount = ref(0)
|
|
|
const stock = ref(0)
|
|
const stock = ref(0)
|
|
|
const category = ref('')
|
|
const category = ref('')
|
|
|
const price = ref(0)
|
|
const price = ref(0)
|
|
|
|
|
|
|
|
|
|
+const amount = ref(1)
|
|
|
|
|
+const totalPrice = ref(price.value)
|
|
|
|
|
+const discountPrice = ref(0)
|
|
|
|
|
+
|
|
|
|
|
+const handleChange = () => {
|
|
|
|
|
+ totalPrice.value = amount.value * price.value
|
|
|
|
|
+}
|
|
|
|
|
+const type = ref()
|
|
|
|
|
+const orderDialogVisible = ref(false)
|
|
|
|
|
+const orderId = ref()
|
|
|
const addStockNumber = ref()
|
|
const addStockNumber = ref()
|
|
|
|
|
|
|
|
-const hasAddStockInput = computed(() => addStockNumber.value != null)
|
|
|
|
|
|
|
+const hasTypeInput = computed(() => type.value != null)
|
|
|
|
|
+const amountLegal = computed(() => amount.value <= stock.value)
|
|
|
|
|
+const createOrderDisabled = computed(() => {
|
|
|
|
|
+ return !(amountLegal.value && hasTypeInput.value)
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+const hasAddStockInput = computed(() => addStockNumber.value != '')
|
|
|
const addStockDisabled = computed(() => {
|
|
const addStockDisabled = computed(() => {
|
|
|
return !(hasAddStockInput.value)
|
|
return !(hasAddStockInput.value)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+const commentList = ref([])
|
|
|
|
|
+
|
|
|
|
|
+getCommentsById(productId).then(res => {
|
|
|
|
|
+ commentList.value = res.data.result
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
getProductDetail()
|
|
getProductDetail()
|
|
|
|
|
|
|
|
function getProductDetail() {
|
|
function getProductDetail() {
|
|
@@ -32,12 +59,14 @@ function getProductDetail() {
|
|
|
storeId.value = productVO.value.storeId
|
|
storeId.value = productVO.value.storeId
|
|
|
name.value = productVO.value.name
|
|
name.value = productVO.value.name
|
|
|
photoUrlList.value = productVO.value.photoUrlList
|
|
photoUrlList.value = productVO.value.photoUrlList
|
|
|
|
|
+ rating.value = productVO.value.rating
|
|
|
|
|
+ number.value = productVO.value.number
|
|
|
|
|
+ salesAmount.value = productVO.value.salesAmount
|
|
|
stock.value = productVO.value.stock
|
|
stock.value = productVO.value.stock
|
|
|
category.value = productVO.value.category
|
|
category.value = productVO.value.category
|
|
|
price.value = productVO.value.price
|
|
price.value = productVO.value.price
|
|
|
|
|
|
|
|
- console.log(storeId)
|
|
|
|
|
- console.log(actualStoreId)
|
|
|
|
|
|
|
+ totalPrice.value = price.value
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -62,6 +91,56 @@ function AddStock() {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 创建订单按钮
|
|
|
|
|
+function handleCreateOrder() {
|
|
|
|
|
+ const payload = {
|
|
|
|
|
+ productId: productId,
|
|
|
|
|
+ amount: amount.value,
|
|
|
|
|
+ type: type.value
|
|
|
|
|
+ }
|
|
|
|
|
+ createOrder(payload).then(res => {
|
|
|
|
|
+ if (res.data.code === '000') {
|
|
|
|
|
+ ElMessage({
|
|
|
|
|
+ message: '创建订单成功!',
|
|
|
|
|
+ type: 'success',
|
|
|
|
|
+ center: true,
|
|
|
|
|
+ })
|
|
|
|
|
+ orderId.value = res.data.result.id
|
|
|
|
|
+ orderDialogVisible.value = true
|
|
|
|
|
+ discountPrice.value = totalPrice.value
|
|
|
|
|
+ } else if (res.data.code === '400') {
|
|
|
|
|
+ ElMessage({
|
|
|
|
|
+ message: res.data.msg,
|
|
|
|
|
+ type: 'error',
|
|
|
|
|
+ center: true,
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// 确定订单按钮
|
|
|
|
|
+function handleConfirmOrder() {
|
|
|
|
|
+ payOrder(orderId.value).then(res => {
|
|
|
|
|
+ if (res.data.code === '000') {
|
|
|
|
|
+ ElMessage({
|
|
|
|
|
+ message: '订单提交成功!',
|
|
|
|
|
+ type: 'success',
|
|
|
|
|
+ center: true,
|
|
|
|
|
+ })
|
|
|
|
|
+ } else if (res.data.code === '400') {
|
|
|
|
|
+ ElMessage({
|
|
|
|
|
+ message: res.data.msg,
|
|
|
|
|
+ type: 'error',
|
|
|
|
|
+ center: true,
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function handlePayDialogClose() {
|
|
|
|
|
+ orderDialogVisible.value = false
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
function toBackPage() {
|
|
function toBackPage() {
|
|
|
router.push("/storeDetail/" + storeId.value)
|
|
router.push("/storeDetail/" + storeId.value)
|
|
|
}
|
|
}
|
|
@@ -96,6 +175,22 @@ function toBackPage() {
|
|
|
{{ price }} 元
|
|
{{ price }} 元
|
|
|
</el-descriptions-item>
|
|
</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="库存">
|
|
<el-descriptions-item style="font-size: 10px" label="库存">
|
|
|
{{ stock }} 件
|
|
{{ stock }} 件
|
|
|
</el-descriptions-item>
|
|
</el-descriptions-item>
|
|
@@ -104,12 +199,36 @@ function toBackPage() {
|
|
|
</el-aside>
|
|
</el-aside>
|
|
|
|
|
|
|
|
<el-main>
|
|
<el-main>
|
|
|
-<!-- 对于顾客,他可以在这里拥有一个创建订单按钮,点击后创建订单,弹出一个订单的弹窗。-->
|
|
|
|
|
-<!-- 他可以在弹窗中查看订单详情,并支付订单;也可以关闭弹窗,之后再在订单列表界面支付那个订单。-->
|
|
|
|
|
-<!-- 我们期待你在这里做一个弹窗,学会弹窗的用法。-->
|
|
|
|
|
-<!-- 当然,有其他形式的实现也可以。-->
|
|
|
|
|
|
|
+ <div v-if="role === 'CUSTOMER'">
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <span class="main-title">购买商品</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <el-form class="buy-form">
|
|
|
|
|
+ <el-form-item>
|
|
|
|
|
+ <label for="amount">购买数量:</label>
|
|
|
|
|
+ <el-input-number v-model="amount" :min="1" :max="stock + 10" @change="handleChange"/>
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+ <el-form-item>
|
|
|
|
|
+ <label for="type">提货方式:</label>
|
|
|
|
|
+ <el-select id="type"
|
|
|
|
|
+ v-model="type"
|
|
|
|
|
+ placeholder="请选择"
|
|
|
|
|
+ >
|
|
|
|
|
+ <el-option value="PICKUP" label="到店自提"/>
|
|
|
|
|
+ <el-option value="DELIVERY" label="快递到家"/>
|
|
|
|
|
+ </el-select>
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+ <el-form-item>
|
|
|
|
|
+ <label for="discountPrice">折扣前总价:</label>
|
|
|
|
|
+ {{ totalPrice }} 元
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+ </el-form>
|
|
|
|
|
+ <el-button @click="handleCreateOrder" :disabled="createOrderDisabled"
|
|
|
|
|
+ class="buy-button" type="primary" plain>创建订单
|
|
|
|
|
+ </el-button>
|
|
|
|
|
+ </div>
|
|
|
|
|
|
|
|
- <div v-if="role === 'STAFF' && storeId === actualStoreId">
|
|
|
|
|
|
|
+ <div v-if="role === 'STAFF'">
|
|
|
<div>
|
|
<div>
|
|
|
<span class="main-title">添加库存</span>
|
|
<span class="main-title">添加库存</span>
|
|
|
</div>
|
|
</div>
|
|
@@ -125,7 +244,45 @@ function toBackPage() {
|
|
|
</el-button>
|
|
</el-button>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <span class="main-title">评论区</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <CommentItem v-for="commentVO in commentList" :commentVO="commentVO">
|
|
|
|
|
+ </CommentItem>
|
|
|
|
|
+ </div>
|
|
|
</el-main>
|
|
</el-main>
|
|
|
|
|
+
|
|
|
|
|
+ <el-dialog v-model="orderDialogVisible" :before-close="handlePayDialogClose">
|
|
|
|
|
+ <el-row>
|
|
|
|
|
+ <span class="pay-dialog-title">订单支付</span>
|
|
|
|
|
+ </el-row>
|
|
|
|
|
+
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <el-form>
|
|
|
|
|
+ <el-form-item>
|
|
|
|
|
+ <label for="amount">购买数量:</label>
|
|
|
|
|
+ {{ amount }} 件
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+ <el-form-item>
|
|
|
|
|
+ <label for="type">提货方式:</label>
|
|
|
|
|
+ {{ parseOrderType(type) }}
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+ <el-form-item>
|
|
|
|
|
+ <label for="discountPrice">折扣前总价:</label>
|
|
|
|
|
+ {{ totalPrice }} 元
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+
|
|
|
|
|
+ <el-form-item>
|
|
|
|
|
+ <label>折扣后金额:</label>
|
|
|
|
|
+ {{ discountPrice }} 元
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+ </el-form>
|
|
|
|
|
+
|
|
|
|
|
+ <el-button @click="handleConfirmOrder" type="primary" plain>确认支付</el-button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </el-dialog>
|
|
|
</el-container>
|
|
</el-container>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
@@ -173,8 +330,24 @@ function toBackPage() {
|
|
|
margin-left: 20px;
|
|
margin-left: 20px;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+.buy-form {
|
|
|
|
|
+ margin-top: 20px;
|
|
|
|
|
+ margin-left: 30px;
|
|
|
|
|
+ width: 20%;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
.add-stock-main {
|
|
.add-stock-main {
|
|
|
margin-top: 20px;
|
|
margin-top: 20px;
|
|
|
margin-left: 30px;
|
|
margin-left: 30px;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+.buy-button {
|
|
|
|
|
+ margin-left: 30px;
|
|
|
|
|
+ margin-bottom: 40px;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.pay-dialog-title {
|
|
|
|
|
+ font-size: 30px;
|
|
|
|
|
+ margin-bottom: 20px;
|
|
|
|
|
+}
|
|
|
</style>
|
|
</style>
|