From 03d820bc9a5eb4e921322c71d8425722a9f8c50a Mon Sep 17 00:00:00 2001 From: YeMingfei666 <1619116647@qq.com> Date: Fri, 15 Nov 2024 15:12:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E5=AE=A2=E4=B8=8B=E5=8D=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=89=AB=E7=A0=81=E9=80=89=E6=8B=A9=E6=A1=8C=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagesCreateOrder/index/index.vue | 116 +++++++++++++++++++++++-------- 1 file changed, 86 insertions(+), 30 deletions(-) diff --git a/pagesCreateOrder/index/index.vue b/pagesCreateOrder/index/index.vue index 5c3c43e..32b69b9 100644 --- a/pagesCreateOrder/index/index.vue +++ b/pagesCreateOrder/index/index.vue @@ -269,6 +269,14 @@ return res } + function returnUrlPar(str) { + let arr = str.split("?")[1].split("&"); //先通过?分解得到?后面的所需字符串,再将其通过&分解开存放在数组里 + let obj = {}; + for (let i of arr) { + obj[i.split("=")[0]] = i.split("=")[1]; //对数组每项用=分解开,=前为对象属性名,=后为属性值 + } + return obj + } function scanCode() { // 只允许通过相机扫码 @@ -278,6 +286,24 @@ success: function(res) { console.log('条码类型:' + res.scanType); console.log('条码内容:' + res.result); + if (res.result.includes('codeplate?code=')) { + const par = returnUrlPar(res.result) + const tableId = par.code + console.log('par'); + console.log(par); + onChooseTable({ + tableId + }) + } else { + uni.showToast({ + icon: 'error', + title: '请扫描正确的桌台码' + }) + } + // uni.showModal({ + // title:'', + // content:res.result + // }) } }); } @@ -329,7 +355,7 @@ return v.foods.length }) data.tabbar = tabbar - nextTick(()=>{ + nextTick(() => { getMenuItemTop() }) storageManage.cacheGoods(data.tabbar) @@ -450,17 +476,20 @@ }) console.log(res); if (res && res.content[0]) { - data.table={...res.content[0],...data.table} + data.table = { + ...res.content[0], + ...data.table + } } } } let $originGoods = [] let $category = [] async function init() { - if(option.type=='add'){ + if (option.type == 'add') { data.masterId = option.masterId setTabBar($category, $originGoods, []) - }else{ + } else { const masterRes = await getMasterId() data.masterId = masterRes.masterId } @@ -490,7 +519,7 @@ }); $originGoods = goods console.log(option); - if(option.type=='add'){ + if (option.type == 'add') { cars.length = 0 setTabBar(category, goods, []) return @@ -506,7 +535,7 @@ setTabBar(category, goods, cars) return } - + const cartRes = await getCart() cars.length = 0 const cartArr = getNowCart(cartRes.records) @@ -588,29 +617,56 @@ }) } + + async function onChooseTable(item) { + console.log('onChooseTable'); + const res = await $returnTableDetail({ + tableId: item.tableId, + }); + if (!res) { + // #ifdef MP-WEIXIN + uni.showModal({ + title: '提示', + content: '桌台不存在或不是该店铺的桌台' + }) + // #endif + // #ifndef MP-WEIXIN + infoBox.showToast('桌台不存在或不是该店铺的桌台') + // #endif + return + } + console.log('---table:detail-----'); + console.log(res); + if (data.table.tableId || cars.length <= 0) { + data.table = { + ...res, + ...item + } + return; + } + if (res.status == "unbind") { + return infoBox.showToast('该台桌未绑定,清先去桌台管理里绑定码牌') + } + if (res.status != "idle") { + return infoBox.showToast('该台桌已在使用中') + } + + if (res.cartCount > 0) { + setModalShow('clear', true, item) + } else { + await $choseTable({ + masterId: data.masterId, + tableId: item.tableId, + isClear: false + }); + data.table = item + } + } + function watchChooseTable() { uni.$off('choose-table') - uni.$on('choose-table', async (item) => { - if (data.table.tableId || cars.length <= 0) { - data.table = item - return; - } - if (item.status != "idle") { - return infoBox.showToast('该台桌已在使用中') - } - const res = await $returnTableDetail({ - tableId: item.tableId, - }); - if (res.cartCount > 0) { - setModalShow('clear', true, item) - } else { - await $choseTable({ - masterId: data.masterId, - tableId: item.tableId, - isClear:false - }); - data.table = item - } + uni.$on('choose-table', (item) => { + onChooseTable(item) }) } @@ -1047,12 +1103,12 @@ }, 10); return; } - let arr=[] + let arr = [] rects.forEach((rect) => { // 这里减去rects[0].top,是因为第一项顶部可能不是贴到导航栏(比如有个搜索框的情况) arr.push(rect.top - rects[0].top); }) - data.arr=arr + data.arr = arr console.log(data.arr); storageManage.cacheGoodsNode(data.arr) resolve(); @@ -1107,7 +1163,7 @@ }) } watch(() => data.table.tableId, (newval, oldval) => { - if(option.type!='add'){ + if (option.type != 'add') { onSelTable() } })