更新代客下单模块

This commit is contained in:
2024-09-28 15:07:26 +08:00
parent 587965020b
commit b88efd1c6c
5 changed files with 199 additions and 110 deletions

View File

@@ -24,7 +24,7 @@
<view>就餐类型</view> <view>就餐类型</view>
<view class="u-m-t-24 u-flex "> <view class="u-m-t-24 u-flex ">
<view class="u-flex color-666"> <view class="u-flex color-666">
<up-radio-group v-model="eatTypes.active" placement="row"> <up-radio-group :disabled="option.type=='add'" v-model="eatTypes.active" placement="row">
<up-radio :customStyle="{marginRight: '30px'}" v-for="(item, index) in eatTypes.list" <up-radio :customStyle="{marginRight: '30px'}" v-for="(item, index) in eatTypes.list"
:key="index" :label="item.name" :name="item.value"> :key="index" :label="item.name" :name="item.value">
</up-radio> </up-radio>
@@ -75,7 +75,7 @@
</view> </view>
</view> </view>
</template> </template>
<template v-if="$shop.registerType!='restaurant'"> <template v-if="!$shop.isTableFee">
<!-- 不免餐位费 --> <!-- 不免餐位费 -->
<view class="block"> <view class="block">
<view class=" "> <view class=" ">
@@ -184,7 +184,9 @@
</view> </view>
<view class="u-flex u-row-right u-m-t-38"> <view class="u-flex u-row-right u-m-t-38">
<view class="color-main" @tap="showModel('editMoney')">修改</view> <template v-if="$shop.registerType=='munchies'">
<view class="color-main" @tap="showModel('editMoney')">修改</view>
</template>
<view class="u-flex price u-m-l-32"> <view class="u-flex price u-m-l-32">
<view class="">实收金额</view> <view class="">实收金额</view>
<view class="font-bold u-font-32">{{formatPrice(allPrice) }}</view> <view class="font-bold u-font-32">{{formatPrice(allPrice) }}</view>
@@ -242,6 +244,7 @@
} from '@/commons/utils/format.js'; } from '@/commons/utils/format.js';
import color from '@/commons/color.js'; import color from '@/commons/color.js';
import * as Api from '@/http/yskApi/Instead.js' import * as Api from '@/http/yskApi/Instead.js'
import $storageManage from '@/commons/utils/storageManage.js'
import { import {
tbShopInfo tbShopInfo
} from '@/http/yskApi/user.js' } from '@/http/yskApi/user.js'
@@ -284,13 +287,15 @@
//更新就餐人数 //更新就餐人数
async function updateChoseCount() { async function updateChoseCount() {
console.log($shop.value); console.log($shop.value);
if($shop.value.registerType!='restaurant'){ if (!$shop.value.isTableFee) {
//不免餐位费 //不免餐位费
await Api.$choseCount({ const res = await Api.$choseCount({
masterId: option.masterId, masterId: option.masterId,
tableId: option.tableId, tableId: table.value.tableId,
num: userNumbers.defaultCateIndex, num: userNumbers.defaultCateIndex,
}) })
Object.assign($seatFee, res)
userNumbers.defaultCateIndex = res.totalNumber
} }
} }
@@ -310,7 +315,7 @@
} = item } = item
const par = { const par = {
masterId: option.masterId, masterId: option.masterId,
tableId: option.tableId, tableId: table.value.tableId,
productId, productId,
num: number, num: number,
skuId skuId
@@ -349,14 +354,18 @@
...table.value ...table.value
}) })
} }
const option = reactive({
masterId: '',
tableId: ""
})
// 监听选择用户事件 // 监听选择用户事件
let user = ref(null) let user = ref(null)
//更新选择用户 //更新选择用户
function setUser(par) { function setUser(par) {
console.log(option);
const submitPar = { const submitPar = {
masterId: option.masterId, masterId: option.masterId,
tableId: option.tableId, tableId: table.value.tableId,
vipUserId: user.value.id ? user.value.id : '', vipUserId: user.value.id ? user.value.id : '',
type: user.value.id ? 0 : 1 //0 设置 1 取消 type: user.value.id ? 0 : 1 //0 设置 1 取消
} }
@@ -392,10 +401,7 @@
}) })
} }
const option = reactive({
masterId: '',
tableId: ""
})
const goods = reactive({ const goods = reactive({
list: [], list: [],
sel: 0 sel: 0
@@ -413,9 +419,10 @@
totalAmount: 0, totalAmount: 0,
}) })
const allPrice = computed(() => { 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) 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) { function setGoodsItem(key, val) {
@@ -430,12 +437,18 @@
page: 0, page: 0,
size: 300, size: 300,
masterId: option.masterId, masterId: option.masterId,
tableId: option.tableId tableId: table.value.tableId
}) { }) {
const { const {
records, records,
seatFee seatFee
} = await Api.getCart(par) } = 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) goods.list = getNowCart(records)
if (seatFee && seatFee.totalNumber) { if (seatFee && seatFee.totalNumber) {
userNumbers.defaultCateIndex = seatFee.totalNumber || 1 userNumbers.defaultCateIndex = seatFee.totalNumber || 1
@@ -445,7 +458,9 @@
console.log(goods.list); console.log(goods.list);
} }
let $shop = ref() let $shop = ref({
registerType: ''
})
// 获取账号信息 // 获取账号信息
async function getTbShopInfo() { async function getTbShopInfo() {
const res = await tbShopInfo() const res = await tbShopInfo()
@@ -461,27 +476,46 @@
note: note.value, note: note.value,
postPay: true, postPay: true,
orderId: '', 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) const res = await Api.$createOrder(par)
console.log($shop.value); console.log($shop.value);
if($shop.value.registerType=='munchies'){ console.log(res);
if ($shop.value.registerType == 'munchies') {
//先付 //先付
return go.to('PAGES_ORDER_DETAIL',{ return go.to('PAGES_CRESATE_ORDER_PAY', {
id:res.id orderId: res.id
}) })
} else {
//后付
uni.navigateBack({delta:2})
// return go.to('PAGES_ORDER_DETAIL', {
// id: res.id
// })
} }
uni.showToast({ uni.showToast({
title: '提交成功', title: '提交成功',
icon: 'none' icon: 'none'
}) })
setTimeout(() => { // setTimeout(() => {
uni.$emit('orderDetail:update') // uni.$emit('orderDetail:update')
uni.navigateBack({ // uni.navigateBack({
delta: 2 // delta: 2
}) // })
}, 500) // }, 500)
}
function init(){
} }
onLoad((opt) => { onLoad((opt) => {
@@ -493,9 +527,10 @@
name: opt.name name: opt.name
} }
} }
init()
getCart() getCart()
getTbShopInfo() getTbShopInfo()
updateChoseCount() // updateChoseCount()
}) })
async function changeUseType() { async function changeUseType() {
@@ -512,8 +547,10 @@
useType = `dine-in-${isPayAfter? "after" : "before"}`; useType = `dine-in-${isPayAfter? "after" : "before"}`;
uni.setStorageSync("useType", useType); uni.setStorageSync("useType", useType);
} }
const tableId = useType=='takeout'?undefined: table.value.tableId;
const res = await Api.$changeUseType({ const res = await Api.$changeUseType({
useType, useType,
tableId,
cartIds: goods.list.map((v) => v.id), cartIds: goods.list.map((v) => v.id),
}) })
return res return res

View File

@@ -55,7 +55,7 @@
<view></view> <view></view>
<view>{{allPrice}}</view> <view>{{allPrice}}</view>
</view> </view>
<my-button shape="circle" height="80" width="220" @tap="toConfimOrder">去下单</my-button> <my-button shape="circle" height="80" width="220" @tap="toConfimOrder">{{table.type=='add'?'确认加菜':'去下单'}} </my-button>
</view> </view>
</template> </template>

View File

@@ -128,6 +128,12 @@
import { import {
getNowCart getNowCart
} from '@/pagesCreateOrder/util.js' } from '@/pagesCreateOrder/util.js'
import {
$returnUseType
} from './util.js'
import {
tbShopInfo
} from '@/http/yskApi/user.js'
const cars = reactive([]) const cars = reactive([])
const data = reactive({ const data = reactive({
scrollTop: 0, //tab标题的滚动条位置 scrollTop: 0, //tab标题的滚动条位置
@@ -154,6 +160,18 @@
}) })
// 获取账号信息
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) { function setTabBar(category, goods, cars) {
@@ -247,6 +265,9 @@
} }
//加入购物车 //加入购物车
function addCart(par) { function addCart(par) {
if(!data.table.tableId){
return infoBox.showToast('请先选择台桌!')
}
const submitPar = { const submitPar = {
masterId: data.masterId, masterId: data.masterId,
tableId: data.table.tableId, tableId: data.table.tableId,
@@ -318,18 +339,8 @@
} }
} }
async function init() { async function init() {
getTbShopInfo()
getTableInfo() 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 categoryRes = await getCategory()
const category = categoryRes.content.reduce((prve, cur) => { const category = categoryRes.content.reduce((prve, cur) => {
prve.push({ prve.push({
@@ -347,6 +358,21 @@
} }
return isShow; 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) setTabBar(category, goods, cars)
@@ -849,12 +875,15 @@
onLoad((opt) => { onLoad((opt) => {
console.log(opt) console.log(opt)
Object.assign(data.table, opt) Object.assign(data.table, opt)
if (!opt.tableId) { if(opt.useType){
infoBox.showErrorToast('暂不支持不选择台桌下载,请从桌台点餐') uni.setStorageSync('useType',opt.useType)
return setTimeout(() => {
go.back()
}, 1500)
} }
// if (!opt.tableId) {
// infoBox.showErrorToast('暂不支持不选择台桌下载,请从桌台点餐')
// return setTimeout(() => {
// go.back()
// }, 1500)
// }
init() init()
}) })
</script> </script>

View File

@@ -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) { export function isCanBuy(goods, isStock) {
return goods.isGrounding && goods.isPauseSale == 0 && (isStock?goods.stockNumber > 0:true) ; return goods.isGrounding && goods.isPauseSale == 0 && (isStock ? goods.stockNumber > 0 : true);
} }
// 一个数组是否包含另外一个数组全部元素 // 一个数组是否包含另外一个数组全部元素
function arrayContainsAll(arr1, arr2) { function arrayContainsAll(arr1, arr2) {
for (let i = 0; i < arr2.length; i++) { for (let i = 0; i < arr2.length; i++) {
if (!arr1.includes(arr2[i])) { if (!arr1.includes(arr2[i])) {
return false; return false;
} }
} }
return true; return true;
} }
//n项 n-1项组合生成全部结果 //n项 n-1项组合生成全部结果
function generateCombinations(arr, k) { function generateCombinations(arr, k) {
let result = []; let result = [];
function helper(index, current) { function helper(index, current) {
if (current.length === k) { if (current.length === k) {
result.push(current.slice()); // 使用slice()来避免直接修改原始数组 result.push(current.slice()); // 使用slice()来避免直接修改原始数组
} else { } else {
for (let i = index; i < arr.length; i++) { for (let i = index; i < arr.length; i++) {
current.push(arr[i]); // 将当前元素添加到组合中 current.push(arr[i]); // 将当前元素添加到组合中
helper(i + 1, current); // 递归调用,索引增加以避免重复选择相同的元素 helper(i + 1, current); // 递归调用,索引增加以避免重复选择相同的元素
current.pop(); // 回溯,移除当前元素以便尝试其他组合 current.pop(); // 回溯,移除当前元素以便尝试其他组合
} }
} }
} }
helper(0, []); // 从索引0开始初始空数组作为起点 helper(0, []); // 从索引0开始初始空数组作为起点
return result; return result;
} }
function returnReverseVal(val, isReturnString = true) { function returnReverseVal(val, isReturnString = true) {
const isBol = typeof val === "boolean"; const isBol = typeof val === "boolean";
const isString = typeof val === "string"; const isString = typeof val === "string";
let reverseNewval = ""; let reverseNewval = "";
if (isBol) { if (isBol) {
reverseNewval = !val; reverseNewval = !val;
} }
if (isString) { if (isString) {
reverseNewval = val === "true" ? "false" : "true"; reverseNewval = val === "true" ? "false" : "true";
} }
return reverseNewval; return reverseNewval;
} }
export default{ export default {
isCanBuy,arrayContainsAll,generateCombinations,returnReverseVal isCanBuy,
arrayContainsAll,
generateCombinations,
returnReverseVal,$returnUseType
} }

View File

@@ -64,8 +64,7 @@
<view class="bg-fff box-shadow u-p-t-30 u-p-l-50 u-p-r-50 card top border-r-12 "> <view class="bg-fff box-shadow u-p-t-30 u-p-l-50 u-p-r-50 card top border-r-12 ">
</view> </view>
<view class="bg-fff box-shadow u-p-t-30 u-p-l-50 u-p-r-50 card bottom border-r-12 "> <view class="bg-fff box-shadow u-p-t-30 u-p-l-50 u-p-r-50 card bottom border-r-12 ">
</view> </view>
@@ -84,7 +83,7 @@
} from '@dcloudio/uni-app' } from '@dcloudio/uni-app'
import * as Api from '@/http/yskApi/Instead.js' import * as Api from '@/http/yskApi/Instead.js'
import infoBox from '@/commons/utils/infoBox.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({ const pays = reactive({
list: ['扫码收款', '二维码收款'], list: ['扫码收款', '二维码收款'],
selIndex: 0, selIndex: 0,
@@ -116,23 +115,33 @@
pays.payTypes.selIndex = i pays.payTypes.selIndex = i
} }
//支付成功回调 //支付成功回调
function paySuccess(){ function paySuccess() {
infoBox.showToast('支付成功') infoBox.showToast('支付成功')
setTimeout(() => { setTimeout(() => {
// uni.$emit('orderDetail:update') // uni.$emit('orderDetail:update')
uni.navigateBack({delta:2}) uni.navigateBack({
delta: 2
})
}, 500) }, 500)
} }
async function payOrder() { async function payOrder(code) {
const payType = pays.payTypes.list[pays.payTypes.selIndex].payType const payType = pays.payTypes.list[pays.payTypes.selIndex].payType
await Api.$payOrder({ console.log({
tableId: order.tableId, tableId: order.tableId,
masterId: order.masterId, masterId: order.masterId,
orderId: order.id||order.orderId, orderId: order.id || order.orderId,
payType, payType,
vipUserId: order.userId, vipUserId: order.userId,
discount: 1, 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() paySuccess()
} }
@@ -148,18 +157,10 @@
const item = pays.payTypes.list[pays.payTypes.selIndex] const item = pays.payTypes.list[pays.payTypes.selIndex]
uni.scanCode({ uni.scanCode({
onlyFromCamera: true, onlyFromCamera: true,
success:function (res) { success: function(res) {
console.log('条码类型:' + res.scanType); console.log('条码类型:' + res.scanType);
console.log('条码内容:' + res.result); console.log('条码内容:' + res.result);
Api.$payOrder({ payOrder(res.result)
"orderId": order.orderId, // 订单id
"payType": item.payType, //
"discount": order.discount,
"code": res.result
}).then(res=>{
console.log(res);
paySuccess()
})
} }
}); });
} }