Compact disposal preview and add select all
This commit is contained in:
parent
08484c1058
commit
994643629e
@ -59,18 +59,8 @@
|
||||
<p v-if="errorMessage" ref="dialogError" class="disposal-feedback text-sm text-status-error" role="alert" tabindex="-1">{{ errorMessage }}</p>
|
||||
|
||||
<div v-if="preview" class="disposal-review" :class="{ 'disposal-review--with-fields': eligibleCandidates.length }">
|
||||
<section ref="previewSection" class="flex min-w-0 flex-col gap-3" aria-label="资产清单" tabindex="-1">
|
||||
<label v-if="autoReturnCandidates.length" class="flex min-h-11 cursor-pointer items-center gap-2 text-sm text-text-primary">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="autoReturnEnabled"
|
||||
:disabled="busy"
|
||||
class="shrink-0 rounded border-border-hover bg-bg-elevated text-accent-primary accent-accent-primary focus:ring-accent-primary focus:ring-offset-bg-secondary"
|
||||
@change="changeAutoReturn"
|
||||
>
|
||||
自动归还所选在借资产
|
||||
</label>
|
||||
<div v-if="blockedCandidates.length || showBulkActions" class="disposal-preview-tools">
|
||||
<section ref="previewSection" class="flex min-w-0 flex-col gap-2" aria-label="资产清单" tabindex="-1">
|
||||
<div v-if="eligibleCandidates.length || blockedCandidates.length" class="disposal-preview-tools">
|
||||
<div v-if="blockedCandidates.length && eligibleCandidates.length" class="segmented-toggle disposal-scope" role="group" aria-label="资产状态">
|
||||
<button
|
||||
type="button"
|
||||
@ -92,25 +82,33 @@
|
||||
</button>
|
||||
</div>
|
||||
<p v-else-if="blockedCandidates.length" class="text-sm text-text-secondary">不可申请 {{ blockedCandidates.length }} 项</p>
|
||||
<div v-if="showBulkActions" class="ml-auto flex flex-wrap gap-1">
|
||||
<button
|
||||
v-if="standaloneCandidates.length"
|
||||
type="button"
|
||||
class="btn-secondary disposal-quiet-button"
|
||||
<label v-if="autoReturnCandidates.length" class="disposal-toolbar-choice">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="autoReturnEnabled"
|
||||
:disabled="busy"
|
||||
@click="selectStandalone"
|
||||
aria-label="自动归还所选在借资产"
|
||||
class="shrink-0 rounded border-border-hover bg-bg-elevated text-accent-primary accent-accent-primary focus:ring-accent-primary focus:ring-offset-bg-secondary"
|
||||
@change="changeAutoReturn"
|
||||
>
|
||||
选中独立资产
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-secondary disposal-quiet-button"
|
||||
:disabled="busy || !selectedCandidates.length"
|
||||
@click="selectedIds = []"
|
||||
自动归还
|
||||
</label>
|
||||
<label
|
||||
v-if="previewScope === 'eligible' && eligibleCandidates.length"
|
||||
class="disposal-toolbar-choice"
|
||||
:class="{ 'ml-auto': blockedCandidates.length || autoReturnCandidates.length }"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="allEligibleSelected"
|
||||
:indeterminate.prop="selectedCandidates.length > 0 && !allEligibleSelected"
|
||||
:disabled="busy"
|
||||
aria-label="全选可申请资产"
|
||||
class="shrink-0 rounded border-border-hover bg-bg-elevated text-accent-primary accent-accent-primary focus:ring-accent-primary focus:ring-offset-bg-secondary"
|
||||
@change="changeAllEligible"
|
||||
>
|
||||
清空
|
||||
</button>
|
||||
</div>
|
||||
全选
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<details v-if="preview.duplicate_codes.length" class="text-sm text-text-secondary">
|
||||
@ -279,7 +277,7 @@ const selectedIds = ref<number[]>([])
|
||||
const expandedCodes = ref(new Set<string>())
|
||||
const previewScope = ref<'eligible' | 'blocked'>('eligible')
|
||||
const previewPage = ref(1)
|
||||
const previewPageSize = 8
|
||||
const previewPageSize = 12
|
||||
const reason = ref('')
|
||||
const method = ref('报废')
|
||||
const notes = ref('')
|
||||
@ -307,10 +305,6 @@ const autoReturnCandidates = computed(() => (preview.value?.candidates || []).fi
|
||||
))
|
||||
const eligibleCandidates = computed(() => (preview.value?.candidates || []).filter(canApply))
|
||||
const blockedCandidates = computed(() => (preview.value?.candidates || []).filter((candidate) => !canApply(candidate)))
|
||||
const standaloneCandidates = computed(() => eligibleCandidates.value.filter((candidate) =>
|
||||
candidate.items.length === 1 && !candidate.auto_return_token
|
||||
))
|
||||
const showBulkActions = computed(() => previewScope.value === 'eligible' && eligibleCandidates.value.length > previewPageSize)
|
||||
const visibleCandidates = computed(() => previewScope.value === 'eligible' ? eligibleCandidates.value : blockedCandidates.value)
|
||||
const previewPageCount = computed(() => Math.max(1, Math.ceil(visibleCandidates.value.length / previewPageSize)))
|
||||
const pageCandidates = computed(() => {
|
||||
@ -323,6 +317,8 @@ const selectedCandidates = computed(() => {
|
||||
.filter((candidate) => selected.has(candidate.equipment_id))
|
||||
.map((candidate) => [candidate.equipment_id, candidate])).values())
|
||||
})
|
||||
const allEligibleSelected = computed(() => eligibleCandidates.value.length > 0 &&
|
||||
selectedCandidates.value.length === eligibleCandidates.value.length)
|
||||
const selectedQuantity = computed(() => {
|
||||
const quantities = selectedCandidates.value.flatMap((candidate) => candidate.items.map((item) => item.total_quantity))
|
||||
return quantities.every((quantity) => quantity !== undefined)
|
||||
@ -348,6 +344,13 @@ const changeAutoReturn = (event: Event) => {
|
||||
previewPage.value = 1
|
||||
}
|
||||
|
||||
const changeAllEligible = (event: Event) => {
|
||||
if (busy.value) return
|
||||
selectedIds.value = (event.currentTarget as HTMLInputElement).checked
|
||||
? eligibleCandidates.value.map((candidate) => candidate.equipment_id)
|
||||
: []
|
||||
}
|
||||
|
||||
const changePreviewPage = (page: number) => {
|
||||
previewPage.value = page
|
||||
void nextTick(() => {
|
||||
@ -370,13 +373,6 @@ const resetPreview = () => {
|
||||
previewScope.value = 'eligible'
|
||||
}
|
||||
|
||||
const selectStandalone = () => {
|
||||
selectedIds.value = Array.from(new Set([
|
||||
...selectedIds.value,
|
||||
...standaloneCandidates.value.map((candidate) => candidate.equipment_id)
|
||||
]))
|
||||
}
|
||||
|
||||
const close = () => {
|
||||
if (submitting.value) return
|
||||
dialogElement.value?.close()
|
||||
@ -395,7 +391,9 @@ const loadPreview = async (params: BatchDisposalPreviewParams) => {
|
||||
if (!response.data) throw new Error('没有读取到报废预览,请重新预览')
|
||||
preview.value = response.data
|
||||
if (!eligibleCandidates.value.length && blockedCandidates.value.length) previewScope.value = 'blocked'
|
||||
selectStandalone()
|
||||
selectedIds.value = eligibleCandidates.value
|
||||
.filter((candidate) => candidate.items.length === 1)
|
||||
.map((candidate) => candidate.equipment_id)
|
||||
void nextTick(() => dialogTitle.value?.focus({ preventScroll: true }))
|
||||
} catch (error) {
|
||||
errorMessage.value = error instanceof Error ? error.message : '预览失败,请重试'
|
||||
@ -583,16 +581,27 @@ onMounted(() => {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.disposal-toolbar-choice {
|
||||
display: inline-flex;
|
||||
flex-shrink: 0;
|
||||
min-height: 44px;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
color: var(--text-primary);
|
||||
font-size: 14px;
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.disposal-scope {
|
||||
gap: var(--space-1);
|
||||
}
|
||||
|
||||
.disposal-scope .segmented-toggle__item {
|
||||
padding-inline: var(--space-3);
|
||||
padding-inline: var(--space-2);
|
||||
}
|
||||
|
||||
.disposal-scope .segmented-toggle__item.is-active {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user