更新代客下单模块

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 class="u-m-t-24 u-flex ">
<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"
:key="index" :label="item.name" :name="item.value">
</up-radio>
@@ -75,7 +75,7 @@
</view>
</view>
</template>
<template v-if="$shop.registerType!='restaurant'">
<template v-if="!$shop.isTableFee">
<!-- 不免餐位费 -->
<view class="block">
<view class=" ">
@@ -89,7 +89,7 @@
</view>
</view>
</template>
<view class="block">
<view class="u-p-b-24 ">
@@ -184,7 +184,9 @@
</view>
<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="">实收金额</view>
<view class="font-bold u-font-32">{{formatPrice(allPrice) }}</view>
@@ -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

View File

@@ -55,7 +55,7 @@
<view></view>
<view>{{allPrice}}</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>
</template>

View File

@@ -81,7 +81,7 @@
</scroll-view>
</view>
<view class="bottom w-full">
<my-car @updateNumber="carsNumberChange" :user="data.vipUser" :masterId="data.masterId" :table="data.table"
<my-car @updateNumber="carsNumberChange" :user="data.vipUser" :masterId="data.masterId" :table="data.table"
:data="cars" @clear="onClearCart"></my-car>
</view>
@@ -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()
})
</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) {
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
}

View File

@@ -58,16 +58,15 @@
</view>
</view>
</template>
</view>
<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 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>
<edit-discount title="优惠金额" :ref="setModel" name="editMoney" :price="order.amount"></edit-discount>
</view>
@@ -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)
}
});
}