代客下单逻辑修改
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
<view class="u-m-t-10 u-flex u-row-center color-main">
|
||||
<view @click="discountShow">修改</view>
|
||||
</view>
|
||||
<view class="u-m-t-10 u-flex u-row-center color-main">
|
||||
<view class="u-m-t-10 u-flex u-row-center color-main u-m-t-24">
|
||||
<view @click="chooseUser()">选择用户</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -58,13 +58,16 @@
|
||||
</view>
|
||||
<view
|
||||
class="border-bottom-dashed u-p-b-30 u-p-t-30"
|
||||
v-if="discountSaleAmount * 1 > 0"
|
||||
v-if="orderCostSummary.fullReduction.actualAmount&&orderCostSummary.fullReduction.usedThreshold"
|
||||
>
|
||||
<view class="u-flex u-p-l-24 u-p-r-24 u-row-between">
|
||||
<view>单品打折优惠</view>
|
||||
<view class="color-red"> -¥{{ discountSaleAmount }} </view>
|
||||
<view>满减活动</view>
|
||||
<view class="color-red">
|
||||
-¥{{ orderCostSummary.fullReduction.actualAmount }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
<view class="border-bottom-dashed u-p-b-30 u-p-t-30">
|
||||
<view class="u-flex u-p-l-24 u-p-r-24 u-row-between" @click="toQuan">
|
||||
@@ -312,6 +315,7 @@
|
||||
import {
|
||||
reactive,
|
||||
onMounted,
|
||||
nextTick,
|
||||
watch,
|
||||
ref,
|
||||
onBeforeUnmount,
|
||||
@@ -338,6 +342,8 @@ import { getDiscountByUserId } from "@/http/yskApi/market/consumeDiscount.js";
|
||||
import { getHistoryOrder } from "@/http/api/order.js";
|
||||
import { getPayTypeList } from "@/http/api/payType.js";
|
||||
import { shopUserDetail } from "@/http/api/shopUser.js";
|
||||
import { discountActivity } from "@/http/yskApi/market/discountActivity.js";
|
||||
|
||||
import {
|
||||
scanPay,
|
||||
microPay,
|
||||
@@ -353,6 +359,7 @@ import {
|
||||
payedDeductPoints,
|
||||
consumeAwardPoints,
|
||||
} from "@/http/api/points.js";
|
||||
|
||||
import yskUtils from "ysk-utils";
|
||||
|
||||
const websocketUtil = inject("websocketUtil"); // 注入 WebSocket 工具类实例
|
||||
@@ -380,8 +387,7 @@ const pageData = reactive({
|
||||
const order = reactive({
|
||||
orderAmount: 0,
|
||||
});
|
||||
//商品数量从0到n每一个对应的价格
|
||||
let $goodsPayPriceMap = {};
|
||||
|
||||
const pays = reactive({
|
||||
list: ["扫码收款", "二维码收款"],
|
||||
selIndex: 0,
|
||||
@@ -420,10 +426,20 @@ onShow(() => {
|
||||
watchChooseQuan();
|
||||
});
|
||||
const options = reactive({});
|
||||
async function getDiscountActivity() {
|
||||
let res = await discountActivity({
|
||||
shopId: uni.getStorageSync("shopId"),
|
||||
});
|
||||
if (res.code == 200) {
|
||||
fullReductionActivities.value = res.data?[res.data]:[];
|
||||
}
|
||||
}
|
||||
onLoad(async (opt) => {
|
||||
Object.assign(order, opt);
|
||||
Object.assign(options, opt);
|
||||
getPayType();
|
||||
await getPayType();
|
||||
await getDiscountActivity()
|
||||
console.log("pays.payTypes.list");
|
||||
init();
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
@@ -445,6 +461,9 @@ function toDiancai() {
|
||||
* 初始化
|
||||
*/
|
||||
async function init() {
|
||||
nextTick(() => {
|
||||
onMessage();
|
||||
});
|
||||
// 获取订单详情
|
||||
const { data: orderRes } = await getHistoryOrder({ orderId: order.orderId });
|
||||
if (orderRes.status == "cancelled") {
|
||||
@@ -466,11 +485,10 @@ async function init() {
|
||||
Object.assign(order, orderRes);
|
||||
pageData.goodsList = objToArrary(orderRes.detailMap);
|
||||
|
||||
$goodsPayPriceMap = returnGoodsPayPriceMap(pageData.goodsList);
|
||||
|
||||
// console.log("order===",order)
|
||||
// console.log("pageData.user===",pageData.user)
|
||||
// 获取用户信息
|
||||
|
||||
if (order.userId || pageData.user.userId) {
|
||||
shopUserDetail({
|
||||
userId: order.userId || pageData.user.userId,
|
||||
@@ -549,42 +567,7 @@ const originPrice = computed(() => {
|
||||
}
|
||||
});
|
||||
|
||||
const newOriginPrice = computed(() => {
|
||||
if (pageData.goodsList) {
|
||||
let goodsPrice = pageData.goodsList
|
||||
.filter((v) => v.price != 0 && v.status !== "return")
|
||||
.reduce((a, b) => {
|
||||
let memberPrice = b.memberPrice ? b.memberPrice : b.price;
|
||||
let tPrice = isVip.value ? memberPrice : b.price;
|
||||
tPrice = b.discountSaleAmount ? b.discountSaleAmount : tPrice;
|
||||
return (
|
||||
a +
|
||||
parseFloat(
|
||||
mathFloorPrice(b.num * tPrice, b) * 1 -
|
||||
mathFloorPrice(b.returnNum * tPrice, b) * 1 -
|
||||
mathFloorPrice(b.refundNum * tPrice, b) * 1
|
||||
)
|
||||
);
|
||||
}, 0);
|
||||
// console.log("减去退款退费的菜品金额===",goodsPrice)
|
||||
return (goodsPrice + tableFee.value + packAmount.value).toFixed(2);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* 菜品折扣金额
|
||||
*/
|
||||
const discountSaleAmount = computed(() => {
|
||||
if (pageData.goodsList) {
|
||||
let price = pageData.goodsList
|
||||
.filter((v) => v.discountSaleAmount > 0 && v.status !== "return")
|
||||
.reduce((a, b) => {
|
||||
return a + (b.num * b.price - b.num * b.discountSaleAmount);
|
||||
}, 0);
|
||||
// console.log("单品折扣金额====",price)
|
||||
return price.toFixed(2);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -756,6 +739,9 @@ watch(
|
||||
v.disabled = false;
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
immediate: true,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -797,14 +783,14 @@ function getPayParam() {
|
||||
newCustomerDiscountAmount: orderCostSummary.value.newUserDiscount, //新客立减
|
||||
newCustomerDiscountId:
|
||||
orderCostSummary.value.newUserDiscount > 0
|
||||
? cartStore.consumeDiscount.id
|
||||
? newUserDiscountRes.value.id
|
||||
: "",
|
||||
|
||||
discountActAmount: orderCostSummary.value.fullReduction.actualAmount, //满减抵扣金额
|
||||
discountActId: orderCostSummary.value.fullReduction.usedActivity
|
||||
discountActId: (orderCostSummary.value.fullReduction.usedActivity&&orderCostSummary.value.fullReduction.usedThreshold)
|
||||
? orderCostSummary.value.fullReduction.usedActivity.id
|
||||
: null,
|
||||
vipPrice: orderCostSummary.value.vipDiscountAmount != 0 ? 1 : 0, // 是否使用会员价
|
||||
vipPrice:isVip.value? 1 : 0, // 是否使用会员价
|
||||
limitRate:
|
||||
order.limitRate && order.limitRate.id
|
||||
? {
|
||||
@@ -840,7 +826,6 @@ function getPayUrl() {
|
||||
if (order.userId || pageData.user.userId) {
|
||||
params.userId = order.userId || pageData.user.userId;
|
||||
}
|
||||
delete params.limitRate;
|
||||
getOrderPayUrl(params).then((res) => {
|
||||
console.log(res, "tishi");
|
||||
payCodeUrl.value = res.data;
|
||||
@@ -854,11 +839,20 @@ function getPayUrl() {
|
||||
async function getPayType() {
|
||||
const payTypeList = await getPayTypeList();
|
||||
pays.payTypes.list = [];
|
||||
const arr = ["cash", "member-account"];
|
||||
payTypeList.data.map((v) => {
|
||||
if (v.payType != "bank") {
|
||||
let disabled = false;
|
||||
if (orderCostSummary.value.finalPayAmount <= 0) {
|
||||
if (arr.includes(v.payType)) {
|
||||
disabled = false;
|
||||
} else {
|
||||
disabled = true;
|
||||
}
|
||||
}
|
||||
pays.payTypes.list.push({
|
||||
...v,
|
||||
disabled: false,
|
||||
disabled
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -927,6 +921,9 @@ function changeAccountPoints() {
|
||||
function toQuan() {
|
||||
console.log("toQuan", order);
|
||||
console.log("pageData.user", pageData.user);
|
||||
if(orderCostSummary.value.usedActivity){
|
||||
return infoBox.showToast("满减活动不可与优惠券同享")
|
||||
}
|
||||
if (!order.userId && !pageData.user.id) {
|
||||
return infoBox.showToast("请先选择会员", 0.5).then(() => {
|
||||
chooseUser();
|
||||
@@ -993,19 +990,80 @@ function chooseUser() {
|
||||
function watchChooseuser() {
|
||||
uni.$off("choose-user");
|
||||
uni.$on("choose-user", (data) => {
|
||||
if (pageData.user.id != data.id) {
|
||||
selCoupon.value = [];
|
||||
accountPoints.sel = false;
|
||||
}
|
||||
pageData.user = data;
|
||||
if (data.id) {
|
||||
getNewUserDiscount();
|
||||
}
|
||||
|
||||
init();
|
||||
});
|
||||
}
|
||||
|
||||
watch(
|
||||
() => pageData.user.id,
|
||||
(newval) => {
|
||||
selCoupon.value = [];
|
||||
accountPoints.sel = false;
|
||||
// 更新购物车和历史订单数据
|
||||
uodateCartAndHistory();
|
||||
if (newval) {
|
||||
getNewUserDiscount();
|
||||
// getShopUserDetail();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* 更新购物车和历史订单数据
|
||||
*/
|
||||
function uodateCartAndHistory() {
|
||||
let newData = {
|
||||
history: [],
|
||||
cart: [],
|
||||
};
|
||||
console.log("uodateCartAndHistory", pageData.user);
|
||||
for (let cart of pageData.goodsList) {
|
||||
const canUseLimitTimeDiscount = yskUtils.limitUtils.canUseLimitTimeDiscount(
|
||||
cart,
|
||||
order.limitRate,
|
||||
pageData.shopInfo,
|
||||
pageData.user,
|
||||
"productId"
|
||||
)
|
||||
? 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: order.takeCode,
|
||||
data: newData,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
function getShopUserDetail() {
|
||||
shopUserDetail({
|
||||
// shopId: uni.getStorageSync("shopInfo").id,
|
||||
id: pageData.user.id,
|
||||
}).then((res) => {
|
||||
if (res.data) {
|
||||
pageData.user = res.data;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const newUserDiscountRes=ref(null)
|
||||
//获取用户新客立减
|
||||
function getNewUserDiscount() {
|
||||
getDiscountByUserId({
|
||||
@@ -1013,6 +1071,7 @@ function getNewUserDiscount() {
|
||||
}).then((res) => {
|
||||
if (res.data) {
|
||||
newUserDiscount.value = res.data.amount || 0;
|
||||
newUserDiscountRes.value = res.data;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1298,6 +1357,64 @@ function cashConfirmShow() {
|
||||
modal.key = "cash";
|
||||
modal.show = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取历史订单并更新商品列表
|
||||
*/
|
||||
async function getHistoryAndUpdateGoodsList() {
|
||||
// 获取订单详情
|
||||
const { data: orderRes } = await getHistoryOrder({ orderId: order.orderId });
|
||||
if (orderRes.status == "cancelled") {
|
||||
uni.showToast({
|
||||
title: "订单已取消",
|
||||
icon: "none",
|
||||
});
|
||||
toDiancai();
|
||||
return;
|
||||
}
|
||||
if (orderRes.status == "done") {
|
||||
uni.showToast({
|
||||
title: "订单已完成",
|
||||
icon: "none",
|
||||
});
|
||||
toDiancai();
|
||||
return;
|
||||
}
|
||||
Object.assign(order, orderRes);
|
||||
pageData.goodsList = objToArrary(orderRes.detailMap);
|
||||
pageData.seatNum = order.seatNum;
|
||||
}
|
||||
/**
|
||||
* socket消息监听
|
||||
*/
|
||||
function onMessage() {
|
||||
websocketUtil.offMessage();
|
||||
websocketUtil.onMessage((res) => {
|
||||
let msg = JSON.parse(res);
|
||||
|
||||
switch (msg.operate_type) {
|
||||
case "pad_init":
|
||||
getHistoryAndUpdateGoodsList();
|
||||
break;
|
||||
case "pad_add":
|
||||
case "add":
|
||||
break;
|
||||
case "pad_edit":
|
||||
case "edit":
|
||||
break;
|
||||
case "pad_del":
|
||||
case "del":
|
||||
break;
|
||||
case "pad_cleanup":
|
||||
case "cleanup":
|
||||
break;
|
||||
case "product_update":
|
||||
break;
|
||||
case "pad_batch":
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
Reference in New Issue
Block a user