代客下单逻辑修改

This commit is contained in:
2025-11-14 18:06:04 +08:00
parent d0cee95145
commit 67ec915181
26 changed files with 5314 additions and 870 deletions

View File

@@ -0,0 +1,610 @@
<template>
<view
class="bg-fff border-r-24 u-m-t-32"
v-if="orderInfo && orderInfo.detailMap"
>
<view
class="u-m-b-20"
v-for="(goods, orderIndex) in orderInfo.detailMap"
:key="orderIndex"
>
<view class="u-p-t-24"> {{ orderIndex }}次下单 </view>
<view class="u-m-t-24 list">
<view class="item u-m-b-32" v-for="(item, index) in goods" :key="index">
<view class="u-flex u-col-top">
<view class="u-flex u-relative">
<view class="limit-discount" v-if="item.isTimeDiscount"
>限时折扣</view
>
<image
v-if="item.isTemporary == 0"
class="img"
:src="item.coverImg || item.productImg"
mode=""
></image>
<view
v-else
style="
background-color: #3f9eff;
width: 152rpx;
height: 152rpx;
line-height: 152rpx;
text-align: center;
color: #fff;
"
>
临时菜
</view>
</view>
<view class="u-p-l-32 u-flex-1">
<view class="u-flex u-row-between u-col-top">
<view class="">
<view class="u-flex">
<view class="tui" v-if="isTui(item)">
{{
item.status == "part_refund" ? "部分已退" : "全部已退"
}}
</view>
<view
:class="{
'line-th':
item.status == 'return' ||
item.status == 'refund' ||
item.status == 'refunding',
}"
>
{{ item.name || item.productName }}
</view>
</view>
<view
class="u-flex u-m-t-8"
style="flex-direction: column; align-items: flex-start"
>
<view class="u-flex u-m-b-8">
<view class="u-m-r-20 u-flex" v-if="item.isGift">
<uni-tag
text="赠送"
custom-style="background-color: #FFF0DF; border-color: #FFF0DF; color: #FF9F2E;"
>
</uni-tag>
</view>
<view class="u-m-r-20 u-flex" v-if="item.userCouponId">
<uni-tag
:text="productCouponDikou(item)"
custom-style="background-color: #FFF0DF; border-color: #FFF0DF; color: #FF9F2E;"
>
</uni-tag>
</view>
<view class="u-m-r-20 u-flex" v-if="item.packNumber > 0">
<uni-tag
custom-style="background-color: #E6F0FF; border-color: #E6F0FF; color: #318AFE;"
size="small"
text="打包"
inverted
type="success"
/>
</view>
</view>
<view class="u-flex u-m-t-8">
<view
class="u-m-r-20 u-font-24 u-flex"
v-if="item.refundNum > 0"
>
<view class="color-666">退款金额:</view>
<view class="color-999 u-m-l-6">{{
item.refundNum * item.unitPrice
}}</view>
</view>
<view
class="u-m-r-20 u-font-24 u-flex"
v-if="item.returnNum"
>
<view class="color-666">退菜数量:</view>
<view class="color-999 u-m-l-6">{{
item.returnNum
}}</view>
</view>
</view>
</view>
<view class="color-999 u-font-24 u-m-t-8">{{
item.skuName || ""
}}</view>
<view class="u-m-t-12 color-666 u-font-24" v-if="item.remark">
备注{{ item.remark }}
</view>
</view>
<view class="u-text-right u-m-t-28">
<view class="u-relative">
<template v-if="item.isGift">
<text class="line-th color-999"
>{{ toFixed(item.price * item.num, item) }}</text
>
<view class="u-absolute" style="right: 0; bottom: 100%">
<text class="font-bold">0</text>
</view>
</template>
<template v-else>
<template
v-if="
item.discountSaleAmount &&
item.discountSaleAmount * 1 > 0
"
>
<text class="line-th color-999"
>¥{{ toFixed(item.price * item.num, item) }}</text
>
<view class="u-absolute" style="right: 0; bottom: 100%">
<text class="font-bold"
>¥{{
toFixed(item.discountSaleAmount * item.num, item)
}}</text
>
</view>
</template>
<template v-else-if="item.isTimeDiscount">
<text class="line-th color-999"
>¥{{ toFixed(item.price * item.num, item) }}</text
>
<view
class="u-absolute xianshi"
style="right: 0; bottom: 100%"
>
<text class="font-bold"
>¥{{ returnLimitTotalMoney(item) }}</text
>
</view>
</template>
<template
v-else-if="
isVip &&
item.price &&
item.price * 1 != item.memberPrice * 1
"
>
<text class="line-th color-999"
>¥{{ toFixed(item.price * item.num, item) }}</text
>
<view class="u-absolute" style="right: 0; bottom: 100%">
<text class="font-bold"
>¥{{
toFixed(item.memberPrice * item.num, item)
}}</text
>
</view>
</template>
<template v-else>
<view class="font-bold">
<text>¥</text>
<text class="">{{
toFixed(item.price * item.num, item)
}}</text>
</view>
</template>
</template>
</view>
<view class="u-m-t-22 color-999 u-font-24"
>X{{ item.num || item.num }}</view
>
</view>
</view>
</view>
</view>
<!-- <template v-if="canTuicai(orderInfo, item)"> -->
<template v-if="false">
<view
class="u-flex u-row-right gap-20 u-m-t-24"
v-if="item.returnNum * item.unitPrice < item.num * item.unitPrice"
>
<my-button
:width="128"
:height="48"
plain
shape="circle"
@tap="tuicai(item, index)"
><text class="no-wrap">退菜</text></my-button
>
</view>
</template>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { computed, reactive,inject } from "vue";
import BigNumber from "bignumber.js";
import { hasPermission } from "@/commons/utils/hasPermission.js";
import {
isTui,
isTuiCai,
isGift,
canTuiKuan,
canTuicai,
mathFloorPrice,
} from "@/commons/utils/goodsUtil.js";
const emits = defineEmits(["tuicai", "tuikuan", "printOrder"]);
const yskUtils = inject("yskUtils");
const shopInfo = inject("shopInfo");
const pageData = inject("pageData");
const pop = reactive({
youhui: false,
});
const props = defineProps({
orderInfo: {
type: Object,
default: () => {},
},
data: {
type: Array,
default: () => [],
},
seatFee: {
type: Object,
default: () => {},
},
user: {
type: Object,
default: () => {
return {
id: "",
isVip: false,
};
},
},
});
/**
* 计算菜品数量
*/
const goodsNumber = computed(() => {
let result = 0;
result = props.data.reduce((a, b) => {
const bTotal = b.info.length;
return a + bTotal;
}, 0);
return result.toFixed(0);
});
/**
* 桌位费
*/
const seatFeePrice = computed(() => {
const n =
props.orderInfo.seatNum > 0
? props.orderInfo.seatNum * uni.getStorageSync("shopInfo").tableFee
: 0;
return n.toFixed(2);
});
function toFixed(price, item) {
if (item) {
if (item.productType == "weight" || item.type == "weight") {
return (Math.floor(price * 100) / 100).toFixed(2);
} else {
return parseFloat(price).toFixed(2);
}
} else {
return parseFloat(price).toFixed(2);
}
}
/**
* 判断是否是会员
*/
const isVip = computed(() => {
return (
uni.getStorageSync("shopInfo").isMemberPrice &&
props.user &&
props.user.id &&
props.user.isVip
);
});
function returnLimitTotalMoney(data) {
const price = yskUtils.limitUtils.returnPrice({
goods: data,
shopInfo: pageData.shopInfo,
limitTimeDiscountRes: pageData.limitTimeDiscount,
shopUserInfo: pageData.user,
idKey: "product_id",
});
return BigNumber(price).times(data.number).toNumber();
}
const vipDiscountPrice = computed(() => {
if (!isVip.value) {
return 0;
}
const goodsPrice = props.data.reduce((prve, cur) => {
const curTotal = cur.info
.filter(
(v) =>
v.discountSaleAmount <= 0 &&
v.isGift != 1 &&
v.status !== "return" &&
v.price != v.unitPrice &&
v.memberPrice != v.price
)
.reduce((a, b) => {
return a + b.num * (b.price - b.memberPrice);
}, 0);
return prve + curTotal;
}, 0);
return goodsPrice.toFixed(2);
});
/**
* 单品打折优惠
*/
const discountSaleAmount = computed(() => {
const goodsPrice = props.data.reduce((prve, cur) => {
const curTotal = cur.info
.filter(
(v) =>
v.discountSaleAmount > 0 && v.isGift != 1 && v.status !== "return"
)
.reduce((a, b) => {
return a + b.num * (b.price - b.discountSaleAmount);
}, 0);
return prve + curTotal;
}, 0);
return goodsPrice.toFixed(2);
});
/**
* 打折优惠
*/
const discountAmount = computed(() => {
return props.orderInfo.discountAmount || 0;
});
/**
* 总优惠金额
*/
const discountsPrice = computed(() => {
// 满减券优惠
let fullCouponDiscountAmount =
props.orderInfo.status == "done"
? props.orderInfo.fullCouponDiscountAmount
: 0;
// 商品券优惠
let productCouponDiscountAmount =
props.orderInfo.status == "done"
? props.orderInfo.productCouponDiscountAmount
: 0;
// 积分抵扣优惠
let pointsDiscountAmount =
props.orderInfo.status == "done" ? props.orderInfo.pointsDiscountAmount : 0;
return (
parseFloat(vipDiscountPrice.value) +
parseFloat(discountSaleAmount.value) +
discountAmount.value +
fullCouponDiscountAmount +
productCouponDiscountAmount +
pointsDiscountAmount
).toFixed(2);
});
// 菜品金额
const productCoupPrice = computed(() => {
if (props.orderInfo.status == "done") {
return props.orderInfo.productCouponDiscountAmount;
}
const goodsPrice = props.data.reduce((a, b) => {
const curTotal = b.info
.filter((v) => !v.isGift)
.reduce((prve, cur) => {
let memberPrice = cur.memberPrice ? cur.memberPrice : cur.price;
let tPrice = isVip.value ? memberPrice : cur.price;
tPrice =
cur.memberPrice != cur.unitPrice && cur.price != cur.unitPrice
? cur.unitPrice
: tPrice;
let Total = Math.floor(tPrice * cur.num * 100) / 100;
return (
prve + Total - cur.returnNum * tPrice - cur.refundNum * cur.unitPrice
);
}, 0);
return a + curTotal;
}, 0);
// console.log("菜品金额==",goodsPrice)
return goodsPrice.toFixed(2);
});
const allPpackFee = computed(() => {
//不是退菜只要有打包费的都计算,包括赠送
const goodsPrice = props.data.reduce((prve, cur) => {
const curTotal = cur.info
.filter((v) => v.packNumber > 0)
.reduce((a, b) => {
return a + parseFloat(b.packAmount * b.packNumber).toFixed(2) * 1;
}, 0);
return prve + curTotal;
}, 0);
return goodsPrice.toFixed(2);
});
const packFee = computed(() => {
//不是退菜只要有打包费的都计算,包括赠送
const goodsPrice = props.data.reduce((prve, cur) => {
const curTotal = cur.info
.filter((v) => v.status !== "return" && v.returnNum + v.refundNum < v.num)
.reduce((a, b) => {
return (
a +
parseFloat(
(
b.packAmount *
(b.num - (b.returnNum + b.refundNum) > b.packNumber
? b.packNumber
: b.num - (b.returnNum + b.refundNum))
).toFixed(2)
)
);
}, 0);
return prve + curTotal;
}, 0);
return goodsPrice.toFixed(2);
});
const allPrice = computed(() => {
let seatAmount = props.orderInfo.seatAmount || 0;
const total = productCoupPrice.value * 1 + seatAmount * 1 + packFee.value * 1;
return (total <= 0 ? 0 : total).toFixed(2);
});
/**
* 已优惠金额
*/
const youhuiAllPrice = computed(() => {
const n = vipDiscountPrice.value * 1;
return (n < 0 ? 0 : n).toFixed(2);
});
function youhuiDetailShow() {
pop.youhui = true;
}
function productCouponDikou(item) {
return "商品券抵扣¥" + returnProductCoupPrice(item);
}
function youhuiDetailHide() {
pop.youhui = false;
}
/**
* 转桌/并桌
*/
function rotatingTables() {
let arr = [];
props.data.forEach((ele) => {
ele.info.forEach((res) => {
// 头像 coverImg
res.coverImg = res.productImg;
// 名字 name
res.name = res.productName;
// 金额 price
res.price = res.price;
// 数量 number
res.number = res.num;
res.masterId = props.orderInfo.masterId;
res.useType = props.orderInfo.useType;
res.tableId = props.orderInfo.tableId;
arr.push(res);
});
});
uni.navigateTo({
url:
"/pagesCreateOrder/confirm-order/rotatingTables?item=" +
JSON.stringify(arr) +
"&tableId=" +
props.orderInfo.tableId,
});
}
function returnProductCoupPrice(item) {
if (!item.isMember) {
return item.price * item.num;
}
const price = item.memberPrice ? item.memberPrice : item.price;
return price * item.num;
}
function returnCanTuiMoney(item) {
// if (props.orderInfo.status == 'unpaid') {
// return returnTotalMoney(item)
// } else {
if (
props.orderInfo.pointsDiscountAmount > 0 ||
props.orderInfo.fullCouponDiscountAmount > 0
) {
return item.canReturnAmount;
} else if (item.price != item.unitPrice) {
return item.price * item.num;
} else {
return (Math.floor(item.num * item.unitPrice * 100) / 100).toFixed(2);
}
// }
}
function tuicai(item, index) {
emits("tuicai", item, index);
}
</script>
<style lang="scss" scoped>
.img {
width: 152rpx;
height: 152rpx;
border-radius: 6px;
}
.border-top {
border-color: #f6f6f6;
}
.border-r-24 {
border-radius: 24rpx;
}
.border-bottom {
// border-color: rgb(240, 240, 240);
border-color: #f6f6f6;
}
.line-th {
text-decoration: line-through;
}
.tag {
padding: 4rpx 8rpx 2rpx 10rpx;
border-radius: 8rpx;
font-size: 24rpx;
&.no-pay {
background-color: rgb(170, 170, 170);
color: #fff;
}
&.refund {
background-color: #fce7e7;
padding: 8rpx 20rpx 6rpx 22rpx;
color: #eb4f4f;
}
}
.tui {
background-color: rgb(239, 239, 239);
border-radius: 4rpx;
margin-right: 6rpx;
color: #666;
padding: 0 4rpx;
font-size: 20rpx;
}
.limit-discount {
background-color: #cc5617;
padding: 2rpx 10rpx;
white-space: nowrap;
text-align: center;
position: absolute;
top: 0;
left: 0;
font-weight: 400;
font-size: 24rpx;
color: #ffffff;
border-radius: 20rpx 0rpx 20rpx 0rpx;
z-index: 9;
color: #fff;
}
</style>

View File

@@ -151,7 +151,7 @@
<view class="block u-m-b-0">
<view class="u-flex">
<view>共</view>
<view class="fen font-bold">{{ goods.list.length }}</view>
<view class="fen font-bold">{{ allGoodsList.length }}</view>
<view>份菜品</view>
</view>
@@ -164,12 +164,12 @@
>
<view class="u-flex u-row-between">
<view class="u-flex">
<image
class="img"
v-if="item.coverImg"
:src="item.coverImg"
mode=""
></image>
<view v-if="item.coverImg" class="u-relative">
<view class="limit-discount" v-if="item.is_time_discount"
>限时折扣</view
>
<image class="img" :src="item.coverImg" mode=""></image>
</view>
<view
style="
background-color: #3f9eff;
@@ -274,7 +274,10 @@
<text class="line-th color-999"
>¥{{ toFixed(item.lowPrice * item.number, item) }}</text
>
<view class="u-absolute" style="right: 0; bottom: 100%">
<view
class="u-absolute xianshi"
style="right: 0; bottom: 100%"
>
<text class="font-bold"
>¥{{ returnLimitTotalMoney(item) }}</text
>
@@ -283,8 +286,8 @@
<template
v-else-if="
isVip &&
item.lowMemberPrice &&
item.lowMemberPrice * 1 != item.lowPrice * 1
item.salePrice &&
item.salePrice * 1 != item.memberPrice * 1
"
>
<text class="line-th color-999"
@@ -383,6 +386,9 @@
</scroll-view>
</view>
</view>
<!-- 历史订单 -->
<orderList :orderInfo="pageData.orderInfo"></orderList>
<view class="border-bottom">
<template v-if="orderCostSummary.seatFee > 0">
<view class="u-flex u-row-between u-m-t-18 u-p-b-34">
@@ -392,6 +398,7 @@
<view>¥{{ orderCostSummary.seatFee }}</view>
</view>
</template>
<template v-if="orderCostSummary.packFee > 0">
<view class="u-flex u-row-between u-m-t-18 u-p-b-34">
<view>
@@ -404,9 +411,14 @@
<view class="u-flex u-row-between u-m-t-38">
<view class="u-flex">
<view class="u-flex price" v-if="youhui * 1 > 0">
<view
class="u-flex price"
v-if="orderCostSummary.totalDiscountAmount"
>
<view class="">优惠金额</view>
<view class="font-bold u-font-32">¥{{ youhui }}</view>
<view class="font-bold u-font-32"
>¥{{ orderCostSummary.totalDiscountAmount }}</view
>
</view>
</view>
@@ -424,12 +436,12 @@
<view class="btn">
<my-button shape="circle" @click="createAnOrder">
<view class="font-bold u-font-32">
{{
pageData.shopInfo.registerType == "before" ||
pageData.eatTypes.active == "take-out"
? "结算"
: "下单"
}}
<text v-if="pageData.shopInfo.registerType == 'before'">
下单
</text>
<text v-if="pageData.shopInfo.registerType == 'after'">
{{ goods.list.length > 0 ? "下单" : "结算" }}
</text>
</view>
</my-button>
</view>
@@ -461,6 +473,9 @@
<script setup>
import { onLoad, onReady, onShow, onHide } from "@dcloudio/uni-app";
import yskUtils from "ysk-utils";
// import yskUtils from "@/lib/index";
const limitUtils = yskUtils.limitUtils;
import {
ref,
inject,
@@ -469,12 +484,15 @@ import {
reactive,
computed,
watch,
provide,
} from "vue";
provide("yskUtils", yskUtils);
import modelDiscount from "./components/discount";
import giveFood from "./components/give-food";
import packNumber from "./components/pack-number";
import oneRemark from "./components/remark";
import orderList from "./components/list";
// import editDiscount from '@/pagesCreateOrder/components/edit-discount.vue'
import { getSafeBottomHeight } from "@/commons/utils/safe-bottom.js";
@@ -486,6 +504,8 @@ import { getShopTableDetail } from "@/http/api/table.js";
import { getShopInfo } from "@/http/api/shop.js";
import { getProductList } from "@/http/api/product.js";
import { createOrder, getHistoryOrder } from "@/http/api/order.js";
import { shopUserDetail } from "@/http/yskApi/shop-user.js";
import { discountActivity } from "@/http/yskApi/market/discountActivity.js";
import BigNumber from "bignumber.js";
const models = new Map();
@@ -498,16 +518,17 @@ const option = reactive({
tableId: "",
});
const shopInfo = uni.getStorageSync("shopInfo");
provide("shopInfo", shopInfo);
function returnLimitTotalMoney(data) {
const price = yskUtils.limitUtils.returnPrice({
// const price = yskUtils.limitUtils.returnPrice({
const price = limitUtils.returnPrice({
goods: data,
shopInfo: shopInfo,
limitTimeDiscountRes: pageData.limitTimeDiscount,
shopUserInfo: null,
idKey: "id",
shopUserInfo: pageData.user,
idKey: "product_id",
});
console.log("pageData.limitTimeDiscount", pageData.limitTimeDiscount);
return BigNumber(price).times(data.number).toNumber();
}
/**
@@ -556,22 +577,34 @@ const pageData = reactive({
orderInfo: {},
limitTimeDiscount: null, //限时折扣
});
provide("pageData", pageData);
async function getDiscountActivity() {
let res = await discountActivity({
shopId: uni.getStorageSync("shopId"),
});
if (res.code == 200) {
fullReductionActivities.value = res.data?[res.data]:[];
}
}
const websocketUtil = inject("websocketUtil"); // 注入 WebSocket 工具类实例
onLoad((opt) => {
onLoad(async (opt) => {
Object.assign(option, opt);
console.log("opt====", opt);
if (opt.tableId || opt.tableCode) {
pageData.table.id = opt.tableId;
pageData.table.tableCode = opt.tableCode;
}
//获取满减活动
await getDiscountActivity();
pageData.shopInfo = uni.getStorageSync("shopInfo");
console.log(uni.getStorageSync("shopInfo"), "提示1");
getTbShopInfo();
});
let bottomHeight = ref(100);
onReady(() => {
getSafeBottomHeight("safe-bottom").then((res) => {
bottomHeight.value = res;
bottomHeight.value = res + 40;
});
});
watch(
@@ -619,37 +652,16 @@ const $seatFee = reactive({
totalAmount: 0,
});
/**
* 打包费
*/
const $packFee = computed(() => {
return goods.list
.reduce((prve, cur) => {
return prve + (cur.packFee || 0) * parseFloat(cur.pack_number).toFixed(2);
}, 0)
.toFixed(2);
});
/**
* 判断是否是会员
*/
const isVip = computed(() => {
return (
pageData.shopInfo.isMemberPrice &&
return pageData.shopInfo.isMemberPrice &&
pageData.user &&
pageData.user.id &&
pageData.user.isVip
);
});
/**
* 计算优惠金额
*/
const youhui = computed(() => {
return 0;
? true
: false;
});
function toFixed(price, item) {
@@ -704,7 +716,6 @@ function onMessage() {
cartItem = getNowCart(item, $goods, pageData.user);
if (cartItem.isGrounding || cartItem.is_temporary == 1) {
cartControls(cartItem, "add");
} else {
delCart(cartItem.id);
}
@@ -796,21 +807,18 @@ function cartControls(cartItem, type) {
}
});
if (type == "del") {
goods.list.splice(cartIndex, 1);
return;
}
if (type == "add") {
goods.list.push({...cartItem,packNumber:cartItem.pack_number});
goods.list.push({ ...cartItem, packNumber: cartItem.pack_number });
}
if (type == "edit") {
goods.list[cartIndex].number = cartItem.number;
goods.list[cartIndex].pack_number = cartItem.pack_number;
goods.list[cartIndex].packNumber = cartItem.pack_number;
}
}
/**
@@ -868,11 +876,66 @@ async function getTableInfo(opt) {
*/
function watchChooseuser() {
uni.$off("choose-user");
uni.$on("choose-user", (data) => {
pageData.user = data;
uni.$on("choose-user", async (data) => {
if (pageData.user.id == data.id) {
return;
}
if (data.id) {
const res = await shopUserDetail({
userId: data.userId,
});
pageData.user = res.data;
} else {
pageData.user = data;
}
// 更新购物车和历史订单数据
uodateCartAndHistory();
});
}
/**
* 更新购物车和历史订单数据
*/
function uodateCartAndHistory() {
let newData = {
history: [],
cart: [],
};
console.log("uodateCartAndHistory", pageData.user);
for (let cart of goods.list) {
const canUseLimitTimeDiscount = yskUtils.limitUtils.canUseLimitTimeDiscount(
cart,
pageData.limitTimeDiscount,
pageData.shopInfo,
pageData.user,
"product_id"
)
? 1
: 0;
console.log("uodateCartAndHistory", pageData.user);
if (canUseLimitTimeDiscount != cart.is_time_discount) {
newData.cart.push({
id: cart.id,
is_time_discount: canUseLimitTimeDiscount,
});
}
}
if (newData.history.length <= 0 && newData.cart.length <= 0) {
return;
}
websocketUtil.send(
JSON.stringify({
type: "pad",
account: uni.getStorageSync("shopInfo").id,
shop_id: uni.getStorageSync("shopInfo").id,
operate_type: "bulk_edit",
table_code: pageData.table.tableCode,
data: newData,
})
);
}
/**
* 就餐类型切换监听
*/
@@ -1136,7 +1199,8 @@ async function createAnOrder() {
dineMode: pageData.eatTypes.active, //用餐模式 堂食 dine-in 外带 take-out 外卖 take-away
remark: pageData.form.note, //备注
seatNum: 0, //用餐人数
packFee:pageData.eatTypes.active=='dine-in'?seatFeeConfig.personCount : 0, //打包费
packFee:
pageData.eatTypes.active == "dine-in" ? seatFeeConfig.personCount : 0, //打包费
originAmount: orderCostSummary.value.goodsRealAmount, //订单原金额(不包含打包费+餐位费)
placeNum: placeNum, //当前订单下单次数
waitCall: 0, //是否等叫 0 否 1 等叫
@@ -1146,30 +1210,33 @@ async function createAnOrder() {
if (!pageData.shopInfo.isTableFee && pageData.table && pageData.table.id) {
par.seatNum = userNumbers.defaultCateIndex * 1 + 1;
}
if (pageData.orderInfo) {
if (pageData.orderInfo && pageData.shopInfo.registerType != "before") {
par.orderId = pageData.orderInfo.id;
}
// console.log(par,22222222);
const res = await createOrder(par);
console.log(res, "创建订单");
if (res.code != 200) {
uni.showToast({
title: res.msg || "创建订单失败!",
icon: "none",
});
return;
let res = {data:{id:''}};
if (goods.list.length) {
res = await createOrder(par);
console.log(res, "创建订单");
if (res.code != 200) {
uni.showToast({
title: res.msg || "创建订单失败!",
icon: "none",
});
return;
}
uni.$emit("update:createOrderIndex");
websocketUtil.send(
JSON.stringify({
type: "pad",
account: uni.getStorageSync("shopInfo").id,
shop_id: uni.getStorageSync("shopInfo").id,
operate_type: "cleanup",
table_code: pageData.table.tableCode,
})
);
uni.removeStorageSync("table_code");
}
uni.$emit("update:createOrderIndex");
websocketUtil.send(
JSON.stringify({
type: "pad",
account: uni.getStorageSync("shopInfo").id,
shop_id: uni.getStorageSync("shopInfo").id,
operate_type: "cleanup",
table_code: pageData.table.tableCode,
})
);
uni.removeStorageSync("table_code");
if (
pageData.shopInfo.registerType == "before" ||
pageData.eatTypes.active == "take-out"
@@ -1185,12 +1252,23 @@ async function createAnOrder() {
"redirect"
);
} else {
if(!res.data.id&&pageData.orderInfo.id){
return go.to(
"PAGES_ORDER_PAY",
{
orderId: pageData.orderInfo.id,
isNowPay: true,
dinnerType: pageData.eatTypes.active,
},
"redirect"
);
}
//后付
if (option.isCreateOrderToDetail != "0") {
go.to(
"PAGES_ORDER_DETAIL",
{
id: res.data.id,
id: res.data.id||pageData.orderInfo.id,
dinnerType: pageData.eatTypes.active,
},
"redirect"
@@ -1243,9 +1321,6 @@ const fullReductionActivities = ref([]);
// 商家霸王餐配置
const freeDineConfig = ref(null);
//限时折扣
const limitTimeDiscount = ref(null);
const orderExtraConfig = computed(() => {
return {
// 引用扩展后的商家减免配置
@@ -1262,15 +1337,35 @@ const orderExtraConfig = computed(() => {
currentDinnerType: pageData.eatTypes.active,
isFreeDine: false, //霸王餐
freeDineConfig: freeDineConfig.value,
limitTimeDiscount: limitTimeDiscount.value,
limitTimeDiscount: pageData.limitTimeDiscount,
shopUserInfo: pageData.user,
};
});
const allGoodsList = computed(() => {
if (!pageData.orderInfo || !pageData.orderInfo.detailMap) {
return goods.list;
}
console.log(Object.values(pageData.orderInfo.detailMap));
const historyGoodsList = Object.values(pageData.orderInfo.detailMap).reduce(
(prve, cur) => {
cur.map((v) => {
v.number = v.num;
v.salePrice = v.price;
});
prve.push(...cur);
return prve;
},
[]
);
return [...goods.list, ...historyGoodsList];
});
// 订单费用汇总
const orderCostSummary = computed(() => {
console.log(goods.list, "购物车数据");
const costSummary = yskUtils.OrderPriceCalculator.calculateOrderCostSummary(
goods.list,
allGoodsList.value,
pageData.eatTypes.active,
selCoupon.value,
activityList.value,
@@ -1327,8 +1422,8 @@ watch(
.item {
.img {
width: 84rpx;
height: 84rpx;
width: 120rpx;
height: 120rpx;
border-radius: 8rpx 8rpx 8rpx 8rpx;
}
}
@@ -1386,4 +1481,19 @@ watch(
.hover-class {
background-color: #e5e5e5;
}
.limit-discount {
background-color: #cc5617;
padding: 2rpx 10rpx;
white-space: nowrap;
text-align: center;
position: absolute;
top: 0;
left: 0;
font-weight: 400;
font-size: 24rpx;
color: #ffffff;
border-radius: 20rpx 0rpx 20rpx 0rpx;
z-index: 9;
color: #fff;
}
</style>

View File

@@ -54,7 +54,10 @@
{{ index + 1 }}
</view>
<view class="">
<view>{{ item.name }}</view>
<view>
<text>{{ item.name }}</text>
<text class="limit" v-if="item.is_time_discount"></text>
</view>
<view class="u-m-t-10 u-font-24 color-666">{{
item.specInfo || ""
}}</view>
@@ -179,7 +182,7 @@
v-if="v.is_time_discount || v.isTimeDiscount"
>
<view class="font-bold red u-m-r-32"
>{{ formatPrice(v.price * (v.num - v.returnNum)) }}</view
>{{ returnLimitPrice({...v,number:v.num,salePrice:v.price}) }}</view
>
<view class="u-m-l-30 u-m-r-30 color-333">
X{{ v.num.toFixed(2) }}
@@ -276,6 +279,8 @@ import { getElRect } from "@/commons/utils/safe-bottom.js";
import * as Api from "@/http/yskApi/Instead.js";
import { computed, ref, onMounted, reactive, watch, inject } from "vue";
import BigNumber from "bignumber.js";
import { limitTimeDiscount } from "../../../http/yskApi/limitTimeDiscount";
import { number } from "uview-plus/libs/function/test";
const yskUtils = inject("yskUtils");
const shopInfo = uni.getStorageSync("shopInfo");
@@ -343,18 +348,19 @@ function returnLimitPrice(data) {
shopInfo: shopInfo,
limitTimeDiscountRes: props.limitTimeDiscount,
shopUserInfo: null,
idKey: "id",
idKey: "product_id",
});
return price
}
function returnLimitTotalPrice(data) {
console.log('returnLimitTotalPrice',data)
const price = yskUtils.limitUtils.returnPrice({
goods: data,
shopInfo: shopInfo,
limitTimeDiscountRes: props.limitTimeDiscount,
shopUserInfo: null,
idKey: "id",
idKey: "product_id",
});
return BigNumber(price).times(data.number).toNumber();
}
@@ -377,16 +383,12 @@ const allPrice = computed(() => {
let price = (cur.is_time_discount? returnLimitPrice(cur) : cur.lowPrice) * cur.number
return BigNumber(prve).plus(price);
}, 0);
console.log('cartPrice',cartPrice)
let historyOrderPrice = allHistoryOrder.value.reduce((prve, cur) => {
const isTimeDiscount=cur.is_time_discount||cur.isTimeDiscount
let price = (isTimeDiscount? returnLimitPrice(cur) : cur.price)* (cur.num - cur.returnNum)
console.log('price',price)
let price = (cur.isTimeDiscount? returnLimitPrice({...cur,salePrice:cur.price}) : cur.price)* (cur.num - cur.returnNum)
return BigNumber(prve).plus(price);
}, 0);
console.log('historyOrderPrice',historyOrderPrice)
return BigNumber(cartPrice).plus(historyOrderPrice);
return BigNumber(cartPrice).plus(historyOrderPrice).decimalPlaces(2, BigNumber.ROUND_UP)
.toNumber();
});
const models = new Map();
const modelData = reactive({
@@ -495,7 +497,7 @@ function getshopsInfo() {
}
function toConfimOrder() {
if (props.data.length <= 0) {
if (props.data.length <= 0&& props.historyOrder.length<=0) {
return infoBox.showToast("还没有选择商品");
}
@@ -687,6 +689,7 @@ $car-top: -16rpx;
right: 0;
top: 0;
bottom: 0;
z-index: 10;
}
.total {
@@ -780,4 +783,17 @@ $car-top: -16rpx;
color: #999;
text-decoration: line-through;
}
.limit{
background-color: #cc5617;
margin-left: 10rpx;
padding: 2rpx 10rpx;
white-space: nowrap;
text-align: center;
position: absolute;
font-weight: 400;
font-size: 24rpx;
color: #ffffff;
border-radius: 14rpx;
color: #fff;
}
</style>

View File

@@ -3,7 +3,7 @@
class="u-relative u-flex item box-shadow"
@tap="emitEvent('showDetail')"
>
<view class="limit-discount" v-if="data.is_time_discount">限时折扣</view>
<view class="limit-discount" v-if="is_time_discount">限时折扣</view>
<!-- 已下架 -->
<view
v-if="!data.isSale"
@@ -175,9 +175,9 @@
<view class="bg-fff u-p-20 w-full">
<view class="u-flex u-row-between u-font-16">
<view>{{ data.name }}</view>
<view class="u-flex" v-if="data.is_time_discount">
<view class="u-flex" v-if="is_time_discount">
<view class="font-bold u-m-t-16">
¥{{ data.timeLimitPrice }}
¥{{ limitPrice }}
</view>
<view class="u-m-t-16 old-price"> ¥{{ data.lowPrice }} </view>
</view>
@@ -194,6 +194,7 @@ import { computed, toRef, toRefs, inject, watch } from "vue";
import dayjs from "dayjs";
import isBetween from "dayjs/plugin/isBetween";
const yskUtils = inject("yskUtils");
const shopInfo = inject("shopInfo");
dayjs.extend(isBetween);
import { onLoad } from "@dcloudio/uni-app";
const props = defineProps({
@@ -277,6 +278,34 @@ const computedImgStyle = computed(() => {
// height: props.img.height
// }
// }
//判断是否是时间折扣商品
const is_time_discount = computed(() => {
if (!props.limitTimeDiscount || !props.limitTimeDiscount.id) {
return false;
}
const isCanuse = yskUtils.limitUtils.canUseLimitTimeDiscount(
props.data,
props.limitTimeDiscount,
shopInfo,
null,
"id"
);
return isCanuse;
});
const limitPrice = computed(() => {
if (!is_time_discount.value) {
return 0;
}
const price = yskUtils.limitUtils.returnPrice({
goods: props.data,
shopInfo: shopInfo,
limitTimeDiscountRes: props.limitTimeDiscount,
shopUserInfo: null,
idKey: "id",
});
return price;
});
//判断是否是菜品
function isGoods() {

View File

@@ -29,8 +29,12 @@
<view class="u-flex u-p-b-30 u-row-between">
<view class="price">
<template v-if="goods && goods.isGrounding">
<text v-if="goodsData.is_time_discount">{{ returnLimitPrice() }}</text>
<text :class="{'old-price':goodsData.is_time_discount}">{{ to2(goods.salePrice * number) }}</text>
<text v-if="is_time_discount"
>{{ returnLimitPrice() }}</text
>
<text :class="{ oldPrice: is_time_discount }"
>{{ goods.salePrice }}</text
>
</template>
</view>
<view class="u-flex">
@@ -67,7 +71,7 @@
</template>
<script setup>
import { computed, reactive, ref, watch,inject } from "vue";
import { computed, reactive, ref, watch, inject } from "vue";
import util from "../util.js";
import infobox from "@/commons/utils/infoBox.js";
import myModel from "@/components/my-components/my-model.vue";
@@ -75,14 +79,15 @@ import myButton from "@/components/my-components/my-button.vue";
import BigNumber from "bignumber.js";
const yskUtils = inject("yskUtils");
const shopInfo = uni.getStorageSync("shopInfo");
const shopUserInfo = uni.getStorageSync("shopUserInfo");
const props = defineProps({
limitTimeDiscount:{
type: Object,
default: () => {
return {};
},
},
limitTimeDiscount: {
type: Object,
default: () => {
return {};
},
},
goodsData: {
type: Object,
default: () => {},
@@ -114,16 +119,33 @@ const props = defineProps({
function to2(number) {
return Number(number).toFixed(2);
}
function returnLimitPrice(){
const price= yskUtils.limitUtils.returnPrice({
const is_time_discount = computed(() => {
if (!props.limitTimeDiscount || !props.limitTimeDiscount.id) {
return false;
}
const isCanuse = yskUtils.limitUtils.canUseLimitTimeDiscount(
goods.value,
props.limitTimeDiscount,
shopInfo,
shopUserInfo,
"productId"
);
console.log('isCanuse');
console.log( goods.value);
return isCanuse;
});
function returnLimitPrice() {
const price = yskUtils.limitUtils.returnPrice({
goods: goods.value,
shopInfo: shopInfo,
limitTimeDiscountRes: props.limitTimeDiscount,
shopUserInfo: null,
idKey: "id",
shopUserInfo: shopUserInfo,
idKey: "productId",
});
return BigNumber(price).times(number.value).toNumber()
return BigNumber(price).times(number.value).toNumber();
}
const selSku = computed(() => {
return props.skus
@@ -228,7 +250,7 @@ function confirm() {
if (isDisabled.value) {
return;
}
emits("confirm", goods.value, number.value);
emits("confirm", goods.value, number.value,is_time_discount.value);
}
defineExpose({
open,
@@ -275,8 +297,8 @@ defineExpose({
.border-top {
border-top: 1px solid #e5e5e5;
}
.old-price{
color: #999;
text-decoration: line-through;
.oldPrice {
color: #999;
text-decoration: line-through;
}
</style>

View File

@@ -1,185 +1,205 @@
<template>
<my-model ref="model" borderRadius="12" :title="datas.title">
<template #desc>
<scroll-view scroll-y="true" style="height: 50vh;" class="u-p-30 guigeModel">
<view class="u-m-b-40" v-for="(item,index) in datas.skus" :key="index">
<view class="u-text-left">
<view class="color-333">{{item.title}} <text
style="color:#999">({{item.count}}{{item.number}})</text> </view>
</view>
<view class="u-flex u-m-t-20 u-flex-wrap">
<view class="item" @tap="chooseSkd(skd,item)" :class="{active:skd.select==true}"
v-for="(skd,skdIndex) in item.goods" :key="skdIndex">
{{skd.proName}}
</view>
</view>
</view>
</scroll-view>
</template>
<template #btn>
<view class="u-p-30 border-top ">
<view class="u-flex u-p-b-30 u-row-between">
<view class="price">
<text></text>
<text>{{datas.price}}</text>
</view>
</view>
<view class="u-m-t-10">
<my-button @tap="confirm">添加</my-button>
</view>
</view>
</template>
</my-model>
<uni-popup ref="popup" type="message">
<uni-popup-message type="info" message="请选择套餐" :duration="2000"></uni-popup-message>
</uni-popup>
<my-model ref="model" borderRadius="12" :title="datas.title">
<template #desc>
<scroll-view
scroll-y="true"
style="height: 50vh"
class="u-p-30 guigeModel"
>
<view class="u-m-b-40" v-for="(item, index) in datas.skus" :key="index">
<view class="u-text-left">
<view class="color-333"
>{{ item.title }}
<text style="color: #999"
>({{ item.count }}{{ item.number }})</text
>
</view>
</view>
<view class="u-flex u-m-t-20 u-flex-wrap">
<view
class="item"
@tap="chooseSkd(skd, item)"
:class="{ active: skd.select == true }"
v-for="(skd, skdIndex) in item.goods"
:key="skdIndex"
>
{{ skd.proName }}
</view>
</view>
</view>
</scroll-view>
</template>
<template #btn>
<view class="u-p-30 border-top">
<view class="u-flex u-p-b-30 u-row-between">
<view class="price">
<text></text>
<text>{{ datas.price }}</text>
</view>
</view>
<view class="u-m-t-10">
<my-button @tap="confirm">添加</my-button>
</view>
</view>
</template>
</my-model>
<uni-popup ref="popup" type="message">
<uni-popup-message
type="info"
message="请选择套餐"
:duration="2000"
></uni-popup-message>
</uni-popup>
</template>
<script setup>
import { computed, reactive, ref, watch } from 'vue';
import infobox from '@/commons/utils/infoBox.js'
import myModel from '@/components/my-components/my-model.vue'
import myButton from '@/components/my-components/my-button.vue'
import { onShow } from '@dcloudio/uni-app';
const props = defineProps({
goodsData: {
type: Object,
default: () => {}
},
})
const model = ref(null)
const popup = ref()
let datas = reactive({
item: "",
title: "",
price: "",
skus: [],
// 几选几,的和
selectNumber: 0,
})
watch(() => props.goodsData, (newval) => {
let gArr = JSON.parse(newval.groupSnap)
gArr.forEach(ele => {
ele.selectData = []
})
console.log(newval,11);
datas.item = newval
datas.title = newval.name
datas.price = newval.lowPrice
datas.skus = gArr
})
const selectNumber = computed(() => {
return datas.skus.reduce((prve, cur) => {
console.log(prve)
return 0 + cur.number
}, 0)
})
const emits = defineEmits(['confirm', 'updateSku'])
function confirm() {
// 将数据保存进对应的值
let arr = []
let arrlength = 0
datas.selectNumber = 0
datas.skus.map(ele => {
let group = {
...ele,
goods: [],
}
if(ele.goods&&ele.goods.length>0){
ele.goods.map(item=>{
if(item.select){
group.goods.push(item)
arrlength++
}
})
}
arr.push(group)
datas.selectNumber += ele.number
})
console.log(arrlength)
console.log(datas.selectNumber)
if (arrlength == datas.selectNumber) {
emits('confirm', arr, datas.item)
close()
} else {
popup.value.open()
}
}
/**
* 套餐选择处理
* @param {Object} skd
* @param {Object} item
*/
function chooseSkd(skd, item) {
if (item.selectData.includes(skd.proId)) {
skd.select = false
let indexs = item.selectData.indexOf(skd.proId)
item.selectData.splice(indexs, 1)
} else {
if (item.selectData.length < item.number) {
skd.select = true
item.selectData.push(skd.proId)
}
}
import { computed, reactive, ref, watch } from "vue";
import infobox from "@/commons/utils/infoBox.js";
import myModel from "@/components/my-components/my-model.vue";
import myButton from "@/components/my-components/my-button.vue";
import { onShow } from "@dcloudio/uni-app";
const props = defineProps({
goodsData: {
type: Object,
default: () => {},
},
});
const model = ref(null);
const popup = ref();
let datas = reactive({
item: "",
title: "",
price: "",
skus: [],
// 几选几,的和
selectNumber: 0,
});
}
watch(
() => props.goodsData,
(newval) => {
let gArr = JSON.parse(newval.groupSnap);
gArr.forEach((ele) => {
ele.selectData = [];
});
console.log(newval, 11);
datas.item = newval;
datas.title = newval.name;
datas.price = newval.lowPrice;
datas.skus = gArr;
}
);
function open() {
model.value.open()
}
const selectNumber = computed(() => {
return datas.skus.reduce((prve, cur) => {
console.log(prve);
return 0 + cur.number;
}, 0);
});
function close() {
datas.selectNumber = 0
model.value.close()
}
defineExpose({
open,
close
})
const emits = defineEmits(["confirm", "updateSku"]);
function confirm() {
// 将数据保存进对应的值
let arr = [];
let arrlength = 0;
datas.selectNumber = 0;
datas.skus.map((ele) => {
let group = {
...ele,
goods: [],
};
if (ele.goods && ele.goods.length > 0) {
ele.goods.map((item) => {
if (item.select) {
group.goods.push(item);
arrlength++;
}
});
}
arr.push(group);
datas.selectNumber += ele.number;
});
console.log(arrlength);
console.log(datas.selectNumber);
if (arrlength == datas.selectNumber) {
emits("confirm", arr, datas.item);
close();
} else {
popup.value.open();
}
}
/**
* 套餐选择处理
* @param {Object} skd
* @param {Object} item
*/
function chooseSkd(skd, item) {
if (item.selectData.includes(skd.proId)) {
skd.select = false;
let indexs = item.selectData.indexOf(skd.proId);
item.selectData.splice(indexs, 1);
} else {
if (item.selectData.length < item.number) {
skd.select = true;
item.selectData.push(skd.proId);
}
}
}
function open() {
model.value.open();
}
function close() {
datas.selectNumber = 0;
model.value.close();
}
defineExpose({
open,
close,
});
</script>
<style lang="scss">
.border-top {}
.border-top {
}
.icon {
width: 40rpx;
height: 40rpx;
}
.icon {
width: 40rpx;
height: 40rpx;
}
.guigeModel {
.item {
color: #666;
font-size: 24rpx;
padding: 4rpx 28rpx;
border: 1px solid #E5E5E5;
border-radius: 8rpx;
margin-right: 20rpx;
margin-bottom: 20rpx;
transition: all .2s ease-in-out;
.guigeModel {
.item {
color: #666;
font-size: 24rpx;
padding: 4rpx 28rpx;
border: 1px solid #e5e5e5;
border-radius: 8rpx;
margin-right: 20rpx;
margin-bottom: 20rpx;
transition: all 0.2s ease-in-out;
&.active {
border-color: $my-main-color;
color: $my-main-color;
}
&.active {
border-color: $my-main-color;
color: $my-main-color;
}
&.disabled {
color: #ccc;
border-color: #eee;
}
}
}
&.disabled {
color: #ccc;
border-color: #eee;
}
}
}
.price {
color: #EB4F4F;
}
.price {
color: #eb4f4f;
}
.border-top {
border-top: 1px solid #E5E5E5;
}
.border-top {
border-top: 1px solid #e5e5e5;
}
</style>

View File

@@ -1,279 +1,354 @@
<template>
<view class="">
<up-overlay :show="overlayshow" @click="overlayshow = false">
<view class="boxoverlay" v-if="form&&form.goods">
<view class="rect" @tap.stop>
<view class="title">
<view> 标题 </view>
<view class="" @click="overlayshow = false">
<up-icon name="close" color="#93969b" size="20"></up-icon>
</view>
</view>
<view class="inputtop">
<view class="dj">
<view class="text">单价</view>
<view class="jg">{{form.goods.lowPrice}}/{{form.goods.unitName}}</view>
</view>
<view class="inputdj">
<view>重量</view>
<view class="inputdjbox">
<view class="inputdisplay">{{ currentInput }}</view>
<text>{{ form.goods.unitName }}</text>
</view>
</view>
</view>
<view class="keyboard">
<button v-for="(num, index) in numberButtons" :key="index" @click="handleClick(num)">
{{ num }}
</button>
<button @click="deleteLast"></button>
</view>
<view class="classmoney">
{{ (Math.floor((form.goods.lowPrice * currentInput)*100)/100).toFixed(2) }}
</view>
<view class="classconfirm" @click="clickconfirm"> 确认 </view>
</view>
</view>
</up-overlay>
</view>
<view class="">
<up-overlay :show="overlayshow" @click="overlayshow = false">
<view class="boxoverlay" v-if="form && form.goods">
<view class="rect" @tap.stop>
<view class="title">
<view> {{ form.goods.name }} </view>
<view class="" @click="overlayshow = false">
<up-icon name="close" color="#93969b" size="20"></up-icon>
</view>
</view>
<view class="inputtop">
<view class="dj">
<view class="text">单价</view>
<view class="jg"
>{{
is_time_discount ? returnLimitPrice() : form.goods.lowPrice
}}/{{ form.goods.unitName }}</view
>
</view>
<view class="inputdj">
<view>重量</view>
<view class="inputdjbox">
<view class="inputdisplay">{{ currentInput }}</view>
<text>{{ form.goods.unitName }}</text>
</view>
</view>
</view>
<view class="keyboard">
<button
v-for="(num, index) in numberButtons"
:key="index"
@click="handleClick(num)"
>
{{ num }}
</button>
<button @click="deleteLast"></button>
</view>
<view class="classmoney">
{{ totalMoney }}
</view>
<view class="classconfirm" @click="clickconfirm"> 确认 </view>
</view>
</view>
</up-overlay>
</view>
</template>
<script setup>
import { onLoad, onShow } from '@dcloudio/uni-app';
import { reactive, ref, watch, defineExpose, defineEmits } from 'vue';
const emit = defineEmits(['refresh'])
const currentInput = ref('');
import { onLoad, onShow } from "@dcloudio/uni-app";
import { BigNumber } from "bignumber.js";
import {
reactive,
computed,
ref,
watch,
defineExpose,
defineEmits,
inject,
} from "vue";
const yskUtils = inject("yskUtils");
const shopInfo = uni.getStorageSync("shopInfo");
const shopUserInfo = uni.getStorageSync("shopUserInfo");
const emit = defineEmits(["refresh"]);
const currentInput = ref("");
const numberButtons = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '.'];
const numberButtons = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "."];
const handleClick = (value) => {
// 首位不能输入0
if (currentInput.value === '') {
if (value === '0') {
return;
}
}
if (value === '.' && currentInput.value.indexOf('.') !== -1) {
return; // 如果已经存在小数点,不再添加
}
if (value === '.' && currentInput.value === '') {
currentInput.value = '0.';
} else {
currentInput.value += value;
}
// 限制小数点后两位
const parts = currentInput.value.split('.');
if (parts.length > 1 && parts[1].length > 2) {
currentInput.value = currentInput.value.slice(0, -1);
}
};
const deleteLast = () => {
currentInput.value = currentInput.value.slice(0, -1);
};
const handleClick = (value) => {
// 首位不能输入0
if (currentInput.value === "") {
if (value === "0") {
return;
}
}
if (value === "." && currentInput.value.indexOf(".") !== -1) {
return; // 如果已经存在小数点,不再添加
}
if (value === "." && currentInput.value === "") {
currentInput.value = "0.";
} else {
currentInput.value += value;
}
// 限制小数点后两位
const parts = currentInput.value.split(".");
if (parts.length > 1 && parts[1].length > 2) {
currentInput.value = currentInput.value.slice(0, -1);
}
};
const clickconfirm = () => {
// 首位不能输入0
if (currentInput.value === '') {
uni.showToast({
title: '请输入',
icon: 'none'
})
return false;
}
console.log(currentInput.value,'称重数量')
emit('weighgoodsUpdate', form.foodsindex, form.index, true, undefined, currentInput.value)
overlayshow.value = false
}
//显示
const overlayshow = ref(false);
const form = reactive({})
const open = (foodsindex, index, goods) => {
console.log("222",goods)
currentInput.value = ''
Object.assign(form, {
foodsindex,
index,
goods
})
overlayshow.value = true
}
defineExpose({
open
})
const deleteLast = () => {
currentInput.value = currentInput.value.slice(0, -1);
};
const clickconfirm = () => {
// 首位不能输入0
if (currentInput.value === "") {
uni.showToast({
title: "请输入",
icon: "none",
});
return false;
}
console.log(currentInput.value, "称重数量");
emit(
"weighgoodsUpdate",
form.foodsindex,
form.index,
true,
undefined,
currentInput.value,
is_time_discount.value
);
overlayshow.value = false;
};
//显示
const overlayshow = ref(false);
const form = reactive({});
const open = (foodsindex, index, goods) => {
console.log(goods);
currentInput.value = "";
Object.assign(form, {
foodsindex,
index,
goods,
});
overlayshow.value = true;
};
const props = defineProps({
limitTimeDiscount: {
type: Object,
default: () => {},
},
});
const is_time_discount = computed(() => {
if (!props.limitTimeDiscount || !props.limitTimeDiscount.id) {
return false;
}
const isCanuse = yskUtils.limitUtils.canUseLimitTimeDiscount(
form.goods,
props.limitTimeDiscount,
shopInfo,
shopUserInfo,
"id"
);
console.log("isCanuse");
return isCanuse;
});
function returnLimitPrice() {
const price = yskUtils.limitUtils.returnPrice({
goods: form.goods,
shopInfo: shopInfo,
limitTimeDiscountRes: props.limitTimeDiscount,
shopUserInfo: shopUserInfo,
idKey: "id",
});
return price;
}
const totalMoney = computed(() => {
if(!currentInput.value) return 0
if (is_time_discount.value) {
return BigNumber(returnLimitPrice())
.times(currentInput.value)
.decimalPlaces(2, BigNumber.ROUND_UP)
.toNumber();
}
return BigNumber(form.goods.lowPrice)
.times(currentInput.value)
.decimalPlaces(2, BigNumber.ROUND_UP)
.toNumber();
});
defineExpose({
open,
});
</script>
<style lang="scss" scoped>
page {
background: #F9F9F9;
}
page {
background: #f9f9f9;
}
.boxoverlay {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
height: 100%;
.boxoverlay {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
height: 100%;
.rect {
padding: 32rpx 28rpx;
width: 30%;
background-color: #fff;
border-radius: 18rpx;
.rect {
padding: 32rpx 28rpx;
width: 30%;
background-color: #fff;
border-radius: 18rpx;
.title {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 20rpx;
font-size: 40rpx;
border-bottom: 1rpx solid #ccc;
}
.title {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 20rpx;
font-size: 40rpx;
border-bottom: 1rpx solid #ccc;
}
.inputtop {
margin-top: 20rpx;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
.inputtop {
margin-top: 20rpx;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
.dj {
width: 32%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
.dj {
width: 32%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
.text {
font-weight: 300;
font-size: 24rpx;
}
.text {
font-weight: 300;
font-size: 24rpx;
}
.jg {
margin-top: 16rpx;
background-color: #e8f4ff;
color: #1890ff;
height: 60rpx;
line-height: 60rpx;
padding: 0 20rpx;
font-size: 24rpx;
color: #1890ff;
border-radius: 10rpx;
}
}
.jg {
margin-top: 16rpx;
background-color: #e8f4ff;
color: #1890ff;
height: 60rpx;
line-height: 60rpx;
padding: 0 20rpx;
font-size: 24rpx;
color: #1890ff;
border-radius: 10rpx;
}
}
.inputdj {
width: 66%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
font-weight: 300;
font-size: 24rpx;
.inputdj {
width: 66%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
font-weight: 300;
font-size: 24rpx;
.inputdjbox {
margin-top: 16rpx;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
border: 1rpx solid #ccc;
border-radius: 10rpx;
padding-left: 20rpx;
height: 60rpx;
line-height: 60rpx;
background: #fff;
.inputdjbox {
margin-top: 16rpx;
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
border: 1rpx solid #ccc;
border-radius: 10rpx;
padding-left: 20rpx;
height: 60rpx;
line-height: 60rpx;
background: #fff;
.inputdisplay {
width: auto;
.inputdisplay {
width: auto;
}
}
text {
border: 1rpx solid #ccc;
border-radius: 10rpx;
border-radius: 10rpx;
padding: 0 20rpx;
background: #f5f7fa;
color: #a7aaaf;
}
}
}
}
text {
border: 1rpx solid #ccc;
border-radius: 10rpx;
border-radius: 10rpx;
padding: 0 20rpx;
background: #f5f7fa;
color: #a7aaaf;
}
}
.keyboard {
margin-top: 20rpx;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
}
}
button {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 28%;
margin: 10rpx;
}
.keyboard {
margin-top: 20rpx;
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
.keyboard-button {
width: 28%;
margin: 10rpx;
border: none;
border-radius: 5rpx;
box-shadow: 0 0 5rpx rgba(0, 0, 0, 0.3), 0 0 10rpx rgba(0, 0, 0, 0.2);
cursor: pointer;
transition: all 0.3s ease;
}
button {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 28%;
margin: 10rpx;
}
// .keyboard-button:hover {
// box-shadow: 0 0 10rpx rgba(255, 0, 0, 0.5), 0 0 20px rgba(255, 0, 0, 0.3);
// transform: translateY(-2rpx);
// }
.keyboard-button {
width: 28%;
margin: 10rpx;
border: none;
border-radius: 5rpx;
box-shadow: 0 0 5rpx rgba(0, 0, 0, 0.3), 0 0 10rpx rgba(0, 0, 0, 0.2);
cursor: pointer;
transition: all 0.3s ease;
}
.dot-button {
// background-color: #FFC107;
}
// .keyboard-button:hover {
// box-shadow: 0 0 10rpx rgba(255, 0, 0, 0.5), 0 0 20px rgba(255, 0, 0, 0.3);
// transform: translateY(-2rpx);
// }
.clear-button {
// background-color: #FF5733;
}
.dot-button {
// background-color: #FFC107;
}
.clear-button:hover {
box-shadow: 0 0 10px rgba(255, 87, 51, 0.5),
0 0 20px rgba(255, 87, 51, 0.3);
}
.clear-button {
// background-color: #FF5733;
}
.delete-button {
// background-color: #33FF57;
}
.clear-button:hover {
box-shadow: 0 0 10px rgba(255, 87, 51, 0.5), 0 0 20px rgba(255, 87, 51, 0.3);
}
.delete-button:hover {
// box-shadow: 0 0 10px rgba(51, 255, 87, 0.5), 0 0 20px rgba(51, 255, 87, 0.3);
}
}
.delete-button {
// background-color: #33FF57;
}
.classmoney {
margin-top: 16rpx;
width: 100%;
font-size: 40rpx;
text-align: left;
color: #ff5152;
font-weight: 600;
}
.delete-button:hover {
// box-shadow: 0 0 10px rgba(51, 255, 87, 0.5), 0 0 20px rgba(51, 255, 87, 0.3);
}
}
.classmoney {
margin-top: 16rpx;
width: 100%;
font-size: 40rpx;
text-align: left;
color: #ff5152;
font-weight: 600;
}
.classconfirm {
width: 100%;
margin: 30rpx auto 0 auto;
border-radius: 16rpx;
text-align: center;
background: #1890ff;
color: #fff;
padding: 10rpx 0;
}
}
}
.classconfirm {
width: 100%;
margin: 30rpx auto 0 auto;
border-radius: 16rpx;
text-align: center;
background: #1890ff;
color: #fff;
padding: 10rpx 0;
}
}
}
</style>

View File

@@ -273,7 +273,11 @@
<!-- 登录弹窗 -->
<my-login v-model="modal.login" @loginSuccess="loginSuccess"></my-login>
<!-- 称重 -->
<weigh-item ref="refweighitem" @weighgoodsUpdate="goodsUpdate"></weigh-item>
<weigh-item
ref="refweighitem"
@weighgoodsUpdate="goodsUpdate"
:limitTimeDiscount="data.limitTimeDiscount"
></weigh-item>
<up-modal
title="提示"
content="该台桌购物车里有商品,是否清除该台桌里的商品?"
@@ -484,7 +488,7 @@ function onMessage() {
);
}
if (msg.status == 0&&msg.type!='time_discount') {
if (msg.status == 0 && msg.type != "time_discount") {
infoBox.showToast(msg.msg || "添加失败");
data.isGoodsAdd = true;
// 如果是商品库存不足起售数量
@@ -506,6 +510,7 @@ function onMessage() {
if (!data.table.tableCode) {
data.table.tableCode = msg.table_code;
uni.setStorageSync("msg_id", msg.msg_id);
data.limitTimeDiscount = limitTimeDiscountRes.value;
websocketUtil.send(
JSON.stringify({
type: "shopping",
@@ -596,6 +601,9 @@ function delCart(id) {
* 获取订单详情
*/
async function getHistoryOrderDetail() {
if(shopInfo.registerType=='before'){
return
}
data.historyOrder = [];
let res = await getHistoryOrder({
tableCode: data.table.tableCode,
@@ -684,11 +692,11 @@ function cartControls(cartItem, type) {
}
if (type == "add") {
cars.push(cartItem);
if ($goods){
$goods.chooseNumber = cartItem.number;
console.log('$goods',$goods)
console.log('cartItem',cartItem)
}
if ($goods) {
$goods.chooseNumber = cartItem.number;
console.log("$goods", $goods);
console.log("cartItem", cartItem);
}
}
if (type == "edit") {
editItem.value = $goods;
@@ -1014,11 +1022,18 @@ function setTabsCurrentPosition(position = "center") {
tabsEle.scrollWidth / 2 +
tabsEle.tabsItems[index].width / 2;
}
const shopInfo = uni.getStorageSync("shopInfo");
provide("shopInfo", shopInfo);
/**
* 获取商品列表
* @param max
* @param isGetPrve
*/
async function getGoodsData(max = 6, isGetPrve = false) {
const fuhao = !isGetPrve ? 1 : -1;
for (let i = 0; i < max; i++) {
if (layoutData.current + i >= layoutData.list.length - 1) {
if (layoutData.current + i > layoutData.list.length - 1) {
break;
} else {
const pageData = layoutData.list[layoutData.current + i * fuhao];
@@ -1033,25 +1048,7 @@ async function getGoodsData(max = 6, isGetPrve = false) {
? layoutArr[res2.data.productList.length]
: "6-grid",
productList: res2.data.productList.map((v) => {
const shopInfo = uni.getStorageSync("shopInfo");
v.is_time_discount = yskUtils.limitUtils.canUseLimitTimeDiscount(
{ ...v, salePrice: v.lowPrice },
data.limitTimeDiscount,
shopInfo,
null,
"id"
)
? 1
: 0;
if (v.is_time_discount) {
v.timeLimitPrice = yskUtils.limitUtils.returnPrice({
goods: { ...v, salePrice: v.lowPrice },
shopInfo: shopInfo,
limitTimeDiscountRes: data.limitTimeDiscount,
shopUserInfo: null,
idKey: "id",
});
}
v.salePrice = v.lowPrice;
const findGoodsInCar = cars.find((cars) => {
return cars.productId == v.id;
});
@@ -1086,14 +1083,18 @@ function animationStart(e) {
}
async function animationfinish(e) {
if (isScrollChangeCategorySel) {
layoutData.current = e.detail.current;
const categoryId = layoutData.list[layoutData.current].productCategoryId
? layoutData.list[layoutData.current].productCategoryId
: layoutData.list[layoutData.current].productList[0].categoryId;
const index = layoutData.category.list.findIndex((v) => v.id == categoryId);
isScrollChangeCategorySel = true;
layoutData.category.sel = index;
await getLayoutGoodsInit();
try {
layoutData.current = e.detail.current;
const categoryId = layoutData.list[layoutData.current].productCategoryId
? layoutData.list[layoutData.current].productCategoryId
: layoutData.list[layoutData.current].productList[0].categoryId;
const index = layoutData.category.list.findIndex(
(v) => v.id == categoryId
);
isScrollChangeCategorySel = true;
layoutData.category.sel = index;
await getLayoutGoodsInit();
} catch (error) {}
}
isScrollChangeCategorySel = false;
isTapChangeCategorySel = false;
@@ -1104,6 +1105,21 @@ async function animationfinish(e) {
* @param {Object} item
*/
async function taocanConfirm(d, item) {
const is_time_discount = yskUtils.limitUtils.canUseLimitTimeDiscount(
{
...item,
salePrice: item.lowPrice,
memberPrice: item.memberPrice
? item.memberPrice
: item.skuList[0].memberPrice,
},
data.limitTimeDiscount,
shopInfo,
null,
"id"
)
? 1
: 0;
editCart(
{
number: item.skuList[0].suitNum,
@@ -1112,6 +1128,7 @@ async function taocanConfirm(d, item) {
sku_id: item.skuList[0].id,
pro_group_info: JSON.stringify(d),
is_temporary: 0, //是否是临时菜
is_time_discount,
},
"add"
);
@@ -1529,6 +1546,7 @@ function setTagDisabled() {
console.log(selArr);
let selArrAllGroup = util.generateCombinations(selArr, selArr.length - 1);
console.log("selArrAllGroup");
console.log(selArrAllGroup);
const matchArr = [];
for (let key in skuMap) {
@@ -1551,6 +1569,7 @@ function setTagDisabled() {
return;
}
const includeSkuMap = matchArr.reduce((prve, cur) => {
console.log("cur.specSnap", cur);
const speArr = cur.specSnap.split(",");
for (let i of speArr) {
if (!prve.hasOwnProperty("i")) {
@@ -1593,7 +1612,7 @@ function chooseGuige(foodsindex, index) {
}
}
async function guigeConfirm(sku, suitNum) {
async function guigeConfirm(sku, number, is_time_discount) {
if (!data.isGoodsAdd) {
return;
}
@@ -1602,6 +1621,7 @@ async function guigeConfirm(sku, suitNum) {
let product_id = goods.id;
let product_type = goods.type;
let res = findGoodsInCar(goods, sku_id);
if (res) {
//更新
let { index } = res;
@@ -1617,7 +1637,7 @@ async function guigeConfirm(sku, suitNum) {
product_id: product_id,
sku_id: sku_id,
is_temporary: carGoods.is_temporary, //是否是临时菜
is_time_discount: goods.is_time_discount,
is_time_discount,
},
"edit"
);
@@ -1626,12 +1646,12 @@ async function guigeConfirm(sku, suitNum) {
//添加
editCart(
{
number: suitNum,
number: number,
product_id: product_id,
product_type: product_type,
sku_id: sku_id,
is_temporary: 0, //是否是临时菜
is_time_discount: goods.is_time_discount,
is_time_discount,
},
"add"
);
@@ -1748,13 +1768,27 @@ async function goodsUpdate(
index,
isAdd,
searchGoodsIndex,
showCurrentInput
showCurrentInput,
is_time_discount
) {
console.log(foodsindex, index, isAdd, searchGoodsIndex, "11111");
if (!data.isGoodsAdd) {
return;
}
const $goods = layoutData.list[foodsindex].productList[index];
console.log($goods);
if (is_time_discount === undefined) {
is_time_discount = yskUtils.limitUtils.canUseLimitTimeDiscount(
{ ...$goods, salePrice: $goods.lowPrice },
data.limitTimeDiscount,
shopInfo,
null,
"id"
)
? 1
: 0;
}
if ($goods.type != "sku") {
const step = isAdd ? 1 : -1;
//增加
@@ -1763,7 +1797,7 @@ async function goodsUpdate(
let { sku_id, product_id, id, number, discount_sale_amount } = isShop;
// 数量加减
let num = number + step;
if (num == 0 ||num<$goods.skuList[0].suitNum) {
if (num == 0 || num < $goods.skuList[0].suitNum) {
let params = {
...data.socketData,
id: id,
@@ -1782,6 +1816,7 @@ async function goodsUpdate(
let cartItem = cars[goodsInCarIndex];
num = cartItem.number * 1 + Number(showCurrentInput);
}
websocketUtil.send(
JSON.stringify({
...data.socketData,
@@ -1796,9 +1831,10 @@ async function goodsUpdate(
operate_type: "edit",
pack_number: 0, //数量
is_temporary: 0, //是否是临时菜
is_time_discount: $goods.is_time_discount,
is_time_discount,
})
);
// $goods.chooseNumber = 1
$goods.chooseNumber = num;
}
@@ -1811,6 +1847,7 @@ async function goodsUpdate(
if (showCurrentInput) {
weightNum = Number(showCurrentInput);
}
let params = {
...data.socketData,
table_code: data.table.tableCode,
@@ -1820,11 +1857,12 @@ async function goodsUpdate(
sku_name: "", // 临时菜规格
number: weightNum,
// discount_sale_amount: $goods.lowPrice,
discount_sale_amount:0,
discount_sale_amount: 0,
pack_number: 0, //数量
is_temporary: 0, //是否是临时菜
is_time_discount: $goods.is_time_discount,
is_time_discount,
};
console.log(params, "发送消息");
websocketUtil.send(JSON.stringify(params));
// $goods.chooseNumber = 1
}
@@ -1912,7 +1950,7 @@ onShow(() => {
title: "购物车加载中",
mask: true,
});
layoutData.current = 0;
// layoutData.current = 0;
watchChooseTable();
watchUpdate();
watchSocketOpen();
@@ -1931,11 +1969,13 @@ let sysInfo = ref({
windowWidth: 0,
windowHeight: 0,
});
console.log(yskUtils);
const limitTimeDiscountRes = ref(null);
async function getLimit() {
const res = await limitTimeDiscountApi.limitTimeDiscount();
data.limitTimeDiscount = res.data;
limitTimeDiscountRes.value = res.data;
if (data.table.tableCode) {
data.limitTimeDiscount = limitTimeDiscountRes.value;
websocketUtil.send(
JSON.stringify({
type: "shopping",
@@ -1943,7 +1983,7 @@ async function getLimit() {
table_code: data.table.tableCode,
shop_id: uni.getStorageSync("shopInfo").id,
operate_type: "time_discount_save",
data: data.limitTimeDiscount,
data: limitTimeDiscountRes.value,
})
);
console.log("limitTimeDiscount", data.limitTimeDiscount);
@@ -1962,6 +2002,8 @@ onLoad(async (opt) => {
isCreateOrderToDetail.value = true;
}
websocketUtil.initializeWebSocket();
xiadanClick();
});
</script>
@@ -1982,6 +2024,7 @@ onLoad(async (opt) => {
min-height: 40px;
padding-top: calc(var(--status-bar-height));
padding-bottom: 6px;
z-index: 5;
}
.top {

View File

@@ -12,16 +12,12 @@ export function getNowCart(carItem,goodsList,user) {
goodsList.map(goodsItem => {
if(carItem.product_id == goodsItem.id){
goodsItem.skuList.map(item=>{
if(carItem.product_id == item.productId){
if(carItem.product_id == item.productId&&item.id==carItem.sku_id){
carItem.lowPrice = item.salePrice
carItem.lowMemberPrice = item.memberPrice
carItem.memberPrice = item.memberPrice
carItem.specInfo = item.specInfo
if( uni.getStorageSync('shopInfo').isMemberPrice && user && user.id && user.isVip ){
carItem.salePrice = item.memberPrice
} else {
carItem.salePrice = item.salePrice
}
carItem.salePrice = item.salePrice
}
})