feat(pl): 实现合同产品用证与额度结转以支持购买证和运输证全流程管理。
This commit is contained in:
1 parent
cb0344498a
commit
fb866c7fa7
104 files changed
+10187
-3833
No files matched your search
@@ -271,10 +271,6 @@
|
||||
label: '送货时间',
|
||||
value: formatMpPlanYmdList(props.plan.deliveryTimes)
|
||||
},
|
||||
hazardCertReady: {
|
||||
label: '证书齐备',
|
||||
value: isHazardCertReady(props.plan) ? '已齐备' : certGapLabel.value
|
||||
},
|
||||
licensePlate: {
|
||||
label: '车牌号',
|
||||
value: formatPlVehiclePlateDisplay(props.plan.licensePlate, props.plan.trailerNo) || '—'
|
||||
|
||||
@@ -1,254 +1,4 @@
|
||||
<template>
|
||||
<MpWebviewShell @ready="init">
|
||||
<main class="cert-module cert-detail-page mp-h5-detail-page">
|
||||
<MpBusinessHeader title="危化品证详情" back-label="返回危化品证列表" @back="back" />
|
||||
<CertDetail
|
||||
v-if="shellReady && userStore.accessToken"
|
||||
:key="'detail-' + recordEpoch"
|
||||
ref="detailRef"
|
||||
:plan-id="id"
|
||||
:can-upload="canUpload"
|
||||
:can-ready="canReady"
|
||||
:can-price="canPrice"
|
||||
:busy="acting"
|
||||
:permission-error="permissionError"
|
||||
:permissions-loaded="permissionsLoaded"
|
||||
@view="openDetail"
|
||||
@upload="openUpload"
|
||||
@ready="setReady"
|
||||
@retry-permissions="loadPermissions"
|
||||
/>
|
||||
<CertUpload
|
||||
v-if="shellReady && userStore.accessToken"
|
||||
:key="'upload-' + recordEpoch"
|
||||
ref="uploadRef"
|
||||
v-model="uploadOpen"
|
||||
:plan-id="id"
|
||||
:permitted="canUpload"
|
||||
@success="saved"
|
||||
/>
|
||||
</main>
|
||||
</MpWebviewShell>
|
||||
</template>
|
||||
|
||||
<template><PlanQuotaPage /></template>
|
||||
<script setup lang="ts">
|
||||
import MpWebviewShell from '@/layouts/MpWebviewShell.vue'
|
||||
import MpBusinessHeader from '@/components/mp/MpBusinessHeader.vue'
|
||||
import { showCrmConfirmDialog } from '@/utils/mp-crm-confirm'
|
||||
import '@/styles/mp-webview.scss'
|
||||
import { fetchGetMenuCodes } from '@/api/auth'
|
||||
import { useUserStore } from '@/store/modules/user'
|
||||
import { planApi, type Plan } from '@/api/pl'
|
||||
import {
|
||||
HAZARD_CERT_READY_CONFIRM_HINT,
|
||||
isHazardCertReady,
|
||||
planHasHazardProducts
|
||||
} from '@/composables/usePlToxicProductCertCheck'
|
||||
import { canEdit } from './model'
|
||||
import CertDetail from './CertDetail.vue'
|
||||
import CertUpload from './CertUpload.vue'
|
||||
import './cert.scss'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const userStore = useUserStore()
|
||||
const id = computed(() => String(route.params.id || ''))
|
||||
const detailRef = ref<InstanceType<typeof CertDetail>>()
|
||||
const uploadRef = ref<InstanceType<typeof CertUpload>>()
|
||||
const shellReady = ref(false)
|
||||
const recordEpoch = ref(0)
|
||||
let disposed = false
|
||||
let recordVersion = 0
|
||||
let operationVersion = 0
|
||||
let permissionVersion = 0
|
||||
let queryVersion = 0
|
||||
const uploadOpen = ref(false)
|
||||
const acting = ref(false)
|
||||
const canUpload = ref(false)
|
||||
const canReady = ref(false)
|
||||
const canPrice = ref(false)
|
||||
const permissionError = ref(false)
|
||||
const permissionsLoaded = ref(false)
|
||||
|
||||
function back() {
|
||||
void router.replace('/m/pl/plan-cert')
|
||||
}
|
||||
|
||||
function openDetail(planId: string) {
|
||||
void router.push(`/m/pl/plan-cert/${planId}`)
|
||||
}
|
||||
|
||||
function openUpload(plan: Plan) {
|
||||
if (
|
||||
!shellReady.value ||
|
||||
disposed ||
|
||||
plan.id !== id.value ||
|
||||
!canUpload.value ||
|
||||
!canEdit(plan) ||
|
||||
acting.value
|
||||
) {
|
||||
ElMessage.warning('无上传权限或该计划不可编辑')
|
||||
return
|
||||
}
|
||||
uploadOpen.value = true
|
||||
}
|
||||
|
||||
async function saved(planId: string) {
|
||||
if (disposed || planId !== id.value) return
|
||||
await detailRef.value?.reload()
|
||||
}
|
||||
|
||||
function invalidateRecord() {
|
||||
recordEpoch.value++
|
||||
recordVersion++
|
||||
operationVersion++
|
||||
queryVersion++
|
||||
// 父路由同步失效,早于 Vue 更新子组件 props / 卸载 keyed 实例。
|
||||
uploadRef.value?.invalidateRecord()
|
||||
detailRef.value?.invalidateRecord()
|
||||
uploadOpen.value = false
|
||||
acting.value = false
|
||||
}
|
||||
|
||||
watch(
|
||||
id,
|
||||
() => {
|
||||
invalidateRecord()
|
||||
if (shellReady.value) void openQueryContract()
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
|
||||
watch(
|
||||
() => JSON.stringify([userStore.accessToken, userStore.info]),
|
||||
() => {
|
||||
invalidateRecord()
|
||||
permissionVersion++
|
||||
canUpload.value = false
|
||||
canReady.value = false
|
||||
canPrice.value = false
|
||||
permissionsLoaded.value = false
|
||||
permissionError.value = false
|
||||
if (shellReady.value && !disposed && userStore.accessToken) {
|
||||
void loadPermissions()
|
||||
void openQueryContract()
|
||||
}
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
disposed = true
|
||||
permissionVersion++
|
||||
invalidateRecord()
|
||||
})
|
||||
|
||||
async function setReady(plan: Plan, ready: boolean) {
|
||||
if (
|
||||
!shellReady.value ||
|
||||
disposed ||
|
||||
plan.id !== id.value ||
|
||||
!canReady.value ||
|
||||
acting.value ||
|
||||
!canEdit(plan)
|
||||
)
|
||||
return
|
||||
const targetId = id.value
|
||||
const version = ++operationVersion
|
||||
const current = () => !disposed && version === operationVersion && targetId === id.value
|
||||
acting.value = true
|
||||
try {
|
||||
const result = await planApi.get(targetId)
|
||||
if (!current() || !canReady.value) return
|
||||
const fresh = (result.data ?? result) as Plan
|
||||
if (!fresh || String(fresh.id || '') !== targetId) throw new Error('计划不存在或已失效')
|
||||
if (!canEdit(fresh) || !planHasHazardProducts(fresh.products)) {
|
||||
ElMessage.warning('该计划当前不可操作')
|
||||
await detailRef.value?.reload()
|
||||
return
|
||||
}
|
||||
if (isHazardCertReady(fresh) === ready) {
|
||||
ElMessage.info(ready ? '证书已齐备' : '证书已取消齐备')
|
||||
await detailRef.value?.reload()
|
||||
return
|
||||
}
|
||||
const message = ready
|
||||
? `${HAZARD_CERT_READY_CONFIRM_HINT}确认后可安排运输,之后仍可补充附件。`
|
||||
: '取消后将无法安排运输。'
|
||||
try {
|
||||
await showCrmConfirmDialog({
|
||||
kind: ready ? 'default' : 'danger',
|
||||
title: ready ? '证书齐备确认' : '取消齐备',
|
||||
message,
|
||||
confirmButtonText: ready ? '确认齐备' : '确认取消'
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!current() || !canReady.value) return
|
||||
await planApi.setHazardCertReady(targetId, ready)
|
||||
if (!current() || !canReady.value) return
|
||||
ElMessage.success(ready ? '证书已标记齐备' : '已取消证书齐备')
|
||||
await detailRef.value?.reload()
|
||||
} catch {
|
||||
if (current()) ElMessage.error('操作失败,请重试')
|
||||
} finally {
|
||||
if (current()) acting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPermissions() {
|
||||
if (disposed || !userStore.accessToken) return
|
||||
const version = ++permissionVersion
|
||||
const current = () => !disposed && version === permissionVersion
|
||||
operationVersion++
|
||||
acting.value = false
|
||||
uploadRef.value?.invalidateRecord()
|
||||
uploadOpen.value = false
|
||||
permissionsLoaded.value = false
|
||||
canUpload.value = false
|
||||
canReady.value = false
|
||||
canPrice.value = false
|
||||
permissionError.value = false
|
||||
try {
|
||||
const permission = await fetchGetMenuCodes()
|
||||
if (!current()) return
|
||||
const all = !!permission?.all || !!permission?.isSuperAdmin
|
||||
canUpload.value = all || (permission?.menuCodes || []).includes('pl:plan-cert:upload')
|
||||
canReady.value = all || (permission?.menuCodes || []).includes('pl:plan-cert:ready')
|
||||
canPrice.value =
|
||||
all || (permission?.menuCodes || []).includes('pl:contract:view-product-price')
|
||||
} catch {
|
||||
if (current()) permissionError.value = true
|
||||
} finally {
|
||||
if (current()) permissionsLoaded.value = true
|
||||
}
|
||||
}
|
||||
|
||||
async function openQueryContract() {
|
||||
if (!shellReady.value || disposed) return
|
||||
const version = ++queryVersion
|
||||
const targetId = id.value
|
||||
const record = recordVersion
|
||||
const contractId = String(route.query.contractId || '')
|
||||
if (!contractId) return
|
||||
await nextTick()
|
||||
if (disposed || record !== recordVersion || version !== queryVersion || targetId !== id.value)
|
||||
return
|
||||
await detailRef.value?.openContract(contractId)
|
||||
}
|
||||
|
||||
async function init() {
|
||||
if (shellReady.value || disposed) return
|
||||
shellReady.value = true
|
||||
const version = recordVersion
|
||||
await loadPermissions()
|
||||
if (disposed || version !== recordVersion) return
|
||||
await openQueryContract()
|
||||
}
|
||||
|
||||
watch(
|
||||
() => route.query.contractId,
|
||||
() => void openQueryContract()
|
||||
)
|
||||
import PlanQuotaPage from './index.vue'
|
||||
</script>
|
||||
@@ -1,650 +1,33 @@
|
||||
<template>
|
||||
<MpWebviewShell @ready="init">
|
||||
<main class="cert-module cert-page mp-plan-cert-list mp-cert-list-touch-scope">
|
||||
<MpBusinessHeader
|
||||
:keyword="keyword"
|
||||
title="危化品证上传"
|
||||
searchable
|
||||
search-placeholder="计划编号 / 供方 / 需方"
|
||||
search-label="搜索计划"
|
||||
back-label="返回工作台"
|
||||
@back="goToMiniWorkbench"
|
||||
@search="search"
|
||||
@update:keyword="onKeywordUpdate"
|
||||
>
|
||||
<template #before-search>
|
||||
<van-tabs
|
||||
:active="tab"
|
||||
class="mp-customer-view-tabs"
|
||||
shrink
|
||||
:ellipsis="false"
|
||||
aria-label="计划分类"
|
||||
@change="changeTab"
|
||||
>
|
||||
<van-tab
|
||||
v-for="item in PL_PLAN_CERT_TABS"
|
||||
:key="item.name"
|
||||
:name="item.name"
|
||||
:title="item.label"
|
||||
/>
|
||||
</van-tabs>
|
||||
</template>
|
||||
<template #after-search>
|
||||
<van-dropdown-menu class="mp-customer-dd">
|
||||
<van-dropdown-item
|
||||
v-model="dateKind"
|
||||
:options="dateDropdownOptions"
|
||||
@change="setDate"
|
||||
/>
|
||||
<van-dropdown-item
|
||||
v-model="readyKind"
|
||||
:options="readyDropdownOptions"
|
||||
@change="setReadyFilter"
|
||||
/>
|
||||
<van-dropdown-item
|
||||
ref="moreDropdown"
|
||||
:title="extraFilterCount > 0 ? '更多·已筛' : '更多'"
|
||||
@open="openMoreFilters"
|
||||
/>
|
||||
</van-dropdown-menu>
|
||||
</template>
|
||||
</MpBusinessHeader>
|
||||
<div class="cert-body">
|
||||
<p v-if="sessionChanged" class="cert-hint" role="alert">
|
||||
登录信息已变更,请重新加载当前会话的数据。
|
||||
<button class="cert-btn" @click="reloadSession">重新加载</button>
|
||||
</p>
|
||||
<p v-if="permissionError" class="cert-hint" role="alert"
|
||||
>操作权限读取失败,暂不可上传或确认齐备。<button
|
||||
class="cert-link"
|
||||
@click="loadPermissions"
|
||||
>重试权限</button
|
||||
></p
|
||||
>
|
||||
<p v-else-if="permissionsLoaded && !canUpload && !canReady" class="cert-hint"
|
||||
>当前仅有查看权限</p
|
||||
>
|
||||
<p v-if="error" class="cert-error" role="alert">{{ error }}</p>
|
||||
<button v-if="error" class="cert-btn" @click="retryLoad">重试加载</button>
|
||||
<div v-if="!loading && !error && !visibleCards.length" class="cert-empty"
|
||||
>暂无符合条件的计划</div
|
||||
>
|
||||
<PlanCard
|
||||
v-for="item in visibleCards"
|
||||
:key="item.plan.id"
|
||||
:plan="planDetails.cardPlan(item.plan)"
|
||||
:rows="item.rows"
|
||||
:can-upload="canUpload"
|
||||
:can-ready="canReady"
|
||||
:busy="acting"
|
||||
:expanded="expandedIds.has(item.plan.id)"
|
||||
:details-ready="!!planDetails.records[item.plan.id]?.plan"
|
||||
:detail-error="planDetails.records[item.plan.id]?.error || ''"
|
||||
@retry="planDetails.ensure(item.plan.id)"
|
||||
@update:expanded="toggleExpanded(item.plan.id, $event)"
|
||||
@view="openDetail"
|
||||
@upload="openUpload"
|
||||
@ready="setReady"
|
||||
@contract="(id) => openContract(item.plan.id, id)"
|
||||
/>
|
||||
<MpListPageSkeleton
|
||||
v-if="loading"
|
||||
variant="body"
|
||||
layout="customer"
|
||||
:card-count="1"
|
||||
:caption="failedMore ? '正在加载更多' : '正在加载计划'"
|
||||
:aria-label="failedMore ? '正在加载更多' : '正在加载计划'"
|
||||
/>
|
||||
<p v-else-if="!error && plans.length" class="cert-total mp-h5-load-hint" role="status">
|
||||
<span>共 {{ total }} 条计划 · 已加载 {{ plans.length }} 条</span>
|
||||
<span v-if="plans.length >= total"> · 已加载全部</span>
|
||||
</p>
|
||||
<div
|
||||
v-if="plans.length < total && !error"
|
||||
ref="loadSentinel"
|
||||
class="mp-h5-load-sentinel"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</div>
|
||||
</main>
|
||||
<CertFilters
|
||||
:key="sessionGeneration"
|
||||
v-model="filtersOpen"
|
||||
:filters="filters"
|
||||
:sort="sort"
|
||||
:context="query()"
|
||||
@apply="applyFilters"
|
||||
/>
|
||||
<CertUpload
|
||||
ref="uploadRef"
|
||||
v-model="uploadOpen"
|
||||
:plan-id="uploadId"
|
||||
:permitted="canUpload"
|
||||
@success="saved"
|
||||
/>
|
||||
</MpWebviewShell>
|
||||
<MpWebviewShell @ready="ready = true"
|
||||
><MpBusinessHeader
|
||||
title="计划用证"
|
||||
back-label="返回工作台"
|
||||
@back="goToMiniWorkbench" /><PlanQuotaList
|
||||
v-if="ready"
|
||||
:key="session"
|
||||
mobile
|
||||
:plan-id="planId"
|
||||
/></MpWebviewShell>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { useListReturnState } from '../../crm/useListReturnState'
|
||||
import { useUserStore } from '@/store/modules/user'
|
||||
import { useMenuStore } from '@/store/modules/menu'
|
||||
import { refreshMenuBadges } from '@/utils/menu-badge-registry'
|
||||
import MpWebviewShell from '@/layouts/MpWebviewShell.vue'
|
||||
import MpBusinessHeader from '@/components/mp/MpBusinessHeader.vue'
|
||||
import MpListPageSkeleton from '@/components/mp/MpListPageSkeleton.vue'
|
||||
import { showCrmConfirmDialog } from '@/utils/mp-crm-confirm'
|
||||
import '@/styles/mp-webview.scss'
|
||||
import '../../crm/customer/customer.scss'
|
||||
import { planApi, type Plan, type PlanListResponse } from '@/api/pl'
|
||||
import { fetchGetMenuCodes } from '@/api/auth'
|
||||
import PlanQuotaList from '@/views/pl/plan-quota/index.vue'
|
||||
import { useUserStore } from '@/store/modules/user'
|
||||
import { goToMiniWorkbench } from '@/utils/mp-webview'
|
||||
import { PL_PLAN_CERT_TABS, PL_PLAN_DEFAULT_FOLLOW_STATUSES } from '@/utils/pl-display'
|
||||
import { plPlanCertColumnFilterDefs } from '@/views/pl/plan-cert/columnFilterDefs'
|
||||
import { useServerColumnFilters } from '@/composables/useServerColumnFilters'
|
||||
import { flattenPlanArchivePairRows } from '@/utils/pl-plan-list-display-rows'
|
||||
import {
|
||||
applyMergedCustomerQueryParams,
|
||||
applyContractSideQueryParams,
|
||||
selectedContractStopKinds,
|
||||
selectedKeywordsFromFilter
|
||||
} from '@/utils/pl-plan-pair-list-query'
|
||||
import {
|
||||
planHasHazardProducts,
|
||||
HAZARD_CERT_READY_CONFIRM_HINT
|
||||
} from '@/composables/usePlToxicProductCertCheck'
|
||||
import { buildQuery, canEdit, readyTargets, dateShortcut } from './model'
|
||||
import CertFilters from './CertFilters.vue'
|
||||
import CertUpload from './CertUpload.vue'
|
||||
import PlanCard from './PlanCard.vue'
|
||||
import { useMobilePlanListDetails } from '../plan/mobileListDetails'
|
||||
import './cert.scss'
|
||||
const userStore = useUserStore()
|
||||
const menuStore = useMenuStore()
|
||||
const sessionScope = () => JSON.stringify([userStore.accessToken, userStore.getUserInfo])
|
||||
async function refreshSidebarBadges() {
|
||||
try {
|
||||
await refreshMenuBadges(menuStore.menuList)
|
||||
} catch {
|
||||
/* badge refresh is best-effort */
|
||||
}
|
||||
}
|
||||
let disposed = false
|
||||
let actionVersion = 0
|
||||
let permissionVersion = 0
|
||||
const tab = ref('cert_incomplete')
|
||||
const keyword = ref('')
|
||||
const appliedKeyword = ref('')
|
||||
const dates = ref<string[]>([])
|
||||
const dateKind = ref('all')
|
||||
const dateOptions = [
|
||||
{ value: 'all', label: '全部日期' },
|
||||
{ value: 'today', label: '今天' },
|
||||
{ value: 'tomorrow', label: '明天' },
|
||||
{ value: 'yesterday', label: '昨天' },
|
||||
{ value: 'week', label: '本周' }
|
||||
]
|
||||
const readyOptions = [
|
||||
{ value: 'all', label: '全部齐备状态' },
|
||||
{ value: '0', label: '未齐备' },
|
||||
{ value: '1', label: '已齐备' }
|
||||
]
|
||||
const { filters, toQueryParams } = useServerColumnFilters(plPlanCertColumnFilterDefs, {
|
||||
initialFilters: { followStatus: { text: '', selected: [...PL_PLAN_DEFAULT_FOLLOW_STATUSES] } }
|
||||
})
|
||||
const sort = reactive({ sortField: '', sortOrder: 'desc' })
|
||||
const readyKind = ref('all')
|
||||
const dateDropdownOptions = computed(() =>
|
||||
dateOptions.map((item) => ({ text: item.label, value: item.value }))
|
||||
)
|
||||
const readyDropdownOptions = computed(() =>
|
||||
readyOptions.map((item) => ({ text: item.label, value: item.value }))
|
||||
)
|
||||
const moreDropdown = ref<{ toggle?: (show?: boolean) => void } | null>(null)
|
||||
const loadSentinel = ref<HTMLElement | null>(null)
|
||||
const extraFilterCount = computed(() => {
|
||||
let count = Object.keys(filters).filter(
|
||||
(key) => !['followStatus', 'planDate', 'hazardCertReady'].includes(key)
|
||||
).length
|
||||
const selectedFollow = (filters.followStatus as any)?.selected || []
|
||||
if (
|
||||
selectedFollow.length !== PL_PLAN_DEFAULT_FOLLOW_STATUSES.length ||
|
||||
selectedFollow.some(
|
||||
(value: string) => !PL_PLAN_DEFAULT_FOLLOW_STATUSES.includes(value as any)
|
||||
)
|
||||
)
|
||||
count++
|
||||
if (sort.sortField) count++
|
||||
return count
|
||||
})
|
||||
const filtersOpen = ref(false)
|
||||
const uploadOpen = ref(false)
|
||||
const uploadId = ref('')
|
||||
const uploadRef = ref<InstanceType<typeof CertUpload> | null>(null)
|
||||
let uploadScope = ''
|
||||
const sessionChanged = ref(false)
|
||||
const sessionGeneration = ref(0)
|
||||
const canUpload = ref(false)
|
||||
const canReady = ref(false)
|
||||
const canPrice = ref(false)
|
||||
const permissionError = ref(false)
|
||||
const permissionsLoaded = ref(false)
|
||||
const plans = ref<Plan[]>([])
|
||||
const page = ref(1)
|
||||
const total = ref(0)
|
||||
const loading = ref(true)
|
||||
const error = ref('')
|
||||
const failedMore = ref(false)
|
||||
const acting = ref(false)
|
||||
let requestVersion = 0
|
||||
const expandedIds = ref(new Set<string>())
|
||||
const hasMore = computed(() => plans.value.length < total.value)
|
||||
const visibleCards = computed(() => {
|
||||
const rows = flattenPlanArchivePairRows(plans.value, {
|
||||
loadCustomerKeywords: selectedKeywordsFromFilter(filters.loadCustomer as any),
|
||||
deliveryCustomerKeywords: selectedKeywordsFromFilter(filters.deliveryCustomer as any),
|
||||
productKeywords: selectedKeywordsFromFilter(filters.productName as any),
|
||||
kinds: selectedContractStopKinds(filters.productContract as any)
|
||||
})
|
||||
return plans.value
|
||||
.map((plan) => ({ plan, rows: rows.filter((row) => row.plan.id === plan.id) }))
|
||||
.filter((item) => item.rows.length)
|
||||
})
|
||||
function query() {
|
||||
const q = buildQuery(
|
||||
tab.value,
|
||||
{ ...toQueryParams(), ...(sort.sortField ? sort : {}) },
|
||||
appliedKeyword.value,
|
||||
dates.value
|
||||
)
|
||||
applyMergedCustomerQueryParams(q)
|
||||
applyContractSideQueryParams(q, filters.productContract as any)
|
||||
return q
|
||||
}
|
||||
function requestKey() {
|
||||
return JSON.stringify([keyword.value, query(), sessionScope()])
|
||||
}
|
||||
const planDetails = useMobilePlanListDetails({
|
||||
scope: requestKey,
|
||||
load: (id) => planApi.get(id, true)
|
||||
})
|
||||
watch(expandedIds, (ids) => {
|
||||
ids.forEach((id) => void planDetails.ensure(id))
|
||||
})
|
||||
async function load(more = false) {
|
||||
if (disposed || (more && loading.value)) return false
|
||||
const v = ++requestVersion
|
||||
const key = requestKey()
|
||||
const params = { ...query() }
|
||||
const current = () => !disposed && v === requestVersion && key === requestKey()
|
||||
const nextPage = more ? page.value + 1 : 1
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
failedMore.value = more
|
||||
if (!more) {
|
||||
planDetails.reset()
|
||||
page.value = 1
|
||||
plans.value = []
|
||||
expandedIds.value = new Set()
|
||||
}
|
||||
try {
|
||||
const res = await planApi.list({ ...params, page: nextPage, pageSize: 20 })
|
||||
if (!current()) return false
|
||||
const data = (res.data ?? res) as PlanListResponse
|
||||
plans.value = more
|
||||
? [...plans.value, ...(data.list || [])].filter(
|
||||
(p, i, all) => all.findIndex((other) => other.id === p.id) === i
|
||||
)
|
||||
: data.list || []
|
||||
total.value = Number(data.total || 0)
|
||||
page.value = nextPage
|
||||
return true
|
||||
} catch {
|
||||
if (current()) error.value = '计划加载失败,请重试'
|
||||
return false
|
||||
} finally {
|
||||
if (current()) loading.value = false
|
||||
}
|
||||
}
|
||||
const filterState = computed({
|
||||
get: () => filters,
|
||||
set: (value) => {
|
||||
Object.keys(filters).forEach((key) => delete filters[key])
|
||||
Object.assign(filters, value)
|
||||
}
|
||||
})
|
||||
const sortState = computed({ get: () => sort, set: (value) => Object.assign(sort, value) })
|
||||
function retryLoad() {
|
||||
return listReturnState.retry(!failedMore.value)
|
||||
}
|
||||
|
||||
const listReturnState = useListReturnState({
|
||||
retryFailedRestore: true,
|
||||
fields: { keyword, appliedKeyword, tab, dates, dateKind, readyKind, filterState, sortState },
|
||||
page,
|
||||
expandedIds,
|
||||
hasMore,
|
||||
queryKey: requestKey,
|
||||
fetchPage: (reset) => load(!reset),
|
||||
restoreExpanded: async (ids) => {
|
||||
const key = requestKey()
|
||||
const version = requestVersion
|
||||
const results = await Promise.all(
|
||||
ids.filter((id) => plans.value.some((plan) => plan.id === id)).map(planDetails.ensure)
|
||||
)
|
||||
if (disposed || key !== requestKey() || version !== requestVersion) return false
|
||||
if (results.some((ok) => !ok)) {
|
||||
error.value = '展开信息恢复失败,请重试'
|
||||
return false
|
||||
}
|
||||
return true
|
||||
},
|
||||
isDetailPath: (path) => /^\/m\/pl\/plan-cert\/[^/]+$/.test(path)
|
||||
})
|
||||
function toggleExpanded(id: string, expanded: boolean) {
|
||||
const next = new Set(expandedIds.value)
|
||||
if (expanded) next.add(id)
|
||||
else next.delete(id)
|
||||
expandedIds.value = next
|
||||
}
|
||||
function search() {
|
||||
if (disposed) return
|
||||
appliedKeyword.value = keyword.value
|
||||
void load()
|
||||
}
|
||||
const scheduleKeywordSearch = useDebounceFn(() => search(), 300)
|
||||
function onKeywordUpdate(value: string) {
|
||||
const cleared = Boolean(keyword.value.trim()) && !value.trim()
|
||||
keyword.value = value
|
||||
if (cleared) {
|
||||
search()
|
||||
return
|
||||
}
|
||||
void scheduleKeywordSearch()
|
||||
}
|
||||
useIntersectionObserver(
|
||||
loadSentinel,
|
||||
([entry]) => {
|
||||
if (
|
||||
!entry?.isIntersecting ||
|
||||
loading.value ||
|
||||
error.value ||
|
||||
listReturnState.restoring.value ||
|
||||
plans.value.length >= total.value
|
||||
)
|
||||
return
|
||||
void load(true)
|
||||
},
|
||||
{ rootMargin: '160px 0px' }
|
||||
)
|
||||
function changeTab(value: string) {
|
||||
tab.value = value
|
||||
delete filters.planType
|
||||
if (value === 'cert_incomplete') {
|
||||
delete filters.hazardCertReady
|
||||
readyKind.value = 'all'
|
||||
}
|
||||
search()
|
||||
}
|
||||
function openMoreFilters() {
|
||||
moreDropdown.value?.toggle?.(false)
|
||||
filtersOpen.value = true
|
||||
}
|
||||
function setDate(kind: string) {
|
||||
dateKind.value = kind
|
||||
dates.value = dateShortcut(kind)
|
||||
delete filters.planDate
|
||||
search()
|
||||
}
|
||||
function setReadyFilter(value: string) {
|
||||
if (value === '1' && tab.value === 'cert_incomplete') tab.value = 'all'
|
||||
readyKind.value = value
|
||||
if (value === 'all') delete filters.hazardCertReady
|
||||
else filters.hazardCertReady = { text: '', selected: [value] } as any
|
||||
search()
|
||||
}
|
||||
function applyFilters(next: Record<string, any>, nextSort: typeof sort, resetQuick = false) {
|
||||
Object.keys(filters).forEach((k) => delete filters[k])
|
||||
Object.assign(filters, next)
|
||||
Object.assign(sort, nextSort)
|
||||
if (resetQuick) {
|
||||
dateKind.value = 'all'
|
||||
dates.value = []
|
||||
}
|
||||
if (filters.planDate) {
|
||||
dateKind.value = 'custom'
|
||||
dates.value = []
|
||||
} else if (dateKind.value === 'custom') {
|
||||
dateKind.value = 'all'
|
||||
}
|
||||
const readyValues = (filters.hazardCertReady as any)?.selected || []
|
||||
if (readyValues.map(String).includes('1') && tab.value === 'cert_incomplete') tab.value = 'all'
|
||||
if (readyValues.length === 1 && ['0', '1'].includes(String(readyValues[0]))) {
|
||||
readyKind.value = String(readyValues[0])
|
||||
} else {
|
||||
readyKind.value = 'all'
|
||||
}
|
||||
search()
|
||||
}
|
||||
function openDetail(id: string) {
|
||||
void router.push(`/m/pl/plan-cert/${id}`)
|
||||
}
|
||||
function openContract(planId: string, contractId: string) {
|
||||
void router.push({ path: `/m/pl/plan-cert/${planId}`, query: { contractId } })
|
||||
}
|
||||
function openUpload(p: Plan) {
|
||||
if (!canUpload.value || !canEdit(p) || acting.value) {
|
||||
ElMessage.warning('无上传权限或该计划不可编辑')
|
||||
return
|
||||
}
|
||||
uploadScope = sessionScope()
|
||||
uploadId.value = p.id
|
||||
uploadOpen.value = true
|
||||
}
|
||||
async function saved(id: string) {
|
||||
if (disposed || !canUpload.value || id !== uploadId.value || uploadScope !== sessionScope())
|
||||
return
|
||||
const scope = uploadScope
|
||||
const generation = sessionGeneration.value
|
||||
const loaded = await load()
|
||||
await refreshSidebarBadges()
|
||||
if (loaded && !disposed && generation === sessionGeneration.value && scope === sessionScope())
|
||||
openDetail(id)
|
||||
}
|
||||
import '@/styles/mp-webview.scss'
|
||||
const route = useRoute(),
|
||||
user = useUserStore(),
|
||||
ready = ref(false),
|
||||
session = ref(0)
|
||||
const planId = computed(() => (typeof route.params.id === 'string' ? route.params.id : undefined))
|
||||
watch(
|
||||
canReady,
|
||||
() => JSON.stringify([user.accessToken, user.getUserInfo]),
|
||||
() => {
|
||||
actionVersion++
|
||||
acting.value = false
|
||||
ready.value = ready.value && !!user.accessToken
|
||||
session.value++
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
async function setReady(row: Plan, ready: boolean) {
|
||||
if (disposed || !canReady.value || acting.value) return
|
||||
const id = row.id
|
||||
const v = ++actionVersion
|
||||
const scope = sessionScope()
|
||||
const current = () =>
|
||||
!disposed && v === actionVersion && scope === sessionScope() && canReady.value
|
||||
acting.value = true
|
||||
try {
|
||||
const res = await planApi.get(id)
|
||||
if (!current()) return
|
||||
const fresh = (res.data ?? res) as Plan
|
||||
if (!fresh || String(fresh.id || '') !== id) {
|
||||
ElMessage.warning('计划信息不匹配,请重新打开')
|
||||
return
|
||||
}
|
||||
if (!readyTargets([fresh], ready, (p) => planHasHazardProducts(p.products)).length) {
|
||||
ElMessage.warning('该计划当前不可操作')
|
||||
return
|
||||
}
|
||||
try {
|
||||
await showCrmConfirmDialog({
|
||||
kind: ready ? 'default' : 'danger',
|
||||
title: ready ? '证书齐备确认' : '取消齐备',
|
||||
message: ready
|
||||
? `${HAZARD_CERT_READY_CONFIRM_HINT}确认后可安排运输,之后仍可补充附件。`
|
||||
: '取消后将无法安排运输。',
|
||||
confirmButtonText: ready ? '确认齐备' : '确认取消'
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!current()) return
|
||||
await planApi.setHazardCertReady(id, ready)
|
||||
if (!current()) return
|
||||
ElMessage({ type: 'success', message: ready ? '已标记证书齐备' : '已取消齐备' })
|
||||
await load()
|
||||
if (current()) await refreshSidebarBadges()
|
||||
} catch {
|
||||
if (current()) ElMessage.warning('操作失败,请重试')
|
||||
} finally {
|
||||
if (!disposed && v === actionVersion) acting.value = false
|
||||
}
|
||||
}
|
||||
async function loadPermissions() {
|
||||
if (disposed) return
|
||||
const v = ++permissionVersion
|
||||
const scope = sessionScope()
|
||||
const current = () => !disposed && v === permissionVersion && scope === sessionScope()
|
||||
canUpload.value = false
|
||||
canReady.value = false
|
||||
canPrice.value = false
|
||||
permissionError.value = false
|
||||
try {
|
||||
const p = await fetchGetMenuCodes()
|
||||
if (!current()) return
|
||||
const all = !!p?.all || !!p?.isSuperAdmin
|
||||
canUpload.value = all || (p?.menuCodes || []).includes('pl:plan-cert:upload')
|
||||
canReady.value = all || (p?.menuCodes || []).includes('pl:plan-cert:ready')
|
||||
canPrice.value = all || (p?.menuCodes || []).includes('pl:contract:view-product-price')
|
||||
} catch {
|
||||
if (current()) permissionError.value = true
|
||||
} finally {
|
||||
if (current()) permissionsLoaded.value = true
|
||||
}
|
||||
}
|
||||
watch(
|
||||
sessionScope,
|
||||
() => {
|
||||
requestVersion++
|
||||
actionVersion++
|
||||
permissionVersion++
|
||||
sessionGeneration.value++
|
||||
// Props update on the next render; invalidate pending child saves in this same tick.
|
||||
uploadRef.value?.invalidateRecord()
|
||||
uploadOpen.value = false
|
||||
uploadId.value = ''
|
||||
uploadScope = ''
|
||||
canUpload.value = false
|
||||
canReady.value = false
|
||||
canPrice.value = false
|
||||
permissionsLoaded.value = false
|
||||
permissionError.value = false
|
||||
plans.value = []
|
||||
expandedIds.value = new Set()
|
||||
total.value = 0
|
||||
page.value = 1
|
||||
loading.value = false
|
||||
acting.value = false
|
||||
error.value = ''
|
||||
failedMore.value = false
|
||||
keyword.value = ''
|
||||
appliedKeyword.value = ''
|
||||
tab.value = 'cert_incomplete'
|
||||
dates.value = []
|
||||
dateKind.value = 'all'
|
||||
readyKind.value = 'all'
|
||||
Object.keys(filters).forEach((key) => delete filters[key])
|
||||
filters.followStatus = { text: '', selected: [...PL_PLAN_DEFAULT_FOLLOW_STATUSES] }
|
||||
Object.assign(sort, { sortField: '', sortOrder: 'desc' })
|
||||
filtersOpen.value = false
|
||||
moreDropdown.value?.toggle?.(false)
|
||||
sessionChanged.value = true
|
||||
},
|
||||
{ flush: 'sync' }
|
||||
)
|
||||
async function reloadSession() {
|
||||
if (disposed) return
|
||||
sessionChanged.value = false
|
||||
await Promise.allSettled([loadPermissions(), load()])
|
||||
}
|
||||
async function init() {
|
||||
if (sessionChanged.value) return reloadSession()
|
||||
await Promise.allSettled([loadPermissions(), listReturnState.restore()])
|
||||
}
|
||||
const router = useRouter()
|
||||
onBeforeUnmount(() => {
|
||||
disposed = true
|
||||
actionVersion++
|
||||
permissionVersion++
|
||||
requestVersion++
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.mp-plan-list,
|
||||
.mp-plan-cert-list {
|
||||
:deep(.mp-wv-header__back),
|
||||
:deep(.van-dropdown-menu__item),
|
||||
:deep(.van-dropdown-menu__title),
|
||||
:deep(.mp-wv-flat-card__toggle),
|
||||
:deep(.mp-wv-flat-card__check),
|
||||
:deep(.cert-link),
|
||||
:deep(.cert-btn),
|
||||
:deep(.mp-wv-btn),
|
||||
:deep(.mp-wv-speed-item) {
|
||||
min-width: 44px;
|
||||
min-height: 44px;
|
||||
height: auto;
|
||||
}
|
||||
:deep(.van-dropdown-menu__title) {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
:deep(.mp-wv-flat-card__check) {
|
||||
flex: 0 0 44px;
|
||||
justify-content: center;
|
||||
}
|
||||
:deep(.mp-wv-card-actions) {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
:deep(.mp-wv-flat-card .mp-wv-card-actions .mp-wv-btn) {
|
||||
min-height: 44px;
|
||||
height: auto;
|
||||
flex: 1 0 auto;
|
||||
white-space: nowrap;
|
||||
}
|
||||
:deep(.mp-wv-flat-card__row > span:first-child),
|
||||
:deep(.mp-wv-flat-card__line > span:first-child),
|
||||
:deep(.mp-wv-card__kv-row > span:first-child) {
|
||||
flex-shrink: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.mp-plan-cert-list .cert-body {
|
||||
padding-bottom: calc(148px + env(safe-area-inset-bottom, 0px));
|
||||
}
|
||||
.mp-plan-cert-list .cert-batch {
|
||||
gap: 8px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="scss">
|
||||
html
|
||||
body
|
||||
:is(.mp-plan-cert-list, .mp-cert-filter-popup).mp-cert-list-touch-scope
|
||||
:is(.mp-wv-btn, .cert-btn, .filter-chip, .van-button, .el-button, .cert-link):not(
|
||||
.mp-wv-speed-main
|
||||
):not(.van-stepper__minus):not(.van-stepper__plus) {
|
||||
min-width: 44px !important;
|
||||
min-height: 44px !important;
|
||||
height: auto !important;
|
||||
line-height: 42px !important;
|
||||
}
|
||||
.mp-plan-cert-list .cert-card-attachments {
|
||||
min-width: 0;
|
||||
padding-top: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -1,51 +1,8 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { test } from 'node:test'
|
||||
import { buildQuery, canEdit, readyTargets, certPayload, canSave, dateShortcut } from './model'
|
||||
import { certPayload, canSave, dateShortcut } from './model'
|
||||
import * as model from './model'
|
||||
|
||||
test('five tabs preserve hazard scope and enforce their constraints', () => {
|
||||
for (const tab of ['cert_incomplete', 'all', 'inbound', 'outbound', 'direct']) {
|
||||
const q = buildQuery(tab, {}, '')
|
||||
assert.equal(q.hasHazardProduct, 1)
|
||||
assert.equal(q.followStatus, undefined, 'default status is supplied by the list filters')
|
||||
if (tab === 'cert_incomplete') {
|
||||
assert.equal(q.certUploadStatus, 'incomplete')
|
||||
assert.equal(q.hazardCertReady, 0)
|
||||
} else if (tab !== 'all') assert.equal(q.planType, tab)
|
||||
else assert.equal(q.planType, undefined)
|
||||
}
|
||||
})
|
||||
test('tab wins conflicts while explicit cancelled status is retained', () => {
|
||||
const q = buildQuery(
|
||||
'cert_incomplete',
|
||||
{ hazardCertReadyIn: '1', followStatusIn: 'cancelled' },
|
||||
' x '
|
||||
)
|
||||
assert.equal(q.hazardCertReady, 0)
|
||||
assert.equal(q.hazardCertReadyIn, undefined)
|
||||
assert.equal(q.followStatus, 'cancelled')
|
||||
assert.equal(q.q, 'x')
|
||||
assert.equal(buildQuery('direct', { planTypeIn: 'outbound' }, '').planTypeIn, undefined)
|
||||
assert.equal(buildQuery('all', { hazardCertReadyIn: '1' }, '').hazardCertReady, 1)
|
||||
})
|
||||
test('closed plans and wrong ready states are skipped; hazard predicate is required', () => {
|
||||
const rows = [
|
||||
{ id: 'a', hazardCertReady: 0 },
|
||||
{ id: 'b', hazardCertReady: 1 },
|
||||
{ id: 'c', followStatus: 'cancelled' },
|
||||
{ id: 'd', archiveStatus: 'archived' },
|
||||
{ id: 'e' }
|
||||
]
|
||||
assert.equal(canEdit(rows[2]), false)
|
||||
assert.deepEqual(
|
||||
readyTargets(rows, true, (p) => p.id !== 'e').map((p) => p.id),
|
||||
['a']
|
||||
)
|
||||
assert.deepEqual(
|
||||
readyTargets(rows, false, () => true).map((p) => p.id),
|
||||
['b']
|
||||
)
|
||||
})
|
||||
test('certificate payload contains only id and trimmed URLs; empty slots are allowed', () => {
|
||||
assert.deepEqual(certPayload([{ id: 'p', productName: 'secret', purchaseCertUrl: ' a,b ' }]), [
|
||||
{ id: 'p', purchaseCertUrl: 'a,b', transportCertUrl: '', legalUseCertUrl: '' }
|
||||
@@ -141,11 +98,6 @@ test('contract reads enrich ids and saved product aliases without changing sourc
|
||||
assert.equal(failed.warnings.length, 3)
|
||||
})
|
||||
|
||||
test('clearing follow status does not silently restore the initial defaults', () => {
|
||||
assert.equal(buildQuery('all', {}, '').followStatus, undefined)
|
||||
assert.equal(buildQuery('all', { followStatusIn: 'cancelled' }, '').followStatus, 'cancelled')
|
||||
})
|
||||
|
||||
test('explicit segment metadata wins over root product including empty alias and brand', () => {
|
||||
const root = [
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user