From 8b34814a90fd3769ec997d31890905af82255d7b Mon Sep 17 00:00:00 2001 From: weipengfei <2187978347@qq.com> Date: Fri, 5 Apr 2024 17:45:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/pay.vue | 103 +++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 49 deletions(-) diff --git a/src/components/pay.vue b/src/components/pay.vue index 98671f5..bfb3b59 100644 --- a/src/components/pay.vue +++ b/src/components/pay.vue @@ -26,9 +26,10 @@ const open = () => { const changeActive = (e) => { active.value = e; - if (active.value == 2) { // 添加键盘事件监听器 - document.addEventListener('keydown', keyboard); - }else document.removeEventListener('keydown', keyboard); + if (active.value == 2) { + // 添加键盘事件监听器 + document.addEventListener("keydown", keyboard); + } else document.removeEventListener("keydown", keyboard); }; const form = ref({}); @@ -191,6 +192,8 @@ const beforeClose = () => { reLoad.value = false; loading.value = false; input.value = ""; + collection.value = ""; + collectionArray.value = []; codeRef.value?.blur(); emit("paySuccess"); drawer.value = false; @@ -206,12 +209,13 @@ defineExpose({ const collectionArray = ref([]); const collection = ref(""); //输入的金额 -const changePrice = computed(()=>{ // 找零 - if(+collection.value>0){ +const changePrice = computed(() => { + // 找零 + if (+collection.value > 0) { return (collection.value - form.value.order_price).toFixed(2); } return -1; -}) +}); const defaultcalc = ref(false); //清除计算机输入的数字 @@ -246,45 +250,43 @@ const numTap = (item) => { }; // 现金结算 const cashBnt = () => { - console.log("结算"); - orderCreateApi({ - address_id: "", - key: form.value.key, - cart_id: cart_id.value, - pay_type: "cash_payment", - source: 300, - }) - .then((res) => { - if (res.status == 200 && res.message == "支付成功") { - drawer.value = false; - ElMessage({ - message: res.message, - type: "success", - }); - audioplay(res.data.message); - beforeClose(); - } else { - if (!res.data.group_order_sn) { - order_id.value = res.data.result.order_id; - loading.value = false; - return ElMessage({ - message: res.message, - type: "error", - }); - } else { - order_id.value = res.data.group_order_id; - count.value = 0; - timecount = 0; - getOrderStatus(res.data.group_order_sn); - } - } - }) - .catch((err) => { - loading.value = false; - nextTick(() => { - codeRef.value?.focus(); + if(changePrice.value!=''&&changePrice.value>=0) orderCreateApi({ + address_id: "", + key: form.value.key, + cart_id: cart_id.value, + pay_type: "cash_payment", + source: 300, + }) + .then((res) => { + if (res.status == 200 && res.message == "支付成功") { + drawer.value = false; + ElMessage({ + message: res.message, + type: "success", }); - }); + audioplay(res.data.message); + beforeClose(); + } else { + if (!res.data.group_order_sn) { + order_id.value = res.data.result.order_id; + collection.value = ""; + collectionArray.value = []; + loading.value = false; + return ElMessage({ + message: res.message, + type: "error", + }); + } else { + order_id.value = res.data.group_order_id; + count.value = 0; + timecount = 0; + getOrderStatus(res.data.group_order_sn); + } + } + }) + .catch((err) => { + loading.value = false; + }); }; // 监听键盘函数 @@ -345,6 +347,9 @@ const keyboard = (event) => { case 8: delNum(); break; + case 13: + cashBnt(); + break; } }; @@ -403,9 +408,11 @@ const keyboard = (event) => {
{{ collection }} - 按下键盘输入客户支付金额 + 按下键盘输入客户支付金额
-
+
需找零(元):¥{{ changePrice }}
不够找零, 请支付更多金额
@@ -433,9 +440,7 @@ const keyboard = (event) => {