优化打印机

This commit is contained in:
gyq
2024-04-03 17:25:22 +08:00
parent a57b45160e
commit ca4eec636a
9 changed files with 175 additions and 31 deletions

View File

@@ -92,10 +92,11 @@
</template>
<script setup>
import { ref } from "vue";
import { onMounted, ref } from "vue";
import { useUser } from "@/store/user.js";
import payCard from "@/components/payCard/payCard.vue";
import { print } from "@/api/pay";
import { bySubType } from "@/api/device";
import { ElMessage } from "element-plus";
import dayjs from "dayjs";
@@ -133,17 +134,45 @@ const props = defineProps({
const isPrint = ref(true);
const printList = ref([]);
// 获取打印机状态
async function bySubTypeAjax() {
try {
const res = await bySubType({
shopId: store.userInfo.shopId,
contentType: "local",
subType: "cash",
});
printList.value = res;
} catch (error) {
console.log(error);
}
}
async function printHandle() {
if (!isPrint.value) return;
const data = {
shop_name: store.userInfo.merchantName,
carts: props.cart,
amount: props.amount,
remark: props.remark,
orderInfo: props.orderInfo,
deviceName: printForm.value.deviceName,
};
ipcRenderer.send("printerInfoSync", JSON.stringify(data));
try {
if (!isPrint.value) return;
if (printList.value.length) {
const data = {
shop_name: store.userInfo.merchantName,
carts: props.cart,
amount: props.amount,
remark: props.remark,
orderInfo: props.orderInfo,
deviceName: printList.value[0].config.deviceName,
createdAt: dayjs(props.orderInfo.createdAt).format(
"YYYY-MM-DD HH:mm:ss"
),
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
};
ipcRenderer.send("printerInfoSync", JSON.stringify(data));
} else {
ElMessage.error("您还没有添加打印设备");
}
} catch (error) {
console.log(error);
}
// try {
// printLoading.value = true
// await print({
@@ -162,6 +191,7 @@ async function printHandle() {
// 订单已支付
function paySuccess() {
dialogVisible.value = false;
printHandle();
emit("paySuccess");
}
@@ -172,6 +202,10 @@ function show() {
defineExpose({
show,
});
onMounted(() => {
bySubTypeAjax();
});
</script>
<style>