代客下单新逻辑梳理

This commit is contained in:
YeMingfei666 2024-10-31 16:36:21 +08:00
parent c6fed2af32
commit 8403afd685
7 changed files with 280 additions and 113 deletions

View File

@ -5,9 +5,9 @@ ENV = 'development'
# VUE_APP_BASE_API = 'http://192.168.2.42:8000'
# VUE_APP_BASE_API = 'http://192.168.2.133:8000'
# 测试
# VUE_APP_BASE_API = 'https://admintestpapi.sxczgkj.cn'
VUE_APP_BASE_API = 'https://admintestpapi.sxczgkj.cn'
#预发布
VUE_APP_BASE_API = 'https://pre-cashieradmin.sxczgkj.cn'
# VUE_APP_BASE_API = 'https://pre-cashieradmin.sxczgkj.cn'
# 生产
# VUE_APP_BASE_API = 'https://cashieradmin.sxczgkj.cn'

View File

@ -130,14 +130,14 @@
{{ scope.row.priceAmount }}
</template>
</el-table-column>
<!-- <el-table-column label="操作">
<el-table-column label="操作">
<template v-slot="scope">
<template v-if="scope.row.status!='refund'">
<el-button v-if="detail.status=='closed'||detail.status=='refund'" type="text" size="mini" @click="tuikuan(scope.row)"><span >退款</span></el-button>
</template>
<el-button v-if="detail.status=='unpaid'" type="text" size="mini" @click="tuiCai(scope.row)"><span >退菜</span></el-button>
</template>
</el-table-column> -->
</el-table-column>
</el-table>
</div>
<!-- </el-tab-pane> -->
@ -280,6 +280,7 @@ export default {
num:e.num
}]
});
this.$message.success("退款成功");
this.update();
},
update(){
@ -291,6 +292,7 @@ export default {
cartId: this.selGoods.id,
tableId: this.detail.tableId,
});
this.$message.success("退菜成功");
this.update();
},
tuikuan(item){

View File

@ -146,9 +146,12 @@
{{ scope.row.createdAt | timeFilter }}
</template>
</el-table-column>
<el-table-column label="操作" width="100">
<el-table-column label="操作">
<template v-slot="scope">
<el-button type="text" @click="$refs.orderDetail.show(scope.row)">详情</el-button>
<div class="u-flex gap-10">
<el-button type="text" @click="$refs.orderDetail.show(scope.row)">详情</el-button>
<el-button v-if="scope.row.status == 'unpaid'" type="primary" size="mini" @click="payOrder(scope.row)">结账</el-button>
</div>
</template>
</el-table-column>
</el-table>
@ -247,6 +250,21 @@ export default {
},
methods: {
//
payOrder(order){
console.log(order);
this.$router.push({
path: "/tool/Instead/index",
query: {
table_name: order.tableName,
tableId: order.tableId,
useType: order.useType,
masterId: order.masterId,
orderId: order.id,
key:'isJieZhang'
},
});
},
//
async payCount() {
try {

View File

@ -76,7 +76,7 @@
}"
>
<span v-if="isSeatFee"> {{ item.totalAmount }}</span>
<span v-else> {{ item.totalAmount }}</span>
<span v-else> {{ (item.salePrice*item.number+(item.packAmount||0)).toFixed(2) }}</span>
</div>
</div>
</div>

View File

@ -154,7 +154,7 @@ export default {
}
if (curretnMoney > money) {
this.$message.error("实收金额不能大于总金额");
this.form.curretnMoney = 0;
this.form.curretnMoney = form.money;
}
this.form.reduceMoney = (money - this.form.curretnMoney).toFixed(2);
this.form.discount =toFixedNoRounding( ((this.form.curretnMoney / money) * 100).toFixed(3) );

View File

@ -46,11 +46,12 @@
trigger="click"
v-model="tableShow"
>
<el-input
<el-input
placeholder="请输入内容"
prefix-icon="el-icon-search"
v-model="tableSearchText"
@input="searchInput">
@input="searchInput"
>
</el-input>
<div style="max-height: 398px; overflow-y: scroll" class="u-m-t-12">
<div
@ -233,7 +234,9 @@
<div class="u-flex">
<div class="u-p-r-14 border-r u-m-r-14">
<template v-if="!shopInfo.isTableFee">
<template
v-if="!shopInfo.isTableFee && key != 'isJieZhang'"
>
<div
class="u-flex cur-pointer"
@click="
@ -404,7 +407,7 @@
<div class="flex mt-14">
<template v-if="table">
<template v-if="!postPay">
<template v-if="isCreateOrder">
<template v-if="!postPay&& isCreateOrder && table && table.tableId">
<!-- <template v-if="false"> -->
<button
class="my-btn flex-1 default"
@ -414,26 +417,28 @@
</button>
</template>
<template v-else>
<button
class="my-btn flex-1 primary"
@click="scanPayClick"
>
<span>微信/支付宝</span>
</button>
<div style="width: 15px"></div>
<button
class="my-btn flex-1 primary"
@click="cashPayClick"
>
<span>现金</span>
</button>
<div style="width: 15px"></div>
<button
class="my-btn flex-1 default"
@click="morePayClick"
>
<span>更多支付</span>
</button>
<template v-if="key != 'isJieZhang'">
<button
class="my-btn flex-1 primary"
@click="scanPayClick"
>
<span>微信/支付宝</span>
</button>
<div style="width: 15px"></div>
<button
class="my-btn flex-1 primary"
@click="cashPayClick"
>
<span>现金</span>
</button>
<div style="width: 15px"></div>
<button
class="my-btn flex-1 default"
@click="morePayClick"
>
<span>更多支付</span>
</button>
</template>
</template>
</template>
<template v-else>
@ -590,7 +595,7 @@
</div> -->
<div
class="btn"
:class="{ disabled: order.selIndex < 0 }"
:class="{ disabled: order.selIndex < 0 && key != 'isJieZhang' }"
@click="refNoteShow(true)"
>
单品备注
@ -1254,6 +1259,7 @@ import moneyKeyboard from "./components/money-keyboard.vue";
import dayjs from "dayjs";
import { tbShopInfo } from "@/api/user";
import { hasPermission } from "@/utils/limits.js";
import { tbOrderInfoDetail } from "@/api/order";
import {
getGoodsLists,
@ -1283,12 +1289,15 @@ import {
isCanBuy,
arrayContainsAll,
generateCombinations,
returnReverseVal,$strMatch,
returnReverseVal,
$strMatch,
returnGiftArr,
returnPackFee,
formatOrderGoodsList
} from "./util.js";
import { $status } from "@/utils/table.js";
let $originTableList=[]
let $originTableList = [];
export default {
components: {
returnCart,
@ -1305,7 +1314,7 @@ export default {
data() {
return {
//
tableSearchText:"",
tableSearchText: "",
//
canShoukuan: false,
//
@ -1605,12 +1614,18 @@ export default {
.reduce((a, b) => {
return a + b.number * b.salePrice;
}, 0);
return (
oldPrice +
price +
+this.order.packFee.totalAmount +
const nowPackFee = returnPackFee(this.order.list, false);
const oldackFee = returnPackFee(this.order.old.list);
const packFee = nowPackFee + oldackFee;
const returnStatus = ["return", "refunding", "refund"];
const seatFee =
this.order.seatFee.totalAmount *
(this.order.seatFee.status == "return" ? 0 : 1)
(returnStatus.includes(this.order.seatFee.status) ? 0 : 1);
console.log(nowPackFee, oldackFee, packFee, seatFee);
return (
(oldPrice + price + +packFee + seatFee) *
this.createOrder.discount
).toFixed(2);
},
allNumber() {
@ -1687,8 +1702,10 @@ export default {
// })
}
},
table(oldval, newval) {
this.onTableChange();
table(newval, oldval) {
if (newval&&newval.tableId) {
this.onTableChange();
}
},
masterId: function (val) {
console.log(val);
@ -1699,15 +1716,15 @@ export default {
}
},
"vipUser.id": async function (val) {
if (!this.table.tableId) {
return;
}
let masterId = this.order.masterId;
if (!masterId) {
const res = await this.getMasterId();
masterId = res.masterId;
}
this.masterId = masterId;
// if (!this.table.tableId) {
// return;
// }
// let masterId = this.order.masterId;
// if (!masterId) {
// const res = await this.getMasterId();
// masterId = res.masterId;
// }
// this.masterId = masterId;
$setUser({
tableId: this.table.tableId,
masterId: this.masterId,
@ -1826,13 +1843,15 @@ export default {
// this.getCategory();
// this.refToggle('refScanCode',true)
// this.refToggle("refDiscount", true);
console.log(this.$route.query.tableId);
this.open(this.$route.query.tableId ? this.$route.query : "");
// this.open(this.$route.query.tableId ? this.$route.query : "");
this.open(this.$route.query);
},
methods: {
searchInput(e){
console.log(e)
this.tableList=$originTableList.filter(v=>$strMatch(v.name,e.trim()))
searchInput(e) {
console.log(e);
this.tableList = $originTableList.filter((v) =>
$strMatch(v.name, e.trim())
);
},
returnTableColor(key) {
const item = $status[key];
@ -1861,7 +1880,8 @@ export default {
this.order.extra.selIndex = index;
},
async morePayClick() {
if (this.order.list.length <= 0) {
if (this.order.list.length <= 0 && !this.createOrder.data) {
return this.$message("请选择菜品");
}
const canJiesuan = await this.shoukuanClick();
@ -1871,13 +1891,14 @@ export default {
// if(this.isCreateOrder){
// return
// }
const res = await this.returnCreateOrderData();
await this.returnCreateOrderData();
this.payBeforeClear();
this.createOrder.data = res;
this.order.payType = "";
this.isCreateOrder = true;
// this.order.payType = "";
},
async cashPayClick() {
if(!this.createOrder.data.id&&this.order.list.length <= 0){
return this.$message("没有要结算的订单或商品!");
}
const canJiesuan = await this.shoukuanClick();
if (!canJiesuan) {
return;
@ -1892,6 +1913,13 @@ export default {
});
},
async returnCreateOrderData() {
if (this.key == "isJieZhang"||this.order.list.length <= 0) {
//
// this.order.old.list = formatOrderGoodsList(this.createOrder.data.detailList||[]);
this.isCreateOrder=true
return this.createOrder.data;
}
this.order.list = [];
const res = await $createOrder({
masterId: this.order.masterId || this.masterId,
vipUserId: this.vipUser.id,
@ -1900,6 +1928,9 @@ export default {
postPay: this.postPay,
orderld: this.order.orderId,
});
this.isCreateOrder=true
this.order.old.list = formatOrderGoodsList(res.detailList||[]);
this.getOrderData({orderId:res.id})
this.createOrder.data = res;
this.createOrder.discount = 1;
// const lastItem = this.order.old.list[this.order.old.list.length - 1];
@ -1908,27 +1939,22 @@ export default {
// ...this.order.old.list,
// { info: this.order.list, placeNum: nowPlaceNum + 1 },
// ];
this.order.list = [];
this.order.old.list = [];
console.log(this.order.old.list);
return res;
},
async payBeforeClear() {
this.getMasterId().then((res) => {
this.masterId = res.masterId;
});
this.loading = false;
this.order.list = [];
this.order.query.page = 1;
this.goods.total = 0;
this.order.list = [];
this.order.selIndex = -1;
this.order.selPlaceNum = -1;
this.order.selGoods = "";
this.order.seatFee = { totalAmount: 0 }; //
this.prveOrder.list = [];
this.prveOrder.selIndex = -1;
this.order.old.selIndex = -1;
this.isCreateOrder = false;
// this.isCreateOrder = false;
this.createOrder.status = "";
this.createOrder.code = "";
this.note.content = "";
@ -1942,7 +1968,6 @@ export default {
this.key = "";
this.order.orderId = "";
this.perpole = "";
// this.useTypes.sel = "dine-in";
},
async cachePay() {
const canJiesuan = await this.shoukuanClick();
@ -1954,12 +1979,14 @@ export default {
this.pays();
},
async scanPayClick() {
if(!this.createOrder.data.id&&this.order.list.length <= 0 ){
return this.$message("没有要结算的订单或商品!");
}
const canJiesuan = await this.shoukuanClick();
if (!canJiesuan) {
return;
}
const order = await this.returnCreateOrderData();
console.log(this.createOrder.data);
this.order.payType = "scanCode";
this.payTypeItemClick({ payType: "scanCode", order });
this.payBeforeClear();
@ -2099,15 +2126,17 @@ export default {
},
//退
async refReturnCartConfirm(e) {
console.log(this.order.selGoods);
const res = await $returnCart({
...e,
cartId: this.order.selGoods.id,
cartId:this.order.selGoods.cartId,
tableId: this.table.tableId,
});
this.order.selGoods.status = "return";
this.order.old.selIndex = -1;
this.getCart();
console.log(this.order.selGoods);
// this.getCart();
this.getOrderData()
// console.log(this.order.selGoods);
},
//
@ -2120,16 +2149,16 @@ export default {
this.tableList = content.filter(
(v) => v.status != "closed" && v.status != "cleaning"
);
$originTableList=this.tableList
$originTableList = this.tableList;
} catch (error) {
console.log(error);
}
},
async changeTable(item) {
console.log(this.table);
if (this.table || this.order.list.length <= 0) {
this.table = item;
this.tableShow = false;
console.log(this.table);
return;
}
if (item.status != "idle") {
@ -2230,7 +2259,7 @@ export default {
isSellOut(item) {
return (
item.isPauseSale ||
(item.typeEnum !== "sku" &&
(
(item.isStock == 1 ? item.stockNumber <= 0 : false))
);
},
@ -2547,7 +2576,9 @@ export default {
//
orderBtnsClick(key) {
const orderGoods = this.order.list[this.order.selIndex];
this.createOrderClose();
if (this.key != "isJieZhang"&&this.postPay) {
this.createOrderClose();
}
if (key === "sku") {
this.selGoods.title = orderGoods.name;
this.selGoods.isEdit = true;
@ -2721,8 +2752,8 @@ export default {
this.$nextTick(() => {
this.getCacheOrder();
});
const masterIdRes = await this.getMasterId();
this.masterId = masterIdRes.masterId;
await this.getMasterId();
},
//
removeCart() {
@ -3277,6 +3308,18 @@ export default {
this.$goodsData = goods;
},
async open(params) {
const item = {
name: params.table_name,
tableId: params.tableId,
useType: params.useType,
maxCapacity: params.maxCapacity * 1,
masterId: params.masterId,
orderId: params.orderId,
},
key = params.key,
perpoleNumber = params.num || "";
this.key = key;
const shopId = localStorage.getItem("shopId");
const shopInfo = await tbShopInfo(shopId);
for (let i in shopInfo.eatModel) {
@ -3290,28 +3333,40 @@ export default {
}
}
this.shopInfo = shopInfo;
this.setPostPay();
if (!params.masterId) {
await this.getMasterId();
this.getCart()
} else {
this.masterId = params.masterId;
}
if (key == "isJieZhang") {
this.postPay = false;
} else {
this.setPostPay();
}
this.setUseType();
this.getGoods();
this.getCategory();
this.getTable();
console.log(params);
const res = await this.getMasterId();
console.log(res);
if (!params) {
//
if (key == "isJieZhang") {
this.perpole = perpoleNumber;
this.table = params.tableId ? { name: item.name } : "";
if (params.orderId) {
const orderRes = await this.getOrderData(params);
if (orderRes.status != "unpaid") {
this.$router.replace({ path: "/tool/Instead/index" });
}
}
this.isCreateOrder = true;
return;
}
const item = {
name: params.table_name,
tableId: params.tableId,
useType: params.useType,
maxCapacity: params.maxCapacity * 1,
masterId: params.masterId,
orderId: params.orderId,
},
key = params.key,
perpoleNumber = params.num;
// this.getCart();
// this.getCacheOrder();
// if (!params) {
// //
// return;
// }
//
if (item && item.useType) {
localStorage.setItem("useType", item.useType);
@ -3320,17 +3375,72 @@ export default {
? item.useType
: item.useType.replace(/-after|-before/g, "");
}
this.key = key;
this.isCreateOrder = this.key == "isPayOrder" ? true : false;
this.isCreateOrder =
this.key == "isPayOrder" || this.key == "isJieZhang" ? true : false;
this.perpole = perpoleNumber;
this.table = item;
this.masterId = item.masterId;
this.table = params.tableId ? { name: item.name } : "";
},
async getOrderData(params) {
const res = await tbOrderInfoDetail(params?params.orderId:this.createOrder.data.id);
if (res.status != "unpaid") {
return res;
}
this.createOrder.data = res;
this.order.packFee.totalAmount = res.seatInfo || { totalAmount: 0 };
const goodsMap = {};
for (let i in res.detailList) {
const goods = res.detailList[i];
if (goods.productId != "-999") {
if (goodsMap.hasOwnProperty(goods.placeNum)) {
goodsMap[goods.placeNum].push(goods);
} else {
goodsMap[goods.placeNum] = [goods];
}
}
}
this.order.seatFee = res.seatInfo
? {
...res.seatInfo,
totalNumber: res.seatInfo.num,
number: res.seatInfo.num,
name: res.seatInfo.productName,
totalAmount: res.seatInfo.priceAmount,
}
: {
name: "客座费",
number: res.seatCount||0,
totalNumber: res.seatCount||0,
totalAmount: res.seatAmount||0,
status: "",
};
console.log(this.order.seatFee);
this.order.old.list = Object.entries(goodsMap).map(([key, value]) => ({
info: value.map((v) => {
return {
...v,
coverImg: v.productImg,
name: v.productName,
specSnap: v.productSkuName,
number: v.num,
totalAmount: v.priceAmount,
salePrice: v.price,
isGift: v.gift ? "true" : "false",
isPack: v.pack ? "true" : "false",
};
}),
placeNum: key,
}));
console.log(this.order.old.list);
return res;
},
close() {
this.reset()
if (this.table.tableId) {
this.$router.replace({ path: "/tool/table_list" });
} else {
this.$router.go(0);
this.$router.replace({ path: "/tool/Instead/index" });
// this.$router.go(0);
// this.reset();
// this.$router.replace({ path: "/tool/Instead/index" });
}

View File

@ -1,16 +1,34 @@
//计算打包费
export function returnPackFee(arr, isOld = true) {
if (isOld) {
return arr.reduce((a, b) => {
const bTotal = b.info
.filter((v) => v.isGift !== "true" && v.status !== "return")
.reduce((prve, cur) => {
return prve + (cur.packFee || cur.packAmount||0);
}, 0);
return a + bTotal;
}, 0);
} else {
return arr.filter(v => v.status !== 'return' && v.isGift !== 'true').reduce((a, b) => {
return a + (b.packFee || b.packAmount||0);
}, 0);
}
}
//判断商品是否可以下单
export function isCanBuy(skuGoods,goods) {
if(goods.typeEnum=='normal'){
export function isCanBuy(skuGoods, goods) {
if (goods.typeEnum == 'normal') {
//单规格
return goods.isGrounding&&goods.isPauseSale==0&&(goods.isStock?goods.stockNumber>0:true);
}else{
return goods.isGrounding && goods.isPauseSale == 0 && (goods.isStock ? goods.stockNumber > 0 : true);
} else {
//多规格
return goods.isGrounding&&goods.isPauseSale==0&&skuGoods.isGrounding&&skuGoods.isPauseSale==0&&(goods.isStock?goods.stockNumber>0:true);
return goods.isGrounding && goods.isPauseSale == 0 && skuGoods.isGrounding && skuGoods.isPauseSale == 0 && (goods.isStock ? goods.stockNumber > 0 : true);
}
}
//字符匹配
export function $strMatch(matchStr,str){
export function $strMatch(matchStr, str) {
return matchStr.toLowerCase().includes(str.toLowerCase())
}
@ -59,15 +77,34 @@ export function returnReverseVal(val, isReturnString = true) {
return reverseNewval;
}
export function returnGiftArr(arr){
let result=[]
for(let i=0;i<arr.length;i++){
const info=arr[i].info
for(let j=0;j<info.length;j++){
if(info[j].isGift==='true'){
export function returnGiftArr(arr) {
let result = []
for (let i = 0; i < arr.length; i++) {
const info = arr[i].info
for (let j = 0; j < info.length; j++) {
if (info[j].isGift === 'true') {
result.push(info[j])
}
}
}
return result
}
export function formatOrderGoodsList(arr){
const goodsMap = {}
for (let i in arr) {
const goods = arr[i]
if (goods.productName != '客座费') {
if (goodsMap.hasOwnProperty(goods.placeNum)) {
goodsMap[goods.placeNum||1].push(goods)
} else {
goodsMap[goods.placeNum||1] = [goods]
}
}
}
return Object.entries(goodsMap).map(([key, value]) => ({
info: value,
placeNum: key||1
}))
}