mall-app-t/peach/hooks/useGoods.js

34 lines
866 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { ref } from "vue";
import dayjs from "dayjs";
/**
* 将分转成元
*
* @param price 分,例如说 100 分
* @returns {string} 元,例如说 1.00 元
*/
export function fen2yuan(price) {
return (price / 100.0).toFixed(2);
}
/**
* 格式化销量
* @param {'exact' | string} type 格式类型exact=精确值,其它=大致数量
* @param {number} num 销量
* @return {string} 格式化后的销量字符串
*/
export function formatSales(type, num) {
let prefix = type !== "exact" && num < 10 ? "销量" : "已售";
return formatNum(prefix, type, num);
}
/**
* 格式化库存
* @param {'exact' | any} type 格式类型exact=精确值,其它=大致数量
* @param {number} num 销量
* @return {string} 格式化后的销量字符串
*/
export function formatStock(type, num) {
return formatNum("库存", type, num);
}