|
@@ -3,6 +3,56 @@
|
|
|
* @description 提供销售预测表单的数据管理、验证规则和业务逻辑的混入组件,支持新增和编辑模式
|
|
|
*/
|
|
|
|
|
|
+/**
|
|
|
+ * 类型定义导入
|
|
|
+ * @description 导入所有必要的TypeScript类型定义,确保类型安全
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @typedef {import('./types').ForecastFormModel} ForecastFormModel
|
|
|
+ * @description 销售预测表单数据模型类型
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @typedef {import('./types').ForecastFormMixinData} ForecastFormMixinData
|
|
|
+ * @description 销售预测表单混入数据类型
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @typedef {import('./types').CustomerOption} CustomerOption
|
|
|
+ * @description 客户选项类型
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @typedef {import('./types').ItemOption} ItemOption
|
|
|
+ * @description 物料选项类型
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @typedef {import('./types').ApprovalStatusOption} ApprovalStatusOption
|
|
|
+ * @description 审批状态选项类型
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @typedef {import('./types').MaterialSelectData} MaterialSelectData
|
|
|
+ * @description 物料选择数据类型
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @typedef {import('./types').CustomerSelectData} CustomerSelectData
|
|
|
+ * @description 客户选择数据类型
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @typedef {import('./types').ApiResponse} ApiResponse
|
|
|
+ * @description API响应数据类型
|
|
|
+ */
|
|
|
+
|
|
|
+/**
|
|
|
+ * @typedef {import('./types').ValidationRule} ValidationRule
|
|
|
+ * @description 表单验证规则类型
|
|
|
+ */
|
|
|
+
|
|
|
// API接口导入
|
|
|
import { addForecast, updateForecast, getForecastDetail } from '@/api/forecast'
|
|
|
|
|
@@ -37,12 +87,19 @@ export const FORECAST_FORM_EVENTS = {
|
|
|
/** 客户选择变更事件 */
|
|
|
CUSTOMER_CHANGE: 'customer-change',
|
|
|
/** 物料选择变更事件 */
|
|
|
- ITEM_CHANGE: 'item-change'
|
|
|
+ ITEM_CHANGE: 'item-change',
|
|
|
+ /** 表单重置事件 */
|
|
|
+ RESET: 'reset',
|
|
|
+ /** 表单提交事件 */
|
|
|
+ SUBMIT: 'submit',
|
|
|
+ /** 更新可见性事件 */
|
|
|
+ UPDATE_VISIBLE: 'update:visible'
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 销售预测表单混入
|
|
|
* @description 提供销售预测表单的数据管理、验证规则和业务逻辑
|
|
|
+ * @mixin
|
|
|
*/
|
|
|
export default {
|
|
|
/**
|
|
@@ -111,13 +168,14 @@ export default {
|
|
|
/**
|
|
|
* 组件响应式数据
|
|
|
* @description 定义组件的响应式数据状态
|
|
|
+ * @returns {ForecastFormMixinData} 组件数据对象
|
|
|
*/
|
|
|
data() {
|
|
|
return {
|
|
|
/**
|
|
|
* 销售预测表单数据模型
|
|
|
* @description 存储销售预测表单的所有字段数据
|
|
|
- * @type {Object}
|
|
|
+ * @type {ForecastFormModel}
|
|
|
*/
|
|
|
formData: this.createInitialFormData(),
|
|
|
|
|
@@ -138,7 +196,7 @@ export default {
|
|
|
/**
|
|
|
* 客户选项列表
|
|
|
* @description 客户下拉选择器的选项数据
|
|
|
- * @type {Array<{value: string|number, label: string, customerCode: string}>}
|
|
|
+ * @type {CustomerOption[]}
|
|
|
*/
|
|
|
customerOptions: [],
|
|
|
|
|
@@ -152,7 +210,7 @@ export default {
|
|
|
/**
|
|
|
* 物料选项列表
|
|
|
* @description 物料下拉选择器的选项数据
|
|
|
- * @type {Array<{value: string|number, label: string, itemCode: string, specs: string}>}
|
|
|
+ * @type {ItemOption[]}
|
|
|
*/
|
|
|
itemOptions: [],
|
|
|
|
|
@@ -166,7 +224,7 @@ export default {
|
|
|
/**
|
|
|
* 审批状态选项列表
|
|
|
* @description 审批状态下拉选择器的选项数据
|
|
|
- * @type {typeof APPROVAL_STATUS_OPTIONS}
|
|
|
+ * @type {ApprovalStatusOption[]}
|
|
|
*/
|
|
|
approvalStatusOptions: APPROVAL_STATUS_OPTIONS,
|
|
|
|
|
@@ -312,7 +370,7 @@ export default {
|
|
|
/**
|
|
|
* 创建初始表单数据
|
|
|
* @description 创建销售预测表单的初始数据结构
|
|
|
- * @returns {Object} 初始化的表单数据对象
|
|
|
+ * @returns {ForecastFormModel} 初始化的表单数据对象
|
|
|
* @private
|
|
|
*/
|
|
|
createInitialFormData() {
|
|
@@ -322,8 +380,8 @@ export default {
|
|
|
/**
|
|
|
* 清理和格式化表单数据
|
|
|
* @description 对表单数据进行清理和格式化处理
|
|
|
- * @param {Object} data - 原始表单数据
|
|
|
- * @returns {Object} 清理和格式化后的表单数据
|
|
|
+ * @param {any} data - 原始表单数据
|
|
|
+ * @returns {ForecastFormModel} 清理和格式化后的表单数据
|
|
|
* @private
|
|
|
*/
|
|
|
cleanAndFormatFormData(data) {
|
|
@@ -641,6 +699,7 @@ export default {
|
|
|
|
|
|
/**
|
|
|
* 客户选择事件处理
|
|
|
+ * @param {CustomerSelectData} customerData - 客户选择数据
|
|
|
*/
|
|
|
handleCustomerSelected(customerData) {
|
|
|
if (customerData && customerData.customerId) {
|
|
@@ -671,12 +730,7 @@ export default {
|
|
|
/**
|
|
|
* 物料选择处理
|
|
|
* @description 处理MaterialSelect组件的物料选择事件
|
|
|
- * @param {Object} materialData - 物料选择数据
|
|
|
- * @param {string|number} materialData.itemId - 物料ID
|
|
|
- * @param {string} materialData.itemCode - 物料编码
|
|
|
- * @param {string} materialData.itemName - 物料名称
|
|
|
- * @param {string} materialData.specification - 物料规格
|
|
|
- * @param {import('@/api/types/common').ItemRecord|null} materialData.materialData - API返回的物料数据对象
|
|
|
+ * @param {MaterialSelectData} materialData - 物料选择数据
|
|
|
*/
|
|
|
handleMaterialSelected(materialData) {
|
|
|
if (materialData && materialData.itemId) {
|
|
@@ -726,7 +780,7 @@ export default {
|
|
|
handleReset() {
|
|
|
this.initFormData()
|
|
|
this.currentInventory = null
|
|
|
- this.$emit('reset')
|
|
|
+ this.$emit(FORECAST_FORM_EVENTS.RESET)
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -739,7 +793,7 @@ export default {
|
|
|
try {
|
|
|
// 提交数据
|
|
|
const submitData = { ...this.formData }
|
|
|
-
|
|
|
+
|
|
|
let res
|
|
|
if (this.isEdit) {
|
|
|
res = await updateForecast(submitData)
|
|
@@ -748,7 +802,7 @@ export default {
|
|
|
}
|
|
|
|
|
|
// 触发提交成功事件,传递API响应数据
|
|
|
- this.$emit('submit', res.data)
|
|
|
+ this.$emit(FORECAST_FORM_EVENTS.SUBMIT, res.data)
|
|
|
} catch (error) {
|
|
|
console.error('提交表单失败:', error)
|
|
|
this.$message.error(error.message || '操作失败,请重试')
|
|
@@ -791,7 +845,7 @@ export default {
|
|
|
this.$emit(FORECAST_FORM_EVENTS.CANCEL)
|
|
|
|
|
|
// 更新可见性
|
|
|
- this.$emit('update:visible', false)
|
|
|
+ this.$emit(FORECAST_FORM_EVENTS.UPDATE_VISIBLE, false)
|
|
|
|
|
|
// 重置表单数据
|
|
|
this.formData = this.createInitialFormData()
|