111 lines
2.7 KiB
JavaScript
111 lines
2.7 KiB
JavaScript
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)
|
||
}
|
||
|
||
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')
|
||
}
|
||
}
|