diff --git a/src/common/fotmat.js b/src/common/fotmat.js index 3a5d9c5..9625cad 100644 --- a/src/common/fotmat.js +++ b/src/common/fotmat.js @@ -42,7 +42,7 @@ export const weightDigit = 1000 */ export const formatPriceDiv = (val, digit = Digit, priceStatus = false) => { let res = strip(Number(val / digit)) || 0 - return priceStatus?res.toLocaleString('zh', {minimumFractionDigits: 2}):res + return priceStatus?numberWithCommas({number: res}):res } /** * 乘以 @@ -82,11 +82,6 @@ export const formatDateTime = (val, fmt = "YYYY-MM-DD HH:mm:ss") => { let s = time.getSeconds() fmt = fmt.replace('YYYY', Y).replace('MM', M.toString().padStart(2, '0')).replace('DD', d.toString().padStart(2, '0')).replace('HH', h.toString().padStart(2, '0')).replace('mm', m.toString().padStart(2, '0')).replace('ss', s.toString().padStart(2, '0')) - // fmt = fmt.replace('MM', M) - // fmt = fmt.replace('DD', d) - // fmt = fmt.replace('HH', h) - // fmt = fmt.replace('mm', m) - // fmt = fmt.replace('ss', s) return fmt } else { @@ -164,3 +159,16 @@ export const isLabImage = (imgurl, rgb, suffix="!w200") => { return {status:3, value: IMG_CND_Prefix+'/mall/no_img.png'} } } + +/** + * + * @param {千位分割付} number + * @returns + */ +export const numberWithCommas = ({number = 0, digit = 2}) => { + if(!isNaN(Number(number))) { + return parseFloat(number).toFixed(digit).replace(/\B(? { return ( <> ¥ - {Number(int_num).toLocaleString()} + {numberWithCommas({number:int_num, digit:0})} .{decimals_num} ) diff --git a/src/pages/order/comfirm.tsx b/src/pages/order/comfirm.tsx index 726c62a..0427e63 100644 --- a/src/pages/order/comfirm.tsx +++ b/src/pages/order/comfirm.tsx @@ -131,7 +131,7 @@ import { throttle } from "@/common/util"; const numText = useMemo(() => { if(formatPreViewOrder) { let total_number = formatPreViewOrder?.sale_mode == 0?formatPreViewOrder?.total_number:(formatPreViewOrder?.total_number/100) - return `${formatPreViewOrder?.total_fabrics} 种面料,${formatPreViewOrder?.total_colors} 种颜色,共 ${total_number}${formatPreViewOrder?.unit}` + return `${formatPreViewOrder?.total_fabrics} 种面料,${formatPreViewOrder?.total_colors} 种颜色,共 ${total_number} ${formatPreViewOrder?.unit}` } }, [formatPreViewOrder]) @@ -178,7 +178,7 @@ import { throttle } from "@/common/util"; - + {numText} submitOrderEven()}>提交订单 diff --git a/src/pages/order/components/kindList/index.tsx b/src/pages/order/components/kindList/index.tsx index 5505f61..1eb8328 100644 --- a/src/pages/order/components/kindList/index.tsx +++ b/src/pages/order/components/kindList/index.tsx @@ -109,7 +109,7 @@ export default memo(({order, comfirm = false}:Param) => { <> { priceList.map(item => { - return <>{item.validatarFunc(order)&&} + return <>{item.validatarFunc(order)&&} }) } @@ -122,14 +122,14 @@ export default memo(({order, comfirm = false}:Param) => { }, [order]) //对应单价 const standardPrice = useCallback(price => { - return formatPriceDiv(price).toLocaleString() + '/' + (order?.sale_mode == 1?'m':'kg') + return formatPriceDiv(price, 100, true) + '/' + (order?.sale_mode == 1?'m':'kg') }, [order]) //数量格式 const numText = useMemo(() => { if(order) { let total_number = order?.sale_mode == 0?order?.total_number:(order?.total_number/100) - return `${order?.total_fabrics} 种面料,${order?.total_colors} 种颜色,共 ${total_number}${order?.unit}` + return `${order?.total_fabrics} 种面料,${order?.total_colors} 种颜色,共 ${total_number} ${order?.unit}` } }, [order]) @@ -137,7 +137,7 @@ export default memo(({order, comfirm = false}:Param) => { const comfirmPriceConDom = useMemo(() => { if(!order) return let item = order.sale_mode == 1?priceList[1]:priceList[0] - return + return }, [order]) //确认金额展示 @@ -148,7 +148,7 @@ export default memo(({order, comfirm = false}:Param) => { //颜色金额小计 const colorPrice = useCallback((item) => { let res = item.total_sale_price||item.estimate_amount - return formatPriceDiv(res).toLocaleString('en', {minimumFractionDigits: 2}) + return formatPriceDiv(res, 100, true) },[order]) diff --git a/src/pages/order/index.tsx b/src/pages/order/index.tsx index 15b0b23..19ede87 100644 --- a/src/pages/order/index.tsx +++ b/src/pages/order/index.tsx @@ -5,8 +5,8 @@ import { import { AddShoppingCartApi } from "@/api/shopCart"; import { SubscriptionMessageApi } from "@/api/user"; import { alert, goLink } from "@/common/common"; -import { ORDER_STATUS, SUBSCRIPTION_MESSAGE_SCENE } from "@/common/enum"; -import { formatDateTime, formatImgUrl, formatPriceDiv } from "@/common/fotmat"; +import { ORDER_STATUS } from "@/common/enum"; +import { formatDateTime, formatImgUrl } from "@/common/fotmat"; import OrderBtns from "@/components/orderBtns"; import Popup from "@/components/popup"; import SearchInput from "@/components/searchInput"; diff --git a/src/pages/orderList/components/order/index.tsx b/src/pages/orderList/components/order/index.tsx index 277a0d4..04eed24 100644 --- a/src/pages/orderList/components/order/index.tsx +++ b/src/pages/orderList/components/order/index.tsx @@ -127,7 +127,7 @@ export default memo(({value, onClickBtn}: Param) => { {numText} - {(value.total_sale_price/100||value.estimate_amount/100)&& ¥{formatPriceDiv(value.total_sale_price, 100, true)||formatPriceDiv(value.estimate_amount, 100, true)}} + ¥{value.total_sale_price?formatPriceDiv(value.total_sale_price, 100, true):formatPriceDiv(value.estimate_amount, 100, true)} diff --git a/src/pages/salesAfter/components/kindList/index.tsx b/src/pages/salesAfter/components/kindList/index.tsx index 6361ec2..4a98a5c 100644 --- a/src/pages/salesAfter/components/kindList/index.tsx +++ b/src/pages/salesAfter/components/kindList/index.tsx @@ -159,7 +159,7 @@ export default memo(({order, comfirm = false}:Param) => { <> { priceList.map(item => { - return <>{showPrice(item)&&} + return <>{showPrice(item)&&} }) }