|
@@ -1428,6 +1428,65 @@ export default {
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
+ * 处理物料批量删除事件
|
|
|
+ * @description 批量删除选中的物料记录,仅允许删除可删除的物料
|
|
|
+ * @param {import('./types').MaterialBatchDeleteEventData} data - 批量删除事件数据
|
|
|
+ * @returns {void}
|
|
|
+ * @public
|
|
|
+ * @this {import('./types').OrderFormMixinComponent}
|
|
|
+ */
|
|
|
+ handleMaterialBatchDelete({ rows, count }) {
|
|
|
+ if (!Array.isArray(rows) || rows.length === 0) {
|
|
|
+ this.$message.warning('请选择要删除的物料')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否有不可删除的物料
|
|
|
+ const undeletableItems = rows.filter(row => !row.isDeletable)
|
|
|
+ if (undeletableItems.length > 0) {
|
|
|
+ const itemNames = undeletableItems.map(item => item.itemName).join('、')
|
|
|
+ this.$message.warning(`以下物料不允许删除:${itemNames}`)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确认删除操作
|
|
|
+ this.$confirm(`确定要删除选中的 ${count} 条物料记录吗?`, '批量删除确认', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ try {
|
|
|
+ // 批量删除物料
|
|
|
+ const deletedItems = []
|
|
|
+ rows.forEach(row => {
|
|
|
+ const materialIndex = this.materialDetails.findIndex(item =>
|
|
|
+ item.itemCode === row.itemCode &&
|
|
|
+ item.dataSource === row.dataSource
|
|
|
+ )
|
|
|
+
|
|
|
+ if (materialIndex !== -1) {
|
|
|
+ const deletedItem = this.materialDetails.splice(materialIndex, 1)[0]
|
|
|
+ deletedItems.push(deletedItem.itemName)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ if (deletedItems.length > 0) {
|
|
|
+ this.$message.success(`成功删除 ${deletedItems.length} 条物料记录`)
|
|
|
+ // 触发选择重置,清空已删除的选中项
|
|
|
+ this.$refs.materialDetailTable?.resetSelection()
|
|
|
+ } else {
|
|
|
+ this.$message.warning('未找到要删除的物料记录')
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ this.$message.error('批量删除物料失败,请重试')
|
|
|
+ console.error('批量删除物料失败:', error)
|
|
|
+ }
|
|
|
+ }).catch(() => {
|
|
|
+ // 用户取消删除操作
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
* 处理物料导入事件
|
|
|
* @description 将导入的物料数据添加到物料明细列表中,格式化数字字段并标记为可删除
|
|
|
* @param {MaterialDetailRecord[]} importedMaterials - 导入的物料数据数组
|