This commit is contained in:
weipengfei 2024-04-05 14:23:21 +08:00
parent 00567505c2
commit 66e606e417
3 changed files with 45 additions and 14 deletions

View File

@ -2,6 +2,7 @@
import { ref, watch, nextTick } from "vue";
import { orderCreateApi, orderStatusApi, orderPayApi } from "@/api/store.js";
import { ElMessage } from "element-plus";
import { audioplay } from "@/utils/audio.js";
const drawer = ref(false);
const active = ref(1);
@ -39,7 +40,7 @@ const emit = defineEmits(["paySuccess"]);
const reLoad = ref(false);
let timeout = 0; //
let timecount = 0; //
const order_id = ref("");
//
@ -57,19 +58,29 @@ const handleEnter = () => {
source: 300,
})
.then((res) => {
if (res.status==200&& res.message=='支付成功') {
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;
timeout = 0;
timecount = 0;
getOrderStatus(res.data.group_order_sn);
}
}
})
.catch((err) => {
loading.value = false;
@ -85,17 +96,18 @@ const orderPay = (id) => {
auth_code: input.value,
})
.then((res) => {
if (res.data.status == "success") {
if (res.status == 200 && res.message == "支付成功") {
drawer.value = false;
ElMessage({
message: res.message,
type: "success",
});
audioplay(res.data.message);
beforeClose();
} else {
order_id.value = res.data.group_order_id;
count.value = 0;
timeout = 0;
timecount = 0;
getOrderStatus(res.data.group_order_sn);
}
})
@ -111,7 +123,7 @@ const orderPay = (id) => {
const count = ref(0); // 3, 3,
const getOrderStatus = (id) => {
count.value++;
timeout+=5000;
timecount += 5000;
orderStatusApi({
order_sn: id,
})
@ -121,6 +133,7 @@ const getOrderStatus = (id) => {
message: res.message,
type: "success",
});
audioplay(res.data.message);
beforeClose();
} else {
ElMessage({
@ -138,7 +151,7 @@ const getOrderStatus = (id) => {
if (reLoad.value && count.value < 3)
setTimeout(() => {
getOrderStatus(id);
}, timeout);
}, 15000 - timecount > 0 ? 15000 - timecount : 0);
else {
input.value = "";
loading.value = false;
@ -163,7 +176,7 @@ const loading = ref(false);
defineExpose({
drawer,
setForm,
setRePay
setRePay,
});
</script>

5
src/utils/audio.js Normal file
View File

@ -0,0 +1,5 @@
export const audioplay = (text) => {
let ssu = new window.SpeechSynthesisUtterance(text);
window.speechSynthesis.speak(ssu);
}

View File

@ -5,6 +5,7 @@ import {
groupOrderListApi,
orderStatusApi,
orderLadingApi,
cartListApi
} from "@/api/store.js";
import { useUserStore } from "@/store/user.js";
import pay from "@/components/pay.vue";
@ -39,6 +40,17 @@ const getOrderList = () => {
getOrderList();
const cartCount = ref(0);
const getCartList = () => {
cartListApi({
source: 300,
}).then((res) => {
cartCount.value = res.data.list?.length;
});
};
getCartList();
const changeTabPosition = (e) => {
where.value.page = 1;
getOrderList();
@ -182,10 +194,11 @@ const goHome = ()=>{
<span>提单前请清空购物车, 避免提单的商品与购物车商品混合, 请确保购物车内无数据后再进行提单</span>
<template #footer>
<div class="dialog-footer">
<el-button @click="goHome">
前去查看购物车
<el-button @click="dialogVisible = false">取消</el-button>
<el-button v-if="cartCount>0" @click="goHome">
前去清空购物车
</el-button>
<el-button type="primary" @click="orderLading">
<el-button v-else type="primary" @click="orderLading">
确认提单
</el-button>
</div>