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

111 lines
2.7 KiB
JavaScript
Raw Normal View History

2024-05-28 18:22:58 +08:00
import { ref } from 'vue'
import dayjs from 'dayjs'
2024-05-27 00:51:03 +08:00
/**
* 将分转成元
*
* @param price 例如说 100
* @returns {string} 例如说 1.00
*/
export function fen2yuan(price) {
2024-05-28 18:22:58 +08:00
return (price / 100.0).toFixed(2)
2024-05-27 00:51:03 +08:00
}
/**
* 格式化销量
* @param {'exact' | string} type 格式类型exact=精确值其它=大致数量
* @param {number} num 销量
* @return {string} 格式化后的销量字符串
*/
export function formatSales(type, num) {
2024-05-28 18:22:58 +08:00
let prefix = type !== 'exact' && num < 10 ? '销量' : '已售'
return formatNum(prefix, type, num)
2024-05-27 00:51:03 +08:00
}
/**
* 格式化库存
* @param {'exact' | any} type 格式类型exact=精确值其它=大致数量
* @param {number} num 销量
* @return {string} 格式化后的销量字符串
*/
export function formatStock(type, num) {
2024-05-28 18:22:58 +08:00
return formatNum('库存', type, num)
}
export 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 '已完成'
}
if (order.status === 50) {
return '待核销'
}
if (order.status === 60) {
return '待配送'
}
return '已关闭'
}
export function formatOrderColor(order) {
if (order.status === 0) {
return 'info-color'
}
if (
order.status === 10 ||
order.status === 20 ||
(order.status === 30 && !order.commentStatus) ||
order.status === 50 ||
order.status === 60
) {
return 'warning-color'
}
if (order.status === 30 && order.commentStatus) {
return 'success-color'
}
return 'danger-color'
}
export 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')
}
2024-05-27 00:51:03 +08:00
}