对接订单打印小票

This commit is contained in:
gyq
2025-03-05 09:35:34 +08:00
parent 573dd88b24
commit db3fc1f6dc
22 changed files with 838 additions and 206 deletions

View File

@@ -1,3 +1,7 @@
import { getOrderById } from "@/api/order.js";
import { useUser } from "@/store/user.js";
import dayjs from "dayjs";
/**
* 生成范围随机数
* @param {Object} Min
@@ -96,3 +100,81 @@ export function inputFilterFloat(value) {
}
return value;
}
/**
* 将手机号中间四位替换为*号
* @param {*} phone
* @returns
*/
export function formatPhoneNumber(phone, isFormat = true) {
if (isFormat) {
return phone.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2");
} else {
return phone;
}
}
/**
* 获取订单详情
* @param {*} orderId
* @returns
*/
export async function getOrderByIdAjax(orderId) {
try {
const res = await getOrderById({ orderId: orderId });
let arr = [];
for (let key in res.detailMap) {
arr.push(res.detailMap[key]);
}
arr = arr.flat();
arr.map((item) => {
if (item.productType == "package") {
item.proGroupInfo = JSON.parse(item.proGroupInfo).flat();
}
});
res.cartList = arr;
return Promise.resolve(res);
} catch (error) {
console.log(error);
return Promise.reject();
}
}
/**
* 将订单小票打印的数据组合起来
* @param {*} orderDetail
*/
export function commOrderPrintData(orderInfo) {
const userStore = useUser();
let data = {
shop_name: userStore.shopInfo.shopName,
loginAccount: userStore.userInfo.name,
carts: [],
amount: formatDecimal(orderInfo.payAmount),
discountAmount: formatDecimal(
orderInfo.originAmount - orderInfo.orderAmount
),
discount: orderInfo.discountRatio,
remark: orderInfo.remark,
orderInfo: orderInfo,
outNumber: orderInfo.tableCode,
createdAt: orderInfo.paidTime,
printTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
};
orderInfo.cartList.map((item) => {
data.carts.push({
categoryId: item.categoryId,
name: item.productName,
number: item.num,
skuName: item.skuName,
salePrice: formatDecimal(item.price),
totalAmount: formatDecimal(+item.payAmount),
proGroupInfo: item.proGroupInfo,
});
});
return data;
}