|
|
@@ -3,6 +3,7 @@ import {useRouter} from "vue-router";
|
|
|
import {ref} from "vue";
|
|
|
import {getProductById} from "../../api/product.ts";
|
|
|
import {createOrder, payOrder} from "../../api/order.ts";
|
|
|
+import {getAvailableCouponsByStoreId} from "../../api/coupon.ts";
|
|
|
|
|
|
const router = useRouter();
|
|
|
const productId = router.currentRoute.value.params.productId;
|
|
|
@@ -21,7 +22,6 @@ getProductDetail()
|
|
|
|
|
|
function getProductDetail() {
|
|
|
getProductById(productId).then(res => {
|
|
|
- console.log(res.result)
|
|
|
productVO.value = res.result
|
|
|
storeId.value = productVO.value.storeId
|
|
|
name.value = productVO.value.name
|
|
|
@@ -35,18 +35,16 @@ function getProductDetail() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-
|
|
|
const amount = ref(1)
|
|
|
const totalPrice = ref(price)
|
|
|
const handleChange = () => {
|
|
|
totalPrice.value = amount.value * price.value
|
|
|
}
|
|
|
-
|
|
|
const type = ref()
|
|
|
-
|
|
|
let orderDialogVisible = ref(false)
|
|
|
-
|
|
|
const orderId = ref()
|
|
|
+const couponId = ref()
|
|
|
+const availableCouponList = ref()
|
|
|
|
|
|
function handleCreateOrder() {
|
|
|
const payload = {
|
|
|
@@ -61,6 +59,7 @@ function handleCreateOrder() {
|
|
|
type: 'success',
|
|
|
center: true,
|
|
|
})
|
|
|
+ getAvailableCouponList()
|
|
|
orderId.value = res.result.id
|
|
|
orderDialogVisible.value = true
|
|
|
} else if (res.code === '400') {
|
|
|
@@ -74,7 +73,8 @@ function handleCreateOrder() {
|
|
|
}
|
|
|
|
|
|
function handleConfirmOrder() {
|
|
|
- payOrder(orderId.value).then(res => {
|
|
|
+ console.log(couponId.value)
|
|
|
+ payOrder(orderId.value, couponId.value).then(res => {
|
|
|
if (res.code === '000') {
|
|
|
ElMessage({
|
|
|
message: '订单支付成功!',
|
|
|
@@ -95,6 +95,40 @@ function handleConfirmOrder() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+function handleOrderType(type) {
|
|
|
+ if (type === "PICKUP") {
|
|
|
+ return "到店自提"
|
|
|
+ } else if (type === "DELIVERY") {
|
|
|
+ return "快递到家"
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function handleCouponType(type) {
|
|
|
+ if (type === "FULL_REDUCTION") {
|
|
|
+ return "满减"
|
|
|
+ } else if (type === "SPECIAL") {
|
|
|
+ return "折扣"
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function getAvailableCouponList() {
|
|
|
+ getAvailableCouponsByStoreId(storeId.value).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ availableCouponList.value = res.result
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+interface Coupon {
|
|
|
+ groupId: number
|
|
|
+}
|
|
|
+const currentRow = ref()
|
|
|
+function handleChooseCoupon(val: Coupon) {
|
|
|
+ couponId.value = val.groupId
|
|
|
+}
|
|
|
+
|
|
|
+const setCurrent = (row?: Coupon) => {
|
|
|
+ singleTableRef.value!.setCurrentRow(row)
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
@@ -102,7 +136,7 @@ function handleConfirmOrder() {
|
|
|
<el-form class="buy-form-main">
|
|
|
<el-form-item>
|
|
|
<label for="amount">商品单价:</label>
|
|
|
- {{price}}
|
|
|
+ {{ price }}
|
|
|
</el-form-item>
|
|
|
<el-form-item>
|
|
|
<label for="amount">购买数量:</label>
|
|
|
@@ -114,8 +148,8 @@ function handleConfirmOrder() {
|
|
|
v-model="type"
|
|
|
placeholder="请选择"
|
|
|
>
|
|
|
- <el-option value="DELIVERY" label="到店自提" />
|
|
|
- <el-option value="PICKUP" label="快递到家" />
|
|
|
+ <el-option value="PICKUP" label="到店自提"/>
|
|
|
+ <el-option value="DELIVERY" label="快递到家"/>
|
|
|
</el-select>
|
|
|
</el-form-item>
|
|
|
<el-form-item>
|
|
|
@@ -131,7 +165,7 @@ function handleConfirmOrder() {
|
|
|
<el-form>
|
|
|
<el-form-item>
|
|
|
<label for="amount">购买数量:</label>
|
|
|
- {{amount}}
|
|
|
+ {{ amount }}
|
|
|
</el-form-item>
|
|
|
<el-form-item>
|
|
|
<label for="discountPrice">折扣前总价:</label>
|
|
|
@@ -139,20 +173,24 @@ function handleConfirmOrder() {
|
|
|
</el-form-item>
|
|
|
<el-form-item>
|
|
|
<label for="type">提货方式:</label>
|
|
|
- {{ type }}
|
|
|
+ {{ handleOrderType(type) }}
|
|
|
</el-form-item>
|
|
|
<el-form-item>
|
|
|
<label for="type">优惠券:</label>
|
|
|
-<!-- <el-select id="type"-->
|
|
|
-<!-- v-model="type"-->
|
|
|
-<!-- placeholder="请选择"-->
|
|
|
-<!-- >-->
|
|
|
-<!-- <el-option value="DELIVERY">到店自提</el-option>-->
|
|
|
-<!-- <el-option value="PICKUP">快递到家</el-option>-->
|
|
|
-<!-- </el-select>-->
|
|
|
+ <el-table :data="availableCouponList" stripe class="coupon-table"
|
|
|
+ highlight-current-row @current-change="handleChooseCoupon">
|
|
|
+ <el-table-column type="index" width="50"/>
|
|
|
+ <el-table-column prop="type" label="类型" width="180">
|
|
|
+ <template #default="scope">
|
|
|
+ {{ handleCouponType(scope.row.type) }}
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="satisfaction" label="满(元)" width="180"/>
|
|
|
+ <el-table-column prop="minus" label="减(元)" width="180"/>
|
|
|
+ </el-table>
|
|
|
</el-form-item>
|
|
|
</el-form>
|
|
|
- <el-button @click="handleConfirmOrder">确认支付</el-button>
|
|
|
+ <el-button @click="handleConfirmOrder" type="primary" plain>确认支付</el-button>
|
|
|
</el-dialog>
|
|
|
</div>
|
|
|
</template>
|