hn-hlw-app/utils/index.js
2026-07-27 11:26:39 +08:00

96 lines
3.2 KiB
JavaScript

import dayjs from "dayjs";
import { isChinaId } from "@/utils/validator";
// 咨询订单状态
// 支付状态 payStatus: pending (待支付) failed(支付失败) success (支付成功) expired (支付超时)
// 订单状态 orderStatus: pending (待处理) , processing (处理中) , completed (已完成) , cancelled (已取消)
export function getOrderStatus(order, showRefundBtn = false) {
const { payStatus, orderStatus, hasPassDiagnostic, reason, refundInfo } = order;
const after20250620 = order.createTime ? order.createTime > dayjs('2025-06-20 00:00:00').valueOf() : false; //2025年6月20日之后的订单可以申请退费
const isStoreMedicinePurchase = order.consultType === 'onlineConsult';
const canApplyRefund = after20250620 && hasPassDiagnostic && !refundInfo && order.orderSource === 'ALIPAY_MINI' && isStoreMedicinePurchase;
const hasAppliedRefund = Boolean(refundInfo);
const showRefund = canApplyRefund || hasAppliedRefund
const refundText = refundInfo ? (refundInfo.status === 'INIT' ? "申请退费中" : "查看退费记录") : showRefund ? "申请退费" : '';
if (payStatus === "pending") {
const diff = order.payExpireTime - order.createTime;
const mins = Math.round(diff / 1000 / 60);
return {
text: "待支付",
subText: `您的订单尚未支付,请在 ${mins > 0 ? mins : 30} 分钟内完成支付,超时订单将自动取消。`,
color: "red",
canPay: true,
canCancel: true,
showFooter: true
};
}
if (payStatus === "failed") {
return {
text: "支付失败",
color: "#666",
};
}
if (orderStatus === "cancelled" || payStatus === "expired") {
return {
text: "已取消",
color: "#666",
showFooter: showRefund,
showRefund,
refundText,
subText: typeof reason == 'string' ? reason : '您的订单已取消',
};
}
if (
orderStatus === "processing" ||
orderStatus === "pending" ||
orderStatus === "completed"
) {
return {
text: hasPassDiagnostic ? "已完成" : "处理中",
subText: '问诊正在进行中,点击底部按钮进入问诊间与医生聊天。',
color: "red",
showRefund,
refundText,
enterRoom: true,
enterRoomText: '进入会话',
showFooter: true
};
}
if (orderStatus === "finished") {
return {
text: "已结束",
subText: '本次问诊已结束。',
color: "#4cd964",
showRefund,
refundText,
enterRoom: true,
enterRoomText: '查看会话',
showFooter: true
};
}
return {};
}
export function calcPersonInfo(idCard, currentTime) {
const [isIdCard, birthday, gender] = isChinaId(idCard);
if (isIdCard && currentTime) {
const startDate = dayjs(currentTime);
const year = startDate.year();
const birthYear = dayjs(birthday).year();
const thisYearBirthday = dayjs(birthday).year(year);
const gap =
year - birthYear - (startDate.isBefore(thisYearBirthday) ? 1 : 0); // 生日是否过了
const age = Math.max(1, gap);
return {
birthday,
age,
sex: gender === "MALE" ? "男" : "女"
};
}
return {
birthday,
age: '',
sex: ""
};
}