|
@@ -76,7 +76,7 @@
|
|
|
<view class="card-content">
|
|
<view class="card-content">
|
|
|
<view class="info-item">
|
|
<view class="info-item">
|
|
|
<view class="info-item-label">菜品总价</view>
|
|
<view class="info-item-label">菜品总价</view>
|
|
|
- <view class="info-item-value">¥{{ formatPrice(orderInfo.totalAmount) }}</view>
|
|
|
|
|
|
|
+ <view class="info-item-value">¥{{ formatPrice(dishTotal) }}</view>
|
|
|
</view>
|
|
</view>
|
|
|
<view class="info-item">
|
|
<view class="info-item">
|
|
|
<view class="info-item-label">餐具费</view>
|
|
<view class="info-item-label">餐具费</view>
|
|
@@ -123,7 +123,7 @@
|
|
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
|
import { onLoad, onShow, onUnload } from "@dcloudio/uni-app";
|
|
import { onLoad, onShow, onUnload } from "@dcloudio/uni-app";
|
|
|
-import { ref } from "vue";
|
|
|
|
|
|
|
+import { ref, computed } from "vue";
|
|
|
import { go } from "@/utils/utils.js";
|
|
import { go } from "@/utils/utils.js";
|
|
|
import { getFileUrl } from "@/utils/file.js";
|
|
import { getFileUrl } from "@/utils/file.js";
|
|
|
import { useUserStore } from "@/store/user.js";
|
|
import { useUserStore } from "@/store/user.js";
|
|
@@ -139,6 +139,7 @@ const orderInfo = ref({
|
|
|
contactPhone: '',
|
|
contactPhone: '',
|
|
|
remark: '',
|
|
remark: '',
|
|
|
totalAmount: 0,
|
|
totalAmount: 0,
|
|
|
|
|
+ dishTotal: null,
|
|
|
utensilFee: 0,
|
|
utensilFee: 0,
|
|
|
discountAmount: 0,
|
|
discountAmount: 0,
|
|
|
payAmount: 0,
|
|
payAmount: 0,
|
|
@@ -155,6 +156,17 @@ const selectedCouponDisplay = ref('');
|
|
|
// 菜品列表(从购物车带过来)
|
|
// 菜品列表(从购物车带过来)
|
|
|
const foodList = ref([]);
|
|
const foodList = ref([]);
|
|
|
|
|
|
|
|
|
|
+// 菜品总价(不含餐具费):优先缓存中的 dishTotal,否则 totalAmount - utensilFee
|
|
|
|
|
+const dishTotal = computed(() => {
|
|
|
|
|
+ const fromCache = orderInfo.value.dishTotal;
|
|
|
|
|
+ if (fromCache != null && fromCache !== '' && !Number.isNaN(Number(fromCache))) {
|
|
|
|
|
+ return Math.max(0, Number(fromCache));
|
|
|
|
|
+ }
|
|
|
|
|
+ const total = Number(orderInfo.value.totalAmount) || 0;
|
|
|
|
|
+ const utensil = Number(orderInfo.value.utensilFee) || 0;
|
|
|
|
|
+ return Math.max(0, total - utensil);
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
// 菜品图片:兼容 cuisineImage/image,逗号分隔取首图
|
|
// 菜品图片:兼容 cuisineImage/image,逗号分隔取首图
|
|
|
function getItemImage(item) {
|
|
function getItemImage(item) {
|
|
|
const raw = item?.cuisineImage ?? item?.image ?? item?.imageUrl ?? '';
|
|
const raw = item?.cuisineImage ?? item?.image ?? item?.imageUrl ?? '';
|
|
@@ -215,7 +227,7 @@ const openCouponModal = async () => {
|
|
|
selectedCouponId.value = first.id != null && first.id !== '' ? String(first.id) : null;
|
|
selectedCouponId.value = first.id != null && first.id !== '' ? String(first.id) : null;
|
|
|
orderInfo.value.couponId = selectedCouponId.value;
|
|
orderInfo.value.couponId = selectedCouponId.value;
|
|
|
selectedCouponDisplay.value = first.amountDisplay || (first.amount ? first.amount + '元' : '');
|
|
selectedCouponDisplay.value = first.amountDisplay || (first.amount ? first.amount + '元' : '');
|
|
|
- const total = Number(orderInfo.value.totalAmount) || 0;
|
|
|
|
|
|
|
+ const total = dishTotal.value;
|
|
|
const couponType = Number(first.couponType) || 0;
|
|
const couponType = Number(first.couponType) || 0;
|
|
|
if (couponType === 2 && first.discountRate != null && total > 0) {
|
|
if (couponType === 2 && first.discountRate != null && total > 0) {
|
|
|
const rate = Number(first.discountRate) || 0;
|
|
const rate = Number(first.discountRate) || 0;
|
|
@@ -241,7 +253,7 @@ const handleCouponSelect = ({ coupon, selectedId }) => {
|
|
|
orderInfo.value.discountAmount = 0;
|
|
orderInfo.value.discountAmount = 0;
|
|
|
} else {
|
|
} else {
|
|
|
selectedCouponDisplay.value = coupon.amountDisplay || (coupon.amount ? coupon.amount + '元' : '');
|
|
selectedCouponDisplay.value = coupon.amountDisplay || (coupon.amount ? coupon.amount + '元' : '');
|
|
|
- const total = Number(orderInfo.value.totalAmount) || 0;
|
|
|
|
|
|
|
+ const total = dishTotal.value;
|
|
|
const couponType = Number(coupon.couponType) || 0;
|
|
const couponType = Number(coupon.couponType) || 0;
|
|
|
if (couponType === 2 && coupon.discountRate != null && total > 0) {
|
|
if (couponType === 2 && coupon.discountRate != null && total > 0) {
|
|
|
// 折扣券:优惠金额 = 菜品总价 × (1 - 折数/10),如 5.5折 即 优惠 = 总价 × 0.45
|
|
// 折扣券:优惠金额 = 菜品总价 × (1 - 折数/10),如 5.5折 即 优惠 = 总价 × 0.45
|
|
@@ -255,12 +267,12 @@ const handleCouponSelect = ({ coupon, selectedId }) => {
|
|
|
couponModalOpen.value = false;
|
|
couponModalOpen.value = false;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-// 根据总价、餐具费、优惠额计算应付金额
|
|
|
|
|
|
|
+// 根据菜品总价(不含餐具)、餐具费、优惠额计算应付金额
|
|
|
const updatePayAmount = () => {
|
|
const updatePayAmount = () => {
|
|
|
- const total = Number(orderInfo.value.totalAmount) || 0;
|
|
|
|
|
|
|
+ const dish = dishTotal.value;
|
|
|
const utensil = Number(orderInfo.value.utensilFee) || 0;
|
|
const utensil = Number(orderInfo.value.utensilFee) || 0;
|
|
|
const discount = Number(orderInfo.value.discountAmount) || 0;
|
|
const discount = Number(orderInfo.value.discountAmount) || 0;
|
|
|
- orderInfo.value.payAmount = Math.max(0, total + utensil - discount);
|
|
|
|
|
|
|
+ orderInfo.value.payAmount = Math.max(0, dish + utensil - discount);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
// 进入页面时调一次优惠券接口:有券则默认选第一张,无券则显示请选择
|
|
// 进入页面时调一次优惠券接口:有券则默认选第一张,无券则显示请选择
|
|
@@ -283,7 +295,7 @@ const fetchCouponsOnEnter = async () => {
|
|
|
selectedCouponId.value = first.id != null && first.id !== '' ? String(first.id) : null;
|
|
selectedCouponId.value = first.id != null && first.id !== '' ? String(first.id) : null;
|
|
|
orderInfo.value.couponId = selectedCouponId.value;
|
|
orderInfo.value.couponId = selectedCouponId.value;
|
|
|
selectedCouponDisplay.value = first.amountDisplay || (first.amount ? first.amount + '元' : '');
|
|
selectedCouponDisplay.value = first.amountDisplay || (first.amount ? first.amount + '元' : '');
|
|
|
- const total = Number(orderInfo.value.totalAmount) || 0;
|
|
|
|
|
|
|
+ const total = dishTotal.value;
|
|
|
const couponType = Number(first.couponType) || 0;
|
|
const couponType = Number(first.couponType) || 0;
|
|
|
if (couponType === 2 && first.discountRate != null && total > 0) {
|
|
if (couponType === 2 && first.discountRate != null && total > 0) {
|
|
|
const rate = Number(first.discountRate) || 0;
|
|
const rate = Number(first.discountRate) || 0;
|
|
@@ -395,6 +407,7 @@ onLoad((options) => {
|
|
|
if (data.remark != null) orderInfo.value.remark = data.remark;
|
|
if (data.remark != null) orderInfo.value.remark = data.remark;
|
|
|
const total = Number(data.totalAmount) || 0;
|
|
const total = Number(data.totalAmount) || 0;
|
|
|
orderInfo.value.totalAmount = total;
|
|
orderInfo.value.totalAmount = total;
|
|
|
|
|
+ if (data.dishTotal != null && data.dishTotal !== '') orderInfo.value.dishTotal = Number(data.dishTotal) || 0;
|
|
|
const fee = data.utensilFee ?? data.tablewareFee;
|
|
const fee = data.utensilFee ?? data.tablewareFee;
|
|
|
if (fee != null && fee !== '') orderInfo.value.utensilFee = Number(fee) || 0;
|
|
if (fee != null && fee !== '') orderInfo.value.utensilFee = Number(fee) || 0;
|
|
|
if (data.discountAmount != null) orderInfo.value.discountAmount = data.discountAmount;
|
|
if (data.discountAmount != null) orderInfo.value.discountAmount = data.discountAmount;
|