895 lines
31 KiB
Vue
895 lines
31 KiB
Vue
<template>
|
||
<QuotaHistoryDialog ref="historyDialog" :can-edit="canEdit" @saved="load" />
|
||
<div class="page-container">
|
||
<section class="panel">
|
||
<div class="panel-top"><h2 class="title-bar-heading">{{ mobile ? '购买证与运输证' : '证件建档' }}</h2></div>
|
||
<div class="list-toolbar"
|
||
><div class="list-toolbar-row"
|
||
><el-select v-model="kind" aria-label="证件种类" style="width: 130px"
|
||
><el-option label="购买证" value="purchase" /><el-option
|
||
label="运输证"
|
||
value="transport" /></el-select
|
||
><ListQuickSearchInput
|
||
v-model="keyword"
|
||
placeholder="证件编号"
|
||
@search="search"
|
||
@clear="search" /><el-button v-if="hasActiveFilters || keyword" @click="reset"
|
||
><el-icon><RefreshLeft /></el-icon>清除筛选</el-button
|
||
><span class="list-toolbar-selected">共 {{ filteredRows.length }} 张</span
|
||
><el-button v-if="canEdit" type="primary" @click="edit()"
|
||
><el-icon><Plus /></el-icon>新增证件</el-button
|
||
><el-button @click="scopeDialog?.open()"
|
||
><el-icon><Connection /></el-icon>关联合同产品</el-button
|
||
><ListToolbarEndActions
|
||
:loading="loading"
|
||
:column-defs="listColumnDefs"
|
||
v-model:visible-columns="visibleColumns"
|
||
v-model:check-all="checkAll"
|
||
:is-indeterminate="isIndeterminate"
|
||
@refresh="load"
|
||
@reset-columns="resetToDefault" /></div
|
||
></div>
|
||
<div class="list-body list-wrap">
|
||
<div ref="tableWrapRef" class="table-scroll"
|
||
><ListTable
|
||
ref="tableRef"
|
||
:height="tableHeight"
|
||
table-key="pl-quota-cert"
|
||
v-loading="loading"
|
||
:data="pageRows"
|
||
stripe
|
||
row-key="id"
|
||
class="list-table"
|
||
@row-dblclick="view"
|
||
>
|
||
<el-table-column
|
||
v-for="column in visibleDefs"
|
||
:key="column.prop"
|
||
:prop="column.prop"
|
||
:label="column.label"
|
||
:min-width="column.type === 'text' ? 190 : 140"
|
||
><template #header
|
||
><div class="col-header-with-filter"
|
||
><span class="col-header-with-filter__label">{{ column.label }}</span>
|
||
<ColumnHeaderFilter
|
||
:prop="column.prop"
|
||
:label="column.label"
|
||
:type="column.type"
|
||
:enable-sort="false"
|
||
:options="collectUniqueOptions(column.prop)"
|
||
:is-active="isFilterActive(column.prop)"
|
||
:model-value="filters[column.prop] || null"
|
||
@update:model-value="(v) => setFilterState(column.prop, v)"
|
||
/> </div></template
|
||
><template #default="{ row }"
|
||
><el-link v-if="column.prop === 'certNo'" type="primary" @click="view(row)">{{
|
||
row.certNo
|
||
}}</el-link
|
||
><el-tag
|
||
v-else-if="column.prop === 'status'"
|
||
size="small"
|
||
:type="tagType(row.status)"
|
||
>{{ statusLabels[row.status as keyof typeof statusLabels] }}</el-tag
|
||
><span v-else-if="column.type === 'number'"
|
||
>{{ row[column.prop] }} {{ row.quantityUnit }}</span
|
||
><span v-else>{{ row[column.prop] || '—' }}</span></template
|
||
></el-table-column
|
||
><el-table-column label="操作" min-width="320" fixed="right"
|
||
><template #default="{ row }">
|
||
<el-button v-if="canEdit" size="small" @click="edit(row)"
|
||
><el-icon><Edit /></el-icon>编辑</el-button
|
||
>
|
||
<el-button
|
||
v-if="canEdit && row.status !== 'void'"
|
||
size="small"
|
||
@click="openConfirm(row)"
|
||
><el-icon><Check /></el-icon
|
||
>{{ row.openingConfirmed ? '复核' : '期初确认' }}</el-button
|
||
>
|
||
<el-button size="small" @click="showContracts(row)"
|
||
><el-icon><Connection /></el-icon>关联合同</el-button
|
||
>
|
||
</template></el-table-column
|
||
>
|
||
</ListTable></div
|
||
>
|
||
<div ref="pagerRef" class="pagination list-pager-bar"
|
||
><el-pagination
|
||
v-model:current-page="page"
|
||
:page-size="20"
|
||
:total="filteredRows.length"
|
||
layout="total, prev, pager, next"
|
||
/></div>
|
||
</div>
|
||
</section>
|
||
<el-dialog
|
||
v-model="formVisible"
|
||
:title="editingId ? `编辑${formKind === 'purchase' ? '购买证' : '运输证'}` : '新增证件'"
|
||
width="1200px"
|
||
align-center
|
||
class="dialog-form-layout quota-cert-form-dialog"
|
||
:close-on-click-modal="false"
|
||
:close-on-press-escape="!saving"
|
||
:show-close="!saving"
|
||
>
|
||
<el-form
|
||
:disabled="saving"
|
||
ref="formRef"
|
||
:model="form"
|
||
:rules="rules"
|
||
:validate-on-rule-change="false"
|
||
label-position="top"
|
||
scroll-to-error
|
||
>
|
||
<section class="view-section form-grid-2">
|
||
<el-form-item>
|
||
<template #label><span class="dialog-section-title">建档方式</span></template>
|
||
<el-radio-group v-model="form.entryMode" :disabled="!!editingId || recognizing"
|
||
><el-radio value="manual">手工录入(可后补图片)</el-radio
|
||
><el-radio value="image_parse">图片解析后核对</el-radio></el-radio-group
|
||
></el-form-item
|
||
>
|
||
<el-form-item>
|
||
<template #label><span class="dialog-section-title">证件类型</span></template>
|
||
<el-radio-group
|
||
v-model="selectedFormKind"
|
||
:disabled="!!editingId"
|
||
@change="changeFormKind"
|
||
>
|
||
<el-radio value="purchase">购买证</el-radio>
|
||
<el-radio value="transport">运输证</el-radio>
|
||
</el-radio-group>
|
||
</el-form-item>
|
||
</section>
|
||
<section class="view-section">
|
||
<el-form-item>
|
||
<template #label><span class="dialog-section-title">证件附件</span></template>
|
||
<AttachmentUploadField
|
||
ref="certAttachments"
|
||
:key="editSession"
|
||
:disabled="saving || recognizing"
|
||
v-model="form.attachmentUrls"
|
||
folder="pl/quota-cert"
|
||
:limit="editingId ? 15 : 1"
|
||
accept="image/*,.pdf"
|
||
:hint="
|
||
editingId
|
||
? '支持图片、PDF;每次仅解析一个附件'
|
||
: '支持图片、PDF;每次仅上传并解析一个附件,更换请先删除原附件'
|
||
"
|
||
@update:model-value="edited.add('attachmentUrls')"
|
||
/></el-form-item>
|
||
<template v-if="form.entryMode === 'image_parse' || !!form.attachmentUrls">
|
||
<div class="recognition-actions">
|
||
<el-select
|
||
v-if="editingId && attachmentOptions.length > 1"
|
||
v-model="recognitionImage"
|
||
:disabled="recognizing"
|
||
placeholder="选择一个附件进行解析"
|
||
><el-option
|
||
v-for="url in attachmentOptions"
|
||
:key="url"
|
||
:value="url"
|
||
:label="url.split('/').pop()"
|
||
/></el-select>
|
||
<el-button :loading="recognizing" :disabled="!recognitionImage" @click="recognize"
|
||
><el-icon><Document /></el-icon>解析{{
|
||
formKind === 'purchase' ? '购买证' : '运输证'
|
||
}}</el-button
|
||
>
|
||
</div>
|
||
<p class="form-tip"
|
||
>请核对证号、数量、单位、有效次数和引用关系。解析只补充未编辑的空字段。</p
|
||
>
|
||
</template>
|
||
</section>
|
||
<section class="view-section"
|
||
><h3 class="dialog-section-title">证面信息</h3
|
||
><div class="form-grid-3">
|
||
<el-form-item
|
||
v-for="field in formFields"
|
||
:key="field[0]"
|
||
:label="field[1]"
|
||
:prop="field[0]"
|
||
>
|
||
<el-date-picker
|
||
v-if="isDate(field[0])"
|
||
v-model="form[field[0]]"
|
||
type="date"
|
||
value-format="YYYY-MM-DD"
|
||
@change="edited.add(field[0])"
|
||
/>
|
||
<el-input
|
||
v-else
|
||
v-model="form[field[0]]"
|
||
:placeholder="
|
||
field[0] === 'validUseText' ? '例如:一次有效、多次有效' : `请输入${field[1]}`
|
||
"
|
||
@input="edited.add(field[0])"
|
||
/>
|
||
</el-form-item> </div
|
||
></section>
|
||
<section v-if="formKind === 'transport'" class="view-section">
|
||
<el-form-item label="车牌号(多车共用额度)"
|
||
><el-select
|
||
v-model="form.vehicleNumbersJson"
|
||
multiple
|
||
filterable
|
||
allow-create
|
||
default-first-option
|
||
@change="edited.add('vehicleNumbersJson')"
|
||
/></el-form-item>
|
||
<h3 class="dialog-section-title">证面引用</h3>
|
||
<el-table :data="form.purchaseRefs" row-key="id" stripe>
|
||
<el-table-column label="引用类型" min-width="160"
|
||
><template #default="{ row }"
|
||
><el-select v-model="row.referenceType" @change="edited.add('purchaseRefs')"
|
||
><el-option
|
||
v-for="(label, value) in refLabels"
|
||
:key="value"
|
||
:value="value"
|
||
:label="label" /></el-select></template
|
||
></el-table-column>
|
||
<el-table-column label="引用证号" min-width="160"
|
||
><template #default="{ row }"
|
||
><el-input
|
||
v-model="row.referenceNo"
|
||
@input="edited.add('purchaseRefs')" /></template
|
||
></el-table-column>
|
||
<el-table-column label="对应购买证档案" min-width="200"
|
||
><template #default="{ row }"
|
||
><el-select
|
||
v-model="row.purchaseCertId"
|
||
filterable
|
||
clearable
|
||
@change="edited.add('purchaseRefs')"
|
||
><el-option
|
||
v-for="c in purchases"
|
||
:key="c.id"
|
||
:value="c.id"
|
||
:label="c.certNo" /></el-select></template
|
||
></el-table-column>
|
||
<el-table-column label="操作" min-width="260" fixed="right"
|
||
><template #default="{ $index }"
|
||
><el-button @click="removeReference($index)"
|
||
><el-icon><Delete /></el-icon>移除引用</el-button
|
||
></template
|
||
></el-table-column
|
||
>
|
||
</el-table>
|
||
<el-button @click="addReference"
|
||
><el-icon><Plus /></el-icon>添加引用</el-button
|
||
>
|
||
</section>
|
||
<el-form-item v-if="editingId" label="停止新增使用">
|
||
<el-select v-model="form.status" clearable placeholder="保持当前状态">
|
||
<el-option label="停用(可复核恢复)" value="suspended" />
|
||
<el-option label="作废(不可恢复)" value="void" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="系统备注"
|
||
><el-input v-model="form.remark" type="textarea"
|
||
/></el-form-item>
|
||
</el-form>
|
||
<template #footer
|
||
><el-button :disabled="saving" @click="formVisible = false"
|
||
><el-icon><Close /></el-icon>取消</el-button
|
||
><el-button type="primary" :loading="saving" @click="save"
|
||
><el-icon><Check /></el-icon>保存草稿/修改</el-button
|
||
></template
|
||
>
|
||
</el-dialog>
|
||
<el-dialog
|
||
v-model="detailVisible"
|
||
title="证件详情"
|
||
width="920px"
|
||
align-center
|
||
class="dialog-form-layout"
|
||
>
|
||
<template v-if="detail">
|
||
<el-button @click="historyDialog?.open(kind, detail)"
|
||
><el-icon><Document /></el-icon>额度流水与总量更正</el-button
|
||
>
|
||
<div class="view-hero"
|
||
><h2>{{ detail.certNo }}</h2
|
||
><el-tag :type="tagType(detail.status)">{{ statusLabels[detail.status] }}</el-tag></div
|
||
>
|
||
<section class="view-section"
|
||
><div class="view-kv-grid"
|
||
><dl v-for="field in fields" :key="field[0]" class="view-kv"
|
||
><dt>{{ field[1] }}</dt
|
||
><dd>{{ detail[field[0] as keyof QuotaCert] ?? '—' }}</dd></dl
|
||
></div
|
||
></section
|
||
>
|
||
<section class="view-section"
|
||
><h3>共享额度</h3
|
||
><p v-for="column in qtyColumns" :key="column.key"
|
||
>{{ column.label }}:{{ detail[column.key as keyof QuotaCert] }}
|
||
{{ detail.quantityUnit }}</p
|
||
><AttachmentUploadField :model-value="detail.attachmentUrls || ''" disabled
|
||
/></section>
|
||
<section v-if="kind === 'transport'" class="view-section">
|
||
<h3>车号及证面引用</h3>
|
||
<p>车牌号:{{ detail.vehicleNumbersJson?.join('、') || '未填写' }}</p>
|
||
<el-table :data="detail.purchaseRefs || []" stripe row-key="id">
|
||
<el-table-column label="引用类型" min-width="160"
|
||
><template #default="{ row }"
|
||
><el-tag size="small" type="info">{{
|
||
refLabels[row.referenceType as keyof typeof refLabels]
|
||
}}</el-tag></template
|
||
></el-table-column
|
||
>
|
||
<el-table-column prop="referenceNo" label="证面引用号" min-width="180" />
|
||
<el-table-column label="对应购买证档案" min-width="180"
|
||
><template #default="{ row }">{{
|
||
purchases.find((p) => p.id === row.purchaseCertId)?.certNo ||
|
||
(row.purchaseCertId ? '无查看权限或已失效' : '未关联')
|
||
}}</template></el-table-column
|
||
>
|
||
</el-table>
|
||
</section>
|
||
<section class="view-section"
|
||
><h3>关联的山峡合同</h3
|
||
><el-empty v-if="!linkedContracts.length" description="尚未关联合同" :image-size="64" /><p
|
||
v-for="c in linkedContracts"
|
||
:key="c.id"
|
||
><el-link type="primary" @click="scopeDialog?.open(c.id)"
|
||
>{{ c.contractNo }} · {{ c.contractName }} — 查看适用产品</el-link
|
||
></p
|
||
><el-button v-if="canEdit" @click="scopeDialog?.open()"
|
||
><el-icon><Connection /></el-icon>关联另一合同</el-button
|
||
></section
|
||
>
|
||
</template>
|
||
<template #footer
|
||
><el-button @click="detailVisible = false"
|
||
><el-icon><Close /></el-icon>关闭</el-button
|
||
></template
|
||
>
|
||
</el-dialog>
|
||
<el-dialog
|
||
v-model="confirmVisible"
|
||
:title="confirmRow?.openingConfirmed ? '复核证件' : '期初核对'"
|
||
width="640px"
|
||
align-center
|
||
class="dialog-form-layout"
|
||
>
|
||
<el-form label-position="top">
|
||
<template v-if="!confirmRow?.openingConfirmed"
|
||
><el-form-item label="历史已用量(证面单位)"
|
||
><el-input v-model="opening.usedQty" /></el-form-item
|
||
><el-form-item label="一次有效证是否已有使用记录"
|
||
><el-switch v-model="opening.singleUseConsumed" /></el-form-item
|
||
><el-form-item label="历史来源说明"
|
||
><el-input v-model="opening.sourceNote" type="textarea" /></el-form-item
|
||
><el-form-item label="核对凭据"
|
||
><AttachmentUploadField
|
||
v-model="opening.evidenceUrls"
|
||
folder="pl/quota-cert" /></el-form-item
|
||
></template>
|
||
<el-form-item label="核对说明(必填)"
|
||
><el-input v-model="opening.reason" type="textarea"
|
||
/></el-form-item>
|
||
</el-form>
|
||
<template #footer
|
||
><el-button @click="confirmVisible = false"
|
||
><el-icon><Close /></el-icon>取消</el-button
|
||
><el-button type="primary" :loading="saving" @click="confirm"
|
||
><el-icon><Check /></el-icon>确认启用</el-button
|
||
></template
|
||
>
|
||
</el-dialog>
|
||
<ContractScopeDialog ref="scopeDialog" :can-edit="canEdit" @saved="refreshDetails" />
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { useListTableViewportHeight } from '@/composables/useListTableViewportHeight'
|
||
import ListQuickSearchInput from '@/components/business/list-quick-search-input/index.vue'
|
||
import ListToolbarEndActions from '@/components/business/list-toolbar-end-actions/index.vue'
|
||
import ColumnHeaderFilter from '@/components/business/column-header-filter/index.vue'
|
||
import { usePersistedListColumns } from '@/composables/usePersistedListColumns'
|
||
import {
|
||
useClientColumnFilters,
|
||
type ColumnFilterDef
|
||
} from '@/composables/useClientColumnFilters'
|
||
|
||
import QuotaHistoryDialog from './QuotaHistoryDialog.vue'
|
||
const historyDialog = ref<InstanceType<typeof QuotaHistoryDialog>>()
|
||
import {
|
||
Check,
|
||
Close,
|
||
Connection,
|
||
Delete,
|
||
Document,
|
||
Edit,
|
||
Plus,
|
||
RefreshLeft
|
||
} from '@element-plus/icons-vue'
|
||
import { useUserStore } from '@/store/modules/user'
|
||
import { fetchGetMenuCodes } from '@/api/auth'
|
||
import {
|
||
quotaCertApi,
|
||
type CertType,
|
||
type QuotaCert,
|
||
type ContractOption
|
||
} from '@/api/pl/quota-cert'
|
||
import AttachmentUploadField from '@/components/business/attachment-upload-field/index.vue'
|
||
import ContractScopeDialog from './ContractScopeDialog.vue'
|
||
import {
|
||
commonFields,
|
||
purchaseFields,
|
||
transportFields,
|
||
newCert,
|
||
certPayload,
|
||
mergeCandidates
|
||
} from './model'
|
||
const route = useRoute()
|
||
const kind = ref<CertType>('purchase')
|
||
const formKind = ref<CertType>('purchase')
|
||
const selectedFormKind = ref<CertType>('purchase')
|
||
const keyword = ref(''),
|
||
page = ref(1)
|
||
const rows = ref<QuotaCert[]>([]),
|
||
purchases = ref<QuotaCert[]>([])
|
||
const loading = ref(false),
|
||
saving = ref(false),
|
||
recognizing = ref(false),
|
||
canEdit = ref(false)
|
||
const formVisible = ref(false),
|
||
detailVisible = ref(false),
|
||
confirmVisible = ref(false)
|
||
const form = ref<Record<string, any>>(newCert('purchase'))
|
||
const formRef = ref(),
|
||
editingId = ref(''),
|
||
recognitionImage = ref('')
|
||
const certAttachments = ref<InstanceType<typeof AttachmentUploadField>>()
|
||
const edited = reactive(new Set<string>())
|
||
const detail = ref<QuotaCert>(),
|
||
linkedContracts = ref<ContractOption[]>([]),
|
||
confirmRow = ref<QuotaCert>()
|
||
const scopeDialog = ref<InstanceType<typeof ContractScopeDialog>>()
|
||
const opening = reactive({
|
||
operationId: '',
|
||
usedQty: '0',
|
||
singleUseConsumed: false,
|
||
reason: '',
|
||
sourceNote: '',
|
||
evidenceUrls: ''
|
||
})
|
||
const fields = computed(() => [
|
||
...commonFields,
|
||
...(kind.value === 'purchase' ? purchaseFields : transportFields)
|
||
])
|
||
const formFields = computed(() => [
|
||
...commonFields,
|
||
...(formKind.value === 'purchase' ? purchaseFields : transportFields)
|
||
])
|
||
const attachmentOptions = computed<string[]>(() =>
|
||
(form.value.attachmentUrls || '')
|
||
.split(',')
|
||
.map((url: string) => url.trim())
|
||
.filter(Boolean)
|
||
)
|
||
watch(
|
||
attachmentOptions,
|
||
(urls) => {
|
||
if (urls.length === 1) recognitionImage.value = urls[0]
|
||
else if (!urls.includes(recognitionImage.value)) recognitionImage.value = ''
|
||
},
|
||
{ flush: 'sync' }
|
||
)
|
||
|
||
const statusLabels = { draft: '待核对', active: '已启用', suspended: '已停用', void: '已作废' }
|
||
const refLabels = {
|
||
purchase_permit: '购买许可证',
|
||
purchase_filing: '购买备案证明',
|
||
export_permit: '出口许可证',
|
||
unknown: '待确认'
|
||
}
|
||
const qtyColumns = [
|
||
{ key: 'totalQty', label: '核定量' },
|
||
{ key: 'reservedQty', label: '已预占' },
|
||
{ key: 'usedQty', label: '已使用' },
|
||
{ key: 'availableQty', label: '可用余额' }
|
||
]
|
||
const tagType = (s: string) =>
|
||
s === 'active' ? 'success' : s === 'void' ? 'danger' : s === 'draft' ? 'warning' : 'info'
|
||
const isDate = (key: string) => ['issueDate', 'validFrom', 'validTo'].includes(key)
|
||
const rules = computed(() =>
|
||
Object.fromEntries(
|
||
[
|
||
'certNo',
|
||
'productNameOnCert',
|
||
'totalQty',
|
||
'quantityUnit',
|
||
'validUseText',
|
||
...(formKind.value === 'purchase' ? ['buyerName', 'sellerName'] : ['shipperName'])
|
||
].map((k) => [k, [{ required: true, message: '请填写此项', trigger: 'blur' }]])
|
||
)
|
||
)
|
||
let listEpoch = 0
|
||
let disposed = false
|
||
async function load() {
|
||
if (disposed) return
|
||
const current = ++listEpoch
|
||
loading.value = true
|
||
try {
|
||
const result = await quotaCertApi.list(kind.value)
|
||
if (current !== listEpoch || disposed) return
|
||
rows.value = result
|
||
} finally {
|
||
if (current === listEpoch && !disposed) loading.value = false
|
||
}
|
||
}
|
||
let editSession = 0
|
||
watch(
|
||
formVisible,
|
||
(visible) => {
|
||
if (!visible) {
|
||
editSession++
|
||
recognizing.value = false
|
||
}
|
||
},
|
||
{ flush: 'sync' }
|
||
)
|
||
watch(
|
||
kind,
|
||
() => {
|
||
editSession++
|
||
formVisible.value = false
|
||
detailVisible.value = false
|
||
confirmVisible.value = false
|
||
rows.value = []
|
||
page.value = 1
|
||
void load()
|
||
},
|
||
{ flush: 'sync' }
|
||
)
|
||
async function edit(row?: QuotaCert) {
|
||
if (saving.value) return
|
||
const session = ++editSession
|
||
const targetKind = kind.value
|
||
const value = row
|
||
? certPayload(targetKind, await quotaCertApi.get(targetKind, row.id))
|
||
: newCert(targetKind)
|
||
const options = targetKind === 'transport' ? await quotaCertApi.list('purchase') : []
|
||
if (session !== editSession || kind.value !== targetKind) return
|
||
editingId.value = row?.id || ''
|
||
formKind.value = targetKind
|
||
selectedFormKind.value = targetKind
|
||
edited.clear()
|
||
recognitionImage.value = ''
|
||
form.value = value
|
||
purchases.value = options
|
||
recognizing.value = false
|
||
formVisible.value = true
|
||
}
|
||
async function changeFormKind(value: string | number | boolean | undefined) {
|
||
try {
|
||
if (
|
||
(value !== 'purchase' && value !== 'transport') ||
|
||
value === formKind.value ||
|
||
editingId.value ||
|
||
saving.value
|
||
)
|
||
return
|
||
if (certAttachments.value?.hasUploading()) {
|
||
ElMessage.warning('请等待附件上传完成')
|
||
return
|
||
}
|
||
const session = editSession
|
||
const hasContent =
|
||
formFields.value.some(([key]) => form.value[key] != null && form.value[key] !== '') ||
|
||
form.value.purchaseRefs?.length ||
|
||
form.value.vehicleNumbersJson?.length
|
||
if (hasContent) {
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
'切换证件类型将清空证面信息,保留建档方式、附件和系统备注。是否继续?',
|
||
'切换证件类型',
|
||
{ type: 'warning' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
}
|
||
if (session !== editSession || !formVisible.value || saving.value) return
|
||
const nextSession = ++editSession
|
||
recognizing.value = false
|
||
const { entryMode, attachmentUrls, remark, orderNum } = form.value
|
||
formKind.value = value
|
||
selectedFormKind.value = value
|
||
form.value = { ...newCert(value), entryMode, attachmentUrls, remark, orderNum }
|
||
purchases.value = []
|
||
edited.clear()
|
||
formRef.value?.clearValidate()
|
||
if (value === 'transport') {
|
||
const options = await quotaCertApi.list('purchase')
|
||
if (nextSession === editSession && formVisible.value && formKind.value === value)
|
||
purchases.value = options
|
||
}
|
||
} finally {
|
||
selectedFormKind.value = formKind.value
|
||
}
|
||
}
|
||
async function save() {
|
||
if (saving.value) return
|
||
if (certAttachments.value?.hasUploading()) {
|
||
ElMessage.warning('请等待附件上传完成')
|
||
return
|
||
}
|
||
const session = editSession
|
||
const targetKind = formKind.value
|
||
saving.value = true
|
||
if (!(await formRef.value.validate().catch(() => false)) || session !== editSession) {
|
||
saving.value = false
|
||
return
|
||
}
|
||
try {
|
||
await quotaCertApi.save(
|
||
targetKind,
|
||
certPayload(targetKind, form.value),
|
||
editingId.value || undefined
|
||
)
|
||
formVisible.value = false
|
||
ElMessage.success('证件已保存')
|
||
if (kind.value !== targetKind) kind.value = targetKind
|
||
else await load()
|
||
} finally {
|
||
saving.value = false
|
||
}
|
||
}
|
||
async function recognize() {
|
||
if (recognizing.value || saving.value) return
|
||
if (certAttachments.value?.hasUploading()) {
|
||
ElMessage.warning('请等待附件上传完成')
|
||
return
|
||
}
|
||
if (
|
||
!recognitionImage.value ||
|
||
!attachmentOptions.value.includes(recognitionImage.value) ||
|
||
(!editingId.value && attachmentOptions.value.length !== 1)
|
||
) {
|
||
ElMessage.warning('请选择一个已上传的证件附件')
|
||
return
|
||
}
|
||
const session = editSession,
|
||
targetKind = formKind.value,
|
||
targetImage = recognitionImage.value
|
||
recognizing.value = true
|
||
try {
|
||
const result = await quotaCertApi.recognize(targetKind, targetImage)
|
||
if (
|
||
session !== editSession ||
|
||
!formVisible.value ||
|
||
formKind.value !== targetKind ||
|
||
recognitionImage.value !== targetImage ||
|
||
!(form.value.attachmentUrls || '').split(',').includes(targetImage)
|
||
)
|
||
return
|
||
mergeCandidates(form.value as any, result.candidates, edited)
|
||
await nextTick()
|
||
if (session !== editSession || !formVisible.value) return
|
||
formRef.value?.clearValidate()
|
||
ElMessage.success(
|
||
Object.keys(result.invalidFields).length
|
||
? '部分字段未识别,请手工核对补全'
|
||
: '候选已填入,请核对后保存'
|
||
)
|
||
} finally {
|
||
if (session === editSession) recognizing.value = false
|
||
}
|
||
}
|
||
function addReference() {
|
||
form.value.purchaseRefs.push({
|
||
referenceType: 'unknown',
|
||
referenceNo: '',
|
||
purchaseCertId: null
|
||
})
|
||
edited.add('purchaseRefs')
|
||
}
|
||
function removeReference(index: number) {
|
||
form.value.purchaseRefs.splice(index, 1)
|
||
edited.add('purchaseRefs')
|
||
}
|
||
async function view(row: QuotaCert) {
|
||
if (kind.value === 'transport') purchases.value = await quotaCertApi.list('purchase')
|
||
const [cert, links] = await Promise.all([
|
||
quotaCertApi.get(kind.value, row.id),
|
||
quotaCertApi.certificateContracts(kind.value, row.id)
|
||
])
|
||
detail.value = cert
|
||
linkedContracts.value = links
|
||
detailVisible.value = true
|
||
}
|
||
const showContracts = view
|
||
async function refreshDetails() {
|
||
if (detail.value && detailVisible.value) await view(detail.value)
|
||
}
|
||
function openConfirm(row: QuotaCert) {
|
||
confirmRow.value = row
|
||
Object.assign(opening, {
|
||
operationId: crypto.randomUUID(),
|
||
usedQty: '0',
|
||
singleUseConsumed: false,
|
||
reason: '',
|
||
sourceNote: '',
|
||
evidenceUrls: ''
|
||
})
|
||
confirmVisible.value = true
|
||
}
|
||
async function confirm() {
|
||
if (!confirmRow.value || !opening.reason.trim()) {
|
||
ElMessage.warning('请填写核对说明')
|
||
return
|
||
}
|
||
saving.value = true
|
||
try {
|
||
if (confirmRow.value.openingConfirmed)
|
||
await quotaCertApi.verify(kind.value, confirmRow.value.id, {
|
||
operationId: opening.operationId,
|
||
reason: opening.reason
|
||
})
|
||
else await quotaCertApi.confirm(kind.value, confirmRow.value.id, opening)
|
||
confirmVisible.value = false
|
||
await load()
|
||
} finally {
|
||
saving.value = false
|
||
}
|
||
}
|
||
const user = useUserStore()
|
||
let authEpoch = 0
|
||
async function init() {
|
||
const current = ++authEpoch
|
||
const p = await fetchGetMenuCodes()
|
||
if (current !== authEpoch || disposed) return
|
||
canEdit.value =
|
||
!!p.all || !!p.isSuperAdmin || (p.menuCodes || []).includes('pl:quota-cert:edit')
|
||
await load()
|
||
if (current === authEpoch && !disposed && typeof route.query.contractId === 'string')
|
||
scopeDialog.value?.open(route.query.contractId)
|
||
}
|
||
watch(
|
||
() => JSON.stringify([user.accessToken, user.getUserInfo]),
|
||
() => {
|
||
authEpoch++
|
||
listEpoch++
|
||
rows.value = []
|
||
page.value = 1
|
||
loading.value = false
|
||
canEdit.value = false
|
||
editSession++
|
||
formVisible.value = false
|
||
detailVisible.value = false
|
||
confirmVisible.value = false
|
||
if (user.accessToken) void init()
|
||
},
|
||
{ flush: 'sync' }
|
||
)
|
||
onMounted(init)
|
||
onBeforeUnmount(() => {
|
||
disposed = true
|
||
listEpoch++
|
||
authEpoch++
|
||
})
|
||
|
||
const listColumnDefs: ColumnFilterDef[] = [
|
||
{ prop: 'certNo', label: '证件编号', type: 'text' },
|
||
{ prop: 'productNameOnCert', label: '证面品名', type: 'text' },
|
||
{
|
||
prop: 'status',
|
||
label: '状态',
|
||
type: 'enum',
|
||
enumOptions: Object.entries(statusLabels).map(([value, label]) => ({ value, label }))
|
||
},
|
||
...qtyColumns.map((c) => ({ prop: c.key, label: c.label, type: 'number' as const })),
|
||
{ prop: 'validTo', label: '有效期至', type: 'datetime' }
|
||
]
|
||
const { visibleColumns, checkAll, isIndeterminate, resetToDefault } = usePersistedListColumns(
|
||
'pl-quota-cert-columns-v1',
|
||
listColumnDefs
|
||
)
|
||
const visibleDefs = computed(() =>
|
||
listColumnDefs.filter((c) => visibleColumns.value.includes(c.prop))
|
||
)
|
||
const appliedKeyword = ref('')
|
||
const searchedRows = computed(() =>
|
||
rows.value.filter((row) => String(row.certNo).includes(appliedKeyword.value))
|
||
)
|
||
const {
|
||
filters,
|
||
filteredRows,
|
||
collectUniqueOptions,
|
||
hasActiveFilters,
|
||
setFilterState,
|
||
clearAllFilters,
|
||
clearFilter,
|
||
isFilterActive
|
||
} = useClientColumnFilters(searchedRows, listColumnDefs)
|
||
const pageRows = computed(() => filteredRows.value.slice((page.value - 1) * 20, page.value * 20))
|
||
function search() {
|
||
appliedKeyword.value = keyword.value.trim()
|
||
page.value = 1
|
||
}
|
||
function reset() {
|
||
keyword.value = ''
|
||
appliedKeyword.value = ''
|
||
clearAllFilters()
|
||
page.value = 1
|
||
}
|
||
watch(
|
||
filters,
|
||
() => {
|
||
page.value = 1
|
||
},
|
||
{ deep: true, flush: 'sync' }
|
||
)
|
||
watch(visibleColumns, (next, prev) => {
|
||
prev.filter((p) => !next.includes(p)).forEach(clearFilter)
|
||
})
|
||
watch(
|
||
() => filteredRows.value.length,
|
||
(total) => {
|
||
page.value = Math.min(page.value, Math.max(1, Math.ceil(total / 20)))
|
||
}
|
||
)
|
||
const tableWrapRef = ref<HTMLElement | null>(null)
|
||
const pagerRef = ref<HTMLElement | null>(null)
|
||
const tableRef = ref()
|
||
const { tableHeight } = useListTableViewportHeight({
|
||
tableEl: tableWrapRef,
|
||
pagerEl: pagerRef,
|
||
tableRef
|
||
})
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
.quota-cert-form-dialog {
|
||
max-width: calc(100vw - 40px);
|
||
--dialog-viewport-inset: 50px;
|
||
--dialog-max-height: calc(100vh - 100px);
|
||
|
||
.view-section {
|
||
padding: 0 0 20px;
|
||
}
|
||
|
||
.dialog-section-title {
|
||
margin: 0 0 14px;
|
||
padding-left: 8px;
|
||
border-left: 3px solid var(--section-bar-border-color);
|
||
color: var(--section-bar-title-color);
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
}
|
||
|
||
span.dialog-section-title {
|
||
margin-bottom: 0;
|
||
}
|
||
|
||
.form-grid-2,
|
||
.form-grid-3 {
|
||
.el-form-item {
|
||
min-width: 0;
|
||
margin-bottom: 0;
|
||
}
|
||
}
|
||
|
||
.el-date-editor.el-input {
|
||
width: 100%;
|
||
}
|
||
|
||
.recognition-actions {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 12px;
|
||
|
||
.el-select {
|
||
width: 320px;
|
||
max-width: 100%;
|
||
}
|
||
}
|
||
}
|
||
</style>
|