wjx пре 1 година
родитељ
комит
13d49ca0cb

+ 4 - 4
src/components/StatisticNull/index.tsx

@@ -1,14 +1,14 @@
-import { Statistic } from "antd"
+import { Statistic, StatisticProps } from "antd"
 import React from "react"
 
-interface Props {
+interface Props extends Omit<StatisticProps, 'value'> {
     data: any
     field: string
 }
 
-const StatisticNull: React.FC<Props> = ({ field, data }) => {
+const StatisticNull: React.FC<Props> = ({ field, data, ...props }) => {
     if (data?.[field] !== undefined && data?.[field] !== null) {
-        return <Statistic value={data?.[field] || 0} />
+        return <Statistic value={data?.[field] || 0} {...props}/>
     } else {
         return <span>--</span>
     }

+ 10 - 2
src/pages/launchSystemNew/adq/ad/adPlanList.tsx

@@ -330,6 +330,14 @@ const AdPlanList: React.FC<{ userId: string }> = (props) => {
         setTrendVisible(true)
     }
 
+
+    const countDecimals = (num: number) => {
+        // 匹配数字的小数部分
+        const match = String(num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
+        // 返回小数位数
+        return match ? Math.max(0, (match[1] ? match[1].length : 0) - (match[2] ? +match[2] : 0)) : 0;
+    }
+
     return <div>
         {/* 列表指标趋势 */}
         {trendVisible && <ColumnTrend visible={trendVisible} data={trendData} onClose={() => { setTrendVisible(false) }} />}
@@ -544,7 +552,7 @@ const AdPlanList: React.FC<{ userId: string }> = (props) => {
                         <Table.Summary.Row className='s_summary'>
                             {tableField.map((item, index) => {
                                 let data = totalData[item.dataIndex]
-                                let value = (data === 0 || data) ? data : '--'
+                                let value = (data === 0 || data) ? countDecimals(data) > 2 ? data.toFixed(2) : data : '--'
                                 if (item.dataIndex === 'zj') {
                                     return <Table.Summary.Cell index={index} key={item.dataIndex} align="center"><strong>总计</strong></Table.Summary.Cell>
                                 } else if (['ctr_total', 'mp_follow_rate_total',
@@ -555,7 +563,7 @@ const AdPlanList: React.FC<{ userId: string }> = (props) => {
                                     return <Table.Summary.Cell index={index} key={item.dataIndex} align="center">
                                         <Space size={4}>
                                             <strong>
-                                                {value !== '--' ? <Statistic value={value.toFixed(2)} precision={2} valueStyle={{ color: '#3f8600' }} suffix="%" /> : '--'}
+                                                {value !== '--' ? <Statistic value={value} precision={2} valueStyle={{ color: '#3f8600' }} suffix="%" /> : '--'}
                                             </strong>
                                             {value !== '--' && <a onClick={() => handleColumnTrend(item.dataIndex)}><LineChartOutlined /></a>}
                                         </Space>

+ 7 - 7
src/pages/launchSystemNew/adq/ad/tablePlanListConfig.tsx

@@ -387,7 +387,7 @@ function tablePlanConfig(
             width: 110,
             sorter: true,
             render: (a: any, b: any) => {
-                return <StatisticNull data={b} field='thousand_display_price_total' />
+                return <StatisticNull data={b} field='thousand_display_price_total' precision={2} />
             }
         },
         {
@@ -538,7 +538,7 @@ function tablePlanConfig(
             width: 120,
             sorter: true,
             render: (a: any, b: any) => {
-                return <StatisticNull data={b} field='mp_follow_pv_cost_total' />
+                return <StatisticNull data={b} field='mp_follow_pv_cost_total' precision={2}/>
             }
         },
         {
@@ -597,7 +597,7 @@ function tablePlanConfig(
             width: 120,
             sorter: true,
             render: (a: any, b: any) => {
-                return <StatisticNull data={b} field='scan_follow_cost_total' />
+                return <StatisticNull data={b} field='scan_follow_cost_total' precision={2} />
             }
         },
         {
@@ -684,7 +684,7 @@ function tablePlanConfig(
             width: 110,
             sorter: true,
             render: (a: any, b: any) => {
-                return <StatisticNull data={b} field='order_cost_total' />
+                return <StatisticNull data={b} field='order_cost_total' precision={2} />
             }
         },
         {
@@ -725,7 +725,7 @@ function tablePlanConfig(
             width: 110,
             sorter: true,
             render: (a: any, b: any) => {
-                return <StatisticNull data={b} field='atv_total' />
+                return <StatisticNull data={b} field='atv_total' precision={2} />
             }
         },
         {
@@ -747,7 +747,7 @@ function tablePlanConfig(
             width: 110,
             sorter: true,
             render: (a: any, b: any) => {
-                return <StatisticNull data={b} field='conversions_cost_total' />
+                return <StatisticNull data={b} field='conversions_cost_total' precision={2} />
             }
         },
         {
@@ -795,7 +795,7 @@ function tablePlanConfig(
             width: 110,
             sorter: true,
             render: (a: any, b: any) => {
-                return <StatisticNull data={b} field='add_fans_cost_total' />
+                return <StatisticNull data={b} field='add_fans_cost_total' precision={2} />
             }
         },
     ]