import { ref } from 'vue' import dayjs from 'dayjs' import { formatDate } from '@/peach/utils' /** * 格式化数字 * @param {string} prefix 前缀 * @param {'exact' | string} type 格式类型:exact=精确值,其它=大致数量 * @param {number} num 销量 * @return {string} 格式化后的销量字符串 */ export function formatNum(prefix, type, num) { num = num || 0 // 情况一:精确数值 if (type === 'exact') { return prefix + num } // 情况二:小于等于 10 if (num < 10) { return `${prefix}≤10` } // 情况三:大于 10,除第一位外,其它位都显示为0 // 例如:100 - 199 显示为 100+ // 9000 - 9999 显示为 9000+ const numStr = num.toString() const first = numStr[0] const other = '0'.repeat(numStr.length - 1) return `${prefix}${first}${other}+` } /** * 将分转成元 * * @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 formatOrderStatusDescription(order) { if (order.status === 0) { if (!order.payExpireTime) { return '当前支付已过期' } return `请在 ${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 '交易完成,感谢您的支持' } if (order.status === 50) { return '请及时到店核销商品' } if (order.status === 60) { return '商家已接单,待配送' } return '交易关闭' } export function formatOrderStatus(order) { if (order.refundStatus === 10) { return '部分退款' } if (order.refundStatus === 20) { return '整单退款' } 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.refundStatus === 10 || order.refundStatus === 20) { return 'danger-color' } 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') } // if (order.status === 50) { // // 核销订单 // order.buttons.push('verification') // } if (order.status === 60) { // 配送完成 order.buttons.push('delivery') } }