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 @@ - 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) } }); }