271 lines
9.1 KiB
Vue
271 lines
9.1 KiB
Vue
<template>
|
||
<main class="mp-h5-list-content mp-plan-cert-list">
|
||
<van-tabs v-model:active="listMode" class="mp-customer-view-tabs" shrink :ellipsis="false">
|
||
<van-tab name="mark" title="待标记齐备" />
|
||
<van-tab name="fulfill" title="已标记待完善" />
|
||
</van-tabs>
|
||
<p class="mp-cert-ready-tip">
|
||
新规则下证书齐备只放行安排;归档前须上传真证并执行「完善并关闭」。旧规则齐备不进待完善列表。
|
||
</p>
|
||
<div v-if="listMode === 'fulfill'" class="mp-cert-ready-actions">
|
||
<button class="mp-wv-btn" type="button" @click="goUpload('purchase')">上传购买证</button>
|
||
<button class="mp-wv-btn" type="button" @click="goUpload('transport')">上传运输证</button>
|
||
<button
|
||
class="mp-wv-btn mp-wv-btn--primary"
|
||
type="button"
|
||
:disabled="!selectedIds.length || batching"
|
||
@click="fulfillBatch"
|
||
>
|
||
{{ batching ? '批量完善中…' : `批量完善并关闭${selectedIds.length ? `(${selectedIds.length})` : ''}` }}
|
||
</button>
|
||
</div>
|
||
<p v-if="error" class="mp-wv-empty" role="alert">
|
||
{{ error }}
|
||
<button class="mp-wv-btn" type="button" @click="reload">重试</button>
|
||
</p>
|
||
<van-list v-model:loading="loading" :finished="finished" finished-text="" @load="load">
|
||
<article v-for="row in rows" :key="row.id" class="mp-wv-card mp-wv-flat-card">
|
||
<div class="mp-wv-card__head">
|
||
<div class="mp-cert-ready-select" v-if="listMode === 'fulfill'">
|
||
<van-checkbox :model-value="selectedIds.includes(row.id)" @click.stop="toggleSelect(row.id)" />
|
||
</div>
|
||
<div>
|
||
<div class="mp-wv-card__no">{{ row.planNo }}</div>
|
||
<div class="mp-wv-card__sub">
|
||
{{ row.licensePlate || '未安排车辆' }} · {{ row.planDate || '未定日期' }}
|
||
</div>
|
||
</div>
|
||
<span
|
||
class="status-tag"
|
||
:class="row.quotaCertWaived ? 'status-tag--success' : 'status-tag--warning'"
|
||
>
|
||
{{
|
||
listMode === 'fulfill'
|
||
? '待完善'
|
||
: row.quotaCertWaived
|
||
? '已齐备'
|
||
: '未齐备'
|
||
}}
|
||
</span>
|
||
</div>
|
||
<div class="mp-wv-card__kv">
|
||
<div class="mp-wv-card__kv-row"><span>易制毒产品</span><span>{{ row.productNames || '—' }}</span></div>
|
||
<div class="mp-wv-card__kv-row"><span>供方</span><span>{{ row.supplierName || '—' }}</span></div>
|
||
<div class="mp-wv-card__kv-row"><span>需方</span><span>{{ row.customerName || '—' }}</span></div>
|
||
<div class="mp-wv-card__kv-row">
|
||
<span>跟进状态</span><span>{{ getPlPlanFollowStatusLabel(row.followStatus || undefined) }}</span>
|
||
</div>
|
||
<div class="mp-wv-card__kv-row">
|
||
<span>确认人</span><span>{{ row.quotaCertWaivedByName || '—' }}</span>
|
||
</div>
|
||
<div class="mp-wv-card__kv-row">
|
||
<span>确认时间</span><span>{{ formatCertReadyTime(row.quotaCertWaivedTime) }}</span>
|
||
</div>
|
||
</div>
|
||
<div
|
||
v-if="listMode === 'mark' && !row.quotaCertWaived"
|
||
class="mp-wv-card-actions mp-wv-card-actions--single"
|
||
>
|
||
<button
|
||
class="mp-wv-btn mp-wv-btn--primary"
|
||
type="button"
|
||
:disabled="markingId === row.id"
|
||
@click="mark(row)"
|
||
>
|
||
{{ markingId === row.id ? '正在确认…' : '证书齐备' }}
|
||
</button>
|
||
</div>
|
||
<div v-else-if="listMode === 'fulfill'" class="mp-wv-card-actions mp-wv-card-actions--single">
|
||
<button
|
||
class="mp-wv-btn mp-wv-btn--primary"
|
||
type="button"
|
||
:disabled="markingId === row.id"
|
||
@click="fulfillOne(row)"
|
||
>
|
||
{{ markingId === row.id ? '正在完善…' : '完善并关闭' }}
|
||
</button>
|
||
</div>
|
||
</article>
|
||
</van-list>
|
||
<van-empty
|
||
v-if="!loading && finished && !error && !rows.length"
|
||
:description="listMode === 'fulfill' ? '暂无待完善证书的计划' : '暂无需要证书齐备的计划'"
|
||
/>
|
||
</main>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { certReadyApi, type CertReadyPlan } from '@/api/pl/quota-cert'
|
||
import { certReadyErrorText, formatCertReadyTime } from '@/utils/pl-quota-cert-waiver'
|
||
import { getPlPlanFollowStatusLabel } from '@/utils/pl-display'
|
||
|
||
const props = defineProps<{
|
||
keyword: string
|
||
waived: string
|
||
followStatus: string
|
||
planDateFrom: string
|
||
planDateTo: string
|
||
}>()
|
||
const router = useRouter()
|
||
const listMode = ref<'mark' | 'fulfill'>('mark')
|
||
const rows = ref<CertReadyPlan[]>([])
|
||
const loading = ref(false)
|
||
const finished = ref(false)
|
||
const error = ref('')
|
||
const page = ref(1)
|
||
const markingId = ref('')
|
||
const batching = ref(false)
|
||
const selectedIds = ref<string[]>([])
|
||
let epoch = 0
|
||
|
||
function reload() {
|
||
epoch++
|
||
page.value = 1
|
||
rows.value = []
|
||
selectedIds.value = []
|
||
loading.value = true
|
||
finished.value = false
|
||
error.value = ''
|
||
void load()
|
||
}
|
||
|
||
async function load() {
|
||
const current = epoch
|
||
loading.value = true
|
||
try {
|
||
const data =
|
||
listMode.value === 'fulfill'
|
||
? await certReadyApi.listPendingFulfill({
|
||
page: page.value,
|
||
pageSize: 20,
|
||
keyword: props.keyword || undefined
|
||
})
|
||
: await certReadyApi.list({
|
||
page: page.value,
|
||
pageSize: 20,
|
||
keyword: props.keyword || undefined,
|
||
waived: props.waived || undefined,
|
||
followStatusIn: props.followStatus || undefined,
|
||
planDateFrom: props.planDateFrom || undefined,
|
||
planDateTo: props.planDateTo || undefined
|
||
})
|
||
if (current !== epoch) return
|
||
const list = data?.list || []
|
||
rows.value = page.value === 1 ? list : rows.value.concat(list)
|
||
finished.value = rows.value.length >= (data?.total || 0) || list.length < 20
|
||
page.value += 1
|
||
} catch (reason) {
|
||
if (current === epoch) {
|
||
error.value = certReadyErrorText(reason, '证书齐备加载失败,请重试')
|
||
finished.value = true
|
||
}
|
||
} finally {
|
||
if (current === epoch) loading.value = false
|
||
}
|
||
}
|
||
|
||
async function mark(row: CertReadyPlan) {
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
'确认后可先安排运输;新规则下归档前仍须到「已标记待完善」上传证件并执行完善并关闭。确认人和时间会记在本行。',
|
||
'标记齐备',
|
||
{ type: 'warning', confirmButtonText: '确认标记', cancelButtonText: '取消' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
markingId.value = row.id
|
||
try {
|
||
await certReadyApi.mark(row.id)
|
||
ElMessage.success('已标记证书齐备')
|
||
reload()
|
||
} catch (reason) {
|
||
ElMessage.error(certReadyErrorText(reason, '标记证书齐备失败'))
|
||
} finally {
|
||
markingId.value = ''
|
||
}
|
||
}
|
||
|
||
async function fulfillOne(row: CertReadyPlan) {
|
||
markingId.value = row.id
|
||
try {
|
||
await certReadyApi.fulfill(row.id)
|
||
ElMessage.success('已完善并关闭')
|
||
reload()
|
||
} catch (reason) {
|
||
ElMessage.error(certReadyErrorText(reason, '完善并关闭失败'))
|
||
} finally {
|
||
markingId.value = ''
|
||
}
|
||
}
|
||
|
||
function toggleSelect(id: string) {
|
||
selectedIds.value = selectedIds.value.includes(id)
|
||
? selectedIds.value.filter((item) => item !== id)
|
||
: selectedIds.value.concat(id)
|
||
}
|
||
|
||
async function fulfillBatch() {
|
||
if (!selectedIds.value.length) return
|
||
batching.value = true
|
||
try {
|
||
const res = await certReadyApi.fulfillBatch(selectedIds.value)
|
||
const failed = (res?.results || []).filter((item) => !item.ok)
|
||
if (failed.length) {
|
||
ElMessage.warning(`部分失败:${failed.map((f) => f.message || f.planId).join(';')}`)
|
||
} else {
|
||
ElMessage.success('批量完善完成')
|
||
}
|
||
reload()
|
||
} catch (reason) {
|
||
ElMessage.error(certReadyErrorText(reason, '批量完善失败'))
|
||
} finally {
|
||
batching.value = false
|
||
}
|
||
}
|
||
|
||
function goUpload(kind: 'purchase' | 'transport') {
|
||
void router.push(`/m/pl/plan-cert/archive/${kind}/create`)
|
||
}
|
||
|
||
watch(listMode, () => reload())
|
||
watch(
|
||
() =>
|
||
[
|
||
props.keyword,
|
||
listMode.value === 'mark' ? props.waived : '',
|
||
listMode.value === 'mark' ? props.followStatus : '',
|
||
listMode.value === 'mark' ? props.planDateFrom : '',
|
||
listMode.value === 'mark' ? props.planDateTo : ''
|
||
].join('\0'),
|
||
() => reload()
|
||
)
|
||
</script>
|
||
|
||
<style scoped>
|
||
.mp-cert-ready-tip {
|
||
margin: 8px 12px 0;
|
||
padding: 10px 12px;
|
||
border-radius: 8px;
|
||
background: #ecfdf5;
|
||
color: #065f46;
|
||
font-size: 12px;
|
||
line-height: 1.5;
|
||
}
|
||
.mp-cert-ready-actions {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 8px;
|
||
margin: 10px 12px 0;
|
||
}
|
||
.mp-cert-ready-select {
|
||
margin-right: 8px;
|
||
display: flex;
|
||
align-items: flex-start;
|
||
padding-top: 2px;
|
||
}
|
||
.mp-wv-card__head {
|
||
align-items: flex-start;
|
||
}
|
||
</style>
|