- 新增 user.check 功能用于核对人员是否已有系统账号 - 在 assistant-table-layout.js 中为用户表格添加 checkedIdentity 和 matchResult 字段 - 优化 AssistantConversationService 中的任务记忆和澄清流程 - 支持对草稿特定行进行修改,无需重新填写整张表 - 限制 user.check 操作最大查询数量为 100 条记录 - 实现中断任务恢复机制,保持原始请求上下文 - 添加针对多行数据选择性修改的目标行标识支持
176 lines
22 KiB
Vue
176 lines
22 KiB
Vue
<template>
|
||
<section ref="container" class="assistant-draft" aria-label="业务确认单">
|
||
<div class="assistant-draft-heading"><strong>{{ draft.label || action?.label || '业务确认单' }}</strong><el-tag :type="statusType" size="small">{{ statusLabel }}</el-tag><span>第 {{ draft.version }} 版 · {{ readOnly ? counts.total : rows.length }} 项</span></div>
|
||
<p v-if="draft.description || action?.description" class="assistant-action-description">{{ draft.description || action.description }}</p>
|
||
<el-alert v-if="action?.allowed === false" :title="action.deniedReason || '这项操作可以请管理员协助确认处理方式。'" type="warning" :closable="false" />
|
||
<el-alert v-for="(error, index) in draftErrors.slice(0, showAllErrors ? draftErrors.length : 3)" :key="index" :title="error" type="warning" :closable="false" />
|
||
<el-button v-if="draftErrors.length > 3" link type="primary" size="small" @click="showAllErrors = !showAllErrors">{{ showAllErrors ? '收起提示' : `查看其余 ${draftErrors.length - 3} 条提示` }}</el-button>
|
||
<div class="assistant-draft-tools"><span>{{ readOnly ? '历史确认单,仅供查看。' : '核对下列数据后再确认;红色信息需先处理。' }}</span><div><el-button v-if="canExclude && rows.length > 1" size="small" :disabled="busy || !selectedIds.length" @click="removeRows(selectedIds)">移出选中项</el-button><el-button v-if="editable && bulkFields.length && rows.length > 1" size="small" :disabled="busy" @click="showBulk = !showBulk">{{ showBulk ? '收起批量设置' : '批量设置' }}</el-button><el-button v-if="!wide && fields.length > 5" size="small" @click="$emit('expand')">展开工作区</el-button><el-checkbox v-if="counts.failed" v-model="onlyFailed">仅未成功项</el-checkbox></div></div>
|
||
<assistant-bulk-edit v-if="editable && showBulk && bulkFields.length" :action="draft.action" :draft="draft" :rows="rows" :fields="bulkFields" :selected-ids="selectedIds" :busy="busy" @change="$emit('change', $event)" />
|
||
<assistant-purchase-project v-if="sharedProject && projectField" :action="draft.action" :field="projectField" :rows="rows" :draft="draft" :editable="editable" :busy="busy" @change="$emit('change',$event)" />
|
||
<p v-else-if="purchase && projectField" class="assistant-purchase-note">本确认单存在多个项目或采购批次,保留逐行项目供核对,不会自动合并归属。</p>
|
||
<div v-if="purchase" class="assistant-purchase-navigation"><el-radio-group v-model="fieldGroup" size="small" aria-label="采购确认单字段分组"><el-radio-button v-for="group in purchaseGroups" :key="group.key" :value="group.key">{{ group.label }}</el-radio-button><el-radio-button value="all">全部字段</el-radio-button></el-radio-group><span>{{ selectedIds.length ? `已选 ${selectedIds.length} 项 · ` : '' }}可横向滚动查看各列</span></div>
|
||
<p v-if="purchase && editable && (fieldGroup === 'items' || fieldGroup === 'all')" class="assistant-purchase-note">选择已有物品可带入档案信息;新物品确认后建档。单位、类别须选用业务字典。更正已有物品类别会同步修改物品档案,确认后才保存。</p>
|
||
<p v-if="purchase && fieldGroup === 'batch'" class="assistant-purchase-note">{{ draft.action === 'purchase.update' ? '已有采购的所属批次保持不变;调整批次请使用采购界面的转批次功能。' : '选择已有批次,或填写新批次名称;两者均不填则保存为未组批明细。采购日期以校验预览为准,供应商可稍后补充。' }}</p>
|
||
<el-table ref="draftTable" :data="pageRows" row-key="_rowId" border :max-height="tableHeight" class="assistant-data-table" :row-class-name="rowClass" @selection-change="setSelection">
|
||
<el-table-column v-if="editable && (bulkFields.length || canExclude) && rows.length > 1" type="selection" width="42" :fixed="tableLayout.fixed ? 'left' : false" reserve-selection :selectable="row => !busy && !isSucceeded(row)" />
|
||
<el-table-column label="行" width="50" align="center" :fixed="tableLayout.fixed ? 'left' : false"><template #default="{ row }">{{ row._sourceRow || rows.indexOf(row) + 1 }}</template></el-table-column>
|
||
<el-table-column v-if="purchase && nameField" label="物品名称 *" :width="identityColumn.displayWidth" :min-width="identityColumn.displayMinWidth" :fixed="identityColumn.fixed" :show-overflow-tooltip="false" class-name="business-control-cell">
|
||
<template #default="{ row }"><div class="assistant-purchase-identity">
|
||
<template v-if="editable && !isSucceeded(row) && ['items', 'all'].includes(fieldGroup)"><assistant-field v-if="catalogField" :action="draft.action" :field="catalogField" :row="row" :disabled="busy" @change="event => changeRow(row, event)"/><assistant-field :action="draft.action" :field="nameField" :row="row" :disabled="busy" @change="event => changeRow(row, event)"/></template>
|
||
<template v-else><strong>{{ row.materialName || row._labels?.productId || '未填写物品名称' }}</strong><span v-if="row.materialParams">{{ row.materialParams }}</span></template>
|
||
<el-tag v-if="itemResolution(row)" size="small" :type="itemResolution(row).type">{{ itemResolution(row).label }}</el-tag>
|
||
</div></template>
|
||
</el-table-column>
|
||
<el-table-column v-for="field in displayFields" :key="field.key" :label="field.label + (field.required ? ' *' : '')" :width="field.displayWidth" :min-width="field.displayMinWidth" :fixed="field.fixed" :show-overflow-tooltip="false" class-name="business-control-cell">
|
||
<template #default="{ row }">
|
||
<assistant-authorization-changes v-if="field.type === 'authorizationChanges'" :row="row" :action="draft.action" />
|
||
<assistant-field v-else-if="editable && !isSucceeded(row) && !field.readonly" :action="draft.action" :field="field" :row="row" :disabled="busy || fieldLocked(row, field)" @change="event => changeRow(row, event)" />
|
||
<span v-else class="assistant-readonly-value">{{ fieldValue(row, field) }}</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="校验 / 结果" min-width="200" :show-overflow-tooltip="false" class-name="business-status-cell">
|
||
<template #default="{ row }">
|
||
<div v-if="resultFor(row)" class="assistant-row-result" :class="isSucceeded(row) ? 'is-success' : 'is-error'"><el-icon><CircleCheck v-if="isSucceeded(row)"/><Warning v-else/></el-icon><span>{{ resultFor(row).message || (isSucceeded(row) ? '已完成' : '未完成') }}</span></div>
|
||
<div v-for="(error, index) in rowErrors(row)" :key="index" class="assistant-validation-error">{{ error }}</div>
|
||
<span v-if="!resultFor(row) && (draft.status === 'CANCELLED' || !rowErrors(row).length)" class="assistant-muted">{{ assistantPendingRowLabel(draft) }}</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column v-if="canExclude" label="本次处理" width="116" fixed="right" class-name="business-operation-cell"><template #default="{ row }"><el-button v-if="!isSucceeded(row)" link type="primary" size="small" :disabled="busy" :aria-label="`移出第${row._sourceRow || rows.indexOf(row) + 1}项`" @click="removeRows([row._rowId])">移出本次</el-button></template></el-table-column>
|
||
</el-table>
|
||
<section v-if="canExclude && excludedRows.length" class="assistant-excluded-rows" aria-label="已移出本次确认单的条目"><strong>已移出本次 {{ excludedRows.length }} 项,未删除业务记录</strong><span>恢复或继续调整后,请重新校验预览。</span><div v-for="entry in excludedRows" :key="entry.row._rowId"><span>{{ entry.row._sourceRow ? `原表第${entry.row._sourceRow}项` : `第${entry.index + 1}项` }} · {{ excludedLabel(entry.row) }}</span><el-button link type="primary" size="small" :disabled="busy" :aria-label="`恢复${excludedLabel(entry.row)}`" @click="!busy && emit('restore', entry.row._rowId)">恢复处理</el-button></div></section>
|
||
<assistant-quote-preview v-if="quoteRows.length" :rows="quoteRows" :busy="busy" @skip="event => emit('change', event)" />
|
||
<assistant-reference-price-preview v-if="referencePriceRows.length" :rows="referencePriceRows" />
|
||
<history-preview v-if="historyRows.length" :rows="historyRows"/>
|
||
<template v-if="noticeContentField"><assistant-notice-content v-for="row in pageRows" :key="row._rowId" :row="row" :editable="editable && !isSucceeded(row) && !noticeContentField.readonly" :busy="busy" @change="event => changeRow(row, event)" /></template>
|
||
<template v-if="draft.action === 'notification.send'"><assistant-notification-preview v-for="row in pageRows.filter(row => row._notificationPreview)" :key="row._rowId" :plan="row._notificationPreview" /></template>
|
||
<template v-for="row in pageRows" :key="row._rowId"><assistant-lines v-for="field in tableFields" :key="field.key" :model-value="row[field.key] || []" :action="draft.action" :title="`第 ${rows.indexOf(row) + 1} 项 · ${field.label}`" :editable="editable && !isSucceeded(row)" :busy="busy" @update:model-value="value => changeRow(row, { key: field.key, value })" /></template>
|
||
<div v-if="filteredRows.length > 20" class="assistant-table-pagination"><el-pagination v-model:current-page="page" v-model:page-size="pageSize" :page-sizes="pageSizes" :total="filteredRows.length" layout="total, sizes, prev, pager, next" :pager-count="5" size="small" /></div>
|
||
<p v-if="counts.succeeded || counts.failed || counts.skipped" class="assistant-result-summary">成功 {{ counts.succeeded }} 项<span v-if="counts.skipped">,跳过 {{ counts.skipped }} 项(未修改)</span><span v-if="counts.failed">,未成功 {{ counts.failed }} 项</span>。已处理的记录不会重复执行。</p>
|
||
</section>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { computed, nextTick, ref, watch } from 'vue'
|
||
import { useElementSize } from '@vueuse/core'
|
||
import { CircleCheck, Warning } from '@element-plus/icons-vue'
|
||
import AssistantField from './AssistantField.vue'
|
||
import AssistantLines from './AssistantLines.vue'
|
||
import AssistantQuotePreview from './AssistantQuotePreview.vue'
|
||
import AssistantReferencePricePreview from './AssistantReferencePricePreview.vue'
|
||
import HistoryPreview from '@/components/PurchaseSheet/HistoryPreview.vue'
|
||
import AssistantBulkEdit from './AssistantBulkEdit.vue'
|
||
import AssistantPurchaseProject from './AssistantPurchaseProject.vue'
|
||
import { purchaseProjectState, purchaseDraftBatchCount } from '@/utils/purchase-project'
|
||
import AssistantAuthorizationChanges from './AssistantAuthorizationChanges.vue'
|
||
import AssistantNotificationPreview from './AssistantNotificationPreview.vue'
|
||
import AssistantNoticeContent from './AssistantNoticeContent.vue'
|
||
import { notificationFieldVisible } from '@/utils/assistant-notification'
|
||
import { assistantComparedFields } from '@/utils/assistant-authorization-changes'
|
||
import { assistantDisplayValue, assistantDraftCounts, assistantDraftStatus, assistantPendingRowLabel, assistantReferenceConditions, assistantTextFieldOptions, isAssistantPending } from '@/utils/business-assistant'
|
||
import { isAssistantPurchase, assistantPurchaseGroups, assistantFieldLocked, assistantItemResolution } from '@/utils/assistant-draft-edit'
|
||
import { assistantOrderedColumns, assistantTableLayout, assistantTableMaxHeight } from '@/utils/assistant-table-layout'
|
||
import { assistantQuotationReviewRows } from '@/utils/assistant-quotation-review'
|
||
import { assistantCanExcludeDraftRows, assistantExcludedRowLabel } from '@/utils/assistant-draft-exclusions'
|
||
import { useAssistantPagination } from '@/utils/assistant-pagination'
|
||
const props = defineProps({ draft: { type: Object, required: true }, action: Object, rows: { type: Array, default: () => [] }, excludedRows: { type: Array, default: () => [] }, busy: Boolean, wide: Boolean, readOnly: Boolean })
|
||
const emit = defineEmits(['change', 'expand', 'remove', 'restore'])
|
||
const onlyFailed = ref(false), showAllErrors = ref(false)
|
||
const showBulk = ref(false), selectedIds = ref([]), fieldGroup = ref('items'), draftTable = ref()
|
||
const container = ref()
|
||
const { width } = useElementSize(container)
|
||
const conversationElement = computed(() => container.value?.closest('.business-assistant-conversation'))
|
||
const { height: conversationHeight } = useElementSize(conversationElement)
|
||
const tableHeight = computed(() => assistantTableMaxHeight(conversationHeight.value))
|
||
// A prepared confirmation owns its schema. The catalog may predate a backend
|
||
// release, or postdate a historical card; neither should hide confirmed fields.
|
||
const fields = computed(() => assistantComparedFields(assistantOrderedColumns((props.draft.fields || props.action?.fields || []).filter(field => !field.hidden && field.type !== 'table'), { action: props.draft.action, editing: true }), props.draft.action))
|
||
const purchase = computed(() => isAssistantPurchase(props.draft.action))
|
||
const purchaseGroups = computed(() => assistantPurchaseGroups(fields.value))
|
||
const nameField = computed(() => fields.value.find(field => field.key === 'materialName'))
|
||
const catalogField = computed(() => fields.value.find(field => field.key === 'productId'))
|
||
const projectField = computed(() => fields.value.find(field => field.key === 'projectId'))
|
||
const sharedProject = computed(() => purchase.value && projectField.value && purchaseDraftBatchCount(props.rows) <= 1 && !purchaseProjectState(props.rows).mixed)
|
||
const bulkFields = computed(() => fields.value.filter(field => field.batch && !field.readonly && !(props.draft.action === 'purchase.update' && ['purchaseBatchId', 'batchName', 'supplierId', 'businessDate'].includes(field.key))))
|
||
const noticeContentField = computed(() => ['notice.create', 'notice.update'].includes(props.draft.action) ? fields.value.find(field => field.key === 'noticeContent') : null)
|
||
const visibleFields = computed(() => {
|
||
const source = fields.value.filter(field => !sharedProject.value || field.key !== 'projectId')
|
||
if (noticeContentField.value) return source.filter(field => field.key !== 'noticeContent')
|
||
if (props.draft.action === 'notification.send') return source.filter(field => notificationFieldVisible(field, props.rows))
|
||
if (!purchase.value || !nameField.value) return source
|
||
const groupKeys = new Set(purchaseGroups.value.find(group => group.key === fieldGroup.value)?.keys || [])
|
||
return source.filter(field => !['productId', 'materialName'].includes(field.key) && (field.key === 'id' || fieldGroup.value === 'all' || groupKeys.has(field.key)))
|
||
})
|
||
const tableFields = computed(() => (props.draft.fields || props.action?.fields || []).filter(field => !field.hidden && field.type === 'table'))
|
||
const counts = computed(() => assistantDraftCounts(props.draft))
|
||
const editable = computed(() => !props.readOnly && !props.draft.readOnly && isAssistantPending(props.draft) && !props.draft.permissionDenied && props.action?.allowed !== false)
|
||
const canExclude = computed(() => editable.value && assistantCanExcludeDraftRows(props.draft, props.action))
|
||
const excludedLabel = assistantExcludedRowLabel
|
||
const tableLayout = computed(() => assistantTableLayout(
|
||
(purchase.value && nameField.value ? [nameField.value, ...visibleFields.value] : visibleFields.value)
|
||
.map(field => ({ ...field, multiline: assistantTextFieldOptions(field, props.draft.action).multiline })),
|
||
{ width: width.value - 30, editing: true, leadingWidth: 50 + (canExclude.value ? 116 : 0) + (editable.value && (bulkFields.value.length || canExclude.value) && props.rows.length > 1 ? 42 : 0) }
|
||
))
|
||
const identityColumn = computed(() => tableLayout.value.columns.find(field => field.key === nameField.value?.key) || {})
|
||
const displayFields = computed(() => tableLayout.value.columns.filter(field => !(purchase.value && nameField.value && field.key === nameField.value.key)))
|
||
const statusLabel = computed(() => assistantDraftStatus(props.draft).label)
|
||
const statusType = computed(() => assistantDraftStatus(props.draft).type)
|
||
const draftErrors = computed(() => messages(props.draft.errors))
|
||
const filteredRows = computed(() => onlyFailed.value ? props.rows.filter(row => !isSucceeded(row)) : props.rows)
|
||
const { page, pageSize, pageRows, pageSizes } = useAssistantPagination(filteredRows)
|
||
const quoteRows = computed(() => assistantQuotationReviewRows(pageRows.value, { draft: props.draft, fields: fields.value, editable: editable.value }))
|
||
const referencePriceRows = computed(() => pageRows.value.flatMap(row => row._referencePricePreview || []))
|
||
const historyRows = computed(() => pageRows.value.flatMap(row => row._historyPreview ? [row._historyPreview] : []))
|
||
function messages(errors) { return Array.isArray(errors) ? errors.map(String) : errors && typeof errors === 'object' ? Object.values(errors).flat().map(String) : errors ? [String(errors)] : [] }
|
||
function rowErrors(row) { return messages(row._errors) }
|
||
function resultFor(row) { return (props.draft.results || []).find(result => String(result.rowId) === String(row._rowId)) }
|
||
function isSucceeded(row) { return resultFor(row)?.status === 'SUCCEEDED' }
|
||
function rowClass({ row }) { return isSucceeded(row) ? 'assistant-row-complete' : '' }
|
||
function setSelection(rows) { selectedIds.value = rows.filter(row => !isSucceeded(row)).map(row => row._rowId) }
|
||
function fieldLocked(row, field) { return assistantFieldLocked(props.draft.action, row, field) }
|
||
function itemResolution(row) { return assistantItemResolution(row) }
|
||
function fieldValue(row, field) {
|
||
if (field.ref) {
|
||
const conditions = assistantReferenceConditions(row[field.key], field.ref)
|
||
if (conditions.length) return conditions.map(item => `${item.label}:${item.value}`).join(';')
|
||
return row._labels?.[field.key] || assistantDisplayValue(row[field.key])
|
||
}
|
||
const option = (field.options || []).find(option => String(option.value ?? option.id ?? option) === String(row[field.key]))
|
||
return option?.label || assistantDisplayValue(row[field.key])
|
||
}
|
||
function changeRow(row, event) { emit('change', { rowId: row._rowId, ...event }) }
|
||
function removeRows(ids) { if (!props.busy && canExclude.value) emit('remove', ids) }
|
||
watch(() => props.draft.id, () => { page.value = 1; onlyFailed.value = false; showAllErrors.value = false; selectedIds.value = []; showBulk.value = false; fieldGroup.value = 'items' })
|
||
watch(() => [props.draft.id, props.draft.version], () => { selectedIds.value = []; nextTick(() => draftTable.value?.clearSelection()) })
|
||
watch(() => props.rows.map(row => row._rowId).join(','), () => { selectedIds.value = []; nextTick(() => draftTable.value?.clearSelection()) })
|
||
watch(onlyFailed, () => { page.value = 1 })
|
||
</script>
|
||
|
||
<style scoped>
|
||
.assistant-draft { background: var(--el-bg-color); border: 1px solid var(--el-border-color); border-radius: 4px; padding: 14px; min-width: 0; }
|
||
.assistant-draft-heading { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
|
||
.assistant-draft-heading strong { font-size: 15px; }
|
||
.assistant-draft-heading>span:last-child { font-size: 12px; color: var(--el-text-color-secondary); margin-left: auto; }
|
||
.assistant-action-description { font-size: 13px; line-height: 1.6; margin: 8px 0 12px; color: var(--el-text-color-regular); white-space: pre-wrap; overflow-wrap: anywhere; }
|
||
.assistant-draft .el-alert { margin-bottom: 8px; }
|
||
.assistant-draft-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 0; font-size: 12px; color: var(--el-text-color-secondary); flex-wrap: wrap; }
|
||
.assistant-draft-tools>div { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }.assistant-draft-tools .el-button { margin: 0; }
|
||
.assistant-purchase-navigation { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 12px 0; }.assistant-purchase-navigation .el-radio-group { display: flex; flex-wrap: wrap; row-gap: 6px; }.assistant-purchase-navigation>span { color: var(--el-text-color-secondary); font-size: 12px; }
|
||
.assistant-purchase-note { margin: 8px 0 12px; color: var(--el-text-color-secondary); font-size: 12px; line-height: 1.6; white-space: normal; }
|
||
.assistant-purchase-identity { display: flex; flex-direction: column; align-items: stretch; min-width: 0; gap: 7px; }.assistant-purchase-identity>strong { font-weight: 500; white-space: normal; overflow-wrap: anywhere; }.assistant-purchase-identity>span:not(.el-tag) { font-size: 12px; color: var(--el-text-color-secondary); white-space: normal; overflow-wrap: anywhere; }.assistant-purchase-identity .el-tag { align-self: flex-start; height: auto; line-height: 20px; white-space: normal; }
|
||
.assistant-readonly-value { white-space: normal; overflow-wrap: anywhere; }
|
||
.assistant-row-result { display: flex; gap: 6px; line-height: 1.5; white-space: normal; }
|
||
.assistant-row-result .el-icon { flex-shrink: 0; margin-top: 3px; }
|
||
.assistant-validation-error { font-size: 12px; color: var(--el-color-danger); line-height: 1.5; white-space: normal; overflow-wrap: anywhere; margin-top: 4px; }
|
||
.is-success { color: var(--el-color-success); }.is-error { color: var(--el-color-danger); }.assistant-muted { color: var(--el-text-color-secondary); font-size: 12px; }
|
||
.assistant-table-pagination { display: flex; justify-content: flex-end; margin-top: 10px; }
|
||
.assistant-table-pagination :deep(.el-pagination) { flex-wrap: wrap; row-gap: 6px; }
|
||
.assistant-result-summary { margin: 10px 0 0; font-size: 12px; color: var(--el-text-color-regular); }
|
||
.assistant-data-table :deep(.cell) { white-space: normal !important; text-overflow: clip !important; overflow: visible !important; padding: 7px 9px; }
|
||
.assistant-data-table :deep(.el-input__wrapper), .assistant-data-table :deep(.el-select__wrapper) { min-height: 32px; }
|
||
.assistant-data-table :deep(.el-table__cell) { padding: 0 !important; }
|
||
.assistant-data-table :deep(.assistant-row-complete) { --el-table-tr-bg-color: var(--el-color-success-light-9); }
|
||
.assistant-excluded-rows { margin-top: 12px; padding: 12px; display: flex; flex-direction: column; gap: 6px; background: var(--el-fill-color-light); color: var(--el-text-color-regular); font-size: 12px; }
|
||
.assistant-excluded-rows>div { display: flex; justify-content: space-between; align-items: center; gap: 12px; }.assistant-excluded-rows>div>span { overflow-wrap: anywhere; }
|
||
</style>
|