acdr-ui/dist/dev/mp-weixin/modules/mall/sheep/hooks/useGoods.js
2024-10-01 09:15:35 +08:00

256 lines
7.3 KiB
JavaScript

"use strict";
const common_vendor = require("../../../../common/vendor.js");
const modules_mall_sheep_url_index = require("../url/index.js");
const modules_mall_sheep_util_index = require("../util/index.js");
function formatSales(type, num) {
const prefix = type !== "exact" && num < 10 ? "销量" : "已售";
return formatNum(prefix, type, num);
}
function formatStock(type, num) {
return formatNum("库存", type, num);
}
function formatNum(prefix, type, num) {
num = num || 0;
if (type === "exact") {
return prefix + num;
}
if (num < 10) {
return `${prefix}≤10`;
}
const numStr = num.toString();
const first = numStr[0];
const other = "0".repeat(numStr.length - 1);
return `${prefix}${first}${other}+`;
}
const VIDEO_SUFFIX_LIST = [".avi", ".mp4"];
function formatGoodsSwiper(urlList) {
return (urlList == null ? void 0 : urlList.filter((url) => url).map((url, key) => {
const isVideo = VIDEO_SUFFIX_LIST.some((suffix) => url.includes(suffix));
const type = isVideo ? "video" : "image";
const src = modules_mall_sheep_url_index.$url.cdn(url);
return { type, src };
})) || [];
}
function formatOrderColor(order) {
if (order.status === 0) {
return "info-color";
}
if (order.status === 10 || order.status === 20 || order.status === 30 && !order.commentStatus) {
return "warning-color";
}
if (order.status === 30 && order.commentStatus) {
return "success-color";
}
return "danger-color";
}
function formatOrderStatus(order) {
if (order.status === 0) {
return "待付款";
}
if (order.status === 10 && order.deliveryType === 1) {
return "待发货";
}
if (order.status === 10 && order.deliveryType === 2) {
return "待核销";
}
if (order.status === 20) {
return "待收货";
}
if (order.status === 30 && !order.commentStatus) {
return "待评价";
}
if (order.status === 30 && order.commentStatus) {
return "已完成";
}
return "已关闭";
}
function formatOrderStatusDescription(order) {
if (order.status === 0) {
return `请在 ${modules_mall_sheep_util_index.formatDate(order.payExpireTime)} 前完成支付`;
}
if (order.status === 10) {
return "商家未发货,请耐心等待";
}
if (order.status === 20) {
return "商家已发货,请耐心等待";
}
if (order.status === 30 && !order.commentStatus) {
return "已收货,快去评价一下吧";
}
if (order.status === 30 && order.commentStatus) {
return "交易完成,感谢您的支持";
}
return "交易关闭";
}
function handleOrderButtons(order) {
order.buttons = [];
if (order.type === 3) {
order.buttons.push("combination");
}
if (order.status === 20) {
order.buttons.push("confirm");
}
if (order.logisticsId > 0) {
order.buttons.push("express");
}
if (order.status === 0) {
order.buttons.push("cancel");
order.buttons.push("pay");
}
if (order.status === 30 && !order.commentStatus) {
order.buttons.push("comment");
}
if (order.status === 40) {
order.buttons.push("delete");
}
}
function formatAfterSaleStatus(afterSale) {
if (afterSale.status === 10) {
return "申请售后";
}
if (afterSale.status === 20) {
return "商品待退货";
}
if (afterSale.status === 30) {
return "商家待收货";
}
if (afterSale.status === 40) {
return "等待退款";
}
if (afterSale.status === 50) {
return "退款成功";
}
if (afterSale.status === 61) {
return "买家取消";
}
if (afterSale.status === 62) {
return "商家拒绝";
}
if (afterSale.status === 63) {
return "商家拒收货";
}
return "未知状态";
}
function formatAfterSaleStatusDescription(afterSale) {
if (afterSale.status === 10) {
return "退款申请待商家处理";
}
if (afterSale.status === 20) {
return "请退货并填写物流信息";
}
if (afterSale.status === 30) {
return "退货退款申请待商家处理";
}
if (afterSale.status === 40) {
return "等待退款";
}
if (afterSale.status === 50) {
return "退款成功";
}
if (afterSale.status === 61) {
return "退款关闭";
}
if (afterSale.status === 62) {
return `商家不同意退款申请,拒绝原因:${afterSale.auditReason}`;
}
if (afterSale.status === 63) {
return `商家拒绝收货,不同意退款,拒绝原因:${afterSale.auditReason}`;
}
return "未知状态";
}
function handleAfterSaleButtons(afterSale) {
afterSale.buttons = [];
if ([10, 20, 30].includes(afterSale.status)) {
afterSale.buttons.push("cancel");
}
if (afterSale.status === 20) {
afterSale.buttons.push("delivery");
}
}
function useDurationTime(toTime, fromTime = "") {
toTime = getDayjsTime(toTime);
if (fromTime === "") {
fromTime = common_vendor.dayjs();
}
const duration = common_vendor.ref(toTime - fromTime);
if (duration.value > 0) {
setTimeout(() => {
if (duration.value > 0) {
duration.value -= 1e3;
}
}, 1e3);
}
const durationTime = common_vendor.dayjs.duration(duration.value);
return {
h: (durationTime.months() * 30 * 24 + durationTime.days() * 24 + durationTime.hours()).toString().padStart(2, "0"),
m: durationTime.minutes().toString().padStart(2, "0"),
s: durationTime.seconds().toString().padStart(2, "0"),
ms: durationTime.$ms
};
}
function getDayjsTime(time) {
time = time.toString();
if (time.indexOf("-") > 0) {
return common_vendor.dayjs(time);
}
if (time.length > 10) {
return common_vendor.dayjs(parseInt(time));
}
if (time.length === 10) {
return common_vendor.dayjs.unix(parseInt(time));
}
}
function fen2yuan(price) {
return (price / 100).toFixed(2);
}
function convertProductPropertyList(skus) {
const result = [];
for (const sku of skus) {
if (!sku.properties) {
continue;
}
for (const property of sku.properties) {
let resultProperty = result.find((item) => item.id === property.propertyId);
if (!resultProperty) {
resultProperty = {
id: property.propertyId,
name: property.propertyName,
values: []
};
result.push(resultProperty);
}
const resultValue = resultProperty.values.find((item) => item.id === property.valueId);
if (!resultValue) {
resultProperty.values.push({
id: property.valueId,
name: property.valueName
});
}
}
}
return result;
}
function formatRewardActivityRule(activity, rule) {
if (activity.conditionType === 10) {
return `${fen2yuan(rule.limit)} 元减 ${fen2yuan(rule.discountPrice)}`;
}
if (activity.conditionType === 20) {
return `${rule.limit} 件减 ${fen2yuan(rule.discountPrice)}`;
}
return "";
}
exports.convertProductPropertyList = convertProductPropertyList;
exports.fen2yuan = fen2yuan;
exports.formatAfterSaleStatus = formatAfterSaleStatus;
exports.formatAfterSaleStatusDescription = formatAfterSaleStatusDescription;
exports.formatGoodsSwiper = formatGoodsSwiper;
exports.formatOrderColor = formatOrderColor;
exports.formatOrderStatus = formatOrderStatus;
exports.formatOrderStatusDescription = formatOrderStatusDescription;
exports.formatRewardActivityRule = formatRewardActivityRule;
exports.formatSales = formatSales;
exports.formatStock = formatStock;
exports.handleAfterSaleButtons = handleAfterSaleButtons;
exports.handleOrderButtons = handleOrderButtons;
exports.useDurationTime = useDurationTime;