|
|
@@ -285,7 +285,10 @@ export default {
|
|
|
selectedStockId: null,
|
|
|
|
|
|
/** 当前库存 */
|
|
|
- currentInventory: null
|
|
|
+ currentInventory: null,
|
|
|
+ // 批量选择的行集合
|
|
|
+ /** @type {Array<import('@/api/types/order').PjpfStockDesc & { forecastQuantity: number, brandCode?: string }>} */
|
|
|
+ selectedRows: []
|
|
|
}
|
|
|
},
|
|
|
|
|
|
@@ -305,6 +308,17 @@ export default {
|
|
|
return this.title
|
|
|
}
|
|
|
return this.isEdit ? '编辑销售预测' : '新增销售预测'
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 当前表单是否允许编辑(用于控制选择与批量删除)
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+ canEditCurrentForm() {
|
|
|
+ try {
|
|
|
+ return canEdit(Number(this.formData.approvalStatus ?? 0))
|
|
|
+ } catch (e) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
|
|
|
@@ -1283,6 +1297,51 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ // 表格选择与批量删除相关方法
|
|
|
+ getRowKey(row) {
|
|
|
+ const keyId = row && (row.id != null ? row.id : row.goodsId)
|
|
|
+ return keyId != null ? String(keyId) : String(row.code || Math.random())
|
|
|
+ },
|
|
|
+ isRowSelectable(row, index) {
|
|
|
+ return this.canEditCurrentForm
|
|
|
+ },
|
|
|
+ handleSelectionChange(selection) {
|
|
|
+ this.selectedRows = Array.isArray(selection) ? selection.slice() : []
|
|
|
+ },
|
|
|
+ async handleBatchDelete() {
|
|
|
+ try {
|
|
|
+ if (!this.selectedRows || this.selectedRows.length === 0) {
|
|
|
+ this.$message && this.$message.warning('请先选择要删除的物料')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!this.canEditCurrentForm) {
|
|
|
+ this.$message && this.$message.warning('当前审批状态不允许编辑')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ await this.$confirm(`确认删除所选的 ${this.selectedRows.length} 条物料吗?`, '提示', {
|
|
|
+ type: 'warning',
|
|
|
+ confirmButtonText: '删除',
|
|
|
+ cancelButtonText: '取消'
|
|
|
+ })
|
|
|
+ const keys = new Set(this.selectedRows.map(r => {
|
|
|
+ const id = r && (r.id != null ? r.id : r.goodsId)
|
|
|
+ return id != null ? String(id) : String(r.code)
|
|
|
+ }))
|
|
|
+ this.stockTableData = this.stockTableData.filter(r => {
|
|
|
+ const id = r && (r.id != null ? r.id : r.goodsId)
|
|
|
+ const key = id != null ? String(id) : String(r.code)
|
|
|
+ return !keys.has(key)
|
|
|
+ })
|
|
|
+ this.selectedRows = []
|
|
|
+ this.$message && this.$message.success('已删除所选物料')
|
|
|
+ } catch (e) {
|
|
|
+ if (e && e !== 'cancel') {
|
|
|
+ console.error('批量删除失败:', e)
|
|
|
+ this.$message && this.$message.error('批量删除失败,请稍后重试')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
/**
|
|
|
* 品牌变更处理
|
|
|
* @param {number} brandId - 品牌ID
|