feat(web-admin): 历史归属维护支持批量调整归属
在历史归属维护列表增加多选与工具栏批量「调整归属」,复用现有单条预览/保存接口逐条提交,便于一次将多条业务记录归属到同一项目。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3a396d79a2
commit
2a0a2ef72a
1 file changed
+130
-29
@@ -78,15 +78,41 @@
|
||||
<el-icon><RefreshRight /></el-icon>重试
|
||||
</el-button>
|
||||
</el-alert>
|
||||
<div v-if="assignment" class="list-toolbar">
|
||||
<div class="list-toolbar-row">
|
||||
<div class="list-toolbar-selected">
|
||||
已选 <span class="sel-num">{{ selectedRows.length }}</span> 项
|
||||
</div>
|
||||
<el-button
|
||||
type="primary"
|
||||
class="btn-main"
|
||||
:disabled="!selectedRows.length || busy"
|
||||
@click="openBatch"
|
||||
>
|
||||
<el-icon><Edit /></el-icon>调整归属
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="list-body list-wrap"
|
||||
><el-table
|
||||
ref="tableRef"
|
||||
:key="query.bizType"
|
||||
:data="rows"
|
||||
v-loading="loading"
|
||||
class="list-table"
|
||||
stripe
|
||||
row-key="id"
|
||||
:empty-text="loading ? '正在加载…' : loadError ? '数据加载失败' : '暂无符合条件的单据'"
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<el-table-column
|
||||
v-if="assignment"
|
||||
type="selection"
|
||||
min-width="48"
|
||||
align="center"
|
||||
header-align="center"
|
||||
fixed
|
||||
/>
|
||||
<el-table-column
|
||||
type="index"
|
||||
label="序号"
|
||||
@@ -151,26 +177,26 @@
|
||||
>
|
||||
<el-form class="form-grid-2" label-position="top">
|
||||
<el-form-item label="原所属项目组">
|
||||
<el-input :model-value="selected.teamName || '未归属'" disabled />
|
||||
<el-input :model-value="originalTeamLabel" disabled />
|
||||
</el-form-item>
|
||||
<el-form-item label="原所属项目">
|
||||
<el-input :model-value="selected.projectName || '未归属'" disabled />
|
||||
<el-input :model-value="originalProjectLabel" disabled />
|
||||
</el-form-item>
|
||||
<el-form-item label="新项目组" required>
|
||||
<ProjectSelect
|
||||
:key="`team-${selected.id}`"
|
||||
:key="`team-${dialogSelectKey}`"
|
||||
team
|
||||
v-model="targetTeamId"
|
||||
:biz-type="selected.bizType"
|
||||
:biz-type="dialogBizType"
|
||||
@update:model-value="onTargetTeamChange"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="新项目" required>
|
||||
<ProjectSelect
|
||||
:key="`project-${selected.id}-${targetTeamId}`"
|
||||
:key="`project-${dialogSelectKey}-${targetTeamId}`"
|
||||
v-model="target"
|
||||
:team-id="targetTeamId"
|
||||
:biz-type="selected.bizType"
|
||||
:biz-type="dialogBizType"
|
||||
:disabled="!targetTeamId"
|
||||
/>
|
||||
</el-form-item>
|
||||
@@ -262,6 +288,7 @@
|
||||
page: 1,
|
||||
pageSize: 20
|
||||
})
|
||||
const tableRef = ref<{ clearSelection?: () => void } | null>(null)
|
||||
const rows = ref<ProjectRecord[]>([]),
|
||||
total = ref(0),
|
||||
statusCounts = ref<Record<string, number>>({}),
|
||||
@@ -273,6 +300,8 @@
|
||||
target = ref(''),
|
||||
reason = ref(''),
|
||||
selected = ref<ProjectRecord>({}),
|
||||
selectedRows = ref<ProjectRecord[]>([]),
|
||||
editTargets = ref<ProjectRecord[]>([]),
|
||||
historyVisible = ref(false),
|
||||
historyRows = ref<ProjectRecord[]>([])
|
||||
const visibleColumns = computed(() =>
|
||||
@@ -283,6 +312,39 @@
|
||||
const keywordHint = computed(() =>
|
||||
query.bizType === 'presign' ? '请输入单据编号' : assignmentKeywordHints[query.bizType]
|
||||
)
|
||||
const dialogBizType = computed(
|
||||
() =>
|
||||
(editTargets.value[0]?.bizType ||
|
||||
selected.value.bizType ||
|
||||
query.bizType) as AssignmentBizType
|
||||
)
|
||||
const dialogSelectKey = computed(() => {
|
||||
if (editTargets.value.length <= 1) {
|
||||
return String(editTargets.value[0]?.id || selected.value.id || 'empty')
|
||||
}
|
||||
const firstId = editTargets.value[0]?.id || ''
|
||||
const lastId = editTargets.value[editTargets.value.length - 1]?.id || ''
|
||||
return `batch-${editTargets.value.length}-${firstId}-${lastId}`
|
||||
})
|
||||
const originalTeamLabel = computed(() => {
|
||||
if (editTargets.value.length <= 1) {
|
||||
return editTargets.value[0]?.teamName || selected.value.teamName || '未归属'
|
||||
}
|
||||
return `共 ${editTargets.value.length} 条`
|
||||
})
|
||||
const originalProjectLabel = computed(() => {
|
||||
if (editTargets.value.length <= 1) {
|
||||
return editTargets.value[0]?.projectName || selected.value.projectName || '未归属'
|
||||
}
|
||||
return `共 ${editTargets.value.length} 条`
|
||||
})
|
||||
function clearSelection() {
|
||||
selectedRows.value = []
|
||||
tableRef.value?.clearSelection?.()
|
||||
}
|
||||
function handleSelectionChange(selection: ProjectRecord[]) {
|
||||
selectedRows.value = selection
|
||||
}
|
||||
let loadVersion = 0
|
||||
function statusLabel(status: string) {
|
||||
return query.bizType === 'presign'
|
||||
@@ -307,6 +369,7 @@
|
||||
loading.value = true
|
||||
loadError.value = false
|
||||
rows.value = []
|
||||
clearSelection()
|
||||
try {
|
||||
const fetchRecords = props.assignment
|
||||
? fetchAssignmentRecords
|
||||
@@ -344,6 +407,7 @@
|
||||
statusCounts.value = {}
|
||||
visible.value = false
|
||||
historyVisible.value = false
|
||||
clearSelection()
|
||||
search()
|
||||
}
|
||||
function switchBusiness(kind: AssignmentBizType) {
|
||||
@@ -360,16 +424,41 @@
|
||||
query.page = page
|
||||
load()
|
||||
}
|
||||
function open(row: ProjectRecord) {
|
||||
selected.value = row
|
||||
function resetDialogForm(targets: ProjectRecord[]) {
|
||||
editTargets.value = targets
|
||||
selected.value = targets[0] || {}
|
||||
targetTeamId.value = ''
|
||||
target.value = ''
|
||||
reason.value = ''
|
||||
visible.value = true
|
||||
}
|
||||
function open(row: ProjectRecord) {
|
||||
resetDialogForm([row])
|
||||
}
|
||||
function openBatch() {
|
||||
if (!selectedRows.value.length) {
|
||||
ElMessage.warning('请先选择要调整的记录')
|
||||
return
|
||||
}
|
||||
resetDialogForm([...selectedRows.value])
|
||||
}
|
||||
function onTargetTeamChange() {
|
||||
target.value = ''
|
||||
}
|
||||
async function assignOne(row: ProjectRecord, projectId: string, assignReason: string) {
|
||||
const preview = await previewAssignment({
|
||||
bizType: row.bizType,
|
||||
id: row.id,
|
||||
projectId
|
||||
})
|
||||
await saveAssignment({
|
||||
bizType: row.bizType,
|
||||
id: row.id,
|
||||
projectId,
|
||||
reason: assignReason,
|
||||
expectedAssignments: assignmentSnapshot(preview.records)
|
||||
})
|
||||
}
|
||||
async function commit() {
|
||||
if (!targetTeamId.value) {
|
||||
ElMessage.warning('请选择新项目组')
|
||||
@@ -383,33 +472,45 @@
|
||||
ElMessage.warning('请填写调整原因')
|
||||
return
|
||||
}
|
||||
const targets = editTargets.value.length ? [...editTargets.value] : [selected.value]
|
||||
if (!targets.length || !targets[0]?.id) {
|
||||
ElMessage.warning('请选择要调整的记录')
|
||||
return
|
||||
}
|
||||
busy.value = true
|
||||
const commitTarget = target.value
|
||||
const commitRecord = selected.value
|
||||
const commitReason = reason.value.trim()
|
||||
const commitTargets = targets
|
||||
let successCount = 0
|
||||
let failCount = 0
|
||||
try {
|
||||
const preview = await previewAssignment({
|
||||
bizType: selected.value.bizType,
|
||||
id: selected.value.id,
|
||||
projectId: target.value
|
||||
})
|
||||
if (selected.value !== commitRecord || target.value !== commitTarget || !visible.value) {
|
||||
for (const row of commitTargets) {
|
||||
if (target.value !== commitTarget || !visible.value) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
await assignOne(row, commitTarget, commitReason)
|
||||
successCount += 1
|
||||
} catch {
|
||||
failCount += 1
|
||||
// API layer already surfaces the conflict / validation message.
|
||||
}
|
||||
}
|
||||
if (target.value !== commitTarget || !visible.value) {
|
||||
return
|
||||
}
|
||||
await saveAssignment({
|
||||
bizType: selected.value.bizType,
|
||||
id: selected.value.id,
|
||||
projectId: target.value,
|
||||
reason: reason.value.trim(),
|
||||
expectedAssignments: assignmentSnapshot(preview.records)
|
||||
})
|
||||
if (selected.value !== commitRecord || target.value !== commitTarget || !visible.value) {
|
||||
return
|
||||
if (successCount > 0) {
|
||||
visible.value = false
|
||||
clearSelection()
|
||||
if (failCount === 0) {
|
||||
ElMessage.success(
|
||||
commitTargets.length > 1 ? `已调整 ${successCount} 条归属` : '归属已调整'
|
||||
)
|
||||
} else {
|
||||
ElMessage.warning(`成功 ${successCount} 条,失败 ${failCount} 条`)
|
||||
}
|
||||
await load()
|
||||
}
|
||||
visible.value = false
|
||||
ElMessage.success('归属已调整')
|
||||
await load()
|
||||
} catch {
|
||||
// API layer already surfaces the conflict / validation message.
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user