From da34a60c9b09c67af6596ca28e178e993edbc98b Mon Sep 17 00:00:00 2001
From: kaeery <3491123437@qq.com>
Date: Thu, 13 Mar 2025 11:18:50 +0800
Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=9C=8D=E5=8A=A1=E5=88=97=E8=A1=A8?=
=?UTF-8?q?=E3=80=91=20=E4=BF=AE=E5=A4=8D#=20=E8=A1=A8=E6=A0=BC=E4=B8=AD?=
=?UTF-8?q?=E7=9A=84=E6=9C=8D=E5=8A=A1=E9=87=91=E9=A2=9D=E6=A0=BC=E5=BC=8F?=
=?UTF-8?q?=E5=8C=96=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/utils/util.ts | 41 ++++++++++++++++++++++++++++++--
src/views/order/lists/detail.vue | 7 +++---
src/views/order/lists/index.vue | 10 ++++----
3 files changed, 48 insertions(+), 10 deletions(-)
diff --git a/src/utils/util.ts b/src/utils/util.ts
index c640665..b4890f9 100644
--- a/src/utils/util.ts
+++ b/src/utils/util.ts
@@ -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}`
+}
diff --git a/src/views/order/lists/detail.vue b/src/views/order/lists/detail.vue
index 8d10960..03fc8d4 100644
--- a/src/views/order/lists/detail.vue
+++ b/src/views/order/lists/detail.vue
@@ -240,7 +240,7 @@
- {{ parsePrice(scope.row) }}
+ ¥{{ parsePrice(scope.row) }}
@@ -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) {
diff --git a/src/views/order/lists/index.vue b/src/views/order/lists/index.vue
index a600aa2..a9efb95 100644
--- a/src/views/order/lists/index.vue
+++ b/src/views/order/lists/index.vue
@@ -95,10 +95,13 @@
+
+ ¥{{ parsePrice(scope.row) }}
+
-
+
{{ scope.row.appointTime }} {{ scope.row.weekDay }} {{ scope.row.appointTimeStartStr }}-{{ scope.row.appointTimeEndStr }}
@@ -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({