Browse Source

refactor(forecast-audit): 将BigInt类型改为字符串并优化数据处理

yz 1 month ago
parent
commit
057f67f015
2 changed files with 30 additions and 40 deletions
  1. 24 32
      src/views/forecast-audit/auditIndex.js
  2. 6 8
      src/views/forecast-audit/types.d.ts

+ 24 - 32
src/views/forecast-audit/auditIndex.js

@@ -1,4 +1,4 @@
-import { approveSalesForecastSummary, getSalesForecastForecastList, approveSalesForecastSummaryParticulars } from '@/api/forecast/forecast-summary'
+import { approveSalesForecastSummary, getSalesForecastMainPage, approveSalesForecastSummaryParticulars } from '@/api/forecast/forecast-summary'
 import { mapGetters } from 'vuex'
 import {
   APPROVAL_STATUS,
@@ -10,6 +10,7 @@ import {
   formatNumber,
   formatDateTime as formatDateTimeUtil
 } from '@/constants/forecast'
+import { safeBigInt } from '@/util/util'
 
 /**
  * @typedef {import('./types').ForecastRecord} ForecastRecord
@@ -288,6 +289,10 @@ export default {
     },
 
     // 新增:格式化日期时间显示,供子表“审批时间”列使用
+    /**
+     * @param {string|null|undefined} dateTime - 日期时间值
+     * @returns {string} 格式化后的日期时间字符串
+     */
     formatDateTime(dateTime) {
       return formatDateTimeUtil(dateTime)
     },
@@ -579,25 +584,11 @@ export default {
     },
 
     /**
-     * 安全转换为 BigInt(若失败返回 null)
-     * @param {string|number|bigint|null|undefined} v
-     * @returns {bigint|null}
-     */
-    toBigIntSafe(v) {
-      try {
-        if (v === null || v === undefined || v === '') return null
-        return BigInt(String(v))
-      } catch (e) {
-        return null
-      }
-    },
-
-    /**
-     * 加载数据(使用销售预测主表分页 forecast/list)
-     * @this {Vue & ForecastAuditComponent}
-     * @param {import('./types').PageConfig} page - 分页配置
-     * @param {Partial<{year: number, month: number, customerName: string}>} [params={}] - 查询参数
-     */
+      * 加载数据(使用销售预测主表分页)
+      * @this {Vue & ForecastAuditComponent}
+      * @param {import('./types').PageConfig} page - 分页配置
+      * @param {Partial<{year: number, month: number, customerName: string}>} [params={}] - 查询参数
+      */
     async onLoad(page, params = {}) {
       try {
         this.loading = true
@@ -608,48 +599,49 @@ export default {
           customerName: params.customerName ?? this.query.customerName
         }
 
-        // 调用新的分页接口(含明细
-        const res = await getSalesForecastForecastList(
+        // 使用新分页接口(主表分页
+        const res = await getSalesForecastMainPage(
           page.currentPage,
           page.pageSize,
           queryParams
         )
         const { records = [], total = 0, current = 1, size = 10 } = (res.data && res.data.data) || {}
 
-        // 处理ID为 BigInt,同时保留字符串ID以便传输
+        // 处理ID为 BigInt 字符串,同时保留字符串ID以便传输
         const mapped = (records || []).map(rec => {
           const idStr = rec && rec.id != null ? String(rec.id) : ''
-          const idBigint = this.toBigIntSafe(idStr)
+          const idBigint = safeBigInt(idStr)
           const subList = Array.isArray(rec.pcBladeSalesForecastSummaryList)
             ? rec.pcBladeSalesForecastSummaryList.map(sub => {
                 const subIdStr = sub && sub.id != null ? String(sub.id) : ''
-                const subIdBigint = this.toBigIntSafe(subIdStr)
+                const subIdBigint = safeBigInt(subIdStr)
                 const fmIdStr = sub && sub.forecastMainId != null ? String(sub.forecastMainId) : idStr
-                const fmIdBigint = this.toBigIntSafe(fmIdStr)
+                const fmIdBigint = safeBigInt(fmIdStr)
                 return {
                   ...sub,
                   id: subIdStr,
                   forecastMainId: fmIdStr,
+                  year: Number(sub.year),
+                  month: Number(sub.month),
+                  forecastQuantity: typeof sub.forecastQuantity === 'string' ? Number(sub.forecastQuantity) : Number(sub.forecastQuantity),
                   idBigint: subIdBigint,
                   forecastMainIdBigint: fmIdBigint,
                   // 继承父级字段,保证子表新增列有值可展示
                   approvalStatus: sub && sub.approvalStatus != null ? sub.approvalStatus : (rec && rec.approvalStatus != null ? rec.approvalStatus : APPROVAL_STATUS.PENDING),
                   customerName: sub && sub.customerName != null ? sub.customerName : rec && rec.customerName,
-                  year: sub && sub.year != null ? sub.year : rec && rec.year,
-                  month: sub && sub.month != null ? sub.month : rec && rec.month,
                   approvedName: sub && sub.approvedName != null ? sub.approvedName : rec && rec.approvedName,
                   approvedTime: sub && sub.approvedTime != null ? sub.approvedTime : rec && rec.approvedTime
                 }
               })
             : []
           const approvalStatus = /** @type {import('@/constants/forecast').ApprovalStatus} */ (rec.approvalStatus ?? APPROVAL_STATUS.PENDING)
-          return { ...rec, id: idStr, idBigint, approvalStatus, pcBladeSalesForecastSummaryList: subList }
+          return { ...rec, id: idStr, idBigint, year: Number(rec.year), month: Number(rec.month), approvalStatus, pcBladeSalesForecastSummaryList: subList }
         })
 
         this.data = /** @type {import('./types').ForecastRecord[]} */ (mapped)
-        this.page.total = total
-        this.page.currentPage = current
-        this.page.pageSize = size
+        this.page.total = Number(total)
+        this.page.currentPage = Number(current)
+        this.page.pageSize = Number(size)
       } catch (error) {
         // eslint-disable-next-line no-console
         console.error('加载列表失败', error)

+ 6 - 8
src/views/forecast-audit/types.d.ts

@@ -5,16 +5,16 @@ import type { SalesForecastMainRecord, SalesForecastMainListItemRecord } from "@
 
 // 子表明细记录,补充 BigInt 派生字段
 export type ForecastChildRecord = SalesForecastMainListItemRecord & {
-  /** ID 的 BigInt 形式 */
-  idBigint?: bigint | null
-  /** 主表ID 的 BigInt 形式 */
-  forecastMainIdBigint?: bigint | null
+  /** ID 的 BigInt 字符串形式 */
+  idBigint?: string | null
+  /** 主表ID 的 BigInt 字符串形式 */
+  forecastMainIdBigint?: string | null
 }
 
 // 主表记录,基于销售预测主表返回结构,补充 BigInt 派生字段与子表类型
 export interface ForecastRecord extends SalesForecastMainRecord {
-  /** ID 的 BigInt 形式 */
-  idBigint?: bigint | null
+  /** ID 的 BigInt 字符串形式 */
+  idBigint?: string | null
   /** 子表明细列表(含 BigInt 派生字段) */
   pcBladeSalesForecastSummaryList: ForecastChildRecord[]
   /** 审批状态(保持与常量定义一致) */
@@ -167,6 +167,4 @@ export interface ForecastAuditComponent extends ForecastAuditComponentData {
   rejectChildRecord(sub: ForecastChildRecord): Promise<void>
   /** 执行子表审批 */
   submitChildApproval(sub: ForecastChildRecord, isApprove: boolean): Promise<void>
-  /** 将 ID 安全转换为 BigInt */
-  toBigIntSafe(v: string | number | bigint | null | undefined): bigint | null
 }