|
@@ -6,22 +6,21 @@ import {
|
|
|
ORDER_TYPE_OPTIONS,
|
|
|
ORDER_STATUS_OPTIONS
|
|
|
} from '@/constants/order'
|
|
|
+import { MaterialDetailDataSource } from './types'
|
|
|
|
|
|
/**
|
|
|
+ * @typedef {import('./types').MaterialDetailRecord} MaterialDetailRecord
|
|
|
* @typedef {import('./types').OrderFormModel} OrderFormModel
|
|
|
- * @typedef {import('./types').ValidationRule} ValidationRule
|
|
|
- * @typedef {import('./types').OrderFormRules} OrderFormRules
|
|
|
- * @typedef {import('./types').OrderFormData} OrderFormMixinData
|
|
|
- */
|
|
|
-
|
|
|
-/**
|
|
|
- * @typedef {Object} ApiResponse
|
|
|
- * @property {number} code - 响应状态码
|
|
|
- * @property {string} message - 响应消息
|
|
|
- * @property {*} data - 响应数据
|
|
|
+ * @typedef {import('./types').MaterialDeleteEventData} MaterialDeleteEventData
|
|
|
+ * @typedef {import('./types').ApiResponse} ApiResponse
|
|
|
+ * @typedef {import('./types').PaginatedResponse} PaginatedResponse
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
+ * @typedef {import('./types').OrderFormModel} OrderFormModel
|
|
|
+ * @typedef {import('./types').ValidationRule} ValidationRule
|
|
|
+ * @typedef {import('./types').OrderFormRules} OrderFormRules
|
|
|
+ * @typedef {import('./types').OrderFormData} OrderFormMixinData
|
|
|
* @typedef {import('./types').OrderTypeOption} OrderTypeOption
|
|
|
* @typedef {import('./types').OrderStatusOption} OrderStatusOption
|
|
|
*/
|
|
@@ -339,9 +338,9 @@ export default {
|
|
|
|
|
|
/**
|
|
|
* 加载订单物料明细数据
|
|
|
- * @description 根据订单ID从服务器获取物料明细列表,用于编辑模式下的数据回显
|
|
|
+ * @description 根据订单ID从服务器获取物料明细列表,远程数据不可删除
|
|
|
* @param {string|number} orderId - 订单唯一标识符
|
|
|
- * @returns {Promise<OrderItemRecord[]>} 物料明细记录列表,失败时返回空数组
|
|
|
+ * @returns {Promise<MaterialDetailRecord[]>} 物料明细记录列表,失败时返回空数组
|
|
|
* @private
|
|
|
*/
|
|
|
async loadMaterialDetails(orderId) {
|
|
@@ -352,9 +351,17 @@ export default {
|
|
|
throw new Error('物料明细数据格式错误')
|
|
|
}
|
|
|
|
|
|
- return response.data.data.records || []
|
|
|
+ const materialDetails = response.data.data.records || []
|
|
|
+
|
|
|
+ // 为远程加载的物料数据添加数据来源标识
|
|
|
+ return materialDetails.map(material => ({
|
|
|
+ ...material,
|
|
|
+ dataSource: MaterialDetailDataSource.REMOTE,
|
|
|
+ isDeletable: false // 远程加载的数据不可删除
|
|
|
+ }))
|
|
|
} catch (error) {
|
|
|
this.$message.warning('加载物料明细失败,请稍后重试')
|
|
|
+ console.error('加载物料明细失败:', error)
|
|
|
return []
|
|
|
}
|
|
|
},
|
|
@@ -548,6 +555,76 @@ export default {
|
|
|
})
|
|
|
|
|
|
return cleanedData
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理物料删除事件
|
|
|
+ * @description 从物料明细列表中删除指定的物料记录,仅允许删除可删除的物料
|
|
|
+ * @param {Object} deleteData - 删除数据对象
|
|
|
+ * @param {MaterialDetailRecord} deleteData.row - 要删除的物料记录
|
|
|
+ * @param {number} deleteData.index - 记录在当前页的索引
|
|
|
+ * @returns {void}
|
|
|
+ * @public
|
|
|
+ */
|
|
|
+ handleMaterialDelete({ row, index }) {
|
|
|
+ if (!row) {
|
|
|
+ this.$message.warning('删除数据无效')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查物料是否可删除
|
|
|
+ if (!row.isDeletable) {
|
|
|
+ this.$message.warning('该物料不允许删除')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 从物料明细列表中移除该记录
|
|
|
+ const materialIndex = this.materialDetails.findIndex(item =>
|
|
|
+ item.itemCode === row.itemCode &&
|
|
|
+ item.dataSource === row.dataSource
|
|
|
+ )
|
|
|
+
|
|
|
+ if (materialIndex !== -1) {
|
|
|
+ this.materialDetails.splice(materialIndex, 1)
|
|
|
+ this.$message.success(`物料 "${row.itemName}" 删除成功`)
|
|
|
+ } else {
|
|
|
+ this.$message.warning('未找到要删除的物料记录')
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error('删除物料失败,请重试')
|
|
|
+ console.error('删除物料失败:', error)
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理物料导入事件
|
|
|
+ * @description 将导入的物料数据添加到物料明细列表中,导入数据可删除
|
|
|
+ * @param {MaterialDetailRecord[]} importedMaterials - 导入的物料数据数组
|
|
|
+ * @returns {void}
|
|
|
+ * @public
|
|
|
+ */
|
|
|
+ handleMaterialImport(importedMaterials) {
|
|
|
+ if (!Array.isArray(importedMaterials) || importedMaterials.length === 0) {
|
|
|
+ this.$message.warning('没有有效的物料数据可导入')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 为导入的物料添加数据来源标识
|
|
|
+ const processedMaterials = importedMaterials.map(material => ({
|
|
|
+ ...material,
|
|
|
+ dataSource: MaterialDetailDataSource.IMPORTED,
|
|
|
+ isDeletable: true // 导入的数据可以删除
|
|
|
+ }))
|
|
|
+
|
|
|
+ // 添加到现有物料列表中
|
|
|
+ this.materialDetails.push(...processedMaterials)
|
|
|
+ this.$message.success(`成功导入 ${importedMaterials.length} 条物料记录`)
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error('导入物料失败,请重试')
|
|
|
+ console.error('导入物料失败:', error)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|