Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas
/
wx-notification
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 3c69f9c2
authored
Aug 25, 2026
by
张立顺
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix 价格精度问题修复
1 parent
1f6f9eab
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
117 additions
and
14 deletions
src/views/orderApproval/index.vue
src/views/orderApproval/orderApprovalFormat.js
tests/orderApprovalFormat.test.cjs
src/views/orderApproval/index.vue
View file @
3c69f9c
...
@@ -108,7 +108,10 @@ import dayjs from 'dayjs'
...
@@ -108,7 +108,10 @@ import dayjs from 'dayjs'
import
{
ImagePreview
}
from
'vant'
import
{
ImagePreview
}
from
'vant'
import
orderApprovalApi
from
'@/api/orderApproval'
import
orderApprovalApi
from
'@/api/orderApproval'
import
mockOrderDetailRes
from
'./mockData'
import
mockOrderDetailRes
from
'./mockData'
import
{
getFormattedFieldValue
as
formatFieldValue
}
from
'./orderApprovalFormat'
import
{
getFormattedFieldValue
as
formatFieldValue
,
normalizeOrderGoodsPrices
}
from
'./orderApprovalFormat'
import
GoodsOrderItem
from
'./components/goodsOrderItem.vue'
import
GoodsOrderItem
from
'./components/goodsOrderItem.vue'
import
ApprovalPopup
from
'./components/approvalPopup.vue'
import
ApprovalPopup
from
'./components/approvalPopup.vue'
import
store
from
'@/store'
import
store
from
'@/store'
...
@@ -232,17 +235,7 @@ export default {
...
@@ -232,17 +235,7 @@ export default {
return
processed
return
processed
},
},
addPackagePrice
(
orderDTO
)
{
addPackagePrice
(
orderDTO
)
{
const
dto
=
{
...
orderDTO
}
return
normalizeOrderGoodsPrices
(
orderDTO
)
if
(
Array
.
isArray
(
dto
.
packageGoodsList
))
{
dto
.
packageGoodsList
=
dto
.
packageGoodsList
.
map
(
pkg
=>
{
let
total
=
0
if
(
Array
.
isArray
(
pkg
.
packageGoodsOrderList
))
{
total
=
pkg
.
packageGoodsOrderList
.
reduce
((
sum
,
item
)
=>
sum
+
(
item
.
finalPrice
||
0
),
0
)
}
return
{
...
pkg
,
packagePrice
:
total
}
})
}
return
dto
},
},
async
loadOrderDetail
(
orderCode
)
{
async
loadOrderDetail
(
orderCode
)
{
this
.
showLoading
()
this
.
showLoading
()
...
...
src/views/orderApproval/orderApprovalFormat.js
View file @
3c69f9c
...
@@ -19,6 +19,75 @@ function getFormattedFieldValue(value, format) {
...
@@ -19,6 +19,75 @@ function getFormattedFieldValue(value, format) {
return
Object
.
prototype
.
hasOwnProperty
.
call
(
fieldMap
,
value
)
?
fieldMap
[
value
]
:
'-'
return
Object
.
prototype
.
hasOwnProperty
.
call
(
fieldMap
,
value
)
?
fieldMap
[
value
]
:
'-'
}
}
const
orderMoneyFields
=
[
'finalPrice'
,
'singleProductFinalPrice'
,
'singleProductSalesPrice'
,
'totalPrice'
,
'upgradePrice'
]
function
toMoneyCents
(
value
)
{
if
(
value
===
null
||
value
===
undefined
||
value
===
''
)
return
null
const
amount
=
Number
(
value
)
if
(
!
Number
.
isFinite
(
amount
))
return
null
const
correction
=
amount
<
0
?
-
Number
.
EPSILON
:
Number
.
EPSILON
return
Math
.
round
((
amount
+
correction
)
*
100
)
}
function
normalizeMoney
(
value
)
{
const
cents
=
toMoneyCents
(
value
)
return
cents
===
null
?
value
:
cents
/
100
}
function
normalizeGoodsLine
(
line
=
{})
{
return
orderMoneyFields
.
reduce
(
(
result
,
field
)
=>
{
if
(
Object
.
prototype
.
hasOwnProperty
.
call
(
result
,
field
))
{
result
[
field
]
=
normalizeMoney
(
result
[
field
])
}
return
result
},
{
...
line
}
)
}
function
sumFinalPrices
(
goodsList
=
[])
{
const
totalCents
=
goodsList
.
reduce
((
total
,
goods
)
=>
{
if
(
Number
(
goods
.
discountType
)
===
4
)
return
total
const
cents
=
toMoneyCents
(
goods
.
finalPrice
)
return
cents
===
null
?
total
:
total
+
cents
},
0
)
return
totalCents
/
100
}
/**
* 统一审批详情普通商品、套餐子商品和套餐汇总的金额精度。
* 套餐总额直接累加非赠品子项的权威 finalPrice,不通过单价和数量反算。
* @param {object} orderDTO 订单商品数据
* @returns {object} 不修改源对象的金额展示数据
*/
function
normalizeOrderGoodsPrices
(
orderDTO
=
{})
{
const
result
=
{
...
orderDTO
}
if
(
Array
.
isArray
(
result
.
subOrderList
))
{
result
.
subOrderList
=
result
.
subOrderList
.
map
(
normalizeGoodsLine
)
}
if
(
Array
.
isArray
(
result
.
packageGoodsList
))
{
result
.
packageGoodsList
=
result
.
packageGoodsList
.
map
(
pkg
=>
{
const
packageGoodsOrderList
=
Array
.
isArray
(
pkg
.
packageGoodsOrderList
)
?
pkg
.
packageGoodsOrderList
.
map
(
normalizeGoodsLine
)
:
[]
return
{
...
pkg
,
packageGoodsOrderList
,
packagePrice
:
sumFinalPrices
(
packageGoodsOrderList
)
}
})
}
return
result
}
module
.
exports
=
{
module
.
exports
=
{
getFormattedFieldValue
getFormattedFieldValue
,
normalizeOrderGoodsPrices
}
}
tests/orderApprovalFormat.test.cjs
View file @
3c69f9c
const assert = require('assert')
const assert = require('assert')
const { getFormattedFieldValue } = require('../src/views/orderApproval/orderApprovalFormat')
const {
getFormattedFieldValue,
normalizeOrderGoodsPrices
} = require('../src/views/orderApproval/orderApprovalFormat')
assert.strictEqual(getFormattedFieldValue(0, 'lowPriceFlag'), '-')
assert.strictEqual(getFormattedFieldValue(0, 'lowPriceFlag'), '-')
assert.strictEqual(getFormattedFieldValue(1, 'lowPriceFlag'), '低价订单')
assert.strictEqual(getFormattedFieldValue(1, 'lowPriceFlag'), '低价订单')
...
@@ -7,4 +10,42 @@ assert.strictEqual(getFormattedFieldValue(undefined, 'lowPriceFlag'), '-')
...
@@ -7,4 +10,42 @@ assert.strictEqual(getFormattedFieldValue(undefined, 'lowPriceFlag'), '-')
assert.strictEqual(getFormattedFieldValue(null, 'lowPriceFlag'), '-')
assert.strictEqual(getFormattedFieldValue(null, 'lowPriceFlag'), '-')
assert.strictEqual(getFormattedFieldValue(2, 'lowPriceFlag'), '-')
assert.strictEqual(getFormattedFieldValue(2, 'lowPriceFlag'), '-')
const source = {
subOrderList: [
{
upgradePrice: 1520,
singleProductSalesPrice: 999.99,
singleProductFinalPrice: 999.9900000000001
}
],
packageGoodsList: [
{
packageGoodsOrderList: [
{
finalPrice: 285.62,
number: 1,
singleProductFinalPrice: 285.62000000000006
},
{
finalPrice: 2142.74,
number: 1,
singleProductFinalPrice: 2142.74
},
{
discountType: 4,
finalPrice: 100,
singleProductFinalPrice: 100
}
]
}
]
}
const normalized = normalizeOrderGoodsPrices(source)
assert.strictEqual(normalized.subOrderList[0].singleProductFinalPrice, 999.99)
assert.strictEqual(normalized.packageGoodsList[0].packagePrice, 2428.36)
assert.strictEqual(normalized.packageGoodsList[0].packageGoodsOrderList[0].singleProductFinalPrice, 285.62)
assert.strictEqual(source.packageGoodsList[0].packagePrice, undefined)
assert.strictEqual(source.packageGoodsList[0].packageGoodsOrderList[0].singleProductFinalPrice, 285.62000000000006)
console.log('orderApprovalFormat tests passed')
console.log('orderApprovalFormat tests passed')
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment