|
@@ -227,6 +227,19 @@ export default {
|
|
|
if (val && this.visible) {
|
|
|
this.formData = this.cleanAndFormatFormData(val)
|
|
|
}
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 监听预测ID变化
|
|
|
+ * @param {string|number} val - 新的预测ID
|
|
|
+ */
|
|
|
+ forecastId: {
|
|
|
+ handler(val) {
|
|
|
+ if (val && this.isEdit && this.visible) {
|
|
|
+ this.loadForecastDetail(val)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ immediate: true
|
|
|
}
|
|
|
},
|
|
|
|
|
@@ -253,11 +266,27 @@ export default {
|
|
|
* @private
|
|
|
*/
|
|
|
cleanAndFormatFormData(data) {
|
|
|
+ // 获取下个月的年份和月份作为默认值
|
|
|
+ const now = new Date()
|
|
|
+ const currentYear = now.getFullYear()
|
|
|
+ const currentMonth = now.getMonth() + 1
|
|
|
+
|
|
|
+ let defaultYear, defaultMonth
|
|
|
+ if (currentMonth === 12) {
|
|
|
+ // 当前是12月,下个月是明年1月
|
|
|
+ defaultYear = currentYear + 1
|
|
|
+ defaultMonth = 1
|
|
|
+ } else {
|
|
|
+ // 其他月份,直接 +1
|
|
|
+ defaultYear = currentYear
|
|
|
+ defaultMonth = currentMonth + 1
|
|
|
+ }
|
|
|
+
|
|
|
return {
|
|
|
id: data.id || null,
|
|
|
forecastCode: String(data.forecastCode || ''),
|
|
|
- year: data.year ? data.year.toString() : new Date().getFullYear().toString(),
|
|
|
- month: Number(data.month) || new Date().getMonth() + 1,
|
|
|
+ year: data.year ? data.year.toString() : defaultYear.toString(),
|
|
|
+ month: Number(data.month) || defaultMonth,
|
|
|
customerId: data.customerId ? data.customerId.toString() : null,
|
|
|
customerCode: String(data.customerCode || ''),
|
|
|
customerName: String(data.customerName || ''),
|
|
@@ -268,7 +297,7 @@ export default {
|
|
|
itemCode: String(data.itemCode || ''),
|
|
|
itemName: String(data.itemName || ''),
|
|
|
specs: String(data.specs || ''),
|
|
|
- forecastQuantity: Number(data.forecastQuantity) || null,
|
|
|
+ forecastQuantity: data.forecastQuantity !== undefined && data.forecastQuantity !== null && data.forecastQuantity !== '' ? Number(data.forecastQuantity) : null,
|
|
|
currentInventory: Number(data.currentInventory) || null,
|
|
|
approvalStatus: Number(data.approvalStatus) || APPROVAL_STATUS.PENDING,
|
|
|
approvedName: String(data.approvedName || ''),
|
|
@@ -296,6 +325,16 @@ export default {
|
|
|
const detailData = res.data.data
|
|
|
this.formData = this.cleanAndFormatFormData(detailData)
|
|
|
|
|
|
+ // 加载客户选项数据,确保客户下拉框能正确显示
|
|
|
+ if (this.formData.customerId) {
|
|
|
+ await this.loadCustomerOption(this.formData.customerId, this.formData.customerName)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加载物料选项数据,确保物料下拉框能正确显示
|
|
|
+ if (this.formData.itemId) {
|
|
|
+ await this.loadItemOption(this.formData.itemId, this.formData.itemName, this.formData.itemCode, this.formData.specs)
|
|
|
+ }
|
|
|
+
|
|
|
// 触发加载完成事件
|
|
|
this.$emit(FORECAST_FORM_EVENTS.LOADED, this.formData)
|
|
|
} else {
|
|
@@ -310,6 +349,25 @@ export default {
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
+ * 加载单个客户选项
|
|
|
+ * @description 为编辑模式加载特定客户的选项数据
|
|
|
+ * @param {string|number} customerId - 客户ID
|
|
|
+ * @param {string} customerName - 客户名称
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
+ async loadCustomerOption(customerId, customerName) {
|
|
|
+ if (!customerId) return
|
|
|
+
|
|
|
+ try {
|
|
|
+ // customer-select组件会自动处理回显,我们只需要确保formData中有正确的值
|
|
|
+ // 组件的watch会监听value变化并调用loadCustomerById方法
|
|
|
+ console.log('客户回显数据:', { customerId, customerName })
|
|
|
+ } catch (error) {
|
|
|
+ console.error('加载客户选项失败:', error)
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
* 远程搜索客户
|
|
|
* @description 根据关键字远程搜索客户数据
|
|
|
* @param {string} query - 搜索关键字
|
|
@@ -345,6 +403,35 @@ export default {
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
+ * 加载单个物料选项
|
|
|
+ * @description 为编辑模式加载特定物料的选项数据
|
|
|
+ * @param {string|number} itemId - 物料ID
|
|
|
+ * @param {string} itemName - 物料名称
|
|
|
+ * @param {string} itemCode - 物料编码
|
|
|
+ * @param {string} specs - 规格
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
+ async loadItemOption(itemId, itemName, itemCode, specs) {
|
|
|
+ if (!itemId) return
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 如果选项中已经存在该物料,则不需要重新加载
|
|
|
+ const existingOption = this.itemOptions.find(option => option.id === itemId)
|
|
|
+ if (existingOption) return
|
|
|
+
|
|
|
+ // 添加当前物料到选项中
|
|
|
+ this.itemOptions = [{
|
|
|
+ id: itemId,
|
|
|
+ code: itemCode,
|
|
|
+ name: itemName,
|
|
|
+ specs: specs
|
|
|
+ }]
|
|
|
+ } catch (error) {
|
|
|
+ console.error('加载物料选项失败:', error)
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
* 远程搜索物料
|
|
|
* @description 根据关键字远程搜索物料数据
|
|
|
* @param {string} query - 搜索关键字
|