【服务列表】 修复# 表格中的服务金额格式化错误的问题

dev1.0
kaeery 2025-03-13 11:18:50 +08:00
parent 0d510cee1b
commit da34a60c9b
3 changed files with 48 additions and 10 deletions

View File

@ -261,9 +261,9 @@ export function formatFileSize(bytes: number) {
*/
export function retain(value: any, n: any): string {
if (n === 'null' || n === 'undefined' || n === 0) return value
let tran = Math.round(value * Math.pow(10, n)) / Math.pow(10, n)
const tran = Math.round(value * Math.pow(10, n)) / Math.pow(10, n)
let tranV = tran.toString()
let newVal = tranV.indexOf('.')
const newVal = tranV.indexOf('.')
if (newVal < 0) {
tranV += '.'
}
@ -272,3 +272,40 @@ export function retain(value: any, n: any): string {
}
return tranV
}
export function formatString(input) {
const processNumber = numStr => {
if (!numStr.includes('.')) return numStr
// 分割整数和小数部分(处理 .00 和 20. 等情况)
const parts = numStr.split('.', 2)
let [intPart, decPart] = parts
// 处理类似 ".00" 的情况
intPart = intPart || '0'
// 处理小数部分全零或无小数部分的情况
if (!decPart || decPart.trimEnd().replace(/^0+$/, '') === '') {
return intPart
}
// 去除末尾零并处理格式问题
const strippedDec = decPart.trimEnd().replace(/^0+$/, '')
const result = `${intPart}.${strippedDec}`
// 处理特殊情况
if (strippedDec === '') return intPart // 123.000 → 123
if (result.endsWith('.')) return intPart // 123. → 123
if (result.startsWith('.') && strippedDec) return `0${result}` // .55 → 0.55
return result
}
if (!input) return
const parts = input.split('-', 2)
if (parts.length !== 2) return input
const left = processNumber(parts[0])
const right = processNumber(parts[1])
return `${left}-${right}`
}

View File

@ -240,7 +240,7 @@
</template>
</el-table-column>
<el-table-column property="goodsPrice" label="价格" width="120">
<template #default="scope">{{ parsePrice(scope.row) }}</template>
<template #default="scope">¥{{ parsePrice(scope.row) }}</template>
</el-table-column>
<el-table-column property="unitName" label="单位" width="120" />
<el-table-column property="goodsNum" label="数量" width="120" />
@ -299,7 +299,7 @@ import { PriceEnum, ReceiveOrderEnum, getTypeMap, useGoodsTypeMap } from '@/enum
import { useCreateModal } from '@/hooks/useCreateModal'
import area from '@/utils/area'
import feedback from '@/utils/feedback'
import { parseCouponTime, parseEmpty } from '@/utils/util'
import { formatString, parseCouponTime, parseEmpty } from '@/utils/util'
import { ref } from 'vue'
import cancelOrderDialog from './components/cancelOrderDialog.vue'
import dispatchDialog from './components/dispatchDialog.vue'
@ -401,8 +401,7 @@ const orderRefundDetailVo = computed(() => (unref(isShowOrderRefundDetailVo) ? u
const isDispatch = computed(() => (status: number) => status === ReceiveOrderEnum.PAUSE)
const parsePrice = computed(() => row => {
const { priceType, priceRange, goodsPrice } = row
const [minPrice = 0, maxPrice = 0] = priceRange.split('-')
return priceType == PriceEnum.CUSTOMER_PRICE ? goodsPrice : minPrice + '-' + maxPrice
return priceType == PriceEnum.CUSTOMER_PRICE ? goodsPrice : formatString(priceRange)
})
function generateCouponFields(res: any) {

View File

@ -95,10 +95,13 @@
</div>
</template>
</el-table-column>
<el-table-column label="服务金额" min-width="100">
<template #default="scope">¥{{ parsePrice(scope.row) }}</template>
</el-table-column>
<!-- <el-table-column label="实付金额" min-width="100">
<template #default="scope">¥{{ scope.row.orderAmount }}</template>
</el-table-column> -->
<el-table-column label="预约日期" min-width="160">
<el-table-column label="预约日期" min-width="180">
<template #default="scope">
{{ scope.row.appointTime }} {{ scope.row.weekDay }} {{ scope.row.appointTimeStartStr }}-{{ scope.row.appointTimeEndStr }}
</template>
@ -168,7 +171,7 @@ import Pagination from '@/components/pagination/index.vue'
import DataPicker from '@/components/daterange-picker/index.vue'
import cancelOrderDialog from './components/cancelOrderDialog.vue'
import { usePaging } from '@/hooks/usePaging'
import { parseEmpty } from '@/utils/util'
import { formatString, parseEmpty } from '@/utils/util'
import { optionMap } from '@/config/status'
import { useCancelOrderAction } from './hook'
@ -211,8 +214,7 @@ const setStatusColor = computed(() => {
})
const parsePrice = computed(() => row => {
const { priceType, priceRange, goodsPrice } = row
const [minPrice = 0, maxPrice = 0] = priceRange.split('-')
return priceType == PriceEnum.CUSTOMER_PRICE ? goodsPrice : minPrice + '-' + maxPrice
return priceType == PriceEnum.CUSTOMER_PRICE ? goodsPrice : formatString(priceRange)
})
const { pager, getLists, resetPage, resetParams } = usePaging({