From b88efd1c6cb0abb78ec8264152d388ba55704af7 Mon Sep 17 00:00:00 2001
From: YeMingfei666 <1619116647@qq.com>
Date: Sat, 28 Sep 2024 15:07:26 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E5=AE=A2=E4=B8=8B?=
=?UTF-8?q?=E5=8D=95=E6=A8=A1=E5=9D=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../confirm-order/confirm-order.vue | 103 ++++++++++++------
pagesCreateOrder/index/components/car.vue | 2 +-
pagesCreateOrder/index/index.vue | 65 ++++++++---
pagesCreateOrder/index/util.js | 90 +++++++++------
pagesCreateOrder/pay-order/pay-order.vue | 49 +++++----
5 files changed, 199 insertions(+), 110 deletions(-)
diff --git a/pagesCreateOrder/confirm-order/confirm-order.vue b/pagesCreateOrder/confirm-order/confirm-order.vue
index 77e253a..e1838e4 100644
--- a/pagesCreateOrder/confirm-order/confirm-order.vue
+++ b/pagesCreateOrder/confirm-order/confirm-order.vue
@@ -24,7 +24,7 @@
就餐类型
-
+
@@ -75,7 +75,7 @@
-
+
@@ -89,7 +89,7 @@
-
+
@@ -184,7 +184,9 @@
- 修改
+
+ 修改
+
实收金额
¥{{formatPrice(allPrice) }}
@@ -242,6 +244,7 @@
} from '@/commons/utils/format.js';
import color from '@/commons/color.js';
import * as Api from '@/http/yskApi/Instead.js'
+ import $storageManage from '@/commons/utils/storageManage.js'
import {
tbShopInfo
} from '@/http/yskApi/user.js'
@@ -284,15 +287,17 @@
//更新就餐人数
async function updateChoseCount() {
console.log($shop.value);
- if($shop.value.registerType!='restaurant'){
+ if (!$shop.value.isTableFee) {
//不免餐位费
- await Api.$choseCount({
+ const res = await Api.$choseCount({
masterId: option.masterId,
- tableId: option.tableId,
+ tableId: table.value.tableId,
num: userNumbers.defaultCateIndex,
})
+ Object.assign($seatFee, res)
+ userNumbers.defaultCateIndex = res.totalNumber
}
-
+
}
function userNumberChange(e) {
@@ -310,7 +315,7 @@
} = item
const par = {
masterId: option.masterId,
- tableId: option.tableId,
+ tableId: table.value.tableId,
productId,
num: number,
skuId
@@ -349,14 +354,18 @@
...table.value
})
}
-
+ const option = reactive({
+ masterId: '',
+ tableId: ""
+ })
// 监听选择用户事件
let user = ref(null)
//更新选择用户
function setUser(par) {
+ console.log(option);
const submitPar = {
masterId: option.masterId,
- tableId: option.tableId,
+ tableId: table.value.tableId,
vipUserId: user.value.id ? user.value.id : '',
type: user.value.id ? 0 : 1 //0 设置 1 取消
}
@@ -392,10 +401,7 @@
})
}
- const option = reactive({
- masterId: '',
- tableId: ""
- })
+
const goods = reactive({
list: [],
sel: 0
@@ -413,9 +419,10 @@
totalAmount: 0,
})
const allPrice = computed(() => {
- return goods.list.reduce((prve, cur) => {
+ const goodsTotalPrice = goods.list.reduce((prve, cur) => {
return prve + cur.salePrice * cur.number * (cur.isGift ? 0 : 1)
- }, 0).toFixed(2)
+ }, 0)
+ return (goodsTotalPrice + $seatFee.totalAmount || 0).toFixed(2)
})
function setGoodsItem(key, val) {
@@ -430,12 +437,18 @@
page: 0,
size: 300,
masterId: option.masterId,
- tableId: option.tableId
+ tableId: table.value.tableId
}) {
const {
records,
seatFee
} = await Api.getCart(par)
+ if (seatFee && seatFee.useType) {
+ $storageManage.useType(seatFee.useType)
+ // uni.setStorageSync('useType',seatFee.useType);
+ eatTypes.active = seatFee.useType == 'takeout' ? seatFee.useType : seatFee.useType.replace(
+ /-after|-before/g, '');
+ }
goods.list = getNowCart(records)
if (seatFee && seatFee.totalNumber) {
userNumbers.defaultCateIndex = seatFee.totalNumber || 1
@@ -445,7 +458,9 @@
console.log(goods.list);
}
- let $shop = ref()
+ let $shop = ref({
+ registerType: ''
+ })
// 获取账号信息
async function getTbShopInfo() {
const res = await tbShopInfo()
@@ -453,7 +468,7 @@
console.log(res);
return res
}
-
+
// 创建订单
async function createOrder(par = {
masterId: option.masterId,
@@ -461,29 +476,48 @@
note: note.value,
postPay: true,
orderId: '',
- tableId: option.tableId
+ tableId: table.value.tableId
}) {
- updateChoseCount()
+ if (!$shop.value.isTableFee) {
+ //不免餐位费
+ await Api.$choseCount({
+ masterId: option.masterId,
+ tableId: table.value.tableId,
+ num: userNumbers.defaultCateIndex,
+ })
+ }
+ // updateChoseCount()
const res = await Api.$createOrder(par)
console.log($shop.value);
- if($shop.value.registerType=='munchies'){
+ console.log(res);
+ if ($shop.value.registerType == 'munchies') {
//先付
- return go.to('PAGES_ORDER_DETAIL',{
- id:res.id
+ return go.to('PAGES_CRESATE_ORDER_PAY', {
+ orderId: res.id
})
+ } else {
+ //后付
+ uni.navigateBack({delta:2})
+ // return go.to('PAGES_ORDER_DETAIL', {
+ // id: res.id
+ // })
}
uni.showToast({
title: '提交成功',
icon: 'none'
})
- setTimeout(() => {
- uni.$emit('orderDetail:update')
- uni.navigateBack({
- delta: 2
- })
- }, 500)
+ // setTimeout(() => {
+ // uni.$emit('orderDetail:update')
+ // uni.navigateBack({
+ // delta: 2
+ // })
+ // }, 500)
}
-
+
+ function init(){
+
+ }
+
onLoad((opt) => {
console.log(opt);
Object.assign(option, opt)
@@ -493,9 +527,10 @@
name: opt.name
}
}
+ init()
getCart()
getTbShopInfo()
- updateChoseCount()
+ // updateChoseCount()
})
async function changeUseType() {
@@ -512,8 +547,10 @@
useType = `dine-in-${isPayAfter? "after" : "before"}`;
uni.setStorageSync("useType", useType);
}
+ const tableId = useType=='takeout'?undefined: table.value.tableId;
const res = await Api.$changeUseType({
useType,
+ tableId,
cartIds: goods.list.map((v) => v.id),
})
return res
diff --git a/pagesCreateOrder/index/components/car.vue b/pagesCreateOrder/index/components/car.vue
index 006bfe9..ea681b8 100644
--- a/pagesCreateOrder/index/components/car.vue
+++ b/pagesCreateOrder/index/components/car.vue
@@ -55,7 +55,7 @@
¥
{{allPrice}}
- 去下单
+ {{table.type=='add'?'确认加菜':'去下单'}}
diff --git a/pagesCreateOrder/index/index.vue b/pagesCreateOrder/index/index.vue
index 92e1f9e..7130eb1 100644
--- a/pagesCreateOrder/index/index.vue
+++ b/pagesCreateOrder/index/index.vue
@@ -81,7 +81,7 @@
-
@@ -128,6 +128,12 @@
import {
getNowCart
} from '@/pagesCreateOrder/util.js'
+ import {
+ $returnUseType
+ } from './util.js'
+ import {
+ tbShopInfo
+ } from '@/http/yskApi/user.js'
const cars = reactive([])
const data = reactive({
scrollTop: 0, //tab标题的滚动条位置
@@ -153,7 +159,19 @@
},
})
-
+
+ // 获取账号信息
+ let $shop=ref({})
+ async function getTbShopInfo() {
+ const res = await tbShopInfo()
+ $shop.value = res
+ const useType=data.table.status=='using'?data.table.useType:$returnUseType(res)
+ uni.setStorageSync('useType',useType)
+ console.log(res);
+ return res
+ }
+
+
function setTabBar(category, goods, cars) {
@@ -247,6 +265,9 @@
}
//加入购物车
function addCart(par) {
+ if(!data.table.tableId){
+ return infoBox.showToast('请先选择台桌!')
+ }
const submitPar = {
masterId: data.masterId,
tableId: data.table.tableId,
@@ -318,18 +339,8 @@
}
}
async function init() {
+ getTbShopInfo()
getTableInfo()
- const {
- masterId
- } = await getMasterId()
- data.masterId = masterId
- const cartRes = await getCart()
- cars.length = 0
- const cartArr = getNowCart(cartRes.records)
- for (let i in cartArr) {
- cars.push(cartArr[i])
- }
-
const categoryRes = await getCategory()
const category = categoryRes.content.reduce((prve, cur) => {
prve.push({
@@ -347,6 +358,21 @@
}
return isShow;
});
+ if(!data.table.tableId){
+ //无台桌
+ setTabBar(category, goods, [])
+ return
+ }
+ const {
+ masterId
+ } = await getMasterId()
+ data.masterId = masterId
+ const cartRes = await getCart()
+ cars.length = 0
+ const cartArr = getNowCart(cartRes.records)
+ for (let i in cartArr) {
+ cars.push(cartArr[i])
+ }
setTabBar(category, goods, cars)
@@ -849,12 +875,15 @@
onLoad((opt) => {
console.log(opt)
Object.assign(data.table, opt)
- if (!opt.tableId) {
- infoBox.showErrorToast('暂不支持不选择台桌下载,请从桌台点餐')
- return setTimeout(() => {
- go.back()
- }, 1500)
+ if(opt.useType){
+ uni.setStorageSync('useType',opt.useType)
}
+ // if (!opt.tableId) {
+ // infoBox.showErrorToast('暂不支持不选择台桌下载,请从桌台点餐')
+ // return setTimeout(() => {
+ // go.back()
+ // }, 1500)
+ // }
init()
})
diff --git a/pagesCreateOrder/index/util.js b/pagesCreateOrder/index/util.js
index 4a2e11c..a76add4 100644
--- a/pagesCreateOrder/index/util.js
+++ b/pagesCreateOrder/index/util.js
@@ -1,52 +1,74 @@
+//根据店铺信息返回是否是后付款
+export function $trturnPayAfter(shop) {
+ //munchies 先付 restaurant 后付
+ const payAfter = shop.registerType == "munchies" ? false : true;
+ return payAfter
+}
+//根据店铺信息返回就餐类型
+export function $returnUseType(shop, useType) {
+ //是否是后付款
+ const payAfter = $trturnPayAfter(shop)
+ let result = "takeout";
+ if (useType == "takeout") {
+ result = 'takeout'
+ } else {
+ //堂食
+ result = `dine-in-${payAfter ? "after" : "before"}`;
+ }
+ return result
+}
//判断商品是否可以下单
-export function isCanBuy(goods,isStock) {
- return goods.isGrounding && goods.isPauseSale == 0 && (isStock?goods.stockNumber > 0:true) ;
+export function isCanBuy(goods, isStock) {
+ return goods.isGrounding && goods.isPauseSale == 0 && (isStock ? goods.stockNumber > 0 : true);
}
// 一个数组是否包含另外一个数组全部元素
function arrayContainsAll(arr1, arr2) {
- for (let i = 0; i < arr2.length; i++) {
- if (!arr1.includes(arr2[i])) {
- return false;
- }
- }
- return true;
+ for (let i = 0; i < arr2.length; i++) {
+ if (!arr1.includes(arr2[i])) {
+ return false;
+ }
+ }
+ return true;
}
//n项 n-1项组合,生成全部结果
function generateCombinations(arr, k) {
- let result = [];
+ let result = [];
- function helper(index, current) {
- if (current.length === k) {
- result.push(current.slice()); // 使用slice()来避免直接修改原始数组
- } else {
- for (let i = index; i < arr.length; i++) {
- current.push(arr[i]); // 将当前元素添加到组合中
- helper(i + 1, current); // 递归调用,索引增加以避免重复选择相同的元素
- current.pop(); // 回溯,移除当前元素以便尝试其他组合
- }
- }
- }
+ function helper(index, current) {
+ if (current.length === k) {
+ result.push(current.slice()); // 使用slice()来避免直接修改原始数组
+ } else {
+ for (let i = index; i < arr.length; i++) {
+ current.push(arr[i]); // 将当前元素添加到组合中
+ helper(i + 1, current); // 递归调用,索引增加以避免重复选择相同的元素
+ current.pop(); // 回溯,移除当前元素以便尝试其他组合
+ }
+ }
+ }
- helper(0, []); // 从索引0开始,初始空数组作为起点
- return result;
+ helper(0, []); // 从索引0开始,初始空数组作为起点
+ return result;
}
function returnReverseVal(val, isReturnString = true) {
- const isBol = typeof val === "boolean";
- const isString = typeof val === "string";
- let reverseNewval = "";
- if (isBol) {
- reverseNewval = !val;
- }
- if (isString) {
- reverseNewval = val === "true" ? "false" : "true";
- }
- return reverseNewval;
+ const isBol = typeof val === "boolean";
+ const isString = typeof val === "string";
+ let reverseNewval = "";
+ if (isBol) {
+ reverseNewval = !val;
+ }
+ if (isString) {
+ reverseNewval = val === "true" ? "false" : "true";
+ }
+ return reverseNewval;
}
-export default{
- isCanBuy,arrayContainsAll,generateCombinations,returnReverseVal
+export default {
+ isCanBuy,
+ arrayContainsAll,
+ generateCombinations,
+ returnReverseVal,$returnUseType
}
\ No newline at end of file
diff --git a/pagesCreateOrder/pay-order/pay-order.vue b/pagesCreateOrder/pay-order/pay-order.vue
index 35f4e27..48bcc5e 100644
--- a/pagesCreateOrder/pay-order/pay-order.vue
+++ b/pagesCreateOrder/pay-order/pay-order.vue
@@ -58,16 +58,15 @@
-
+
-
+
-
+
-
-
+
-
+
@@ -84,7 +83,7 @@
} from '@dcloudio/uni-app'
import * as Api from '@/http/yskApi/Instead.js'
import infoBox from '@/commons/utils/infoBox.js'
- import editDiscount from '@/pagesCreateOrder/components/edit-discount.vue'
+ import editDiscount from '/pagesCreateOrder/components/edit-discount.vue'
const pays = reactive({
list: ['扫码收款', '二维码收款'],
selIndex: 0,
@@ -116,27 +115,37 @@
pays.payTypes.selIndex = i
}
//支付成功回调
- function paySuccess(){
+ function paySuccess() {
infoBox.showToast('支付成功')
setTimeout(() => {
// uni.$emit('orderDetail:update')
- uni.navigateBack({delta:2})
+ uni.navigateBack({
+ delta: 2
+ })
}, 500)
}
- async function payOrder() {
+ async function payOrder(code) {
const payType = pays.payTypes.list[pays.payTypes.selIndex].payType
- await Api.$payOrder({
+ console.log({
tableId: order.tableId,
masterId: order.masterId,
- orderId: order.id||order.orderId,
+ orderId: order.id || order.orderId,
payType,
vipUserId: order.userId,
discount: 1,
- code: ''
+ code: code
+ });
+ await Api.$payOrder({
+ tableId: order.tableId,
+ masterId: order.masterId,
+ orderId: order.id || order.orderId,
+ payType,
+ vipUserId: order.userId,
+ code: code
})
paySuccess()
}
-
+
onMounted(() => {
getPayType()
})
@@ -148,18 +157,10 @@
const item = pays.payTypes.list[pays.payTypes.selIndex]
uni.scanCode({
onlyFromCamera: true,
- success:function (res) {
+ success: function(res) {
console.log('条码类型:' + res.scanType);
console.log('条码内容:' + res.result);
- Api.$payOrder({
- "orderId": order.orderId, // 订单id
- "payType": item.payType, //
- "discount": order.discount,
- "code": res.result
- }).then(res=>{
- console.log(res);
- paySuccess()
- })
+ payOrder(res.result)
}
});
}