优化台桌点餐

This commit is contained in:
gyq
2024-10-11 14:26:39 +08:00
parent cfd04625dd
commit 72cf926747
11 changed files with 350 additions and 59 deletions

View File

@@ -50,9 +50,30 @@
</div>
<!-- <span class="tips">开始新订单</span> -->
<div class="btn_wrap" v-if="props.tableInfo.status == 'idle'">
<el-button type="primary" style="width: 100%;" @click="toOrderMeal(1)">开始新订单</el-button>
<el-button type="primary" style="width: 100%;" @click="showPeopleNumHandle">开始新订单</el-button>
</div>
<div class="btn_wrap" v-if="props.tableInfo.status == 'cleaning'">
<el-button type="primary" style="width: 100%;" @click="clearTableStatus">清理完成</el-button>
</div>
</div>
<transition name="el-fade-in">
<div class="people_num_wrap" v-show="showPeopleNum">
<div class="title">应选择就餐人数</div>
<div class="num_btns">
<div class="item" :class="{ active: peopleNum == item }" v-for="item in 8"
@click="peopleNum = item">{{ item }}</div>
<div class="item" :class="{ active: peopleNum == 'custom' }">
<input class="ipt" @focus="inputFocus" placeholder="自定义" v-model="peopleNumInputValue"
@change="" />
</div>
</div>
<div class="btn">
<el-button type="primary" style="width: 100%;"
:disabled="(!peopleNum && !peopleNumInputValue) || (peopleNum == 'custom' && !peopleNumInputValue)"
@click="orderDownHandle">确认</el-button>
</div>
</div>
</transition>
</div>
<!-- 结算订单 -->
<settleAccount ref="settleAccountRef" :cart="cartList" :amount="orderInfo.orderAmount"
@@ -69,6 +90,8 @@ import { queryMembermember } from '@/api/member/index.js'
import { orderDetail } from '@/api/order/index.js'
import { formatDecimal } from '@/utils/index.js'
import settleAccount from "@/views/home/components/settleAccount.vue";
import { ElMessage } from 'element-plus'
import { clearTable } from '@/api/table.js'
const router = useRouter()
const global = useGlobal()
@@ -83,10 +106,20 @@ const props = defineProps({
}
})
const showPeopleNum = ref(false)
const peopleNum = ref(0)
const peopleNumInputValue = ref('')
watch(props, () => {
getOrderDetail()
})
// 自定义人数输入获得焦点
function inputFocus() {
peopleNum.value = 'custom'
}
const settleAccountRef = ref(null)
const orderInfo = ref({})
const cartList = ref([])
@@ -108,6 +141,27 @@ function showPayHandle() {
settleAccountRef.value.show()
}
// 显示就就餐人数
function showPeopleNumHandle() {
showPeopleNum.value = true
}
// 清理桌台
const clearLoading = ref(false)
async function clearTableStatus() {
try {
clearLoading.value = true
const res = await clearTable({
shopId: store.userInfo.shopId,
tableId: props.tableInfo.qrcode
})
clearLoading.value = false
emits('success')
} catch (error) {
console.log(error);
}
}
// 获取订单详情
async function getOrderDetail() {
try {
@@ -141,6 +195,30 @@ function close() {
emits('close')
}
// 判断数字是不是正整数
function isPositiveInteger(num) {
return Number.isInteger(num) && num > 0;
}
// 选择人数后确认下单
function orderDownHandle() {
if (peopleNum.value == 'custom') {
if (!isPositiveInteger(parseFloat(peopleNumInputValue.value))) {
ElMessage.error('请输入有效的就餐人数')
return
}
}
// 直接点单
global.setOrderTable({
...props.tableInfo,
num: peopleNum.value == 'custom' ? peopleNumInputValue.value : peopleNum.value
})
router.push({
name: 'home',
})
}
// 点单
function toOrderMeal(t) {
if (t == 1) {
@@ -324,6 +402,77 @@ onMounted(() => {
width: $size;
}
}
.people_num_wrap {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 9;
background-color: rgba(255, 255, 255, 0.3);
backdrop-filter: blur(10px);
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
.title {
padding-bottom: 40px;
font-size: 18px;
font-weight: bold;
}
.num_btns {
width: 80%;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 40px 40px 40px;
gap: 20px;
.item {
color: #fff;
border-radius: 4px;
background-color: var(--el-color-danger);
display: flex;
align-items: center;
justify-content: center;
position: relative;
transition: all .1s ease-in-out;
&.active {
font-size: 14px;
background-color: #e96565;
box-shadow: inset 0 4px 5px rgba(0, 0, 0, 0.3);
.ipt {
font-size: 14px;
}
}
.ipt {
width: 100%;
height: 100%;
outline: none;
border: none;
background: transparent;
color: #fff;
text-align: center;
font-size: 16px;
transition: all .1s ease-in-out;
&::-webkit-input-placeholder {
color: #fff;
}
}
}
}
.btn {
width: 80%;
padding-top: 40px;
}
}
}
}
</style>

View File

@@ -254,13 +254,13 @@ onMounted(() => {
gap: var(--el-font-size-base);
.item {
$usingColor: #D2441F;
$subColor: #3274D5;
$closedColor: #aeb8c9;
background-color: #efefef;
border-radius: 6px;
overflow: hidden;
border: 2px solid #fff;
$usingColor: #D2441F;
$subColor: #3274D5;
$closedColor: #aeb8c9;
&.active {
border-color: $subColor;