401 lines
15 KiB
Vue
401 lines
15 KiB
Vue
<template>
|
||
<MpWebviewShell @ready="ready = true">
|
||
<div v-if="ready" class="mp-plan-cert-page">
|
||
<MpBusinessHeader
|
||
v-model:keyword="keyword"
|
||
title="运输证件管理"
|
||
searchable
|
||
:search-placeholder="placeholder"
|
||
search-label="搜索运输证件管理"
|
||
back-label="返回工作台"
|
||
@back="goToMiniWorkbench"
|
||
@search="committed = keyword"
|
||
>
|
||
<template #before-search>
|
||
<van-tabs
|
||
v-if="visibleTabs.length"
|
||
v-model:active="tab"
|
||
class="mp-customer-view-tabs"
|
||
shrink
|
||
:ellipsis="false"
|
||
aria-label="运输证件管理"
|
||
@change="onTab"
|
||
>
|
||
<van-tab
|
||
v-for="item in visibleTabs"
|
||
:key="item.name"
|
||
:name="item.name"
|
||
:title="item.title"
|
||
/>
|
||
</van-tabs>
|
||
</template>
|
||
<template #after-search>
|
||
<div v-if="tab === 'archive'" class="mp-cert-archive-filters">
|
||
<van-dropdown-menu class="mp-customer-dd">
|
||
<van-dropdown-item v-model="archiveKind" :options="kindOptions" />
|
||
<van-dropdown-item v-model="archiveStatus" :options="archiveStatusOptions" />
|
||
</van-dropdown-menu>
|
||
<button
|
||
type="button"
|
||
class="mp-cert-expiry"
|
||
:class="{ 'is-active': expiringSoon }"
|
||
@click="expiringSoon = !expiringSoon"
|
||
>
|
||
近7日到期({{ expiringCount }}个)
|
||
</button>
|
||
</div>
|
||
<van-dropdown-menu v-else-if="tab === 'usage'" class="mp-customer-dd">
|
||
<van-dropdown-item v-model="usageKind" :options="kindOptions" />
|
||
</van-dropdown-menu>
|
||
<van-dropdown-menu v-else-if="tab === 'ready'" class="mp-customer-dd">
|
||
<van-dropdown-item v-model="readyState" :options="readyStateOptions" />
|
||
<van-dropdown-item :title="readyFollowTitle">
|
||
<van-cell
|
||
v-for="option in readyFollowOptions"
|
||
:key="option.value || 'all'"
|
||
clickable
|
||
:title="option.text"
|
||
class="van-dropdown-item__option"
|
||
:class="{ 'van-dropdown-item__option--active': readyFollowActive(option.value) }"
|
||
role="menuitemcheckbox"
|
||
:aria-checked="readyFollowActive(option.value)"
|
||
@click="toggleReadyFollow(option.value)"
|
||
>
|
||
<template v-if="readyFollowActive(option.value)" #right-icon>
|
||
<van-icon name="success" class="van-dropdown-item__icon" />
|
||
</template>
|
||
</van-cell>
|
||
</van-dropdown-item>
|
||
<van-dropdown-item
|
||
ref="readyDateFilter"
|
||
:title="readyDateTitle"
|
||
@open="syncReadyDateDraft"
|
||
>
|
||
<div class="mp-plan-quota-filter">
|
||
<PlanDateField v-model="readyDateFromDraft" label="开始日期" clearable />
|
||
<PlanDateField v-model="readyDateToDraft" label="结束日期" clearable />
|
||
<div class="mp-plan-quota-filter__actions">
|
||
<button class="mp-wv-btn" type="button" @click="clearReadyDate">清除</button>
|
||
<button
|
||
class="mp-wv-btn mp-wv-btn--primary"
|
||
type="button"
|
||
@click="applyReadyDate"
|
||
>
|
||
确定
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</van-dropdown-item>
|
||
</van-dropdown-menu>
|
||
<van-dropdown-menu v-else-if="tab === 'plan'" class="mp-customer-dd">
|
||
<van-dropdown-item v-model="planScope" :options="planScopeOptions" />
|
||
<van-dropdown-item v-model="planStatus" :options="planStatusOptions" />
|
||
<van-dropdown-item ref="planFilter" :title="planFilterTitle" @open="syncPlanFilterDraft">
|
||
<div class="mp-plan-quota-filter">
|
||
<van-field v-model="planPlateDraft" label="车号" placeholder="输入车号" clearable />
|
||
<PlanDateField v-model="planDateFromDraft" label="开始日期" clearable />
|
||
<PlanDateField v-model="planDateToDraft" label="结束日期" clearable />
|
||
<div class="mp-plan-quota-filter__actions">
|
||
<button class="mp-wv-btn" type="button" @click="clearPlanFilter">清除</button>
|
||
<button class="mp-wv-btn mp-wv-btn--primary" type="button" @click="applyPlanFilter">
|
||
确定
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</van-dropdown-item>
|
||
</van-dropdown-menu>
|
||
</template>
|
||
</MpBusinessHeader>
|
||
<van-empty
|
||
v-if="tabsReady && !visibleTabs.length"
|
||
description="没有可使用的运输证件功能"
|
||
/>
|
||
<ArchiveTab
|
||
v-else-if="tabsReady && tab === 'archive'"
|
||
:key="session + committed"
|
||
:keyword="committed"
|
||
:kind="archiveKind"
|
||
:status="archiveStatus"
|
||
:expiring-soon="expiringSoon"
|
||
@expiring-count="expiringCount = $event"
|
||
/>
|
||
<ContractTab
|
||
v-else-if="tabsReady && tab === 'contract'"
|
||
:key="session + committed"
|
||
:keyword="committed"
|
||
/>
|
||
<UsageTab
|
||
v-else-if="tabsReady && tab === 'usage'"
|
||
:key="session + committed"
|
||
:keyword="committed"
|
||
:kind="usageKind"
|
||
/>
|
||
<PlanTab
|
||
v-else-if="tabsReady && tab === 'plan'"
|
||
:key="session + committed"
|
||
:keyword="committed"
|
||
:status="planStatus"
|
||
:license-plate="planPlate"
|
||
:plan-date-from="planDateFrom"
|
||
:plan-date-to="planDateTo"
|
||
:show-all="showAllPlans"
|
||
/>
|
||
<ReadyTab
|
||
v-else-if="tabsReady && tab === 'ready'"
|
||
:key="session + committed"
|
||
:keyword="committed"
|
||
:waived="readyState"
|
||
:follow-status="readyFollowQuery"
|
||
:plan-date-from="readyDateFrom"
|
||
:plan-date-to="readyDateTo"
|
||
/>
|
||
</div>
|
||
</MpWebviewShell>
|
||
</template>
|
||
<script setup lang="ts">
|
||
import MpWebviewShell from '@/layouts/MpWebviewShell.vue'
|
||
import MpBusinessHeader from '@/components/mp/MpBusinessHeader.vue'
|
||
import { fetchGetMenuCodes } from '@/api/auth'
|
||
import { useUserStore } from '@/store/modules/user'
|
||
import { goToMiniWorkbench } from '@/utils/mp-webview'
|
||
import { certReadyDefaultPlanDates } from '@/utils/cert-ready-plan-date'
|
||
import {
|
||
PL_PLAN_CERT_READY_DEFAULT_FOLLOW_STATUSES,
|
||
PL_PLAN_FOLLOW_STATUS_OPTIONS
|
||
} from '@/utils/pl-display'
|
||
import PlanDateField from '../plan/PlanDateField.vue'
|
||
import ArchiveTab from './ArchiveTab.vue'
|
||
import ContractTab from './ContractTab.vue'
|
||
import UsageTab from './UsageTab.vue'
|
||
import PlanTab from './PlanTab.vue'
|
||
import ReadyTab from './ReadyTab.vue'
|
||
import { certStatusLabels } from './face-model'
|
||
import '@/styles/mp-webview.scss'
|
||
import '../../crm/customer/customer.scss'
|
||
import './cert-mobile.scss'
|
||
|
||
const route = useRoute()
|
||
const router = useRouter()
|
||
const user = useUserStore()
|
||
const ready = ref(false)
|
||
const session = ref(0)
|
||
const keyword = ref('')
|
||
const committed = ref('')
|
||
const CERT_TABS = [
|
||
{ name: 'archive', title: '证件建档', perm: 'mini:pl:quota-cert:list' },
|
||
{ name: 'contract', title: '客户用证', perm: 'mini:pl:contract-quota:list' },
|
||
{ name: 'usage', title: '证件用量', perm: 'mini:pl:certificate-usage:list' },
|
||
{ name: 'plan', title: '计划段次用证', perm: 'mini:pl:plan-cert:segment' },
|
||
{ name: 'ready', title: '证书齐备', perm: 'mini:pl:cert-ready:list' }
|
||
] as const
|
||
type CertTabName = (typeof CERT_TABS)[number]['name']
|
||
const tabs = CERT_TABS.map((item) => item.name)
|
||
const tabsReady = ref(false)
|
||
const allowedTabNames = ref<CertTabName[]>([])
|
||
const visibleTabs = computed(() =>
|
||
CERT_TABS.filter((item) => allowedTabNames.value.includes(item.name))
|
||
)
|
||
const tab = ref<CertTabName>(
|
||
tabs.includes(route.query.tab as CertTabName) ? (route.query.tab as CertTabName) : 'archive'
|
||
)
|
||
|
||
function selectAllowedTab() {
|
||
if (!allowedTabNames.value.length) return
|
||
if (allowedTabNames.value.includes(tab.value)) return
|
||
tab.value = allowedTabNames.value[0]
|
||
void router.replace({ query: { ...route.query, tab: tab.value } })
|
||
}
|
||
|
||
async function loadTabPermissions() {
|
||
const permissions = await fetchGetMenuCodes().catch(() => null)
|
||
const allowAll = !!permissions?.all || !!permissions?.isSuperAdmin
|
||
const codes = new Set(permissions?.menuCodes || [])
|
||
allowedTabNames.value = CERT_TABS.filter((item) => allowAll || codes.has(item.perm)).map(
|
||
(item) => item.name
|
||
)
|
||
tabsReady.value = true
|
||
selectAllowedTab()
|
||
}
|
||
|
||
watch(ready, (shown) => {
|
||
if (shown) void loadTabPermissions()
|
||
})
|
||
const archiveKind = ref('')
|
||
const expiringSoon = ref(false)
|
||
const expiringCount = ref(0)
|
||
const usageKind = ref('')
|
||
const archiveStatus = ref('')
|
||
const planStatus = ref('')
|
||
const planScope = ref('')
|
||
const showAllPlans = computed(() => planScope.value === '1')
|
||
const defaultReadyDates = certReadyDefaultPlanDates()
|
||
const readyState = ref('0')
|
||
const readyFollow = ref<string[]>([...PL_PLAN_CERT_READY_DEFAULT_FOLLOW_STATUSES])
|
||
const readyFollowOptions = [
|
||
{ text: '全部跟进状态', value: '' },
|
||
...PL_PLAN_FOLLOW_STATUS_OPTIONS.filter((item) => item.value !== 'cancelled').map((item) => ({
|
||
text: item.label,
|
||
value: item.value
|
||
}))
|
||
]
|
||
const readyFollowQuery = computed(() =>
|
||
readyFollowOptions
|
||
.filter((item) => item.value && readyFollow.value.includes(item.value))
|
||
.map((item) => item.value)
|
||
.join(',')
|
||
)
|
||
const readyFollowTitle = computed(() => {
|
||
const labels = readyFollowOptions
|
||
.filter((item) => item.value && readyFollow.value.includes(item.value))
|
||
.map((item) => item.text)
|
||
if (labels.length === 1) return labels[0]
|
||
if (labels.length > 1) return `${labels[0]}等${labels.length}项`
|
||
return '全部跟进状态'
|
||
})
|
||
function readyFollowActive(value: string) {
|
||
return value ? readyFollow.value.includes(value) : readyFollow.value.length === 0
|
||
}
|
||
function toggleReadyFollow(value: string) {
|
||
if (!value) {
|
||
readyFollow.value = []
|
||
return
|
||
}
|
||
readyFollow.value = readyFollow.value.includes(value)
|
||
? readyFollow.value.filter((item) => item !== value)
|
||
: [...readyFollow.value, value]
|
||
}
|
||
const readyDateFrom = ref(defaultReadyDates.from)
|
||
const readyDateTo = ref(defaultReadyDates.to)
|
||
const readyDateFromDraft = ref(defaultReadyDates.from)
|
||
const readyDateToDraft = ref(defaultReadyDates.to)
|
||
const readyDateFilter = ref<{ toggle: (show?: boolean) => void }>()
|
||
const readyDateTitle = computed(() => {
|
||
if (!readyDateFrom.value && !readyDateTo.value) return '计划日期'
|
||
const short = (value: string) => (value ? value.slice(5) : '')
|
||
return `${short(readyDateFrom.value)} ~ ${short(readyDateTo.value)}`
|
||
})
|
||
function syncReadyDateDraft() {
|
||
readyDateFromDraft.value = readyDateFrom.value
|
||
readyDateToDraft.value = readyDateTo.value
|
||
}
|
||
function clearReadyDate() {
|
||
readyDateFromDraft.value = ''
|
||
readyDateToDraft.value = ''
|
||
readyDateFrom.value = ''
|
||
readyDateTo.value = ''
|
||
readyDateFilter.value?.toggle(false)
|
||
}
|
||
function applyReadyDate() {
|
||
const from = readyDateFromDraft.value
|
||
const to = readyDateToDraft.value
|
||
if (from && to && from > to) {
|
||
ElMessage.warning('计划日期起始不能晚于结束')
|
||
return
|
||
}
|
||
readyDateFrom.value = from
|
||
readyDateTo.value = to
|
||
readyDateFilter.value?.toggle(false)
|
||
}
|
||
const readyStateOptions = [
|
||
{ text: '全部齐备状态', value: '' },
|
||
{ text: '未齐备', value: '0' },
|
||
{ text: '已齐备', value: '1' }
|
||
]
|
||
const planPlate = ref('')
|
||
const planDateFrom = ref('')
|
||
const planDateTo = ref('')
|
||
const planPlateDraft = ref('')
|
||
const planDateFromDraft = ref('')
|
||
const planDateToDraft = ref('')
|
||
const planFilter = ref<{ toggle: (show?: boolean) => void }>()
|
||
const planFilterTitle = computed(() =>
|
||
planPlate.value || planDateFrom.value || planDateTo.value ? '已筛选' : '车号 / 日期'
|
||
)
|
||
function syncPlanFilterDraft() {
|
||
planPlateDraft.value = planPlate.value
|
||
planDateFromDraft.value = planDateFrom.value
|
||
planDateToDraft.value = planDateTo.value
|
||
}
|
||
function clearPlanFilter() {
|
||
planPlateDraft.value = ''
|
||
planDateFromDraft.value = ''
|
||
planDateToDraft.value = ''
|
||
planPlate.value = ''
|
||
planDateFrom.value = ''
|
||
planDateTo.value = ''
|
||
planFilter.value?.toggle(false)
|
||
}
|
||
function applyPlanFilter() {
|
||
const from = planDateFromDraft.value
|
||
const to = planDateToDraft.value
|
||
if (from && to && from > to) {
|
||
ElMessage.warning('计划日期起始不能晚于结束')
|
||
return
|
||
}
|
||
planPlate.value = planPlateDraft.value.trim()
|
||
planDateFrom.value = from
|
||
planDateTo.value = to
|
||
planFilter.value?.toggle(false)
|
||
}
|
||
const planScopeOptions = [
|
||
{ text: '需单位换算', value: '' },
|
||
{ text: '查看全部', value: '1' }
|
||
]
|
||
const kindOptions = [
|
||
{ text: '全部证种', value: '' },
|
||
{ text: '购买证', value: 'purchase' },
|
||
{ text: '运输证', value: 'transport' }
|
||
]
|
||
const archiveStatusOptions = [
|
||
{ text: '全部状态', value: '' },
|
||
...Object.entries(certStatusLabels).map(([value, text]) => ({ text, value }))
|
||
]
|
||
const planStatusOptions = [
|
||
{ text: '全部状态', value: '' },
|
||
{ text: '无需两证', value: 'not_required' },
|
||
{ text: '待配置', value: 'needs_configuration' },
|
||
{ text: '待校验条件与余额', value: 'needs_validation' },
|
||
{ text: '已持有预占', value: 'reserved' },
|
||
{ text: '已核销', value: 'settled' },
|
||
{ text: '结转异常', value: 'exception' }
|
||
]
|
||
const placeholder = computed(() =>
|
||
tab.value === 'contract'
|
||
? '客户名称 / 编号'
|
||
: tab.value === 'plan' || tab.value === 'ready'
|
||
? '计划编号 / 供方 / 需方'
|
||
: '证件编号 / 品名 / 销售或购买单位'
|
||
)
|
||
|
||
function onTab(name: string | number) {
|
||
const next = String(name)
|
||
if (!tabs.includes(next as CertTabName)) return
|
||
keyword.value = ''
|
||
committed.value = ''
|
||
void router.replace({ query: { ...route.query, tab: next } })
|
||
}
|
||
|
||
watch(
|
||
() => JSON.stringify([user.accessToken, user.getUserInfo]),
|
||
() => {
|
||
ready.value = ready.value && !!user.accessToken
|
||
session.value++
|
||
},
|
||
{ flush: 'sync' }
|
||
)
|
||
</script>
|
||
<style scoped>
|
||
.mp-plan-quota-filter {
|
||
padding: 8px 12px 12px;
|
||
background: #fff;
|
||
}
|
||
.mp-plan-quota-filter__actions {
|
||
display: flex;
|
||
gap: 8px;
|
||
margin-top: 12px;
|
||
}
|
||
.mp-plan-quota-filter__actions .mp-wv-btn {
|
||
flex: 1;
|
||
}
|
||
</style>
|