|
@@ -59,7 +59,7 @@
|
|
|
|
|
|
// API接口导入
|
|
|
import { addForecast, updateForecast, getForecastDetail } from '@/api/forecast'
|
|
|
-import { addSalesForecastMain, updateSalesForecastMain } from '@/api/forecast/forecast-summary'
|
|
|
+import { addSalesForecastMain, updateSalesForecastMain, getSalesForecastSummaryByMonth } from '@/api/forecast/forecast-summary'
|
|
|
import { getUserLinkGoods } from '@/api/order/sales-order'
|
|
|
|
|
|
// 常量和枚举导入
|
|
@@ -102,7 +102,9 @@ export const FORECAST_FORM_EVENTS = {
|
|
|
/** 表单提交失败事件 */
|
|
|
SUBMIT_ERROR: 'submit-error',
|
|
|
/** 更新可见性事件 */
|
|
|
- UPDATE_VISIBLE: 'update:visible'
|
|
|
+ UPDATE_VISIBLE: 'update:visible',
|
|
|
+ /** 保存禁用状态变更(用于父级按钮禁用控制) */
|
|
|
+ SAVE_DISABLED_CHANGE: 'save-disabled-change'
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -327,7 +329,8 @@ export default {
|
|
|
if (this.initialFormData) {
|
|
|
this.formData = this.cleanAndFormatFormData(this.initialFormData)
|
|
|
} else {
|
|
|
- this.formData = this.createInitialFormData()
|
|
|
+ // 使用 initFormData,确保新增模式默认填入“下个月”而不是当前月
|
|
|
+ this.initFormData()
|
|
|
}
|
|
|
|
|
|
// 如果是编辑模式且有ID,则加载详情数据
|
|
@@ -344,6 +347,11 @@ export default {
|
|
|
if (!this.isEdit) {
|
|
|
this.loadCurrentCustomerInfo()
|
|
|
}
|
|
|
+
|
|
|
+ // 新增模式下进行年月预测存在性检查(默认年月)
|
|
|
+ if (!this.isEdit) {
|
|
|
+ this.checkForecastByMonthAndEmit && this.checkForecastByMonthAndEmit()
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
},
|
|
@@ -422,10 +430,30 @@ export default {
|
|
|
if (!newVal) {
|
|
|
this.initFormData()
|
|
|
}
|
|
|
+ // 切换为编辑态时,通知父级恢复保存按钮可点击
|
|
|
+ if (newVal && this.$emit) {
|
|
|
+ this.$emit(FORECAST_FORM_EVENTS.SAVE_DISABLED_CHANGE, false)
|
|
|
+ }
|
|
|
},
|
|
|
immediate: true
|
|
|
},
|
|
|
|
|
|
+ // 新增:监听年份与月份变更以触发按月校验(仅新增模式)
|
|
|
+ 'formData.year': {
|
|
|
+ handler() {
|
|
|
+ if (this.visible && !this.isEdit) {
|
|
|
+ this.checkForecastByMonthAndEmit && this.checkForecastByMonthAndEmit()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 'formData.month': {
|
|
|
+ handler() {
|
|
|
+ if (this.visible && !this.isEdit) {
|
|
|
+ this.checkForecastByMonthAndEmit && this.checkForecastByMonthAndEmit()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
/**
|
|
|
* 监听预测ID变化
|
|
|
* @param {string|number} val - 新的预测ID
|
|
@@ -1056,7 +1084,7 @@ export default {
|
|
|
|
|
|
// 新增模式下需要至少一条有效明细;编辑模式下仅提交主表四个字段,不校验明细条数
|
|
|
if (!this.isEdit && !items.length) {
|
|
|
- this.$message && this.$message.warning('请至少填写一条有效的预测数量')
|
|
|
+ // this.$message && this.$message.warning('请至少填写一条有效的预测数量')
|
|
|
// 通知父组件失败,便于父侧重置保存按钮loading
|
|
|
this.$emit && this.$emit(FORECAST_FORM_EVENTS.SUBMIT_ERROR, { message: '未填写有效的预测明细' })
|
|
|
return
|
|
@@ -1181,7 +1209,7 @@ export default {
|
|
|
this.$message.error('未找到所选物料数据,请重新选择')
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 防止重复导入 - 使用多个字段进行更全面的重复检查
|
|
|
const exists = this.stockTableData.some(row => {
|
|
|
// 优先使用 id 进行匹配
|
|
@@ -1198,13 +1226,13 @@ export default {
|
|
|
}
|
|
|
return false
|
|
|
})
|
|
|
-
|
|
|
+
|
|
|
if (exists) {
|
|
|
this.$message.warning('该物料已在列表中')
|
|
|
this.selectedStockId = null
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 添加到表格,默认预测数量为 0
|
|
|
this.stockTableData.push({ ...stock, forecastQuantity: 0 })
|
|
|
// 清空已选
|
|
@@ -1345,6 +1373,29 @@ export default {
|
|
|
} catch (e) {
|
|
|
console.warn('回显库存合并失败:', e)
|
|
|
}
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增模式:检查指定年月是否已有预测,并通过事件通知父组件控制保存按钮禁用
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
+ async checkForecastByMonthAndEmit() {
|
|
|
+ try {
|
|
|
+ const year = typeof this.formData.year === 'string' ? parseInt(this.formData.year, 10) : Number(this.formData.year)
|
|
|
+ const month = Number(this.formData.month)
|
|
|
+ if (!year || !month) return
|
|
|
+ // 仅新增模式需要校验
|
|
|
+ if (this.isEdit) {
|
|
|
+ this.$emit && this.$emit(FORECAST_FORM_EVENTS.SAVE_DISABLED_CHANGE, false)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ const res = await getSalesForecastSummaryByMonth(year, month)
|
|
|
+ const hasData = !!(res && res.data && res.data.success && Array.isArray(res.data.data) && res.data.data.length > 0)
|
|
|
+ this.$emit && this.$emit(FORECAST_FORM_EVENTS.SAVE_DISABLED_CHANGE, hasData)
|
|
|
+ } catch (e) {
|
|
|
+ // 异常时不阻塞新增,默认允许保存
|
|
|
+ this.$emit && this.$emit(FORECAST_FORM_EVENTS.SAVE_DISABLED_CHANGE, false)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|