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 { ref, watch, nextTick } from "vue";
import { orderCreateApi, orderStatusApi, orderPayApi } from "@/api/store.js"; import { orderCreateApi, orderStatusApi, orderPayApi } from "@/api/store.js";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { audioplay } from "@/utils/audio.js";
const drawer = ref(false); const drawer = ref(false);
const active = ref(1); const active = ref(1);
@ -39,7 +40,7 @@ const emit = defineEmits(["paySuccess"]);
const reLoad = ref(false); const reLoad = ref(false);
let timeout = 0; // let timecount = 0; //
const order_id = ref(""); const order_id = ref("");
// //
@ -57,18 +58,28 @@ const handleEnter = () => {
source: 300, source: 300,
}) })
.then((res) => { .then((res) => {
if (res.status==200&& res.message=='支付成功') { if (res.status == 200 && res.message == "支付成功") {
drawer.value = false; drawer.value = false;
ElMessage({ ElMessage({
message: res.message, message: res.message,
type: "success", type: "success",
}); });
audioplay(res.data.message);
beforeClose(); beforeClose();
} else { } else {
order_id.value = res.data.group_order_id; if (!res.data.group_order_sn) {
count.value = 0; order_id.value = res.data.result.order_id;
timeout = 0; loading.value = false;
getOrderStatus(res.data.group_order_sn); 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) => { .catch((err) => {
@ -85,17 +96,18 @@ const orderPay = (id) => {
auth_code: input.value, auth_code: input.value,
}) })
.then((res) => { .then((res) => {
if (res.data.status == "success") { if (res.status == 200 && res.message == "支付成功") {
drawer.value = false; drawer.value = false;
ElMessage({ ElMessage({
message: res.message, message: res.message,
type: "success", type: "success",
}); });
audioplay(res.data.message);
beforeClose(); beforeClose();
} else { } else {
order_id.value = res.data.group_order_id; order_id.value = res.data.group_order_id;
count.value = 0; count.value = 0;
timeout = 0; timecount = 0;
getOrderStatus(res.data.group_order_sn); getOrderStatus(res.data.group_order_sn);
} }
}) })
@ -111,7 +123,7 @@ const orderPay = (id) => {
const count = ref(0); // 3, 3, const count = ref(0); // 3, 3,
const getOrderStatus = (id) => { const getOrderStatus = (id) => {
count.value++; count.value++;
timeout+=5000; timecount += 5000;
orderStatusApi({ orderStatusApi({
order_sn: id, order_sn: id,
}) })
@ -121,6 +133,7 @@ const getOrderStatus = (id) => {
message: res.message, message: res.message,
type: "success", type: "success",
}); });
audioplay(res.data.message);
beforeClose(); beforeClose();
} else { } else {
ElMessage({ ElMessage({
@ -138,7 +151,7 @@ const getOrderStatus = (id) => {
if (reLoad.value && count.value < 3) if (reLoad.value && count.value < 3)
setTimeout(() => { setTimeout(() => {
getOrderStatus(id); getOrderStatus(id);
}, timeout); }, 15000 - timecount > 0 ? 15000 - timecount : 0);
else { else {
input.value = ""; input.value = "";
loading.value = false; loading.value = false;
@ -163,7 +176,7 @@ const loading = ref(false);
defineExpose({ defineExpose({
drawer, drawer,
setForm, setForm,
setRePay setRePay,
}); });
</script> </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, groupOrderListApi,
orderStatusApi, orderStatusApi,
orderLadingApi, orderLadingApi,
cartListApi
} from "@/api/store.js"; } from "@/api/store.js";
import { useUserStore } from "@/store/user.js"; import { useUserStore } from "@/store/user.js";
import pay from "@/components/pay.vue"; import pay from "@/components/pay.vue";
@ -39,6 +40,17 @@ const getOrderList = () => {
getOrderList(); getOrderList();
const cartCount = ref(0);
const getCartList = () => {
cartListApi({
source: 300,
}).then((res) => {
cartCount.value = res.data.list?.length;
});
};
getCartList();
const changeTabPosition = (e) => { const changeTabPosition = (e) => {
where.value.page = 1; where.value.page = 1;
getOrderList(); getOrderList();
@ -182,10 +194,11 @@ const goHome = ()=>{
<span>提单前请清空购物车, 避免提单的商品与购物车商品混合, 请确保购物车内无数据后再进行提单</span> <span>提单前请清空购物车, 避免提单的商品与购物车商品混合, 请确保购物车内无数据后再进行提单</span>
<template #footer> <template #footer>
<div class="dialog-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>
<el-button type="primary" @click="orderLading"> <el-button v-else type="primary" @click="orderLading">
确认提单 确认提单
</el-button> </el-button>
</div> </div>