|
@@ -15,7 +15,6 @@
|
|
|
:key="i"
|
|
|
class="p-1 flex-wrap float-left text-center md:w-28 h-28 w-1/3"
|
|
|
>
|
|
|
-
|
|
|
<a href="javascript:void(0);" @click="order_(i)"
|
|
|
><div
|
|
|
class="rounded w-full h-full pt-3 relative"
|
|
@@ -86,14 +85,54 @@
|
|
|
</el-radio-group>
|
|
|
<el-button class="w-full" plain @click="order()">开始点餐</el-button>
|
|
|
</div>
|
|
|
- <el-button class="w-full mt-1" plain @click="dialogVisible = false">关闭</el-button>
|
|
|
+ <el-button v-if="currentDeskStatus != 2" class="w-full mt-1" plain @click="rockover()">翻台</el-button>
|
|
|
+ </el-dialog>
|
|
|
+ <el-dialog
|
|
|
+ v-model="scanDialogVisible"
|
|
|
+ title="请使用扫码枪扫码支付"
|
|
|
+ width="300px"
|
|
|
+ center
|
|
|
+ :show-close="false"
|
|
|
+ :close-on-click-modal="false"
|
|
|
+ :close-on-press-escape="false"
|
|
|
+ >
|
|
|
+ <div class="text-center">
|
|
|
+ <img
|
|
|
+ src="@/assets/images/scan.gif"
|
|
|
+ alt="扫码"
|
|
|
+ class="mx-auto mb-4"
|
|
|
+ style="width: 150px"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <template #footer>
|
|
|
+ <div class="dialog-footer">
|
|
|
+ <el-button @click="scanDialogVisible = false">取消支付</el-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
+ <el-dialog
|
|
|
+ v-model="payingDialogVisible"
|
|
|
+ title="支付处理中"
|
|
|
+ width="300px"
|
|
|
+ :show-close="false"
|
|
|
+ :close-on-click-modal="false"
|
|
|
+ :close-on-press-escape="false"
|
|
|
+ >
|
|
|
+ <div class="flex flex-col items-center justify-center py-4">
|
|
|
+ <el-icon class="is-loading mb-4" :size="32">
|
|
|
+ <Loading />
|
|
|
+ </el-icon>
|
|
|
+ <p class="text-gray-600">正在支付中,请不要关闭或退出界面</p>
|
|
|
+ </div>
|
|
|
</el-dialog>
|
|
|
</div>
|
|
|
<console @init="init()" ref="consoleRef"></console>
|
|
|
</template>
|
|
|
<script lang="ts" setup>
|
|
|
+// 在 script setup 部分添加
|
|
|
+import { Loading } from '@element-plus/icons-vue'
|
|
|
import { postAll } from '@/api/org/post'
|
|
|
-import { orderDeskList, createOrders, orderCheckout } from '@/api/order'
|
|
|
+import { orderDeskList, createOrders, orderCheckout, orderPay, queryPayStatus, cancelOrder, rockoverDesk } from '@/api/order'
|
|
|
import Console from './console.vue'
|
|
|
import { getOrdersCurrent } from '@/api/orders'
|
|
|
import feedback from '@/utils/feedback'
|
|
@@ -114,7 +153,8 @@ const consoleRef = ref<InstanceType<typeof Console>>()
|
|
|
const data = reactive({
|
|
|
userNum: 1, //当前就餐人数
|
|
|
deskId: null,
|
|
|
- type: 0 //后台点餐类型:0
|
|
|
+ type: 0, //后台点餐类型:0
|
|
|
+ canScan: false
|
|
|
})
|
|
|
const order_ = (i: any) => {
|
|
|
dialogVisible.value = true
|
|
@@ -129,34 +169,162 @@ const order = () => {
|
|
|
consoleRef.value?.open(currentDesk, data.userNum, res)
|
|
|
init()
|
|
|
})
|
|
|
- console.warn("***order***",currentDesk)
|
|
|
+ console.warn('***order***', currentDesk)
|
|
|
// router.push({ path: '/order/console', query: { deskID: id } })
|
|
|
}
|
|
|
+const rockover = () => {
|
|
|
+ feedback.confirm('将重置桌号状态, 确定翻台吗?').then(() => {
|
|
|
+ rockoverDesk(data).then(() => {
|
|
|
+ feedback.notifySuccess('翻台成功!')
|
|
|
+ dialogVisible.value = false
|
|
|
+ init()
|
|
|
+ })
|
|
|
+ }).catch(()=>{
|
|
|
+ dialogVisible.value = false
|
|
|
+ })
|
|
|
+}
|
|
|
const reorder = () => {
|
|
|
dialogVisible.value = false
|
|
|
- consoleRef.value?.open(currentDesk);//继续下单时会把当前餐桌上的订单号ordersId传进去
|
|
|
- console.warn("***reorder***",currentDesk)
|
|
|
+ consoleRef.value?.open(currentDesk) //继续下单时会把当前餐桌上的订单号ordersId传进去
|
|
|
+ console.warn('***reorder***', currentDesk)
|
|
|
}
|
|
|
const refresh = () => {
|
|
|
isLoading.value = true
|
|
|
init()
|
|
|
}
|
|
|
+const scanDialogVisible = ref(false)
|
|
|
+const scanCode = ref('')
|
|
|
+
|
|
|
+// 添加支付中对话框的控制变量
|
|
|
+const payingDialogVisible = ref(false)
|
|
|
+
|
|
|
+// 添加扫码事件监听函数
|
|
|
+const handleScanInput = (event: KeyboardEvent) => {
|
|
|
+ if (event.key === 'Enter') {
|
|
|
+ const code = scanCode.value
|
|
|
+ console.log('扫码内容:', code)
|
|
|
+ if (!data.canScan) {
|
|
|
+ feedback.notifyWarning('正在处理支付,请勿重复扫码')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ data.canScan = false
|
|
|
+ payingDialogVisible.value = true // 显示支付中对话框
|
|
|
+ document.removeEventListener('keydown', handleScanInput)
|
|
|
+
|
|
|
+ // 修改支付处理逻辑
|
|
|
+ orderPay({ oid: currentDesk.oid, code: code })
|
|
|
+ .then((res) => {
|
|
|
+ console.log(res)
|
|
|
+ // 实际上支付成功之后,res返回的是[],如果不是实时成功,返回的是个对象, 形如:{orderId: '123456789', sn: '7895004131583689'}
|
|
|
+ if (res == null || res.length == 0) {
|
|
|
+ feedback.notifySuccess('成功结账' + currentDesk.amount + '元')
|
|
|
+ scanDialogVisible.value = false
|
|
|
+ dialogVisible.value = false
|
|
|
+ payingDialogVisible.value = false // 隐藏支付中对话框
|
|
|
+ init()
|
|
|
+ } else {
|
|
|
+ console.log('支付中')
|
|
|
+ return queryPayStatusWithRetry(res)
|
|
|
+ .then((paySuccess) => {
|
|
|
+ if (paySuccess) {
|
|
|
+ feedback.notifySuccess('成功结账' + currentDesk.amount + '元')
|
|
|
+ scanDialogVisible.value = false
|
|
|
+ dialogVisible.value = false
|
|
|
+ init()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ payingDialogVisible.value = false // 隐藏支付中对话框
|
|
|
+
|
|
|
+ feedback.confirm('支付失败,请重试').then(() => {
|
|
|
+ data.canScan = true
|
|
|
+ scanDialogVisible.value = true
|
|
|
+ // 添加键盘事件监听
|
|
|
+ document.addEventListener('keydown', handleScanInput)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ scanCode.value = ''
|
|
|
+ } else {
|
|
|
+ scanCode.value += event.key
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 定义查询支付状态的函数
|
|
|
+const queryPayStatusWithRetry = (data): Promise<boolean> => {
|
|
|
+ const intervals = [3000, 5000, 10000]
|
|
|
+ let currentIndex = 0
|
|
|
+ payingDialogVisible.value = true
|
|
|
+
|
|
|
+ const tryQuery = () => {
|
|
|
+ return new Promise<boolean>((resolve) => {
|
|
|
+ setTimeout(() => {
|
|
|
+ queryPayStatus({ orderId: data.orderId,sn: data.sn })
|
|
|
+ .then((result) => {
|
|
|
+ if (result.result_code == '200' && result.biz_response.data.order_status == 'SUCCESS') {
|
|
|
+ resolve(true)
|
|
|
+ } else if (currentIndex < intervals.length - 1) {
|
|
|
+ currentIndex++
|
|
|
+ tryQuery().then(resolve)
|
|
|
+ } else {
|
|
|
+ resolve(false)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ if (currentIndex < intervals.length - 1) {
|
|
|
+ currentIndex++
|
|
|
+ tryQuery().then(resolve)
|
|
|
+ } else {
|
|
|
+ resolve(false)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }, intervals[currentIndex])
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ return tryQuery().then((success) => {
|
|
|
+ payingDialogVisible.value = false
|
|
|
+ if (!success) {
|
|
|
+ return cancelOrder({ orderId: data.orderId,sn: data.sn })
|
|
|
+ .then(() => {
|
|
|
+ feedback.notifyWarning('支付超时,已自动撤销本次支付')
|
|
|
+ return false
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ console.error('撤单失败:', error)
|
|
|
+ feedback.notifyError('支付失败,请重试')
|
|
|
+ return false
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return success
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
const checkout = () => {
|
|
|
refresh()
|
|
|
//结账
|
|
|
- console.warn("***结账***",currentDesk)
|
|
|
- if(currentDesk && !currentDesk.amount){
|
|
|
+ console.warn('***结账***', currentDesk)
|
|
|
+ if (currentDesk && !currentDesk.amount) {
|
|
|
feedback.notify('当前桌未出单,无法结账')
|
|
|
return false
|
|
|
}
|
|
|
- feedback.confirm('结账金额为' + currentDesk.amount + ',确定要结账吗?').then(() => {
|
|
|
- orderCheckout({ did: currentDesk.id }).then(() => {
|
|
|
- feedback.notifySuccess('成功结账' + currentDesk.amount + '元')
|
|
|
- dialogVisible.value = false
|
|
|
- init()
|
|
|
+ orderCheckout({ did: currentDesk.id }).then((res) => {
|
|
|
+ console.log('结账', res)
|
|
|
+ currentDesk.oid = res.id
|
|
|
+ feedback.confirm(currentDesk.name + ' 结账金额为' + currentDesk.amount + ',确定要结账吗?').then(() => {
|
|
|
+ data.canScan = true
|
|
|
+ scanDialogVisible.value = true
|
|
|
+ // 添加键盘事件监听
|
|
|
+ document.addEventListener('keydown', handleScanInput)
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+// 在组件卸载时移除事件监听
|
|
|
+onUnmounted(() => {
|
|
|
+ document.removeEventListener('keydown', handleScanInput)
|
|
|
+})
|
|
|
const tabChange = (name: any) => {
|
|
|
if (name != 'all') {
|
|
|
deskList.value = deskListAll.filter((ele: any) => {
|
|
@@ -167,11 +335,11 @@ const tabChange = (name: any) => {
|
|
|
}
|
|
|
}
|
|
|
const init = async () => {
|
|
|
- let _list: any[] = [];
|
|
|
+ let _list: any[] = []
|
|
|
await orderDeskList().then((res: any) => {
|
|
|
// deskList.value = res
|
|
|
deskListAll = res
|
|
|
- _list = res;
|
|
|
+ _list = res
|
|
|
getOrdersCurrent().then((res) => {
|
|
|
deskList.value = _list.map((item) => {
|
|
|
res.forEach((element: any) => {
|
|
@@ -208,3 +376,15 @@ onMounted(() => {
|
|
|
init()
|
|
|
})
|
|
|
</script>
|
|
|
+<style scoped>
|
|
|
+.scan-dialog ::v-deep(.el-dialog__header) {
|
|
|
+ margin-right: 0;
|
|
|
+ padding: 20px;
|
|
|
+ text-align: center;
|
|
|
+}
|
|
|
+
|
|
|
+.scan-dialog ::v-deep(.el-dialog__title) {
|
|
|
+ font-size: 16px;
|
|
|
+ font-weight: 500;
|
|
|
+}
|
|
|
+</style>
|