代客下单逻辑修改
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user