同市易制毒段只校验购买证;同步 Web/H5 表单、额度统计展示与相关回归测试。 Co-authored-by: Cursor <cursoragent@cursor.com>
237 lines
8.4 KiB
Vue
237 lines
8.4 KiB
Vue
<template>
|
||
<main class="mp-h5-list-content mp-plan-cert-list" :class="{ 'mp-cert-has-fab': canEdit }">
|
||
<p v-if="error" class="mp-wv-empty" role="alert">
|
||
{{ error }}
|
||
<button class="mp-wv-btn" type="button" @click="load">重试</button>
|
||
</p>
|
||
<van-loading v-if="loading" />
|
||
<article
|
||
v-for="row in visibleRows"
|
||
:key="row.certType + row.id"
|
||
class="mp-wv-card mp-wv-flat-card"
|
||
@click="open(row)"
|
||
>
|
||
<div class="mp-wv-card__head">
|
||
<div class="mp-cert-card__main">
|
||
<div class="mp-wv-card__no">{{ row.certNo }}</div>
|
||
<span
|
||
class="status-tag mp-cert-kind-tag"
|
||
:class="`status-tag--${certKindMobileTone(row.certType)}`"
|
||
>{{ certKindLabel(row.certType) }}</span
|
||
>
|
||
</div>
|
||
<span class="status-tag" :class="`status-tag--${statusTag(row.status)}`">{{
|
||
statusLabel(row.status)
|
||
}}</span>
|
||
</div>
|
||
<div class="mp-wv-card__kv">
|
||
<div class="mp-wv-card__kv-row"
|
||
><span>销售单位</span><span>{{ salePartyName(row) || '—' }}</span></div
|
||
>
|
||
<div class="mp-wv-card__kv-row"
|
||
><span>购买单位</span><span>{{ buyPartyName(row) || '—' }}</span></div
|
||
>
|
||
<div class="mp-wv-card__kv-row"
|
||
><span>有效次数</span><span>{{ row.validUseText || '—' }}</span></div
|
||
>
|
||
<div class="mp-wv-card__kv-row">
|
||
<span>是否预警</span>
|
||
<span v-if="warningText(row)" class="status-tag status-tag--danger">{{
|
||
warningText(row)
|
||
}}</span>
|
||
<span v-else>—</span>
|
||
</div>
|
||
<div class="mp-wv-card__kv-row"
|
||
><span>品名</span><span>{{ row.productNameOnCert || '—' }}</span></div
|
||
>
|
||
<div class="mp-wv-card__kv-row">
|
||
<span>数量</span><span>{{ qty(row.totalQty) }} {{ unit(row.quantityUnit) }}</span>
|
||
</div>
|
||
<div class="mp-wv-card__kv-row">
|
||
<span>可用余额</span><span>{{ qty(row.availableQty) }} {{ unit(row.quantityUnit) }}</span>
|
||
</div>
|
||
<div class="mp-wv-card__kv-row"
|
||
><span>上传时间</span><span>{{ uploadTime(row.createTime) }}</span></div
|
||
>
|
||
</div>
|
||
<div class="mp-wv-card-actions" @click.stop>
|
||
<button class="mp-wv-btn" type="button" @click="open(row)">查看</button>
|
||
<button v-if="canEdit" class="mp-wv-btn mp-wv-btn--primary" type="button" @click="edit(row)"
|
||
>编辑</button
|
||
>
|
||
<button
|
||
v-if="canEdit && row.status !== 'void' && row.status !== 'closed'"
|
||
class="mp-wv-btn"
|
||
type="button"
|
||
@click="confirmRow = row"
|
||
>
|
||
{{ row.openingConfirmed ? '复核' : '期初确认' }}
|
||
</button>
|
||
</div>
|
||
</article>
|
||
<van-empty v-if="!loading && !error && !visibleRows.length" description="暂无证件" />
|
||
<ArchiveForm
|
||
v-if="editor.open"
|
||
popup
|
||
:model-kind="editor.kind"
|
||
:model-id="editor.id"
|
||
@close="editor.open = false"
|
||
@saved="load"
|
||
/>
|
||
<CertConfirmSheet :row="confirmRow" @close="confirmRow = null" @saved="load" />
|
||
<template v-if="canEdit">
|
||
<div class="mp-wv-speed-mask" :class="{ open: speedOpen }" @click="speedOpen = false" />
|
||
<div class="mp-wv-speed-dial" :class="{ open: speedOpen }">
|
||
<div v-if="createActions.length > 1" class="mp-wv-speed-menu">
|
||
<button
|
||
v-if="createActions.includes('transport')"
|
||
class="mp-wv-speed-item"
|
||
type="button"
|
||
@click="create('transport')"
|
||
>
|
||
新增运输证
|
||
</button>
|
||
<button class="mp-wv-speed-item primary" type="button" @click="create('purchase')"
|
||
>新增购买证</button
|
||
>
|
||
</div>
|
||
<button class="mp-wv-speed-main" type="button" aria-label="新增证件" @click="onCreate"
|
||
>+</button
|
||
>
|
||
</div>
|
||
</template>
|
||
</main>
|
||
</template>
|
||
<script setup lang="ts">
|
||
import { fetchGetMenuCodes } from '@/api/auth'
|
||
import { quotaCertApi, type CertType, type QuotaCert } from '@/api/pl/quota-cert'
|
||
import ArchiveForm from './archive-form.vue'
|
||
import CertConfirmSheet from './CertConfirmSheet.vue'
|
||
import { formatDateTime } from '@/utils/format'
|
||
import { formatCertQty } from '@/views/pl/quota-cert/model'
|
||
import {
|
||
buyPartyName,
|
||
certKindLabel,
|
||
certKindMobileTone,
|
||
compareCertUploadTime,
|
||
expiryWarning,
|
||
salePartyName
|
||
} from '@/views/pl/quota-cert/cert-list-face'
|
||
import { useDictStore } from '@/store/modules/dict'
|
||
import { getProductUnitLabel } from '@/utils/crm-product-display'
|
||
import { certStatusLabels } from './face-model'
|
||
|
||
const props = defineProps<{
|
||
keyword: string
|
||
kind: string
|
||
status: string
|
||
expiringSoon?: boolean
|
||
}>()
|
||
const emit = defineEmits<{ 'expiring-count': [count: number] }>()
|
||
const router = useRouter()
|
||
const loading = ref(false)
|
||
const canEdit = ref(false)
|
||
const error = ref('')
|
||
const confirmRow = ref<QuotaCert | null>(null)
|
||
const speedOpen = ref(false)
|
||
const editor = reactive({ open: false, kind: 'purchase' as CertType, id: '' })
|
||
const createActions = computed(() => {
|
||
const actions: CertType[] = []
|
||
if (!props.kind || props.kind === 'purchase') actions.push('purchase')
|
||
if (!props.kind || props.kind === 'transport') actions.push('transport')
|
||
return actions
|
||
})
|
||
const rows = ref<QuotaCert[]>([])
|
||
const visibleRows = computed(() =>
|
||
rows.value.filter((row) => {
|
||
if (props.kind && row.certType !== props.kind) return false
|
||
return !props.expiringSoon || Boolean(expiryWarning(row.validTo))
|
||
})
|
||
)
|
||
const expiringCount = computed(
|
||
() => rows.value.filter((row) => expiryWarning(row.validTo)).length
|
||
)
|
||
watch(expiringCount, (count) => emit('expiring-count', count), { immediate: true })
|
||
let epoch = 0
|
||
|
||
function statusLabel(value: string) {
|
||
return certStatusLabels[value] || value || '—'
|
||
}
|
||
function statusTag(value: string) {
|
||
if (value === 'active') return 'success'
|
||
if (value === 'void') return 'danger'
|
||
if (value === 'suspended' || value === 'closed') return 'warning'
|
||
return 'info'
|
||
}
|
||
function warningText(row: QuotaCert) {
|
||
return expiryWarning(row.validTo)?.label || ''
|
||
}
|
||
function qty(value: unknown) {
|
||
return formatCertQty(value)
|
||
}
|
||
function uploadTime(value?: string | null) {
|
||
return formatDateTime(value) || '—'
|
||
}
|
||
function unit(value?: string | null) {
|
||
const label = getProductUnitLabel(useDictStore().getLabel, value)
|
||
return !label || label === '—' ? '' : label
|
||
}
|
||
function open(row: QuotaCert) {
|
||
void router.push(`/m/pl/plan-cert/archive/${row.certType || 'purchase'}/${row.id}`)
|
||
}
|
||
function editNew(certType: CertType) {
|
||
speedOpen.value = false
|
||
editor.kind = certType
|
||
editor.id = ''
|
||
editor.open = true
|
||
}
|
||
function onCreate() {
|
||
if (createActions.value.length === 1) {
|
||
editNew(createActions.value[0])
|
||
return
|
||
}
|
||
speedOpen.value = !speedOpen.value
|
||
}
|
||
function create(certType: CertType) {
|
||
editNew(certType)
|
||
}
|
||
function edit(row: QuotaCert) {
|
||
editor.kind = row.certType === 'transport' ? 'transport' : 'purchase'
|
||
editor.id = row.id
|
||
editor.open = true
|
||
}
|
||
onMounted(async () => {
|
||
const permissions = await fetchGetMenuCodes().catch(() => null)
|
||
canEdit.value =
|
||
!!permissions?.all ||
|
||
!!permissions?.isSuperAdmin ||
|
||
(permissions?.menuCodes || []).includes('pl:quota-cert:edit')
|
||
})
|
||
async function load() {
|
||
const current = ++epoch
|
||
loading.value = true
|
||
error.value = ''
|
||
try {
|
||
const params = { keyword: props.keyword || undefined, status: props.status || undefined }
|
||
const kinds: CertType[] = props.kind ? [props.kind as CertType] : ['purchase', 'transport']
|
||
const lists = await Promise.all(kinds.map((item) => quotaCertApi.list(item, params)))
|
||
if (current !== epoch) return
|
||
rows.value = kinds
|
||
.flatMap((item, index) =>
|
||
lists[index].map((row) => ({ ...row, certType: row.certType || item }))
|
||
)
|
||
.sort(compareCertUploadTime)
|
||
} catch {
|
||
if (current === epoch) error.value = '证件加载失败,请重试'
|
||
} finally {
|
||
if (current === epoch) loading.value = false
|
||
}
|
||
}
|
||
watch(
|
||
() => [props.keyword, props.kind, props.status].join('\0'),
|
||
() => void load(),
|
||
{ immediate: true }
|
||
)
|
||
</script>
|
||
<style lang="scss" src="./cert-mobile.scss"></style>
|