瀏覽代碼

feat(forecast): 完善销售预测类型定义和组件逻辑

yz 4 周之前
父節點
當前提交
a0f400b07f
共有 4 個文件被更改,包括 141 次插入31 次删除
  1. 3 2
      src/api/forecast/types.d.ts
  2. 11 0
      src/api/types/forecast.d.ts
  3. 35 22
      src/views/forecast/forecastIndex.js
  4. 92 7
      src/views/forecast/types.d.ts

+ 3 - 2
src/api/forecast/types.d.ts

@@ -1,4 +1,5 @@
 // Forecast 模块类型定义
+import { ApprovalStatus } from "@/constants/forecast"
 
 // 基础查询参数
 export interface ForecastQueryParams {
@@ -14,7 +15,7 @@ export interface ForecastQueryParams {
   itemCode?: string
   itemName?: string
   specs?: string
-  approvalStatus?: number
+  approvalStatus?: ApprovalStatus
   forecastCode?: string
 }
 
@@ -36,7 +37,7 @@ export interface ForecastForm {
   specs: string
   forecastQuantity: number | null
   currentInventory?: number | null
-  approvalStatus?: number
+  approvalStatus?: ApprovalStatus
   approvedBy?: number
   approvedName?: string
   approvedTime?: string | null

+ 11 - 0
src/api/types/forecast.d.ts

@@ -238,6 +238,17 @@ export interface ForecastForm {
 }
 
 /**
+ * 销售预测表单模型类型
+ * @description 定义销售预测表单组件的数据模型
+ */
+export interface ForecastFormModel extends ForecastForm {
+  /** 创建时间 */
+  createTime?: string;
+  /** 更新时间 */
+  updateTime?: string;
+}
+
+/**
  * 销售预测记录接口
  */
 export interface ForecastRecord extends ForecastForm, BaseEntity {}

+ 35 - 22
src/views/forecast/forecastIndex.js

@@ -12,7 +12,7 @@ import {
   DEFAULT_FORECAST_FORM
 } from '@/constants/forecast'
 import { mapGetters } from 'vuex'
-import ForecastFormAvue from '@/components/forecast-form/index.vue'
+import ForecastFormAvue from '@/components/forecast-form/index'
 
 /**
  * @typedef {import('@/api/forecast/types').ForecastRecord} ForecastRecord
@@ -21,6 +21,8 @@ import ForecastFormAvue from '@/components/forecast-form/index.vue'
  * @typedef {import('./types').ItemOption} ItemOption
  * @typedef {import('./types').PageConfig} PageConfig
  * @typedef {import('./types').ForecastComponent} ForecastComponent
+ * @typedef {import('@/api/forecast/types').ForecastForm} ForecastFormModel
+   * @typedef {import('@/api/forecast/types').ForecastRecord} ForecastItem
  */
 
 /**
@@ -35,9 +37,7 @@ export default {
   components: {
     ForecastFormAvue
   },
-  /**
-   * @returns {{form: ForecastFormModel, query: Record<string, any>, loading: boolean, submitting: boolean, saveLoading: boolean, dialogVisible: boolean, isEdit: boolean, editVisible: boolean, editMode: string, editTitle: string, currentForecastId: string|number|null, page: {pageSize: number, currentPage: number, total: number}, data: ForecastItem[], customerOptions: CustomerOption[], customerLoading: boolean, itemOptions: ItemOption[], itemLoading: boolean, option: AvueCrudOption, formRules: Record<string, FormItemRule[]>}}
-   */
+
   data() {
     return {
       /** @type {ForecastForm} 表单数据 */
@@ -56,7 +56,7 @@ export default {
       isEdit: false,
       /** @type {boolean} 表单页面显示状态 */
       editVisible: false,
-      /** @type {string} 表单模式:'add' | 'edit' | 'view' */
+      /** @type {'add'|'edit'|'view'} 表单模式:'add' | 'edit' | 'view' */
       editMode: 'add',
       /** @type {string} 表单标题 */
       editTitle: '',
@@ -254,6 +254,7 @@ export default {
 
     /**
      * 权限配置
+     * @this {Vue & ForecastComponent}
      * @returns {{addBtn: boolean, viewBtn: boolean, delBtn: boolean, editBtn: boolean}} 权限配置对象
      */
     permissionList() {
@@ -271,6 +272,7 @@ export default {
 
     /**
      * 弹窗标题
+     * @this {Vue & ForecastComponent}
      * @returns {string} 弹窗标题文本
      */
     dialogTitle() {
@@ -278,6 +280,10 @@ export default {
     }
   },
 
+  /**
+   * 组件创建时初始化
+   * @this {Vue & ForecastComponent}
+   */
   created() {
     this.loadCustomerOptions()
     this.loadItemOptions()
@@ -295,8 +301,9 @@ export default {
         const res = await getCustomerList(1, 20)
         if (res.data && res.data.success) {
           this.customerOptions = res.data.data.records.map(item => ({
-            value: item.Customer_ID.toString(),
+            value: parseInt(item.Customer_ID.toString()),
             label: item.Customer_NAME,
+            customerId: parseInt(item.Customer_ID.toString()),
             customerCode: item.Customer_CODE,
             customerName: item.Customer_NAME
           }))
@@ -323,13 +330,18 @@ export default {
 
       try {
         this.customerLoading = true
-        const res = await getCustomerList(1, 50, {
-          Customer_NAME: query
-        })
+        /** @type {import('@/api/types/common').CustomerQueryParams} */
+        const params = {
+          customerName: query,
+          current: 1,
+          size: 50
+        }
+        const res = await getCustomerList(1, 50, params)
         if (res.data && res.data.success) {
           this.customerOptions = res.data.data.records.map(item => ({
-            value: item.Customer_ID.toString(),
+            value: parseInt(item.Customer_ID.toString()),
             label: item.Customer_NAME,
+            customerId: parseInt(item.Customer_ID.toString()),
             customerCode: item.Customer_CODE,
             customerName: item.Customer_NAME
           }))
@@ -343,13 +355,14 @@ export default {
 
     /**
      * 客户选择变化处理
+     * @this {Vue & ForecastComponent}
      * @param {number} customerId - 客户ID
      * @returns {void}
      */
     handleCustomerChange(customerId) {
       const customer = this.customerOptions.find(item => item.value === customerId)
       if (customer) {
-        this.form.customerId = customer.value.toString()
+        this.form.customerId = customer.value
         this.form.customerCode = customer.customerCode
         this.form.customerName = customer.customerName
       }
@@ -357,7 +370,7 @@ export default {
 
     /**
      * 加载物料选项
-     * @this {Vue & {itemLoading: boolean, itemOptions: Array<ItemOption>, $message: any}}
+     * @this {Vue & ForecastComponent}
      * @returns {Promise<void>}
      */
     async loadItemOptions() {
@@ -384,7 +397,7 @@ export default {
 
     /**
      * 远程搜索物料
-     * @this {Vue & {itemLoading: boolean, itemOptions: Array<ItemOption>, loadItemOptions: () => Promise<void>}}
+     * @this {Vue & ForecastComponent}
      * @param {string} query - 搜索关键词
      * @returns {Promise<void>}
      */
@@ -418,7 +431,7 @@ export default {
 
     /**
      * 物料选择变化处理
-     * @this {Vue & {itemOptions: Array<ItemOption>, form: ForecastForm}}
+     * @this {Vue & ForecastComponent}
      * @param {number} itemId - 物料ID
      * @returns {void}
      */
@@ -448,11 +461,11 @@ export default {
 
     /**
      * 检查是否可以编辑
-     * @param {ForecastRecord} row - 行数据
+     * @param {ForecastRecord|ForecastItem} row - 行数据
      * @returns {boolean} 是否可以编辑
      */
     canEditRow(row) {
-      return canEdit(row.approvalStatus)
+      return row.approvalStatus !== undefined ? canEdit(row.approvalStatus) : false
     },
 
     /**
@@ -564,13 +577,13 @@ export default {
       this.editTitle = '新增预测申报'
       this.currentForecastId = null
       this.editVisible = true
-      
+
       // 重置表单数据
       this.form = { ...DEFAULT_FORECAST_FORM }
-      
+
       // 生成预测编码
       this.generateForecastCode()
-      
+
       // 保持兼容性
       this.isEdit = false
       this.dialogVisible = true
@@ -613,10 +626,10 @@ export default {
       this.editTitle = '编辑预测申报'
       this.currentForecastId = row.id
       this.editVisible = true
-      
+
       // 设置表单数据
       this.form = { ...row }
-      
+
       // 保持兼容性
       this.isEdit = true
       this.dialogVisible = true
@@ -634,7 +647,7 @@ export default {
       this.editTitle = ''
       this.currentForecastId = null
       this.form = { ...DEFAULT_FORECAST_FORM }
-      
+
       // 保持兼容性
       this.dialogVisible = false
       this.isEdit = false

+ 92 - 7
src/views/forecast/types.d.ts

@@ -94,12 +94,97 @@ export interface ForecastComponentData {
 }
 
 /**
- * 销售预测申报页面组件类型
+ * 销售预测组件接口
+ * @description 定义销售预测组件的方法和属性
  */
-export interface ForecastComponent extends ForecastComponentData {
-  /** Vue实例方法 */
-  $message: any
-  $confirm: any
-  $store: any
-  $refs: any
+export interface ForecastComponent {
+  /** 表单数据 */
+  form: ForecastForm;
+  /** 查询条件 */
+  query: Record<string, any>;
+  /** 加载状态 */
+  loading: boolean;
+  /** 提交状态 */
+  submitting: boolean;
+  /** 保存加载状态 */
+  saveLoading: boolean;
+  /** 对话框可见性 */
+  dialogVisible: boolean;
+  /** 是否编辑模式 */
+  isEdit: boolean;
+  /** 编辑对话框可见性 */
+  editVisible: boolean;
+  /** 编辑模式 */
+  editMode: 'add' | 'edit' | 'view';
+  /** 编辑标题 */
+  editTitle: string;
+  /** 当前预测ID */
+  currentForecastId: string | number | null;
+  /** 分页配置 */
+  page: PageConfig;
+  /** 数据列表 */
+  data: Array<ForecastRecord>;
+  /** 客户选项 */
+  customerOptions: Array<CustomerOption>;
+  /** 客户加载状态 */
+  customerLoading: boolean;
+  /** 物料选项 */
+  itemOptions: Array<ItemOption>;
+  /** 物料加载状态 */
+  itemLoading: boolean;
+  /** 表格配置选项 */
+  option: AvueCrudOption;
+  /** 表单验证规则 */
+  formRules: Record<string, Array<ValidationRule>>;
+  /** 组件引用 */
+  $refs: {
+    forecastForm?: {
+      handleSubmit(): void;
+    };
+  };
+
+  /** 加载客户选项 */
+  loadCustomerOptions(keyword?: string): Promise<void>;
+  /** 加载物料选项 */
+  loadItemOptions(keyword?: string): Promise<void>;
+  /** 远程搜索客户 */
+  remoteSearchCustomer(query: string): Promise<void>;
+  /** 客户改变处理 */
+  handleCustomerChange(customerId: number): void;
+  /** 处理编辑 */
+  handleEdit(row: ForecastRecord, index: number): void;
+  /** 处理删除 */
+  handleDelete(row: ForecastRecord, index: number): void;
+  /** 处理提交 */
+  handleSubmit(): Promise<void>;
+  /** 处理取消 */
+  handleCancel(): void;
+  /** 刷新数据 */
+  refreshChange(): void;
+  /** 搜索数据 */
+  searchChange(): void;
+  /** 重置搜索 */
+  searchReset(): void;
+  /** 分页改变 */
+  currentChange(currentPage: number): void;
+  /** 页大小改变 */
+  sizeChange(pageSize: number): void;
+  /** 行点击 */
+  rowClick(row: ForecastRecord, column: any, event: Event): void;
+  /** 行双击 */
+  rowDblclick(row: ForecastRecord, column: any, event: Event): void;
+  /** 选择改变 */
+  selectionChange(selection: Array<ForecastRecord>): void;
+  /** 生成预测编码 */
+  generateForecastCode(): void;
+  /** 加载数据 */
+  onLoad(page: any, params?: any): Promise<void>;
+  /** 判断行是否可编辑 */
+  canEditRow(row: ForecastRecord): boolean;
+  /** 返回列表 */
+  handleBackToList(): void;
+  /** 远程搜索物料 */
+  remoteSearchItem(query: string): Promise<void>;
+  /** 物料改变处理 */
+  handleItemChange(itemId: number): void;
 }