提交“
This commit is contained in:
1 parent
5d9fb5ce19
commit
9177e1b7f1
231 files changed
+21207
No files matched your search
@@ -0,0 +1,57 @@
|
||||
<template>
|
||||
<ol class="mp-crm-approval-timeline" aria-label="审批进度">
|
||||
<li
|
||||
v-for="(item, index) in items"
|
||||
:key="item.id || index"
|
||||
class="mp-crm-approval-timeline__item"
|
||||
>
|
||||
<div class="mp-crm-approval-timeline__rail" aria-hidden="true">
|
||||
<span class="mp-crm-approval-timeline__avatar">{{
|
||||
item.avatar || avatarText(item.name)
|
||||
}}</span>
|
||||
</div>
|
||||
<div class="mp-crm-approval-timeline__content">
|
||||
<div class="mp-crm-approval-timeline__head">
|
||||
<strong>{{ item.name }}</strong>
|
||||
<span class="status-tag" :class="`status-tag--${item.tone || 'info'}`">
|
||||
{{ item.status }}
|
||||
</span>
|
||||
</div>
|
||||
<p v-if="item.opinion" class="mp-crm-approval-timeline__opinion">{{ item.opinion }}</p>
|
||||
<time
|
||||
v-if="item.time"
|
||||
class="mp-crm-approval-timeline__time"
|
||||
:datetime="item.datetime || undefined"
|
||||
>{{ item.time }}</time
|
||||
>
|
||||
</div>
|
||||
</li>
|
||||
</ol>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
type MpStatusTone = 'success' | 'warning' | 'danger' | 'info' | 'primary'
|
||||
|
||||
interface MpApprovalTimelineItem {
|
||||
id?: string
|
||||
name: string
|
||||
avatar?: string
|
||||
status: string
|
||||
tone?: MpStatusTone
|
||||
opinion?: string
|
||||
time?: string
|
||||
datetime?: string
|
||||
}
|
||||
|
||||
defineProps<{
|
||||
items: MpApprovalTimelineItem[]
|
||||
}>()
|
||||
|
||||
function avatarText(name: string) {
|
||||
return (
|
||||
String(name || '审')
|
||||
.trim()
|
||||
.slice(-1) || '审'
|
||||
)
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,92 @@
|
||||
<template>
|
||||
<ul class="mp-crm-att-grid" aria-label="附件列表">
|
||||
<li v-if="editable" class="att-item att-item--add">
|
||||
<button class="att-add" type="button" @click="emit('add')">
|
||||
<span aria-hidden="true">+</span>
|
||||
<small>上传</small>
|
||||
</button>
|
||||
</li>
|
||||
<li
|
||||
v-for="item in items"
|
||||
:key="item.id || item.url || item.name"
|
||||
class="att-item"
|
||||
:class="{ 'is-uploading': item.uploading }"
|
||||
>
|
||||
<button
|
||||
v-if="editable && !item.uploading"
|
||||
class="att-icon att-icon--del"
|
||||
type="button"
|
||||
:aria-label="`删除附件:${item.name || '未命名附件'}`"
|
||||
@click.stop="emit('remove', item)"
|
||||
>
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
<button
|
||||
v-if="item.url && !item.uploading"
|
||||
class="att-icon att-icon--dl"
|
||||
type="button"
|
||||
:aria-label="`下载附件:${item.name || '未命名附件'}`"
|
||||
@click.stop="emit('download', item)"
|
||||
>
|
||||
<span aria-hidden="true">↓</span>
|
||||
</button>
|
||||
<button
|
||||
class="att-preview"
|
||||
type="button"
|
||||
:disabled="Boolean(item.uploading) || !item.url"
|
||||
@click="emit('preview', item)"
|
||||
>
|
||||
<img v-if="isImage(item)" class="att-img" :src="item.url" :alt="item.name || '附件'" />
|
||||
<span v-else class="att-doc" :class="{ 'att-doc--word': isWord(item) }">
|
||||
<strong>{{ extension(item) }}</strong>
|
||||
</span>
|
||||
</button>
|
||||
<span class="att-name">{{ item.name || '附件' }}</span>
|
||||
<span v-if="item.uploading" class="att-uploading">上传中…</span>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
export interface MpAttachmentItem {
|
||||
id?: string
|
||||
url: string
|
||||
name?: string
|
||||
isImage?: boolean
|
||||
uploading?: boolean
|
||||
}
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
items: MpAttachmentItem[]
|
||||
editable?: boolean
|
||||
}>(),
|
||||
{
|
||||
editable: false
|
||||
}
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
add: []
|
||||
preview: [item: MpAttachmentItem]
|
||||
download: [item: MpAttachmentItem]
|
||||
remove: [item: MpAttachmentItem]
|
||||
}>()
|
||||
|
||||
function isImage(item: MpAttachmentItem) {
|
||||
if (item.isImage !== undefined) return item.isImage
|
||||
return /\.(?:avif|gif|jpe?g|png|webp)(?:\?.*)?$/i.test(item.url || item.name || '')
|
||||
}
|
||||
|
||||
function extension(item: MpAttachmentItem) {
|
||||
const value = (item.name || item.url).split('?')[0]
|
||||
const suffix = value.includes('.') ? value.split('.').pop() : 'FILE'
|
||||
return String(suffix || 'FILE')
|
||||
.slice(0, 5)
|
||||
.toUpperCase()
|
||||
}
|
||||
|
||||
function isWord(item: MpAttachmentItem) {
|
||||
return /^(DOC|DOCX|XLS|XLSX|PPT)/.test(extension(item))
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,83 @@
|
||||
<template>
|
||||
<article class="expense-card mp-crm-expense-card" @click="emit('open')">
|
||||
<div class="ec-top">
|
||||
<button
|
||||
v-if="selectable"
|
||||
class="expense-card__select mp-wv-touch-target"
|
||||
type="button"
|
||||
:aria-label="selected ? '取消选择' : '选择'"
|
||||
:aria-pressed="selected"
|
||||
@click.stop="emit('select', !selected)"
|
||||
>
|
||||
<span aria-hidden="true">{{ selected ? '✓' : '' }}</span>
|
||||
</button>
|
||||
<h2 class="ec-title">
|
||||
<button
|
||||
class="expense-card__open mp-wv-touch-target"
|
||||
type="button"
|
||||
:aria-label="openLabel || `查看${title}`"
|
||||
@click.stop="emit('open')"
|
||||
>
|
||||
{{ title }}
|
||||
</button>
|
||||
</h2>
|
||||
<span class="status-tag" :class="`status-tag--${statusTone}`">{{ status }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="amount !== undefined && amount !== ''" class="ec-amount">
|
||||
<span class="ec-amount__label">{{ amountLabel }}</span>
|
||||
<strong class="ec-amount__value">{{ amount }}</strong>
|
||||
</div>
|
||||
|
||||
<div v-if="slots.emphasis" class="ec-emphasis">
|
||||
<slot name="emphasis" />
|
||||
</div>
|
||||
|
||||
<div v-if="slots.kv" class="list-card-kv">
|
||||
<slot name="kv" />
|
||||
</div>
|
||||
|
||||
<p v-if="time" class="ec-time">{{ time }}</p>
|
||||
|
||||
<div v-if="showActions && slots.actions" class="ec-bottom" @click.stop>
|
||||
<div class="op-actions">
|
||||
<slot name="actions" />
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
type MpStatusTone = 'success' | 'warning' | 'danger' | 'info' | 'primary'
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
title: string
|
||||
status: string
|
||||
statusTone?: MpStatusTone
|
||||
amount?: string
|
||||
amountLabel?: string
|
||||
time?: string
|
||||
selectable?: boolean
|
||||
selected?: boolean
|
||||
openLabel?: string
|
||||
showActions?: boolean
|
||||
}>(),
|
||||
{
|
||||
statusTone: 'info',
|
||||
amount: undefined,
|
||||
amountLabel: '金额',
|
||||
time: '',
|
||||
selectable: false,
|
||||
selected: false,
|
||||
openLabel: '',
|
||||
showActions: true
|
||||
}
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
open: []
|
||||
select: [selected: boolean]
|
||||
}>()
|
||||
const slots = useSlots()
|
||||
</script>
|
||||
@@ -0,0 +1,370 @@
|
||||
<template>
|
||||
<div
|
||||
class="mp-list-skel"
|
||||
:class="{
|
||||
'mp-list-skel--full': variant === 'full',
|
||||
'mp-customer-list': layout === 'customer'
|
||||
}"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
aria-busy="true"
|
||||
:aria-label="ariaLabel"
|
||||
>
|
||||
<template v-if="variant === 'full' && layout === 'customer'">
|
||||
<!-- 与正式页 MpBusinessHeader 同结构:返回和标题保持可读,Tab / 搜索 / 筛选走骨架闪动 -->
|
||||
<header class="mp-wv-header">
|
||||
<div class="mp-wv-header__row">
|
||||
<button
|
||||
class="mp-wv-header__back mp-wv-touch-target"
|
||||
type="button"
|
||||
aria-label="返回"
|
||||
@click="emit('back')"
|
||||
>
|
||||
←
|
||||
</button>
|
||||
<h1 class="mp-wv-header__title">{{ title }}</h1>
|
||||
</div>
|
||||
<div v-if="tabs.length" class="mp-list-skel__tabs" aria-hidden="true">
|
||||
<span
|
||||
v-for="(tab, index) in tabs"
|
||||
:key="tab"
|
||||
class="mp-wv-skel mp-list-skel__header-bar mp-list-skel__tab-bar"
|
||||
:class="{ 'is-active': index === 0 }"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-if="searchable"
|
||||
class="mp-wv-skel mp-list-skel__header-bar mp-list-skel__search-bar"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div v-if="filters.length" class="mp-list-skel__dd" aria-hidden="true">
|
||||
<span
|
||||
v-for="filter in filters"
|
||||
:key="filter"
|
||||
class="mp-wv-skel mp-list-skel__header-bar mp-list-skel__dd-bar"
|
||||
/>
|
||||
</div>
|
||||
</header>
|
||||
</template>
|
||||
<template v-else-if="variant === 'full'">
|
||||
<header class="mp-wv-header">
|
||||
<div class="mp-wv-header__row">
|
||||
<button
|
||||
class="mp-wv-header__back mp-wv-touch-target"
|
||||
type="button"
|
||||
aria-label="返回"
|
||||
@click="emit('back')"
|
||||
>
|
||||
←
|
||||
</button>
|
||||
<h1 class="mp-wv-header__title">{{ title }}</h1>
|
||||
</div>
|
||||
</header>
|
||||
</template>
|
||||
|
||||
<p v-if="caption" class="mp-list-skel__caption">{{ caption }}</p>
|
||||
|
||||
<p v-if="layout !== 'customer'" class="mp-list-skel__summary" aria-hidden="true">
|
||||
<span class="mp-wv-skel mp-list-skel__summary-bar" />
|
||||
</p>
|
||||
|
||||
<div
|
||||
class="mp-list-skel__cards"
|
||||
:class="{
|
||||
'mp-customer-content mp-wv-pad-speed': variant === 'full' && layout === 'customer'
|
||||
}"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<article
|
||||
v-for="n in cardCount"
|
||||
:key="n"
|
||||
class="mp-list-skel__card"
|
||||
:class="
|
||||
layout === 'customer'
|
||||
? 'mp-wv-card mp-customer-list-card mp-wv-card--skeleton'
|
||||
: 'mp-crm-expense-card'
|
||||
"
|
||||
>
|
||||
<template v-if="layout === 'customer'">
|
||||
<div class="mp-list-skel__card-top">
|
||||
<div class="mp-list-skel__card-titles">
|
||||
<div class="mp-wv-skel mp-wv-skel--title" />
|
||||
<div class="mp-wv-skel mp-wv-skel--sub mp-list-skel__meta" />
|
||||
</div>
|
||||
<div class="mp-wv-skel mp-wv-skel--tag" />
|
||||
</div>
|
||||
<div class="mp-list-skel__card-preview">
|
||||
<div class="mp-list-skel__preview-line">
|
||||
<div class="mp-wv-skel mp-list-skel__preview-label" />
|
||||
<div class="mp-wv-skel mp-list-skel__preview-value" />
|
||||
</div>
|
||||
<div class="mp-list-skel__preview-line">
|
||||
<div class="mp-wv-skel mp-list-skel__preview-label" />
|
||||
<div class="mp-wv-skel mp-list-skel__preview-value mp-list-skel__preview-value--short" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="mp-list-skel__card-toggle">
|
||||
<div class="mp-wv-skel mp-list-skel__toggle-bar" />
|
||||
</div>
|
||||
<div class="mp-list-skel__card-actions mp-list-skel__card-actions--stretch">
|
||||
<div class="mp-wv-skel mp-wv-skel--btn" />
|
||||
<div class="mp-wv-skel mp-wv-skel--btn" />
|
||||
<div class="mp-wv-skel mp-wv-skel--btn" />
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="mp-list-skel__card-top">
|
||||
<div class="mp-wv-skel mp-wv-skel--title" />
|
||||
<div class="mp-wv-skel mp-wv-skel--tag" />
|
||||
</div>
|
||||
<div class="mp-list-skel__card-emphasis">
|
||||
<div class="mp-wv-skel mp-wv-skel--sub" />
|
||||
<div class="mp-wv-skel mp-wv-skel--sub" />
|
||||
</div>
|
||||
<div class="mp-list-skel__card-kv">
|
||||
<div class="mp-wv-skel mp-wv-skel--line" />
|
||||
<div class="mp-wv-skel mp-wv-skel--line mp-wv-skel--mid" />
|
||||
<div class="mp-wv-skel mp-wv-skel--line mp-wv-skel--short" />
|
||||
<div class="mp-wv-skel mp-wv-skel--line" />
|
||||
</div>
|
||||
<div class="mp-list-skel__card-actions">
|
||||
<div class="mp-wv-skel mp-wv-skel--btn" />
|
||||
<div class="mp-wv-skel mp-wv-skel--btn" />
|
||||
<div class="mp-wv-skel mp-wv-skel--btn mp-wv-skel--btn-wide" />
|
||||
</div>
|
||||
</template>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const emit = defineEmits<{ back: [] }>()
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
variant?: 'full' | 'body'
|
||||
layout?: 'default' | 'customer'
|
||||
title?: string
|
||||
searchable?: boolean
|
||||
searchPlaceholder?: string
|
||||
tabs?: string[]
|
||||
filters?: string[]
|
||||
cardCount?: number
|
||||
caption?: string
|
||||
ariaLabel?: string
|
||||
}>(),
|
||||
{
|
||||
variant: 'body',
|
||||
layout: 'default',
|
||||
title: '',
|
||||
searchable: false,
|
||||
searchPlaceholder: '搜索',
|
||||
tabs: () => [],
|
||||
filters: () => [],
|
||||
cardCount: 3,
|
||||
caption: '',
|
||||
ariaLabel: '页面加载中'
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
/* 绿头上的骨架条:半透明白闪动,和卡片区浅色骨架区分开 */
|
||||
.mp-list-skel__header-bar {
|
||||
background: linear-gradient(
|
||||
90deg,
|
||||
rgb(255 255 255 / 22%) 25%,
|
||||
rgb(255 255 255 / 52%) 37%,
|
||||
rgb(255 255 255 / 22%) 63%
|
||||
);
|
||||
background-size: 400% 100%;
|
||||
}
|
||||
|
||||
.mp-list-skel__tabs {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
margin-top: 8px;
|
||||
min-height: 34px;
|
||||
}
|
||||
|
||||
.mp-list-skel__tab-bar {
|
||||
flex: 1;
|
||||
height: 12px;
|
||||
margin: 0;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.mp-list-skel__tab-bar.is-active {
|
||||
height: 14px;
|
||||
}
|
||||
|
||||
.mp-list-skel__search-bar {
|
||||
height: 36px;
|
||||
margin: 10px 0 0;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.mp-list-skel__dd {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
margin-top: 8px;
|
||||
min-height: 36px;
|
||||
}
|
||||
|
||||
.mp-list-skel__dd-bar {
|
||||
flex: 1;
|
||||
height: 12px;
|
||||
margin: 0;
|
||||
border-radius: 999px;
|
||||
}
|
||||
|
||||
.mp-list-skel__caption {
|
||||
margin: 2px 0 12px;
|
||||
font-size: 12px;
|
||||
color: #6b7b74;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.mp-list-skel__summary {
|
||||
margin: 0 0 10px;
|
||||
}
|
||||
|
||||
.mp-list-skel__summary-bar {
|
||||
display: block;
|
||||
width: 52%;
|
||||
height: 12px;
|
||||
}
|
||||
|
||||
.mp-list-skel__card {
|
||||
pointer-events: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.mp-list-skel__card-top {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.mp-list-skel__card-titles {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.mp-list-skel__card-top .mp-wv-skel--title {
|
||||
max-width: 78%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.mp-list-skel__meta {
|
||||
width: 88%;
|
||||
max-width: 280px;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.mp-list-skel__card-preview {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.mp-list-skel__preview-line {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.mp-list-skel__preview-label {
|
||||
width: 4.5em;
|
||||
height: 12px;
|
||||
margin: 0;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.mp-list-skel__preview-value {
|
||||
width: 42%;
|
||||
height: 12px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.mp-list-skel__preview-value--short {
|
||||
width: 32%;
|
||||
}
|
||||
|
||||
.mp-list-skel__card-toggle {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-top: 10px;
|
||||
padding-top: 10px;
|
||||
border-top: 1px dashed #dcebe4;
|
||||
}
|
||||
|
||||
.mp-list-skel__toggle-bar {
|
||||
width: 4.5em;
|
||||
height: 12px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.mp-list-skel__card-emphasis {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 0 12px 8px;
|
||||
}
|
||||
|
||||
.mp-list-skel__card-emphasis .mp-wv-skel {
|
||||
width: 36%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.mp-list-skel__card-kv {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
padding: 4px 12px 10px;
|
||||
}
|
||||
|
||||
.mp-list-skel__card-kv .mp-wv-skel {
|
||||
margin-top: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.mp-list-skel__card-kv .mp-wv-skel--mid {
|
||||
width: 78%;
|
||||
}
|
||||
|
||||
.mp-list-skel__card-kv .mp-wv-skel--short {
|
||||
width: 58%;
|
||||
}
|
||||
|
||||
.mp-list-skel__card-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
padding: 0 12px 12px;
|
||||
}
|
||||
|
||||
.mp-list-skel__card-actions--stretch {
|
||||
justify-content: stretch;
|
||||
margin-top: 12px;
|
||||
padding: 10px 0 0;
|
||||
border-top: 1px dashed #dcebe4;
|
||||
|
||||
.mp-wv-skel--btn {
|
||||
flex: 1;
|
||||
width: auto;
|
||||
height: 36px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
/* default expense-card 骨架仍用区块内边距 */
|
||||
.mp-crm-expense-card.mp-list-skel__card .mp-list-skel__card-top {
|
||||
padding: 12px 12px 8px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,16 @@
|
||||
<template>
|
||||
<MpStructSkeleton kind="detail" :caption="title" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import MpStructSkeleton from '@/components/mp/MpStructSkeleton.vue'
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
title?: string
|
||||
}>(),
|
||||
{
|
||||
title: '正在加载'
|
||||
}
|
||||
)
|
||||
</script>
|
||||
@@ -0,0 +1,48 @@
|
||||
<template>
|
||||
<nav class="mp-wv-status-tabs" :aria-label="ariaLabel">
|
||||
<button
|
||||
v-for="tab in tabs"
|
||||
:key="String(tab.value)"
|
||||
class="filter-tag"
|
||||
:class="{ 'is-active': tab.value === modelValue }"
|
||||
type="button"
|
||||
:aria-pressed="tab.value === modelValue"
|
||||
:disabled="tab.disabled"
|
||||
@click="selectTab(tab)"
|
||||
>
|
||||
<span>{{ tab.label }}</span>
|
||||
<span v-if="tab.count !== undefined" class="filter-tag__count">{{ tab.count }}</span>
|
||||
</button>
|
||||
</nav>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" generic="T extends string | number">
|
||||
interface MpStatusTab<T extends string | number = string> {
|
||||
label: string
|
||||
value: T
|
||||
count?: number
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
modelValue: T
|
||||
tabs: MpStatusTab<T>[]
|
||||
ariaLabel?: string
|
||||
}>(),
|
||||
{
|
||||
ariaLabel: '状态筛选'
|
||||
}
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: T]
|
||||
change: [value: T]
|
||||
}>()
|
||||
|
||||
function selectTab(tab: MpStatusTab<T>) {
|
||||
if (tab.disabled) return
|
||||
emit('update:modelValue', tab.value)
|
||||
emit('change', tab.value)
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,141 @@
|
||||
<template>
|
||||
<div
|
||||
class="mp-struct"
|
||||
:class="`mp-struct--${kind}`"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
aria-busy="true"
|
||||
:aria-label="caption"
|
||||
>
|
||||
<p v-if="caption" class="mp-struct__caption">{{ caption }}</p>
|
||||
|
||||
<template v-if="kind === 'detail'">
|
||||
<article class="mp-struct__card">
|
||||
<div class="mp-struct__bar mp-struct__bar--title" />
|
||||
<div class="mp-struct__lines">
|
||||
<div class="mp-struct__bar" />
|
||||
<div class="mp-struct__bar mp-struct__bar--mid" />
|
||||
<div class="mp-struct__bar" />
|
||||
<div class="mp-struct__bar mp-struct__bar--short" />
|
||||
<div class="mp-struct__bar" />
|
||||
<div class="mp-struct__bar mp-struct__bar--mid" />
|
||||
</div>
|
||||
</article>
|
||||
<article class="mp-struct__card">
|
||||
<div class="mp-struct__bar mp-struct__bar--label" />
|
||||
<div class="mp-struct__bar mp-struct__bar--block" />
|
||||
<div class="mp-struct__bar mp-struct__bar--block" />
|
||||
</article>
|
||||
</template>
|
||||
|
||||
<template v-else-if="kind === 'media'">
|
||||
<div class="mp-struct__media" />
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<div v-for="n in count" :key="n" class="mp-struct__field">
|
||||
<div class="mp-struct__bar mp-struct__bar--label" />
|
||||
<div class="mp-struct__bar mp-struct__bar--block" />
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
kind?: 'detail' | 'sheet' | 'media'
|
||||
caption?: string
|
||||
count?: number
|
||||
}>(),
|
||||
{
|
||||
kind: 'detail',
|
||||
caption: '正在加载',
|
||||
count: 3
|
||||
}
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.mp-struct {
|
||||
padding: 4px 0 12px;
|
||||
}
|
||||
|
||||
.mp-struct__caption {
|
||||
margin: 2px 0 12px;
|
||||
font-size: 12px;
|
||||
color: #6b7b74;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.mp-struct__card {
|
||||
margin-bottom: 12px;
|
||||
padding: 14px;
|
||||
background: #fff;
|
||||
border: 1px solid #dcebe4;
|
||||
border-radius: 14px;
|
||||
}
|
||||
|
||||
.mp-struct__lines {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.mp-struct__field + .mp-struct__field {
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.mp-struct__media {
|
||||
width: min(220px, 70%);
|
||||
height: 220px;
|
||||
margin: 12px auto 8px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.mp-struct__bar,
|
||||
.mp-struct__media {
|
||||
border-radius: 6px;
|
||||
background: linear-gradient(90deg, #e7f3ed 25%, #f7fbf9 37%, #e7f3ed 63%);
|
||||
background-size: 400% 100%;
|
||||
animation: mp-struct-shimmer 1.2s ease infinite;
|
||||
}
|
||||
|
||||
.mp-struct__bar {
|
||||
height: 12px;
|
||||
}
|
||||
|
||||
.mp-struct__bar--title {
|
||||
width: 46%;
|
||||
height: 16px;
|
||||
}
|
||||
|
||||
.mp-struct__bar--mid {
|
||||
width: 72%;
|
||||
}
|
||||
|
||||
.mp-struct__bar--short {
|
||||
width: 46%;
|
||||
}
|
||||
|
||||
.mp-struct__bar--label {
|
||||
width: 28%;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.mp-struct__bar--block {
|
||||
width: 100%;
|
||||
height: 36px;
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
@keyframes mp-struct-shimmer {
|
||||
0% {
|
||||
background-position: 100% 0;
|
||||
}
|
||||
|
||||
100% {
|
||||
background-position: 0 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<div class="mp-wv-filter-wrap mp-wv-filter-wrap--business">
|
||||
<div class="mp-wv-filter-bar mp-wv-filter-bar--three">
|
||||
<button
|
||||
v-for="filter in visibleFilters"
|
||||
:key="filter.key"
|
||||
class="mp-wv-filter-trig"
|
||||
:class="{ open: openKey === filter.key }"
|
||||
type="button"
|
||||
:aria-expanded="openKey === filter.key"
|
||||
@click="toggle(filter.key)"
|
||||
>
|
||||
<span class="mp-wv-filter-trig__val">{{ filter.label }}</span>
|
||||
<span class="mp-wv-filter-trig__arrow" aria-hidden="true">▼</span>
|
||||
</button>
|
||||
<button
|
||||
class="mp-wv-filter-trig mp-wv-filter-more"
|
||||
type="button"
|
||||
:aria-label="moreActive ? `${moreLabel},已有筛选` : moreLabel"
|
||||
@click="openMore"
|
||||
>
|
||||
<span>{{ moreLabel }}</span>
|
||||
<span v-if="moreActive" class="mp-wv-filter-more__dot" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="mp-wv-filter-panel" :class="{ open: Boolean(activeFilter) }">
|
||||
<button
|
||||
v-for="option in activeFilter?.options || []"
|
||||
:key="String(option.value)"
|
||||
class="mp-wv-filter-opt"
|
||||
:class="{ active: option.value === activeFilter?.value }"
|
||||
type="button"
|
||||
@click="selectOption(option.value)"
|
||||
>
|
||||
<span>{{ option.label }}</span>
|
||||
<span class="mp-wv-filter-opt__check" aria-hidden="true">✓</span>
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
class="mp-wv-filter-mask"
|
||||
:class="{ open: Boolean(activeFilter) }"
|
||||
type="button"
|
||||
aria-label="关闭筛选"
|
||||
@click="close"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
interface MpQuickFilterOption {
|
||||
label: string
|
||||
value: string | number
|
||||
}
|
||||
|
||||
interface MpQuickFilter {
|
||||
key: string
|
||||
label: string
|
||||
value: string | number
|
||||
options: MpQuickFilterOption[]
|
||||
}
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
quickFilters: [MpQuickFilter, MpQuickFilter]
|
||||
moreLabel?: string
|
||||
moreActive?: boolean
|
||||
}>(),
|
||||
{
|
||||
moreLabel: '更多',
|
||||
moreActive: false
|
||||
}
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
select: [payload: { key: string; value: string | number }]
|
||||
more: []
|
||||
}>()
|
||||
|
||||
const openKey = ref('')
|
||||
const visibleFilters = computed(() => props.quickFilters.slice(0, 2))
|
||||
const activeFilter = computed(() =>
|
||||
visibleFilters.value.find((filter) => filter.key === openKey.value)
|
||||
)
|
||||
|
||||
function toggle(key: string) {
|
||||
openKey.value = openKey.value === key ? '' : key
|
||||
}
|
||||
|
||||
function close() {
|
||||
openKey.value = ''
|
||||
}
|
||||
|
||||
function selectOption(value: string | number) {
|
||||
if (!activeFilter.value) return
|
||||
emit('select', { key: activeFilter.value.key, value })
|
||||
close()
|
||||
}
|
||||
|
||||
function openMore() {
|
||||
close()
|
||||
emit('more')
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,208 @@
|
||||
<template>
|
||||
<div class="mp-customer-attachments">
|
||||
<input
|
||||
ref="fileInputRef"
|
||||
class="mp-customer-file-input"
|
||||
type="file"
|
||||
multiple
|
||||
:accept="accept"
|
||||
@change="onPick"
|
||||
/>
|
||||
<MpAttachmentGrid
|
||||
:items="gridItems"
|
||||
:editable="!readonly"
|
||||
@add="openPicker"
|
||||
@preview="onPreview"
|
||||
@download="onDownload"
|
||||
@remove="onRemove"
|
||||
/>
|
||||
<p v-if="hint" class="mp-customer-attachment-hint">{{ hint }}</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { showFailToast, showToast } from 'vant'
|
||||
import { fetchUploadAttachment } from '@/api/admin'
|
||||
import MpAttachmentGrid, { type MpAttachmentItem } from '@/components/mp/MpAttachmentGrid.vue'
|
||||
import { buildAttachmentUploadFormData } from '@/utils/crm-upload'
|
||||
import {
|
||||
downloadCrmAttachment,
|
||||
isCrmImageFile,
|
||||
openCrmAttachmentPreviewInNewTab,
|
||||
parseCrmAttachmentField,
|
||||
resolveCrmAttachmentFiles,
|
||||
resolveCrmAttachmentUrl
|
||||
} from '@/utils/crm-attachment'
|
||||
|
||||
type LocalFile = {
|
||||
uid: string
|
||||
name: string
|
||||
url: string
|
||||
stored: string
|
||||
isImage: boolean
|
||||
status: 'uploading' | 'done' | 'failed'
|
||||
}
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue?: string
|
||||
readonly?: boolean
|
||||
folder?: string
|
||||
limit?: number
|
||||
accept?: string
|
||||
hint?: string
|
||||
}>(),
|
||||
{
|
||||
folder: 'crm/customer',
|
||||
limit: 15,
|
||||
accept: 'image/*,video/*,.pdf,.doc,.docx,.xls,.xlsx'
|
||||
}
|
||||
)
|
||||
const emit = defineEmits<{ 'update:modelValue': [string] }>()
|
||||
const uploading = ref(0)
|
||||
const fileList = ref<LocalFile[]>([])
|
||||
const fileInputRef = ref<HTMLInputElement>()
|
||||
let syncing = false
|
||||
let uidSeq = 0
|
||||
|
||||
function nextUid() {
|
||||
uidSeq += 1
|
||||
return `att-${uidSeq}`
|
||||
}
|
||||
|
||||
function toFileList(value: string): LocalFile[] {
|
||||
return resolveCrmAttachmentFiles(parseCrmAttachmentField(value || '')).map((file) => ({
|
||||
uid: nextUid(),
|
||||
name: file.name,
|
||||
url: resolveCrmAttachmentUrl(file.url),
|
||||
stored: file.url,
|
||||
isImage: isCrmImageFile(file),
|
||||
status: 'done' as const
|
||||
}))
|
||||
}
|
||||
|
||||
const gridItems = computed<MpAttachmentItem[]>(() =>
|
||||
fileList.value.map((file) => ({
|
||||
id: file.uid,
|
||||
url: file.url,
|
||||
name: file.name,
|
||||
isImage: file.isImage,
|
||||
uploading: file.status === 'uploading'
|
||||
}))
|
||||
)
|
||||
|
||||
function emitFromList() {
|
||||
const urls = fileList.value
|
||||
.filter((file) => file.status === 'done' && file.stored)
|
||||
.map((file) => file.stored)
|
||||
emit('update:modelValue', urls.join(','))
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(value) => {
|
||||
if (syncing) return
|
||||
fileList.value = toFileList(value || '')
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
function openPicker() {
|
||||
if (uploading.value > 0) {
|
||||
showToast('附件正在上传,请稍候')
|
||||
return
|
||||
}
|
||||
if (fileList.value.length >= props.limit) {
|
||||
showToast(`最多上传 ${props.limit} 个附件`)
|
||||
return
|
||||
}
|
||||
fileInputRef.value?.click()
|
||||
}
|
||||
|
||||
async function onPick(event: Event) {
|
||||
const input = event.target as HTMLInputElement
|
||||
const picked = Array.from(input.files || [])
|
||||
input.value = ''
|
||||
if (!picked.length) return
|
||||
const remaining = Math.max(0, props.limit - fileList.value.length)
|
||||
if (!remaining) {
|
||||
showToast(`最多上传 ${props.limit} 个附件`)
|
||||
return
|
||||
}
|
||||
const batch = picked.slice(0, remaining)
|
||||
if (picked.length > remaining) showToast(`最多上传 ${props.limit} 个附件`)
|
||||
if (batch.some((file) => file.size > 20 * 1024 * 1024)) {
|
||||
showToast('单个附件不能超过 20MB')
|
||||
return
|
||||
}
|
||||
for (const raw of batch) await uploadOne(raw)
|
||||
}
|
||||
|
||||
async function uploadOne(raw: File) {
|
||||
const item: LocalFile = {
|
||||
uid: nextUid(),
|
||||
name: raw.name,
|
||||
url: '',
|
||||
stored: '',
|
||||
isImage: isCrmImageFile({ name: raw.name }),
|
||||
status: 'uploading'
|
||||
}
|
||||
fileList.value.push(item)
|
||||
uploading.value += 1
|
||||
try {
|
||||
const formData = buildAttachmentUploadFormData(raw, {
|
||||
bizType: 'crm_customer_certificate',
|
||||
folder: props.folder
|
||||
})
|
||||
const response = await fetchUploadAttachment(formData)
|
||||
const uploaded = (response as { data?: Record<string, unknown> })?.data ?? response
|
||||
const url = String(
|
||||
(uploaded as { fileUrl?: string; url?: string; id?: string })?.fileUrl ||
|
||||
(uploaded as { url?: string })?.url ||
|
||||
(uploaded as { id?: string })?.id ||
|
||||
''
|
||||
)
|
||||
if (!url) throw new Error(`${raw.name} 上传后未返回地址`)
|
||||
item.stored = url
|
||||
item.url = resolveCrmAttachmentUrl(url)
|
||||
item.status = 'done'
|
||||
syncing = true
|
||||
emitFromList()
|
||||
nextTick(() => {
|
||||
syncing = false
|
||||
})
|
||||
} catch (error) {
|
||||
item.status = 'failed'
|
||||
showFailToast(error instanceof Error ? error.message : `${raw.name} 上传失败`)
|
||||
} finally {
|
||||
uploading.value = Math.max(0, uploading.value - 1)
|
||||
}
|
||||
}
|
||||
|
||||
function onRemove(item: MpAttachmentItem) {
|
||||
fileList.value = fileList.value.filter((file) => file.uid !== item.id)
|
||||
syncing = true
|
||||
emitFromList()
|
||||
nextTick(() => {
|
||||
syncing = false
|
||||
})
|
||||
}
|
||||
|
||||
function fileOf(item: MpAttachmentItem) {
|
||||
return fileList.value.find((file) => file.uid === item.id)
|
||||
}
|
||||
|
||||
function onPreview(item: MpAttachmentItem) {
|
||||
const file = fileOf(item)
|
||||
if (!file?.stored) return
|
||||
void openCrmAttachmentPreviewInNewTab({ ossId: file.stored, name: file.name })
|
||||
}
|
||||
|
||||
function onDownload(item: MpAttachmentItem) {
|
||||
const file = fileOf(item)
|
||||
if (!file?.stored) return
|
||||
void downloadCrmAttachment({ ossId: file.stored, name: file.name })
|
||||
}
|
||||
|
||||
defineExpose({ hasUploading: () => uploading.value > 0 })
|
||||
</script>
|
||||
@@ -0,0 +1,217 @@
|
||||
<template>
|
||||
<van-cell-group :inset="!readonly" class="mp-customer-fields-vant">
|
||||
<template v-for="field in fields" :key="field.key">
|
||||
<template v-if="readonly">
|
||||
<van-cell :title="field.label" :value="readonlyText(field)" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<van-field
|
||||
v-if="field.type === 'switch'"
|
||||
:label="fieldLabel(field)"
|
||||
input-align="right"
|
||||
>
|
||||
<template #input>
|
||||
<van-switch
|
||||
:model-value="Number(modelValue[field.key]) === 1"
|
||||
size="20px"
|
||||
@update:model-value="(v) => set(field.key, v ? 1 : 0)"
|
||||
/>
|
||||
</template>
|
||||
</van-field>
|
||||
<van-field
|
||||
v-else-if="field.type === 'textarea'"
|
||||
:model-value="String(modelValue[field.key] ?? '')"
|
||||
rows="3"
|
||||
autosize
|
||||
type="textarea"
|
||||
:label="fieldLabel(field)"
|
||||
:required="field.required"
|
||||
:maxlength="field.max"
|
||||
:placeholder="'请输入' + field.label"
|
||||
@update:model-value="(v) => set(field.key, v)"
|
||||
/>
|
||||
<van-field
|
||||
v-else-if="field.dict || field.options || field.type === 'select' || field.key === 'ownerUserId'"
|
||||
is-link
|
||||
readonly
|
||||
:label="fieldLabel(field)"
|
||||
:required="field.required"
|
||||
:model-value="selectLabel(field)"
|
||||
:placeholder="'请选择' + field.label"
|
||||
@click="openSelect(field)"
|
||||
/>
|
||||
<van-field
|
||||
v-else-if="field.type === 'datetime-local' || field.type === 'date'"
|
||||
is-link
|
||||
readonly
|
||||
:label="fieldLabel(field)"
|
||||
:required="field.required"
|
||||
:model-value="displayDate(field)"
|
||||
:placeholder="'请选择' + field.label"
|
||||
@click="openDate(field)"
|
||||
/>
|
||||
<van-field
|
||||
v-else
|
||||
:model-value="String(modelValue[field.key] ?? '')"
|
||||
:type="fieldInputType(field)"
|
||||
:label="fieldLabel(field)"
|
||||
:required="field.required"
|
||||
:maxlength="field.max"
|
||||
:placeholder="
|
||||
field.key === 'namePinyinAbbr' ? '保存时自动生成,可手动填写' : '请输入' + field.label
|
||||
"
|
||||
clearable
|
||||
@update:model-value="(v) => set(field.key, v)"
|
||||
>
|
||||
<template v-if="field.key === 'namePinyinAbbr'" #button>
|
||||
<van-button size="small" type="primary" plain @click="set(field.key, '')"
|
||||
>重新生成</van-button
|
||||
>
|
||||
</template>
|
||||
</van-field>
|
||||
</template>
|
||||
</template>
|
||||
</van-cell-group>
|
||||
|
||||
<van-popup v-model:show="selectOpen" position="bottom" round>
|
||||
<van-picker
|
||||
:columns="selectColumns"
|
||||
:model-value="selectValue"
|
||||
@confirm="onSelectConfirm"
|
||||
@cancel="selectOpen = false"
|
||||
/>
|
||||
</van-popup>
|
||||
|
||||
<van-popup v-model:show="dateOpen" position="bottom" round>
|
||||
<van-picker-group
|
||||
v-if="dateNeedTime"
|
||||
:title="'选择' + (dateField?.label || '')"
|
||||
:tabs="['日期', '时间']"
|
||||
next-step-text="下一步"
|
||||
@confirm="onDateConfirm"
|
||||
@cancel="dateOpen = false"
|
||||
>
|
||||
<van-date-picker v-model="dateParts" />
|
||||
<van-time-picker v-model="timeParts" />
|
||||
</van-picker-group>
|
||||
<van-date-picker
|
||||
v-else
|
||||
:title="'选择' + (dateField?.label || '')"
|
||||
v-model="dateParts"
|
||||
@confirm="onDateOnlyConfirm"
|
||||
@cancel="dateOpen = false"
|
||||
/>
|
||||
</van-popup>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useDictStore } from '@/store/modules/dict'
|
||||
import type { Field, Row } from './model'
|
||||
|
||||
const props = defineProps<{
|
||||
fields: Field[]
|
||||
modelValue: Row
|
||||
readonly?: boolean
|
||||
users?: { value: string; label: string }[]
|
||||
}>()
|
||||
const emit = defineEmits<{ 'update:modelValue': [Row] }>()
|
||||
const dict = useDictStore()
|
||||
|
||||
const selectOpen = ref(false)
|
||||
const selectField = ref<Field | null>(null)
|
||||
const selectColumns = ref<{ text: string; value: string }[]>([])
|
||||
const selectValue = ref<string[]>([])
|
||||
|
||||
const dateOpen = ref(false)
|
||||
const dateField = ref<Field | null>(null)
|
||||
const dateNeedTime = ref(false)
|
||||
const dateParts = ref<string[]>([])
|
||||
const timeParts = ref<string[]>(['00', '00'])
|
||||
|
||||
function hasValue(value: any) {
|
||||
return value !== '' && value != null
|
||||
}
|
||||
function fieldLabel(field: Field) {
|
||||
return field.label
|
||||
}
|
||||
function options(field: Field) {
|
||||
const list =
|
||||
field.key === 'ownerUserId'
|
||||
? props.users || []
|
||||
: field.options || (field.dict ? dict.getOptions(field.dict) : [])
|
||||
return list.map((o) => ({ value: String(o.value), label: o.label }))
|
||||
}
|
||||
function selectLabel(field: Field) {
|
||||
const value = props.modelValue[field.key]
|
||||
if (!hasValue(value)) return ''
|
||||
return options(field).find((o) => o.value === String(value))?.label || String(value)
|
||||
}
|
||||
function readonlyText(field: Field) {
|
||||
const value = props.modelValue[field.key]
|
||||
if (field.type === 'switch') return Number(value) ? '是' : '否'
|
||||
if (field.dict || field.options || field.type === 'select' || field.key === 'ownerUserId') {
|
||||
return selectLabel(field) || '—'
|
||||
}
|
||||
return hasValue(value) ? String(value) : '—'
|
||||
}
|
||||
function fieldInputType(field: Field): 'text' | 'tel' | 'email' | 'digit' | 'number' {
|
||||
if (field.type === 'tel') return 'tel'
|
||||
if (field.type === 'email') return 'email'
|
||||
if (field.type === 'number') return 'number'
|
||||
return 'text'
|
||||
}
|
||||
function displayDate(field: Field) {
|
||||
const raw = String(props.modelValue[field.key] || '')
|
||||
.replace(' ', 'T')
|
||||
.slice(0, field.type === 'date' ? 10 : 16)
|
||||
return raw ? raw.replace('T', ' ') : ''
|
||||
}
|
||||
function set(key: string, value: any) {
|
||||
emit('update:modelValue', { ...props.modelValue, [key]: value })
|
||||
}
|
||||
|
||||
function openSelect(field: Field) {
|
||||
selectField.value = field
|
||||
selectColumns.value = [
|
||||
{ text: `请选择${field.label}`, value: '' },
|
||||
...options(field).map((o) => ({ text: o.label, value: o.value }))
|
||||
]
|
||||
selectValue.value = [String(props.modelValue[field.key] ?? '')]
|
||||
selectOpen.value = true
|
||||
}
|
||||
function onSelectConfirm({ selectedValues }: { selectedValues: Array<string | number> }) {
|
||||
if (selectField.value) set(selectField.value.key, String(selectedValues[0] ?? ''))
|
||||
selectOpen.value = false
|
||||
}
|
||||
|
||||
function openDate(field: Field) {
|
||||
dateField.value = field
|
||||
dateNeedTime.value = field.type === 'datetime-local'
|
||||
const raw = String(props.modelValue[field.key] || '').replace(' ', 'T')
|
||||
const d = raw ? new Date(raw) : new Date()
|
||||
const valid = Number.isNaN(d.getTime()) ? new Date() : d
|
||||
dateParts.value = [
|
||||
String(valid.getFullYear()),
|
||||
String(valid.getMonth() + 1).padStart(2, '0'),
|
||||
String(valid.getDate()).padStart(2, '0')
|
||||
]
|
||||
timeParts.value = [
|
||||
String(valid.getHours()).padStart(2, '0'),
|
||||
String(valid.getMinutes()).padStart(2, '0')
|
||||
]
|
||||
dateOpen.value = true
|
||||
}
|
||||
function onDateConfirm() {
|
||||
if (!dateField.value) return
|
||||
const [y, m, day] = dateParts.value
|
||||
const [hh, mm] = timeParts.value
|
||||
set(dateField.value.key, `${y}-${m}-${day}T${hh}:${mm}`)
|
||||
dateOpen.value = false
|
||||
}
|
||||
function onDateOnlyConfirm() {
|
||||
if (!dateField.value) return
|
||||
const [y, m, day] = dateParts.value
|
||||
set(dateField.value.key, `${y}-${m}-${day}`)
|
||||
dateOpen.value = false
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,614 @@
|
||||
<template>
|
||||
<van-popup
|
||||
:show="modelValue"
|
||||
position="bottom"
|
||||
round
|
||||
:style="{ height: '82%' }"
|
||||
class="mp-customer-vant-popup"
|
||||
@update:show="emit('update:modelValue', $event)"
|
||||
>
|
||||
<div class="mp-customer-filter-vant">
|
||||
<van-nav-bar title="更多筛选" left-text="关闭" @click-left="close" />
|
||||
<div class="mp-customer-filter-vant__body">
|
||||
<van-cell-group inset title="常用">
|
||||
<van-field
|
||||
v-model="contextDraft.keyword"
|
||||
label="关键词"
|
||||
placeholder="客户名称 / 编号 / 手机号 / 拼音"
|
||||
clearable
|
||||
/>
|
||||
<van-field
|
||||
is-link
|
||||
readonly
|
||||
label="业务视图"
|
||||
:model-value="viewLabel"
|
||||
placeholder="请选择"
|
||||
@click="openSingle('view')"
|
||||
/>
|
||||
</van-cell-group>
|
||||
|
||||
<van-cell-group inset>
|
||||
<van-field
|
||||
v-for="d in enumDefsWithOptions"
|
||||
:key="d.prop"
|
||||
is-link
|
||||
readonly
|
||||
:label="d.label"
|
||||
:model-value="enumSummary(d.prop, d.enumOptions || [])"
|
||||
placeholder="请选择(可多选)"
|
||||
@click="openEnumPicker(d.prop, d.enumOptions || [])"
|
||||
/>
|
||||
</van-cell-group>
|
||||
|
||||
<van-cell-group inset>
|
||||
<van-field
|
||||
v-for="d in enumDefsNeedFacet"
|
||||
:key="d.prop"
|
||||
is-link
|
||||
readonly
|
||||
:label="d.label"
|
||||
:model-value="enumSummary(d.prop, facetSelectOptions(d))"
|
||||
placeholder="请选择(可多选)"
|
||||
@click="openEnumPicker(d.prop, facetSelectOptions(d), true)"
|
||||
/>
|
||||
</van-cell-group>
|
||||
|
||||
<van-cell-group inset>
|
||||
<van-field
|
||||
v-for="d in textDefs"
|
||||
:key="d.prop"
|
||||
v-model="draft[d.prop]"
|
||||
:label="d.label"
|
||||
:placeholder="`输入${d.label}`"
|
||||
clearable
|
||||
/>
|
||||
</van-cell-group>
|
||||
|
||||
<van-cell-group v-for="d in datetimeDefs" :key="d.prop" inset :title="d.label">
|
||||
<van-field
|
||||
is-link
|
||||
readonly
|
||||
label="起始"
|
||||
:model-value="displayDateTime(draft[d.queryKeyFrom || d.prop + 'From'])"
|
||||
placeholder="请选择"
|
||||
@click="openDateTime(d.queryKeyFrom || d.prop + 'From')"
|
||||
/>
|
||||
<van-field
|
||||
is-link
|
||||
readonly
|
||||
label="截止"
|
||||
:model-value="displayDateTime(draft[d.queryKeyTo || d.prop + 'To'])"
|
||||
placeholder="请选择"
|
||||
@click="openDateTime(d.queryKeyTo || d.prop + 'To')"
|
||||
/>
|
||||
</van-cell-group>
|
||||
|
||||
<van-cell-group v-for="d in numberDefs" :key="d.prop" inset :title="d.label">
|
||||
<van-field
|
||||
is-link
|
||||
readonly
|
||||
label="比较方式"
|
||||
:model-value="numberOpLabel(draft[d.prop + 'Op'])"
|
||||
@click="openSingle('numberOp', d.prop)"
|
||||
/>
|
||||
<template v-if="!draft[d.prop + 'Op'] || draft[d.prop + 'Op'] === 'between'">
|
||||
<van-field v-model="draft[d.prop + 'Min']" type="number" label="最小值" clearable />
|
||||
<van-field v-model="draft[d.prop + 'Max']" type="number" label="最大值" clearable />
|
||||
</template>
|
||||
<van-field v-else v-model="draft[d.prop]" type="number" label="数值" clearable />
|
||||
</van-cell-group>
|
||||
|
||||
<p v-if="error" class="mp-customer-error">{{ error }}</p>
|
||||
</div>
|
||||
|
||||
<div class="mp-customer-filter-vant__foot">
|
||||
<button class="mp-wv-btn" type="button" @click="resetAndApply">重置</button>
|
||||
<button class="mp-wv-btn mp-wv-btn--primary" type="button" @click="apply">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</van-popup>
|
||||
|
||||
<van-popup v-model:show="singleOpen" position="bottom" round>
|
||||
<van-picker
|
||||
:columns="singleColumns"
|
||||
:model-value="singleValue"
|
||||
@confirm="onSingleConfirm"
|
||||
@cancel="singleOpen = false"
|
||||
/>
|
||||
</van-popup>
|
||||
|
||||
<van-popup
|
||||
v-model:show="enumOpen"
|
||||
position="bottom"
|
||||
round
|
||||
:style="{ height: '72%' }"
|
||||
class="mp-customer-vant-popup mp-customer-enum-popup"
|
||||
>
|
||||
<div class="mp-customer-filter-vant__multi">
|
||||
<van-nav-bar
|
||||
:title="enumTitle"
|
||||
left-text="取消"
|
||||
right-text="完成"
|
||||
@click-left="enumOpen = false"
|
||||
@click-right="confirmEnum"
|
||||
/>
|
||||
<div class="mp-customer-enum-toolbar">
|
||||
<span class="mp-customer-enum-toolbar__count"
|
||||
>已选 <strong>{{ enumDraft.length }}</strong> 项</span
|
||||
>
|
||||
<div class="mp-customer-enum-toolbar__acts">
|
||||
<button class="mp-wv-btn mp-wv-btn--primary" type="button" @click="selectAllEnum">
|
||||
全选
|
||||
</button>
|
||||
<button class="mp-wv-btn" type="button" @click="clearEnum">清空</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="enumDraft.length" class="mp-customer-enum-chips">
|
||||
<van-tag
|
||||
v-for="v in enumDraft"
|
||||
:key="v"
|
||||
closeable
|
||||
type="primary"
|
||||
size="medium"
|
||||
@close="toggleEnum(v)"
|
||||
>{{ enumOptionLabel(v) }}</van-tag
|
||||
>
|
||||
</div>
|
||||
<van-search
|
||||
v-if="enumRemote"
|
||||
v-model="enumKeyword"
|
||||
shape="round"
|
||||
background="#f7faf8"
|
||||
placeholder="输入关键字,从全库检索可选值"
|
||||
@update:model-value="onEnumSearch"
|
||||
/>
|
||||
<van-checkbox-group v-model="enumDraft" class="mp-customer-filter-vant__checks">
|
||||
<MpStructSkeleton
|
||||
v-if="enumRemote && enumLoading"
|
||||
kind="sheet"
|
||||
caption="正在检索筛选项"
|
||||
:count="4"
|
||||
/>
|
||||
<van-cell-group v-else :border="false">
|
||||
<van-cell
|
||||
v-for="o in enumOptions"
|
||||
:key="o.value"
|
||||
clickable
|
||||
class="mp-customer-enum-option"
|
||||
:class="{ 'is-checked': enumDraft.includes(o.value) }"
|
||||
@click="toggleEnum(o.value)"
|
||||
>
|
||||
<template #title>
|
||||
<span class="mp-customer-enum-option__label">{{ o.label }}</span>
|
||||
</template>
|
||||
<template #right-icon>
|
||||
<van-checkbox :name="o.value" shape="square" icon-size="18px" @click.stop />
|
||||
</template>
|
||||
</van-cell>
|
||||
</van-cell-group>
|
||||
<van-empty
|
||||
v-if="!enumLoading && !enumOptions.length"
|
||||
description="暂无匹配项,请换个关键字"
|
||||
image-size="72"
|
||||
/>
|
||||
</van-checkbox-group>
|
||||
</div>
|
||||
</van-popup>
|
||||
|
||||
<van-popup v-model:show="dateOpen" position="bottom" round>
|
||||
<van-picker-group
|
||||
title="选择日期时间"
|
||||
:tabs="['日期', '时间']"
|
||||
next-step-text="下一步"
|
||||
@confirm="onDateConfirm"
|
||||
@cancel="dateOpen = false"
|
||||
>
|
||||
<van-date-picker v-model="dateValue" />
|
||||
<van-time-picker v-model="timeValue" />
|
||||
</van-picker-group>
|
||||
</van-popup>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import MpStructSkeleton from '@/components/mp/MpStructSkeleton.vue'
|
||||
import { useDebounceFn } from '@vueuse/core'
|
||||
import { buildCustomerColumnFilterDefs } from '@/views/crm/customer/columnFilterDefs'
|
||||
import { stripSelfColumnParams } from '@/composables/columnFacetContext'
|
||||
import { useDictStore } from '@/store/modules/dict'
|
||||
import { fetchCustomerColumnFacetValues } from '@/api/crm/customer'
|
||||
import { apiTime, unwrapRows, type Row } from './model'
|
||||
|
||||
type ViewKey = 'all' | 'mine' | 'toFollow' | 'key'
|
||||
type EnumOpt = { value: string; label: string }
|
||||
type SingleKind = 'view' | 'numberOp'
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: boolean
|
||||
query: Row
|
||||
context: Row
|
||||
}>()
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [boolean]
|
||||
apply: [value: { query: Row; keyword: string; viewMode: ViewKey }]
|
||||
}>()
|
||||
|
||||
const dict = useDictStore()
|
||||
const defs = computed(() => buildCustomerColumnFilterDefs((code) => dict.getOptions(code)))
|
||||
const enumDefsWithOptions = computed(() =>
|
||||
defs.value.filter((d) => d.type === 'enum' && (d.enumOptions?.length || 0) > 0)
|
||||
)
|
||||
const enumDefsNeedFacet = computed(() =>
|
||||
defs.value.filter((d) => d.type === 'enum' && !(d.enumOptions?.length || 0))
|
||||
)
|
||||
const textDefs = computed(() => defs.value.filter((d) => d.type === 'text'))
|
||||
const datetimeDefs = computed(() => defs.value.filter((d) => d.type === 'datetime'))
|
||||
const numberDefs = computed(() => defs.value.filter((d) => d.type === 'number'))
|
||||
|
||||
const viewOptions = [
|
||||
{ value: 'all' as ViewKey, label: '全部' },
|
||||
{ value: 'mine' as ViewKey, label: '我的' },
|
||||
{ value: 'toFollow' as ViewKey, label: '待跟进' },
|
||||
{ value: 'key' as ViewKey, label: '重点' }
|
||||
]
|
||||
const numberOpOptions = [
|
||||
{ value: 'between', label: '区间' },
|
||||
{ value: 'eq', label: '等于' },
|
||||
{ value: 'gt', label: '大于' },
|
||||
{ value: 'gte', label: '大于等于' },
|
||||
{ value: 'lt', label: '小于' },
|
||||
{ value: 'lte', label: '小于等于' }
|
||||
]
|
||||
|
||||
const draft = ref<Row>({})
|
||||
const contextDraft = ref<{ keyword: string; viewMode: ViewKey }>({
|
||||
keyword: '',
|
||||
viewMode: 'all'
|
||||
})
|
||||
const facets = ref<Record<string, EnumOpt[]>>({})
|
||||
const facetKeywords = ref<Row>({})
|
||||
const facetLoading = ref<Record<string, boolean>>({})
|
||||
const error = ref('')
|
||||
const facetVersions: Record<string, number> = {}
|
||||
const facetTimers: Record<string, ReturnType<typeof setTimeout> | undefined> = {}
|
||||
let facetContextVersion = 0
|
||||
|
||||
const singleOpen = ref(false)
|
||||
const singleKind = ref<SingleKind>('view')
|
||||
const numberOpProp = ref('')
|
||||
const singleColumns = computed(() => {
|
||||
if (singleKind.value === 'view') {
|
||||
return viewOptions.map((o) => ({ text: o.label, value: o.value }))
|
||||
}
|
||||
return numberOpOptions.map((o) => ({ text: o.label, value: o.value }))
|
||||
})
|
||||
const singleValue = computed(() => {
|
||||
if (singleKind.value === 'view') return [contextDraft.value.viewMode]
|
||||
return [draft.value[numberOpProp.value + 'Op'] || 'between']
|
||||
})
|
||||
|
||||
const enumOpen = ref(false)
|
||||
const enumProp = ref('')
|
||||
const enumTitle = ref('')
|
||||
const enumOptions = ref<EnumOpt[]>([])
|
||||
const enumDraft = ref<string[]>([])
|
||||
const enumRemote = ref(false)
|
||||
const enumKeyword = ref('')
|
||||
const enumLoading = computed(() =>
|
||||
enumRemote.value && enumProp.value ? Boolean(facetLoading.value[enumProp.value]) : false
|
||||
)
|
||||
|
||||
const dateOpen = ref(false)
|
||||
const dateKey = ref('')
|
||||
const dateValue = ref<string[]>([])
|
||||
const timeValue = ref<string[]>([])
|
||||
|
||||
const viewLabel = computed(
|
||||
() => viewOptions.find((o) => o.value === contextDraft.value.viewMode)?.label || '全部'
|
||||
)
|
||||
function numberOpLabel(op: string) {
|
||||
return numberOpOptions.find((o) => o.value === (op || 'between'))?.label || '区间'
|
||||
}
|
||||
function displayDateTime(value: unknown) {
|
||||
const raw = String(value || '').trim()
|
||||
return raw ? raw.replace('T', ' ').slice(0, 16) : ''
|
||||
}
|
||||
function enumSummary(prop: string, options: EnumOpt[]) {
|
||||
const selected = Array.isArray(draft.value[prop]) ? draft.value[prop] : []
|
||||
if (!selected.length) return ''
|
||||
const labels = selected.map((v: string) => options.find((o) => o.value === v)?.label || v)
|
||||
return labels.length <= 2 ? labels.join('、') : `已选 ${labels.length} 项`
|
||||
}
|
||||
|
||||
function clearFacets() {
|
||||
facetContextVersion += 1
|
||||
facets.value = {}
|
||||
facetKeywords.value = {}
|
||||
facetLoading.value = {}
|
||||
}
|
||||
|
||||
function resetDraft() {
|
||||
draft.value = {
|
||||
...Object.fromEntries(defs.value.filter((d) => d.type === 'enum').map((d) => [d.prop, []])),
|
||||
...Object.fromEntries(
|
||||
defs.value.filter((d) => d.type === 'number').map((d) => [d.prop + 'Op', 'between'])
|
||||
)
|
||||
}
|
||||
error.value = ''
|
||||
contextDraft.value = { keyword: '', viewMode: 'all' }
|
||||
}
|
||||
|
||||
let hydrating = false
|
||||
const scheduleLiveApply = useDebounceFn(() => {
|
||||
if (!props.modelValue || hydrating) return
|
||||
emit('apply', {
|
||||
query: buildQuery(),
|
||||
keyword: contextDraft.value.keyword.trim(),
|
||||
viewMode: contextDraft.value.viewMode
|
||||
})
|
||||
}, 300)
|
||||
|
||||
function syncFromProps() {
|
||||
hydrating = true
|
||||
resetDraft()
|
||||
Object.assign(draft.value, props.query)
|
||||
delete draft.value.sortField
|
||||
delete draft.value.sortOrder
|
||||
contextDraft.value = {
|
||||
keyword: String(props.context.keyword || ''),
|
||||
viewMode: (['all', 'mine', 'toFollow', 'key'] as ViewKey[]).includes(
|
||||
props.context.viewMode as ViewKey
|
||||
)
|
||||
? (props.context.viewMode as ViewKey)
|
||||
: 'all'
|
||||
}
|
||||
for (const d of defs.value) {
|
||||
if (d.type === 'enum') {
|
||||
draft.value[d.prop] =
|
||||
props.query[(d.queryKey || d.prop) + 'In']?.split(',').filter(Boolean) || []
|
||||
}
|
||||
if (d.type === 'number' && !draft.value[d.prop + 'Op']) {
|
||||
draft.value[d.prop + 'Op'] = 'between'
|
||||
}
|
||||
}
|
||||
for (const key of Object.keys(draft.value)) {
|
||||
if (typeof draft.value[key] === 'string' && /From$|To$|beginTime|endTime/.test(key)) {
|
||||
draft.value[key] = draft.value[key].replace(' ', 'T')
|
||||
}
|
||||
}
|
||||
nextTick(() => {
|
||||
hydrating = false
|
||||
})
|
||||
}
|
||||
|
||||
watch(
|
||||
[draft, contextDraft],
|
||||
() => {
|
||||
if (!props.modelValue || hydrating) return
|
||||
void scheduleLiveApply()
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(open) => {
|
||||
if (open) syncFromProps()
|
||||
}
|
||||
)
|
||||
watch(
|
||||
() => JSON.stringify(props.context),
|
||||
() => clearFacets()
|
||||
)
|
||||
watch(
|
||||
() => `${contextDraft.value.viewMode}|${contextDraft.value.keyword}`,
|
||||
() => {
|
||||
if (props.modelValue) clearFacets()
|
||||
}
|
||||
)
|
||||
|
||||
function close() {
|
||||
emit('update:modelValue', false)
|
||||
}
|
||||
|
||||
function facetSelectOptions(d: { prop: string; enumOptions?: EnumOpt[] }): EnumOpt[] {
|
||||
const selected = Array.isArray(draft.value[d.prop]) ? draft.value[d.prop] : []
|
||||
const map = new Map<string, EnumOpt>()
|
||||
for (const o of [...(d.enumOptions || []), ...(facets.value[d.prop] || [])]) {
|
||||
map.set(o.value, o)
|
||||
}
|
||||
for (const value of selected) {
|
||||
if (!map.has(value)) map.set(value, { value, label: value })
|
||||
}
|
||||
return [...map.values()]
|
||||
}
|
||||
|
||||
function ensureFacet(field: string) {
|
||||
void searchFacet(field, String(facetKeywords.value[field] || ''))
|
||||
}
|
||||
|
||||
function onFacetInput(field: string, keyword: string) {
|
||||
facetKeywords.value[field] = keyword
|
||||
if (facetTimers[field]) clearTimeout(facetTimers[field])
|
||||
facetTimers[field] = setTimeout(() => void searchFacet(field, keyword), 280)
|
||||
}
|
||||
|
||||
async function searchFacet(field: string, keyword: string) {
|
||||
facetKeywords.value[field] = keyword
|
||||
const version = (facetVersions[field] || 0) + 1
|
||||
facetVersions[field] = version
|
||||
const contextVersion = facetContextVersion
|
||||
facetLoading.value[field] = true
|
||||
if (enumOpen.value && enumProp.value === field && enumRemote.value) {
|
||||
enumOptions.value = []
|
||||
}
|
||||
try {
|
||||
const rawContext = {
|
||||
...props.context,
|
||||
viewMode: contextDraft.value.viewMode,
|
||||
...buildQuery(),
|
||||
// 列表顶栏/常用关键词:缩小上下文;本列搜索词走 keyword(列 LIKE)
|
||||
listKeyword: contextDraft.value.keyword.trim() || undefined
|
||||
}
|
||||
delete (rawContext as Row).keyword
|
||||
const context = stripSelfColumnParams(rawContext, field, defs.value)
|
||||
delete context.sortField
|
||||
delete context.sortOrder
|
||||
delete context.page
|
||||
delete context.pageSize
|
||||
|
||||
const rows = unwrapRows(
|
||||
await fetchCustomerColumnFacetValues({
|
||||
...context,
|
||||
field: field as 'customerNo' | 'customerName' | 'shortName',
|
||||
keyword: keyword.trim() || undefined,
|
||||
limit: 500
|
||||
})
|
||||
)
|
||||
if (facetVersions[field] === version && facetContextVersion === contextVersion) {
|
||||
facets.value[field] = rows
|
||||
.map((row: any) => ({
|
||||
value: String(row.value ?? row.id ?? row.label ?? ''),
|
||||
label: String(row.label ?? row.value ?? row.id ?? '')
|
||||
}))
|
||||
.filter((o) => o.value)
|
||||
if (enumOpen.value && enumProp.value === field && enumRemote.value) {
|
||||
enumOptions.value = facetSelectOptions({ prop: field })
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
if (facetVersions[field] === version && facetContextVersion === contextVersion) {
|
||||
error.value = e.message || '可选值加载失败'
|
||||
facets.value[field] = []
|
||||
if (enumOpen.value && enumProp.value === field && enumRemote.value) {
|
||||
enumOptions.value = facetSelectOptions({ prop: field })
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (facetVersions[field] === version) facetLoading.value[field] = false
|
||||
}
|
||||
}
|
||||
|
||||
function openSingle(kind: SingleKind, prop = '') {
|
||||
singleKind.value = kind
|
||||
numberOpProp.value = prop
|
||||
singleOpen.value = true
|
||||
}
|
||||
|
||||
function onSingleConfirm({ selectedValues }: { selectedValues: Array<string | number> }) {
|
||||
const value = String(selectedValues[0] ?? '')
|
||||
if (singleKind.value === 'view') contextDraft.value.viewMode = (value || 'all') as ViewKey
|
||||
if (singleKind.value === 'numberOp' && numberOpProp.value) {
|
||||
draft.value[numberOpProp.value + 'Op'] = value || 'between'
|
||||
}
|
||||
singleOpen.value = false
|
||||
}
|
||||
|
||||
function openEnumPicker(prop: string, options: EnumOpt[], remote = false) {
|
||||
enumProp.value = prop
|
||||
enumTitle.value = defs.value.find((d) => d.prop === prop)?.label || '请选择'
|
||||
enumDraft.value = Array.isArray(draft.value[prop]) ? [...draft.value[prop]] : []
|
||||
enumRemote.value = remote
|
||||
enumKeyword.value = String(facetKeywords.value[prop] || '')
|
||||
enumOpen.value = true
|
||||
if (remote) {
|
||||
enumOptions.value = []
|
||||
ensureFacet(prop)
|
||||
} else {
|
||||
enumOptions.value = options
|
||||
}
|
||||
}
|
||||
|
||||
function enumOptionLabel(value: string) {
|
||||
return enumOptions.value.find((o) => o.value === value)?.label || value
|
||||
}
|
||||
function toggleEnum(value: string) {
|
||||
const idx = enumDraft.value.indexOf(value)
|
||||
if (idx >= 0) enumDraft.value.splice(idx, 1)
|
||||
else enumDraft.value.push(value)
|
||||
}
|
||||
function selectAllEnum() {
|
||||
const set = new Set(enumDraft.value)
|
||||
for (const o of enumOptions.value) set.add(o.value)
|
||||
enumDraft.value = [...set]
|
||||
}
|
||||
function clearEnum() {
|
||||
enumDraft.value = []
|
||||
}
|
||||
|
||||
function confirmEnum() {
|
||||
if (enumProp.value) draft.value[enumProp.value] = [...enumDraft.value]
|
||||
enumOpen.value = false
|
||||
}
|
||||
|
||||
function onEnumSearch(keyword: string) {
|
||||
if (!enumRemote.value || !enumProp.value) return
|
||||
onFacetInput(enumProp.value, keyword)
|
||||
}
|
||||
|
||||
function openDateTime(key: string) {
|
||||
dateKey.value = key
|
||||
const raw = String(draft.value[key] || '').replace(' ', 'T')
|
||||
const d = raw ? new Date(raw) : new Date()
|
||||
const valid = Number.isNaN(d.getTime()) ? new Date() : d
|
||||
dateValue.value = [
|
||||
String(valid.getFullYear()),
|
||||
String(valid.getMonth() + 1).padStart(2, '0'),
|
||||
String(valid.getDate()).padStart(2, '0')
|
||||
]
|
||||
timeValue.value = [
|
||||
String(valid.getHours()).padStart(2, '0'),
|
||||
String(valid.getMinutes()).padStart(2, '0')
|
||||
]
|
||||
dateOpen.value = true
|
||||
}
|
||||
|
||||
function onDateConfirm() {
|
||||
const [y, m, day] = dateValue.value
|
||||
const [hh, mm] = timeValue.value
|
||||
draft.value[dateKey.value] = `${y}-${m}-${day}T${hh}:${mm}`
|
||||
dateOpen.value = false
|
||||
}
|
||||
|
||||
function buildQuery() {
|
||||
const q: Row = {}
|
||||
for (const d of defs.value) {
|
||||
if (d.type === 'enum') {
|
||||
if (draft.value[d.prop]?.length) {
|
||||
q[(d.queryKey || d.prop) + 'In'] = draft.value[d.prop].join(',')
|
||||
}
|
||||
} else if (d.type === 'datetime') {
|
||||
for (const key of [d.queryKeyFrom || d.prop + 'From', d.queryKeyTo || d.prop + 'To']) {
|
||||
if (draft.value[key]) q[key] = apiTime(draft.value[key])
|
||||
}
|
||||
} else if (d.type === 'number') {
|
||||
const op = draft.value[d.prop + 'Op'] || 'between'
|
||||
const keys = op === 'between' ? [d.prop + 'Min', d.prop + 'Max'] : [d.prop]
|
||||
for (const key of keys) {
|
||||
if (draft.value[key] !== '' && draft.value[key] != null) {
|
||||
q[key] = String(draft.value[key])
|
||||
q[d.prop + 'Op'] = op
|
||||
}
|
||||
}
|
||||
} else if (typeof draft.value[d.prop] === 'string' && draft.value[d.prop].trim()) {
|
||||
q[d.queryKey || d.prop] = draft.value[d.prop].trim()
|
||||
}
|
||||
}
|
||||
return q
|
||||
}
|
||||
|
||||
function apply() {
|
||||
emit('apply', {
|
||||
query: buildQuery(),
|
||||
keyword: contextDraft.value.keyword.trim(),
|
||||
viewMode: contextDraft.value.viewMode
|
||||
})
|
||||
emit('update:modelValue', false)
|
||||
}
|
||||
|
||||
function resetAndApply() {
|
||||
resetDraft()
|
||||
clearFacets()
|
||||
emit('apply', { query: {}, keyword: '', viewMode: 'all' })
|
||||
emit('update:modelValue', false)
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,49 @@
|
||||
<template>
|
||||
<div>
|
||||
<van-collapse v-if="!readonly" v-model="pasteActive" class="mp-customer-paste">
|
||||
<van-collapse-item title="快速识别开票信息" name="paste">
|
||||
<van-field
|
||||
v-model="paste"
|
||||
rows="5"
|
||||
autosize
|
||||
type="textarea"
|
||||
label="粘贴开票资料"
|
||||
placeholder="粘贴客户发来的开票资料"
|
||||
/>
|
||||
<div class="mp-customer-paste__actions">
|
||||
<van-button size="small" native-type="button" @click="recognize">识别并填入</van-button>
|
||||
</div>
|
||||
<p v-if="hint" class="mp-customer-paste__hint" role="status">{{ hint }}</p>
|
||||
</van-collapse-item>
|
||||
</van-collapse>
|
||||
<CustomerFields
|
||||
:fields="fields"
|
||||
:model-value="modelValue"
|
||||
:readonly="readonly"
|
||||
@update:model-value="$emit('update:modelValue', $event)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import CustomerFields from './CustomerFields.vue'
|
||||
import { invoiceFields, type Row } from './model'
|
||||
import { parseCrmInvoicePaste, mergeInvoiceRemark } from '@/utils/crm-invoice-paste-recognize'
|
||||
|
||||
const props = defineProps<{ modelValue: Row; optional?: boolean; readonly?: boolean }>()
|
||||
const emit = defineEmits<{ 'update:modelValue': [Row] }>()
|
||||
const paste = ref('')
|
||||
const hint = ref('')
|
||||
const pasteActive = ref<string[]>([])
|
||||
const fields = computed(() =>
|
||||
invoiceFields.map((f) => ({ ...f, required: props.optional ? false : f.required }))
|
||||
)
|
||||
function recognize() {
|
||||
const parsed = parseCrmInvoicePaste(paste.value)
|
||||
const next = { ...props.modelValue }
|
||||
for (const field of invoiceFields)
|
||||
if (field.key !== 'remark' && parsed[field.key]) next[field.key] = parsed[field.key]
|
||||
if (parsed.remarkParts.length) next.remark = mergeInvoiceRemark(next.remark, parsed.remarkParts)
|
||||
emit('update:modelValue', next)
|
||||
hint.value = `已识别 ${parsed.filledCount} 个字段。${parsed.warnings.join(';')}`
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,191 @@
|
||||
<template>
|
||||
<van-collapse v-model="rootActive" class="mp-customer-paste">
|
||||
<van-collapse-item
|
||||
:title="`字段筛选${hasActiveFilters ? ' · 已启用' : ''}`"
|
||||
name="root"
|
||||
>
|
||||
<van-button size="small" @click="clearAllFilters">清空筛选</van-button>
|
||||
<van-collapse v-model="fieldActive">
|
||||
<van-collapse-item
|
||||
v-for="d in definitions"
|
||||
:key="d.prop"
|
||||
:title="d.label"
|
||||
:name="d.prop"
|
||||
>
|
||||
<template v-if="d.type === 'enum'">
|
||||
<van-checkbox-group v-model="state(d.prop).selected">
|
||||
<van-cell-group>
|
||||
<van-cell
|
||||
v-for="option in d.enumOptions || collectUniqueOptions(d.prop)"
|
||||
:key="option.value"
|
||||
clickable
|
||||
:title="option.label"
|
||||
@click="toggleEnum(d.prop, option.value)"
|
||||
>
|
||||
<template #right-icon>
|
||||
<van-checkbox :name="option.value" @click.stop />
|
||||
</template>
|
||||
</van-cell>
|
||||
</van-cell-group>
|
||||
</van-checkbox-group>
|
||||
</template>
|
||||
<template v-else-if="d.type === 'datetime'">
|
||||
<van-field
|
||||
is-link
|
||||
readonly
|
||||
:label="d.label + '起'"
|
||||
:model-value="state(d.prop).from"
|
||||
placeholder="请选择"
|
||||
@click="openDate(d.prop, 'from')"
|
||||
/>
|
||||
<van-field
|
||||
is-link
|
||||
readonly
|
||||
:label="d.label + '止'"
|
||||
:model-value="state(d.prop).to"
|
||||
placeholder="请选择"
|
||||
@click="openDate(d.prop, 'to')"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="d.type === 'number'">
|
||||
<van-field
|
||||
is-link
|
||||
readonly
|
||||
label="比较方式"
|
||||
:model-value="numberOpLabel(state(d.prop).op)"
|
||||
@click="openOp(d.prop)"
|
||||
/>
|
||||
<template v-if="state(d.prop).op === 'between'">
|
||||
<van-field
|
||||
v-model="state(d.prop).min"
|
||||
type="number"
|
||||
label="最小值"
|
||||
clearable
|
||||
/>
|
||||
<van-field
|
||||
v-model="state(d.prop).max"
|
||||
type="number"
|
||||
label="最大值"
|
||||
clearable
|
||||
/>
|
||||
</template>
|
||||
<van-field
|
||||
v-else
|
||||
v-model="state(d.prop).value"
|
||||
type="number"
|
||||
label="数值"
|
||||
clearable
|
||||
/>
|
||||
</template>
|
||||
<van-field
|
||||
v-else
|
||||
v-model="state(d.prop).text"
|
||||
:label="d.label"
|
||||
:placeholder="'输入' + d.label"
|
||||
clearable
|
||||
/>
|
||||
</van-collapse-item>
|
||||
</van-collapse>
|
||||
</van-collapse-item>
|
||||
</van-collapse>
|
||||
|
||||
<van-popup v-model:show="dateOpen" position="bottom" round>
|
||||
<van-date-picker
|
||||
title="选择日期"
|
||||
v-model="dateParts"
|
||||
@confirm="onDateConfirm"
|
||||
@cancel="dateOpen = false"
|
||||
/>
|
||||
</van-popup>
|
||||
|
||||
<van-popup v-model:show="opOpen" position="bottom" round>
|
||||
<van-picker
|
||||
:columns="opColumns"
|
||||
:model-value="opValue"
|
||||
@confirm="onOpConfirm"
|
||||
@cancel="opOpen = false"
|
||||
/>
|
||||
</van-popup>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
useClientColumnFilters,
|
||||
type ColumnFilterDef,
|
||||
type NumberFilterOp
|
||||
} from '@/composables/useClientColumnFilters'
|
||||
import type { Row } from './model'
|
||||
|
||||
const props = defineProps<{ rows: Row[]; definitions: ColumnFilterDef[] }>()
|
||||
const emit = defineEmits<{ change: [Row[]] }>()
|
||||
const { filteredRows, getFilterState, hasActiveFilters, clearAllFilters, collectUniqueOptions } =
|
||||
useClientColumnFilters(
|
||||
computed(() => props.rows),
|
||||
props.definitions
|
||||
)
|
||||
|
||||
const rootActive = ref<string[]>([])
|
||||
const fieldActive = ref<string[]>([])
|
||||
const dateOpen = ref(false)
|
||||
const dateProp = ref('')
|
||||
const dateField = ref<'from' | 'to'>('from')
|
||||
const dateParts = ref<string[]>([])
|
||||
const opOpen = ref(false)
|
||||
const opProp = ref('')
|
||||
const opValue = ref<string[]>(['between'])
|
||||
const opColumns = [
|
||||
{ text: '区间', value: 'between' },
|
||||
{ text: '等于', value: 'eq' },
|
||||
{ text: '大于', value: 'gt' },
|
||||
{ text: '大于等于', value: 'gte' },
|
||||
{ text: '小于', value: 'lt' },
|
||||
{ text: '小于等于', value: 'lte' }
|
||||
]
|
||||
|
||||
function state(prop: string): Row {
|
||||
return getFilterState(prop)
|
||||
}
|
||||
function numberOpLabel(op: NumberFilterOp) {
|
||||
return opColumns.find((c) => c.value === op)?.text || '区间'
|
||||
}
|
||||
function toggleEnum(prop: string, value: string) {
|
||||
const selected = state(prop).selected as string[]
|
||||
const idx = selected.indexOf(value)
|
||||
if (idx >= 0) selected.splice(idx, 1)
|
||||
else selected.push(value)
|
||||
}
|
||||
function openDate(prop: string, field: 'from' | 'to') {
|
||||
dateProp.value = prop
|
||||
dateField.value = field
|
||||
const current = String(state(prop)[field] || '')
|
||||
if (current) {
|
||||
const [y, m, d] = current.split('-')
|
||||
dateParts.value = [y, m, d]
|
||||
} else {
|
||||
const now = new Date()
|
||||
dateParts.value = [
|
||||
String(now.getFullYear()),
|
||||
String(now.getMonth() + 1).padStart(2, '0'),
|
||||
String(now.getDate()).padStart(2, '0')
|
||||
]
|
||||
}
|
||||
dateOpen.value = true
|
||||
}
|
||||
function onDateConfirm() {
|
||||
if (dateProp.value) {
|
||||
const [y, m, d] = dateParts.value
|
||||
state(dateProp.value)[dateField.value] = `${y}-${m}-${d}`
|
||||
}
|
||||
dateOpen.value = false
|
||||
}
|
||||
function openOp(prop: string) {
|
||||
opProp.value = prop
|
||||
opValue.value = [state(prop).op || 'between']
|
||||
opOpen.value = true
|
||||
}
|
||||
function onOpConfirm({ selectedValues }: { selectedValues: string[] }) {
|
||||
if (opProp.value) state(opProp.value).op = selectedValues[0] || 'between'
|
||||
opOpen.value = false
|
||||
}
|
||||
|
||||
watch(filteredRows, (rows) => emit('change', rows), { immediate: true })
|
||||
</script>
|
||||
@@ -0,0 +1,793 @@
|
||||
<template>
|
||||
<section class="mp-customer-related-panel">
|
||||
<div class="mp-customer-actions">
|
||||
<van-button size="small" :disabled="loading" @click="load(true)">刷新</van-button>
|
||||
<span>共 {{ total }} 条</span>
|
||||
</div>
|
||||
|
||||
<input
|
||||
v-model="keyword"
|
||||
class="mp-wv-search mp-customer-contact-search"
|
||||
type="search"
|
||||
:placeholder="searchPlaceholder"
|
||||
:aria-label="searchPlaceholder"
|
||||
autocomplete="off"
|
||||
/>
|
||||
|
||||
<van-dropdown-menu class="mp-customer-dd mp-customer-contact-dd" :z-index="3000">
|
||||
<van-dropdown-item v-model="quick1" teleport="body" :options="quick1Options" />
|
||||
<van-dropdown-item v-model="quick2" teleport="body" :options="quick2Options" />
|
||||
<van-dropdown-item
|
||||
ref="moreDropdown"
|
||||
teleport="body"
|
||||
:title="moreActive ? '更多·已筛' : '更多'"
|
||||
@open="onMoreOpen"
|
||||
/>
|
||||
</van-dropdown-menu>
|
||||
|
||||
<p v-if="error" class="mp-customer-error">{{ error }}</p>
|
||||
<MpListPageSkeleton
|
||||
v-if="loading && !rows.length"
|
||||
variant="body"
|
||||
layout="customer"
|
||||
:card-count="2"
|
||||
caption="正在加载"
|
||||
aria-label="正在加载"
|
||||
/>
|
||||
<van-empty v-else-if="!filtered.length && !error" description="暂无记录" />
|
||||
|
||||
<article
|
||||
v-for="row in filtered"
|
||||
:key="String(row.id || row.operId)"
|
||||
class="mp-wv-card mp-customer-detail-card"
|
||||
>
|
||||
<div class="mp-customer-detail-card__head">
|
||||
<div class="mp-customer-detail-card__main">
|
||||
<div class="mp-customer-detail-card__title">{{ cardTitle(row) }}</div>
|
||||
<div class="mp-customer-detail-card__meta">{{ cardMeta(row) }}</div>
|
||||
</div>
|
||||
<span class="status-tag" :class="`status-tag--${cardTone(row)}`">{{ cardTag(row) }}</span>
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="mp-customer-detail-card__toggle"
|
||||
type="button"
|
||||
:aria-expanded="isExpanded(row.id || row.operId)"
|
||||
@click="toggleExpand(row.id || row.operId)"
|
||||
>
|
||||
{{ isExpanded(row.id || row.operId) ? '收起' : '展开' }}
|
||||
<span class="mp-customer-detail-card__toggle-icon" aria-hidden="true">{{
|
||||
isExpanded(row.id || row.operId) ? '▴' : '▾'
|
||||
}}</span>
|
||||
</button>
|
||||
|
||||
<div v-show="isExpanded(row.id || row.operId)" class="mp-customer-detail-card__extra">
|
||||
<div class="mp-customer-detail-card__rows">
|
||||
<div
|
||||
v-for="field in listFields"
|
||||
:key="field.key"
|
||||
class="mp-customer-detail-card__row"
|
||||
>
|
||||
<span>{{ field.label }}</span>
|
||||
<span>{{ fieldText(row, field) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mp-customer-detail-card__actions">
|
||||
<button class="mp-wv-btn" type="button" @click="open(row)">查看</button>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
<MpListPageSkeleton
|
||||
v-if="loading && rows.length"
|
||||
variant="body"
|
||||
layout="customer"
|
||||
:card-count="1"
|
||||
caption="正在加载更多"
|
||||
aria-label="正在加载更多"
|
||||
/>
|
||||
<van-button
|
||||
v-else-if="rows.length < total"
|
||||
block
|
||||
round
|
||||
style="margin-top: 8px"
|
||||
@click="load(false)"
|
||||
>
|
||||
加载更多
|
||||
</van-button>
|
||||
|
||||
<van-popup
|
||||
:show="moreOpen"
|
||||
position="bottom"
|
||||
round
|
||||
teleport="body"
|
||||
class="mp-customer-vant-popup"
|
||||
:style="{ height: '70%' }"
|
||||
@update:show="moreOpen = $event"
|
||||
>
|
||||
<div class="mp-customer-filter-vant">
|
||||
<van-nav-bar title="更多筛选" left-text="关闭" @click-left="moreOpen = false" />
|
||||
<div class="mp-customer-filter-vant__body">
|
||||
<van-cell-group inset>
|
||||
<van-field
|
||||
v-for="item in moreFieldDefs"
|
||||
:key="item.prop"
|
||||
v-model="moreDraft[item.prop]"
|
||||
:label="item.label"
|
||||
:placeholder="`输入${item.label}`"
|
||||
clearable
|
||||
/>
|
||||
</van-cell-group>
|
||||
</div>
|
||||
<div class="mp-customer-filter-vant__foot">
|
||||
<button class="mp-wv-btn" type="button" @click="resetMore">重置</button>
|
||||
<button class="mp-wv-btn mp-wv-btn--primary" type="button" @click="applyMore">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</van-popup>
|
||||
|
||||
<van-popup
|
||||
:show="detailOpen"
|
||||
position="bottom"
|
||||
round
|
||||
teleport="body"
|
||||
class="mp-customer-vant-popup"
|
||||
:style="{ height: '82%' }"
|
||||
@update:show="onDetailShow"
|
||||
>
|
||||
<div class="mp-customer-pool-vant">
|
||||
<van-nav-bar :title="detailTitle" left-text="关闭" @click-left="closeDetail" />
|
||||
<div class="mp-customer-pool-vant__body">
|
||||
<MpStructSkeleton v-if="detailLoading" kind="detail" caption="正在加载详情" />
|
||||
<p v-else-if="detailError" class="mp-customer-error">{{ detailError }}</p>
|
||||
<template v-else-if="detail">
|
||||
<section class="mp-wv-section">
|
||||
<h3>{{ detailHeading }}</h3>
|
||||
<CustomerFields :fields="detailFields" :model-value="detail" readonly />
|
||||
</section>
|
||||
|
||||
<template v-if="kind === 'log'">
|
||||
<section class="mp-wv-section">
|
||||
<h3>请求参数</h3>
|
||||
<pre class="mp-customer-pre">{{ detail.operParam || '无' }}</pre>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<template v-else-if="kind === 'opportunity'">
|
||||
<OpportunityActions
|
||||
ref="opportunityActions"
|
||||
:opportunity="detail"
|
||||
@changed="refreshOpportunity"
|
||||
@deleted="onOpportunityDeleted"
|
||||
/>
|
||||
|
||||
<section class="mp-wv-section">
|
||||
<h3>跟进记录</h3>
|
||||
<van-empty v-if="!follows.length" description="暂无跟进记录" image-size="64" />
|
||||
<article
|
||||
v-for="row in follows"
|
||||
:key="row.id"
|
||||
class="mp-wv-card mp-customer-detail-card"
|
||||
>
|
||||
<div class="mp-customer-detail-card__head">
|
||||
<div class="mp-customer-detail-card__main">
|
||||
<div class="mp-customer-detail-card__title">
|
||||
{{ row.followContent || '—' }}
|
||||
</div>
|
||||
<div class="mp-customer-detail-card__meta">
|
||||
{{ row.followByName || row.createByName || row.ownerUserName || '—' }} ·
|
||||
{{ row.followTime || row.createTime || '—' }}
|
||||
</div>
|
||||
</div>
|
||||
<span class="status-tag status-tag--info">{{
|
||||
dict.getLabel('crm_opportunity_follow_type', row.followType) || '跟进'
|
||||
}}</span>
|
||||
</div>
|
||||
<button
|
||||
class="mp-customer-detail-card__toggle"
|
||||
type="button"
|
||||
:aria-expanded="isSubExpanded('f', row.id)"
|
||||
@click="toggleSubExpand('f', row.id)"
|
||||
>
|
||||
{{ isSubExpanded('f', row.id) ? '收起' : '展开' }}
|
||||
<span class="mp-customer-detail-card__toggle-icon" aria-hidden="true">{{
|
||||
isSubExpanded('f', row.id) ? '▴' : '▾'
|
||||
}}</span>
|
||||
</button>
|
||||
<div v-show="isSubExpanded('f', row.id)" class="mp-customer-detail-card__extra">
|
||||
<div class="mp-customer-detail-card__rows">
|
||||
<div v-if="row.nextTime" class="mp-customer-detail-card__row">
|
||||
<span>下次联系</span>
|
||||
<span>{{ row.nextTime }}</span>
|
||||
</div>
|
||||
<div v-if="row.nextPlan || row.nextContent" class="mp-customer-detail-card__row">
|
||||
<span>下次计划</span>
|
||||
<span>{{ row.nextPlan || row.nextContent }}</span>
|
||||
</div>
|
||||
<div v-if="row.remark" class="mp-customer-detail-card__row">
|
||||
<span>备注</span>
|
||||
<span>{{ row.remark }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<CustomerAttachments
|
||||
v-if="row.attachment || row.attachments"
|
||||
:model-value="row.attachment || row.attachments"
|
||||
readonly
|
||||
/>
|
||||
<div
|
||||
v-if="canDeleteByCreator(row)"
|
||||
class="mp-customer-detail-card__actions"
|
||||
>
|
||||
<button
|
||||
class="mp-wv-btn"
|
||||
type="button"
|
||||
@click="opportunityActions?.editFollow(row)"
|
||||
>
|
||||
编辑
|
||||
</button>
|
||||
<button
|
||||
class="mp-wv-btn"
|
||||
type="button"
|
||||
@click="opportunityActions?.deleteFollow(row)"
|
||||
>
|
||||
删除
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section class="mp-wv-section">
|
||||
<h3>阶段记录</h3>
|
||||
<van-empty v-if="!stages.length" description="暂无阶段记录" image-size="64" />
|
||||
<article
|
||||
v-for="row in stages"
|
||||
:key="row.id"
|
||||
class="mp-wv-card mp-customer-detail-card"
|
||||
>
|
||||
<div class="mp-customer-detail-card__head">
|
||||
<div class="mp-customer-detail-card__main">
|
||||
<div class="mp-customer-detail-card__title">
|
||||
{{
|
||||
row.fromStageName ||
|
||||
dict.getLabel('crm_opportunity_stage', row.fromStage) ||
|
||||
'—'
|
||||
}}
|
||||
→
|
||||
{{
|
||||
row.toStageName ||
|
||||
dict.getLabel('crm_opportunity_stage', row.toStage) ||
|
||||
'—'
|
||||
}}
|
||||
</div>
|
||||
<div class="mp-customer-detail-card__meta">
|
||||
{{ row.createByName || row.operatorName || '—' }} ·
|
||||
{{ row.createTime || '—' }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
class="mp-customer-detail-card__toggle"
|
||||
type="button"
|
||||
:aria-expanded="isSubExpanded('s', row.id)"
|
||||
@click="toggleSubExpand('s', row.id)"
|
||||
>
|
||||
{{ isSubExpanded('s', row.id) ? '收起' : '展开' }}
|
||||
<span class="mp-customer-detail-card__toggle-icon" aria-hidden="true">{{
|
||||
isSubExpanded('s', row.id) ? '▴' : '▾'
|
||||
}}</span>
|
||||
</button>
|
||||
<div v-show="isSubExpanded('s', row.id)" class="mp-customer-detail-card__extra">
|
||||
<div class="mp-customer-detail-card__rows">
|
||||
<div v-if="row.toPercent != null" class="mp-customer-detail-card__row">
|
||||
<span>阶段进度</span>
|
||||
<span>{{ row.toPercent }}%</span>
|
||||
</div>
|
||||
<div v-if="row.lostDetail" class="mp-customer-detail-card__row">
|
||||
<span>输单说明</span>
|
||||
<span>{{ row.lostDetail }}</span>
|
||||
</div>
|
||||
<div v-if="row.wonRemark" class="mp-customer-detail-card__row">
|
||||
<span>赢单说明</span>
|
||||
<span>{{ row.wonRemark }}</span>
|
||||
</div>
|
||||
<div class="mp-customer-detail-card__row">
|
||||
<span>说明</span>
|
||||
<span>{{ row.remark || row.changeReason || '—' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</section>
|
||||
</template>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</van-popup>
|
||||
</section>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import MpListPageSkeleton from '@/components/mp/MpListPageSkeleton.vue'
|
||||
import MpStructSkeleton from '@/components/mp/MpStructSkeleton.vue'
|
||||
import CustomerFields from './CustomerFields.vue'
|
||||
import OpportunityActions from './OpportunityActions.vue'
|
||||
import CustomerAttachments from './CustomerAttachments.vue'
|
||||
import { canDeleteByCreator } from '@/utils/creator-delete'
|
||||
import {
|
||||
OPPORTUNITY_SOURCE_FALLBACK,
|
||||
OPPORTUNITY_TYPE_FALLBACK
|
||||
} from '@/utils/crm-opportunity-labels'
|
||||
import {
|
||||
listOpportunity,
|
||||
getOpportunity,
|
||||
listFollowByOpportunity,
|
||||
getStageLogList
|
||||
} from '@/api/crm/opportunity'
|
||||
import { listContract } from '@/api/crm/contract'
|
||||
import { list as listOperLog } from '@/api/monitor/operlog'
|
||||
import { useDictStore } from '@/store/modules/dict'
|
||||
import { unwrapData, unwrapRows, type Row, type Field } from './model'
|
||||
|
||||
const props = defineProps<{ customerId: string; kind: 'opportunity' | 'contract' | 'log' }>()
|
||||
const dict = useDictStore()
|
||||
|
||||
const rows = ref<Row[]>([])
|
||||
const page = ref(0)
|
||||
const total = ref(0)
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
const keyword = ref('')
|
||||
const quick1 = ref('')
|
||||
const quick2 = ref('')
|
||||
const moreOpen = ref(false)
|
||||
const moreDropdown = ref<{ toggle?: (show?: boolean) => void } | null>(null)
|
||||
const expandedIds = ref<Record<string, boolean>>({})
|
||||
const subExpandedIds = ref<Record<string, boolean>>({})
|
||||
const detailOpen = ref(false)
|
||||
const detailLoading = ref(false)
|
||||
const detailError = ref('')
|
||||
const detail = ref<Row>()
|
||||
const opportunityActions = ref<InstanceType<typeof OpportunityActions>>()
|
||||
const follows = ref<Row[]>([])
|
||||
const stages = ref<Row[]>([])
|
||||
|
||||
type MoreItem = { prop: string; label: string }
|
||||
const moreFieldDefs = computed<MoreItem[]>(() => {
|
||||
if (props.kind === 'opportunity') {
|
||||
return [
|
||||
{ prop: 'opportunityName', label: '商机名称' },
|
||||
{ prop: 'ownerUserName', label: '负责人' },
|
||||
{ prop: 'expectDealDate', label: '预计成交日期' },
|
||||
{ prop: 'createTime', label: '创建时间' }
|
||||
]
|
||||
}
|
||||
if (props.kind === 'contract') {
|
||||
return [
|
||||
{ prop: 'contractNo', label: '合同编号' },
|
||||
{ prop: 'contractName', label: '合同名称' },
|
||||
{ prop: 'ownerUserName', label: '负责人' },
|
||||
{ prop: 'signDate', label: '签订日期' },
|
||||
{ prop: 'amount', label: '合同金额' }
|
||||
]
|
||||
}
|
||||
return [
|
||||
{ prop: 'operTime', label: '操作时间' },
|
||||
{ prop: 'title', label: '操作模块' },
|
||||
{ prop: 'operName', label: '操作人员' },
|
||||
{ prop: 'operIp', label: '操作IP' },
|
||||
{ prop: 'costTime', label: '耗时' }
|
||||
]
|
||||
})
|
||||
|
||||
const emptyMore = () =>
|
||||
Object.fromEntries(moreFieldDefs.value.map((i) => [i.prop, ''])) as Record<string, string>
|
||||
const moreApplied = ref<Record<string, string>>({})
|
||||
const moreDraft = ref<Record<string, string>>({})
|
||||
|
||||
const searchPlaceholder = computed(() => {
|
||||
if (props.kind === 'opportunity') return '商机名称 / 编号 / 负责人'
|
||||
if (props.kind === 'contract') return '合同名称 / 编号 / 负责人'
|
||||
return '模块 / 人员 / IP'
|
||||
})
|
||||
|
||||
const quick1Options = computed(() => {
|
||||
if (props.kind === 'opportunity') {
|
||||
return [
|
||||
{ text: '全部阶段', value: '' },
|
||||
...dict.getOptions('crm_opportunity_stage').map((o) => ({
|
||||
text: o.label,
|
||||
value: String(o.value)
|
||||
}))
|
||||
]
|
||||
}
|
||||
if (props.kind === 'contract') {
|
||||
return [
|
||||
{ text: '全部类型', value: '' },
|
||||
...dict.getOptions('crm_contract_type').map((o) => ({
|
||||
text: o.label,
|
||||
value: String(o.value)
|
||||
}))
|
||||
]
|
||||
}
|
||||
return [
|
||||
{ text: '全部类型', value: '' },
|
||||
...dict.getOptions('sys_oper_type').map((o) => ({ text: o.label, value: String(o.value) }))
|
||||
]
|
||||
})
|
||||
|
||||
const quick2Options = computed(() => {
|
||||
if (props.kind === 'opportunity') {
|
||||
return [
|
||||
{ text: '全部状态', value: '' },
|
||||
...dict.getOptions('crm_opportunity_status').map((o) => ({
|
||||
text: o.label,
|
||||
value: String(o.value)
|
||||
}))
|
||||
]
|
||||
}
|
||||
if (props.kind === 'contract') {
|
||||
return [
|
||||
{ text: '全部状态', value: '' },
|
||||
...dict.getOptions('crm_contract_status').map((o) => ({
|
||||
text: o.label,
|
||||
value: String(o.value)
|
||||
}))
|
||||
]
|
||||
}
|
||||
return [
|
||||
{ text: '全部结果', value: '' },
|
||||
{ text: '成功', value: '0' },
|
||||
{ text: '失败', value: '1' }
|
||||
]
|
||||
})
|
||||
|
||||
const moreActive = computed(() =>
|
||||
moreFieldDefs.value.some((i) => !!String(moreApplied.value[i.prop] ?? '').trim())
|
||||
)
|
||||
|
||||
const fieldsFrom = (map: Record<string, string>): Field[] =>
|
||||
Object.entries(map).map(([key, label]) => ({ key, label }))
|
||||
|
||||
const opportunityFields: Field[] = [
|
||||
...fieldsFrom({
|
||||
opportunityNo: '商机编号',
|
||||
customerName: '客户名称',
|
||||
contactName: '联系人',
|
||||
amount: '商机金额(元)',
|
||||
expectDealDate: '预计成交日期',
|
||||
actualDealDate: '实际成交日期',
|
||||
ownerUserName: '负责人',
|
||||
stagePercent: '阶段进度(%)',
|
||||
winRate: '预估赢单率(%)'
|
||||
}),
|
||||
{ key: 'stage', label: '商机阶段', dict: 'crm_opportunity_stage' },
|
||||
{ key: 'status', label: '商机状态', dict: 'crm_opportunity_status' },
|
||||
{
|
||||
key: 'type',
|
||||
label: '商机类型',
|
||||
options: [
|
||||
...Object.entries(OPPORTUNITY_TYPE_FALLBACK).map(([value, label]) => ({ value, label })),
|
||||
...dict.getOptions('crm_opportunity_type')
|
||||
]
|
||||
},
|
||||
{
|
||||
key: 'source',
|
||||
label: '商机来源',
|
||||
options: [
|
||||
...dict.getOptions('crm_clue_source'),
|
||||
...Object.entries(OPPORTUNITY_SOURCE_FALLBACK).map(([value, label]) => ({ value, label }))
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
const contractFields: Field[] = [
|
||||
...fieldsFrom({
|
||||
contractNo: '合同编号',
|
||||
amount: '合同金额',
|
||||
signDate: '签订日期',
|
||||
ownerUserName: '负责人'
|
||||
}),
|
||||
{ key: 'contractType', label: '合同类型', dict: 'crm_contract_type' },
|
||||
{ key: 'status', label: '合同状态', dict: 'crm_contract_status' }
|
||||
]
|
||||
|
||||
const logFields: Field[] = [
|
||||
...fieldsFrom({
|
||||
title: '操作模块',
|
||||
operName: '操作人员',
|
||||
operTime: '操作时间',
|
||||
operIp: '操作IP',
|
||||
costTime: '耗时(毫秒)'
|
||||
}),
|
||||
{ key: 'businessType', label: '操作类型', dict: 'sys_oper_type' },
|
||||
{
|
||||
key: 'status',
|
||||
label: '状态',
|
||||
options: [
|
||||
{ value: '0', label: '成功' },
|
||||
{ value: '1', label: '失败' }
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
const listFields = computed<Field[]>(() => {
|
||||
if (props.kind === 'opportunity') return opportunityFields
|
||||
if (props.kind === 'log') return logFields
|
||||
return contractFields
|
||||
})
|
||||
|
||||
const detailFields = computed(() => {
|
||||
if (props.kind === 'log') {
|
||||
return [...logFields, ...fieldsFrom({ operUrl: '请求地址', errorMsg: '错误信息' })]
|
||||
}
|
||||
if (props.kind === 'contract') {
|
||||
return [
|
||||
{ key: 'contractName', label: '合同名称' },
|
||||
...contractFields
|
||||
]
|
||||
}
|
||||
return [
|
||||
{ key: 'opportunityName', label: '商机名称' },
|
||||
...opportunityFields,
|
||||
...fieldsFrom({
|
||||
followCount: '跟进次数',
|
||||
productCount: '产品数量',
|
||||
lastTime: '最后跟进时间',
|
||||
nextTime: '下次联系时间',
|
||||
stageChangeTime: '阶段变更时间',
|
||||
createByName: '创建人',
|
||||
createTime: '创建时间',
|
||||
updateTime: '更新时间',
|
||||
competitors: '竞争对手',
|
||||
keyFactors: '关键决策因素',
|
||||
description: '商机描述',
|
||||
lostReason: '输单原因',
|
||||
remark: '备注'
|
||||
})
|
||||
]
|
||||
})
|
||||
|
||||
const detailTitle = computed(() => {
|
||||
if (props.kind === 'log') return '操作日志详情'
|
||||
if (props.kind === 'contract') return '合同详情'
|
||||
return '商机详情'
|
||||
})
|
||||
|
||||
const detailHeading = computed(() => {
|
||||
if (!detail.value) return '—'
|
||||
if (props.kind === 'log') return String(detail.value.title || '操作日志')
|
||||
if (props.kind === 'contract') {
|
||||
return String(detail.value.contractName || detail.value.contractNo || '合同详情')
|
||||
}
|
||||
return String(detail.value.opportunityName || '商机详情')
|
||||
})
|
||||
|
||||
function isExpanded(id: unknown) {
|
||||
return !!expandedIds.value[String(id)]
|
||||
}
|
||||
function toggleExpand(id: unknown) {
|
||||
const key = String(id)
|
||||
expandedIds.value = { ...expandedIds.value, [key]: !expandedIds.value[key] }
|
||||
}
|
||||
function isSubExpanded(prefix: string, id: unknown) {
|
||||
return !!subExpandedIds.value[`${prefix}:${id}`]
|
||||
}
|
||||
function toggleSubExpand(prefix: string, id: unknown) {
|
||||
const key = `${prefix}:${id}`
|
||||
subExpandedIds.value = { ...subExpandedIds.value, [key]: !subExpandedIds.value[key] }
|
||||
}
|
||||
|
||||
function fieldText(row: Row, field: Field) {
|
||||
const value = row[field.key]
|
||||
if (field.dict) return dict.getLabel(field.dict, value) || (value ? String(value) : '—')
|
||||
if (field.options) {
|
||||
const hit = field.options.find((o) => String(o.value) === String(value ?? ''))
|
||||
return hit?.label || (value ? String(value) : '—')
|
||||
}
|
||||
return value !== '' && value != null ? String(value) : '—'
|
||||
}
|
||||
|
||||
function cardTitle(row: Row) {
|
||||
if (props.kind === 'opportunity') return String(row.opportunityName || '未命名商机')
|
||||
if (props.kind === 'contract') {
|
||||
return String(row.contractName || row.contractNo || '未命名合同')
|
||||
}
|
||||
return String(row.title || '操作日志')
|
||||
}
|
||||
function cardMeta(row: Row) {
|
||||
if (props.kind === 'opportunity') {
|
||||
return `${row.amount != null && row.amount !== '' ? row.amount : '—'} · ${row.ownerUserName || '—'}`
|
||||
}
|
||||
if (props.kind === 'contract') {
|
||||
return `${row.amount != null && row.amount !== '' ? row.amount : '—'} · ${row.signDate || '—'}`
|
||||
}
|
||||
return `${row.operName || '—'} · ${row.operTime || '—'}`
|
||||
}
|
||||
function cardTag(row: Row) {
|
||||
if (props.kind === 'opportunity') {
|
||||
return dict.getLabel('crm_opportunity_stage', row.stage) || String(row.stage || '—')
|
||||
}
|
||||
if (props.kind === 'contract') {
|
||||
return dict.getLabel('crm_contract_status', row.status) || String(row.status || '—')
|
||||
}
|
||||
return String(row.status) === '1' ? '失败' : '成功'
|
||||
}
|
||||
function cardTone(row: Row) {
|
||||
if (props.kind === 'log') return String(row.status) === '1' ? 'danger' : 'success'
|
||||
if (props.kind === 'contract') {
|
||||
const s = String(row.status || '')
|
||||
if (s.includes('cancel') || s.includes('void') || s === 'rejected') return 'danger'
|
||||
if (s.includes('draft') || s.includes('pending')) return 'warning'
|
||||
return 'success'
|
||||
}
|
||||
return 'info'
|
||||
}
|
||||
|
||||
function matchQuick(row: Row) {
|
||||
if (props.kind === 'opportunity') {
|
||||
if (quick1.value && String(row.stage ?? '') !== quick1.value) return false
|
||||
if (quick2.value && String(row.status ?? '') !== quick2.value) return false
|
||||
} else if (props.kind === 'contract') {
|
||||
if (quick1.value && String(row.contractType ?? '') !== quick1.value) return false
|
||||
if (quick2.value && String(row.status ?? '') !== quick2.value) return false
|
||||
} else {
|
||||
if (quick1.value && String(row.businessType ?? '') !== quick1.value) return false
|
||||
if (quick2.value && String(row.status ?? '') !== quick2.value) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
function matchKeyword(row: Row) {
|
||||
const kw = keyword.value.trim().toLowerCase()
|
||||
if (!kw) return true
|
||||
if (props.kind === 'opportunity') {
|
||||
return [row.opportunityName, row.opportunityNo, row.ownerUserName].some((v) =>
|
||||
String(v ?? '')
|
||||
.toLowerCase()
|
||||
.includes(kw)
|
||||
)
|
||||
}
|
||||
if (props.kind === 'contract') {
|
||||
return [row.contractName, row.contractNo, row.ownerUserName].some((v) =>
|
||||
String(v ?? '')
|
||||
.toLowerCase()
|
||||
.includes(kw)
|
||||
)
|
||||
}
|
||||
return [row.title, row.operName, row.operIp].some((v) =>
|
||||
String(v ?? '')
|
||||
.toLowerCase()
|
||||
.includes(kw)
|
||||
)
|
||||
}
|
||||
|
||||
const filtered = computed(() =>
|
||||
rows.value.filter((row) => {
|
||||
if (!matchQuick(row)) return false
|
||||
for (const item of moreFieldDefs.value) {
|
||||
const tip = String(moreApplied.value[item.prop] ?? '')
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
if (tip && !String(row[item.prop] ?? '').toLowerCase().includes(tip)) return false
|
||||
}
|
||||
return matchKeyword(row)
|
||||
})
|
||||
)
|
||||
|
||||
function onMoreOpen() {
|
||||
moreDraft.value = { ...emptyMore(), ...moreApplied.value }
|
||||
moreOpen.value = true
|
||||
nextTick(() => moreDropdown.value?.toggle?.(false))
|
||||
}
|
||||
function resetMore() {
|
||||
moreDraft.value = emptyMore()
|
||||
}
|
||||
function applyMore() {
|
||||
moreApplied.value = { ...moreDraft.value }
|
||||
moreOpen.value = false
|
||||
}
|
||||
watch(
|
||||
moreDraft,
|
||||
() => {
|
||||
if (!moreOpen.value) return
|
||||
moreApplied.value = { ...moreDraft.value }
|
||||
},
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
function onDetailShow(show: boolean) {
|
||||
detailOpen.value = show
|
||||
}
|
||||
function closeDetail() {
|
||||
detailOpen.value = false
|
||||
}
|
||||
|
||||
async function load(reset = true) {
|
||||
if (loading.value) return
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
const nextPage = reset ? 1 : page.value + 1
|
||||
try {
|
||||
const query = {
|
||||
customerId: props.customerId,
|
||||
pageNum: nextPage,
|
||||
page: nextPage,
|
||||
pageSize: 20
|
||||
}
|
||||
const res =
|
||||
props.kind === 'opportunity'
|
||||
? await listOpportunity(query)
|
||||
: props.kind === 'contract'
|
||||
? await listContract(query)
|
||||
: await listOperLog({
|
||||
pageNum: nextPage,
|
||||
page: nextPage,
|
||||
pageSize: 20,
|
||||
businessId: props.customerId,
|
||||
businessTitle: 'CRM客户管理'
|
||||
})
|
||||
const data = unwrapData(res)
|
||||
rows.value = reset ? unwrapRows(data) : [...rows.value, ...unwrapRows(data)]
|
||||
total.value = data.total ?? rows.value.length
|
||||
page.value = nextPage
|
||||
} catch (e: any) {
|
||||
error.value = e.message || '记录加载失败'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function open(row: Row) {
|
||||
detailOpen.value = true
|
||||
detailLoading.value = true
|
||||
detailError.value = ''
|
||||
detail.value = undefined
|
||||
follows.value = []
|
||||
stages.value = []
|
||||
try {
|
||||
if (props.kind === 'log' || props.kind === 'contract') {
|
||||
detail.value = row
|
||||
} else {
|
||||
const [info, follow, stage] = await Promise.all([
|
||||
getOpportunity(String(row.id)),
|
||||
listFollowByOpportunity(String(row.id), 500),
|
||||
getStageLogList(String(row.id))
|
||||
])
|
||||
detail.value = unwrapData(info)
|
||||
follows.value = unwrapRows(follow)
|
||||
stages.value = unwrapRows(stage)
|
||||
}
|
||||
} catch (e: any) {
|
||||
detailError.value = e.message || '详情加载失败'
|
||||
} finally {
|
||||
detailLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshOpportunity() {
|
||||
if (detail.value) await open(detail.value)
|
||||
await load(true)
|
||||
}
|
||||
function onOpportunityDeleted() {
|
||||
detailOpen.value = false
|
||||
void load(true)
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.kind,
|
||||
() => {
|
||||
quick1.value = ''
|
||||
quick2.value = ''
|
||||
moreApplied.value = {}
|
||||
moreDraft.value = emptyMore()
|
||||
keyword.value = ''
|
||||
void load(true)
|
||||
}
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
moreApplied.value = emptyMore()
|
||||
moreDraft.value = emptyMore()
|
||||
void load(true)
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,124 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import {
|
||||
customerPayload,
|
||||
customerForm,
|
||||
unwrapRows,
|
||||
apiTime,
|
||||
customerCardTime,
|
||||
customerFilterSummaryLabel,
|
||||
saveCustomerAndInvoice,
|
||||
stageSuggestion,
|
||||
splitCustomerListFields,
|
||||
customerListCardMeta
|
||||
} from './model'
|
||||
|
||||
test('商机阶段建议与 Web 保持一致,未知阶段不覆盖手工值', () => {
|
||||
assert.deepEqual(stageSuggestion('quote'), { stagePercent: 60, winRate: 65 })
|
||||
assert.deepEqual(stageSuggestion('won'), { stagePercent: 100, winRate: 100 })
|
||||
assert.deepEqual(stageSuggestion('custom'), {})
|
||||
})
|
||||
|
||||
test('编辑保留精确 ID,清空证件,排除旧别名和只读字段', () => {
|
||||
const form = customerForm({
|
||||
id: '90071992547409931',
|
||||
customerName: ' 客户 ',
|
||||
businessLicenseImg: 'old.pdf',
|
||||
tenantNo: 'other'
|
||||
})
|
||||
assert.equal(form.businessLicenseImages, 'old.pdf')
|
||||
form.businessLicenseImages = ''
|
||||
const payload = customerPayload(form)
|
||||
assert.equal(payload.id, '90071992547409931')
|
||||
assert.equal(payload.customerName, '客户')
|
||||
assert.equal(payload.businessLicenseImages, '')
|
||||
assert.equal(payload.namePinyinAbbr, '')
|
||||
assert.ok(!('businessLicenseImg' in payload))
|
||||
assert.ok(!('tenantNo' in payload))
|
||||
})
|
||||
|
||||
test('联系人和跟进支持已解包数组及分页响应', () => {
|
||||
const rows = [{ id: 'a' }]
|
||||
for (const value of [rows, { rows }, { list: rows }, { data: rows }, { data: { rows } }]) {
|
||||
assert.deepEqual(unwrapRows(value), rows)
|
||||
}
|
||||
})
|
||||
|
||||
test('手机日期输入转接口格式,不发生 UTC 时区偏移', () => {
|
||||
assert.equal(apiTime('2026-10-17T09:30'), '2026-10-17 09:30:00')
|
||||
assert.equal(apiTime(''), '')
|
||||
})
|
||||
|
||||
test('客户卡时间按下次联系、最后跟进、创建时间依次回退', () => {
|
||||
assert.equal(customerCardTime({ nextTime: '2026-10-20' }), '下次联系:2026-10-20')
|
||||
assert.equal(customerCardTime({ lastTime: '2026-10-19' }), '最后跟进:2026-10-19')
|
||||
assert.equal(customerCardTime({ createTime: '2026-10-18' }), '创建时间:2026-10-18')
|
||||
assert.equal(customerCardTime({}), '')
|
||||
})
|
||||
|
||||
test('多选快捷筛选显示选择数量,单选显示字典名称', () => {
|
||||
const label = (value: string) => ({ company: '企业', person: '个人' })[value] || value
|
||||
assert.equal(customerFilterSummaryLabel('', label, '客户类型'), '客户类型')
|
||||
assert.equal(customerFilterSummaryLabel('company', label, '客户类型'), '企业')
|
||||
assert.equal(customerFilterSummaryLabel('company,person', label, '客户类型'), '已选2项')
|
||||
})
|
||||
|
||||
test('列表卡字段:固定全量 Web 列,预览简称+手机,其余进展开', () => {
|
||||
const { preview, extra } = splitCustomerListFields()
|
||||
assert.deepEqual(
|
||||
preview.map((f) => f.key),
|
||||
['shortName', 'mobile']
|
||||
)
|
||||
assert.ok(extra.some((f) => f.key === 'customerNo'))
|
||||
assert.ok(extra.some((f) => f.key === 'status'))
|
||||
assert.ok(extra.some((f) => f.key === 'remark'))
|
||||
assert.ok(!extra.some((f) => f.key === 'shortName'))
|
||||
assert.ok(!extra.some((f) => f.key === 'mobile'))
|
||||
assert.ok(!extra.some((f) => f.key === 'customerName'))
|
||||
assert.equal(preview.length + extra.length, 36)
|
||||
})
|
||||
|
||||
test('列表卡摘要:状态·编号·创建时间,缺省为—', () => {
|
||||
assert.equal(
|
||||
customerListCardMeta({
|
||||
statusLabel: '正常',
|
||||
customerNo: 'C001',
|
||||
createTime: '2026-10-18 09:00'
|
||||
}),
|
||||
'正常 · C001 · 2026-10-18 09:00'
|
||||
)
|
||||
assert.equal(
|
||||
customerListCardMeta({
|
||||
statusLabel: '',
|
||||
customerNo: '',
|
||||
createTime: ''
|
||||
}),
|
||||
'— · — · —'
|
||||
)
|
||||
})
|
||||
|
||||
test('开票保存失败后重试仅补开票,不重复创建客户', async () => {
|
||||
const state = { customerId: '' }
|
||||
let creates = 0
|
||||
let invoices = 0
|
||||
const api = {
|
||||
create: async () => {
|
||||
creates++
|
||||
return { id: 'precise-id' }
|
||||
},
|
||||
update: async () => {},
|
||||
invoice: async (data: any) => {
|
||||
assert.equal(data.customerId, 'precise-id')
|
||||
invoices++
|
||||
if (invoices === 1) throw new Error('网络失败')
|
||||
}
|
||||
}
|
||||
await assert.rejects(saveCustomerAndInvoice(customerForm(), { companyName: '客户' }, state, api))
|
||||
assert.equal(state.customerId, 'precise-id')
|
||||
assert.equal(
|
||||
await saveCustomerAndInvoice(customerForm(), { companyName: '客户' }, state, api),
|
||||
'precise-id'
|
||||
)
|
||||
assert.equal(creates, 1)
|
||||
assert.equal(invoices, 2)
|
||||
})
|
||||
@@ -0,0 +1,299 @@
|
||||
export type Row = Record<string, any>
|
||||
export type Field = {
|
||||
key: string
|
||||
label: string
|
||||
type?:
|
||||
| 'text'
|
||||
| 'textarea'
|
||||
| 'datetime-local'
|
||||
| 'date'
|
||||
| 'email'
|
||||
| 'tel'
|
||||
| 'select'
|
||||
| 'switch'
|
||||
| 'number'
|
||||
dict?: string
|
||||
options?: { value: string; label: string }[]
|
||||
required?: boolean
|
||||
max?: number
|
||||
minValue?: number
|
||||
maxValue?: number
|
||||
}
|
||||
export const CUSTOMER_PATH = '/m/crm/customer'
|
||||
export const customerGroups: { title: string; fields: Field[] }[] = [
|
||||
{
|
||||
title: '基本信息',
|
||||
fields: [
|
||||
{ key: 'customerName', label: '客户名称', required: true, max: 200 },
|
||||
{ key: 'namePinyinAbbr', label: '拼音首字母', max: 100 },
|
||||
{ key: 'shortName', label: '客户简称', required: true, max: 100 },
|
||||
{ key: 'customerType', label: '客户类型', dict: 'crm_customer_type', required: true },
|
||||
{ key: 'level', label: '客户级别', dict: 'crm_customer_level' },
|
||||
{ key: 'mobile', label: '手机号', type: 'tel', max: 11 },
|
||||
{ key: 'telephone', label: '固定电话', type: 'tel', max: 30 },
|
||||
{ key: 'email', label: '邮箱', type: 'email', max: 100 },
|
||||
{ key: 'website', label: '客户网站', max: 500 }
|
||||
]
|
||||
},
|
||||
{
|
||||
title: '详细信息',
|
||||
fields: [
|
||||
{ key: 'source', label: '客户来源', dict: 'crm_clue_source', required: true },
|
||||
{ key: 'industry', label: '所属行业', dict: 'crm_customer_industry' },
|
||||
{ key: 'parkArea', label: '所在园区', dict: 'crm_customer_park', required: true },
|
||||
{ key: 'scale', label: '企业规模', dict: 'crm_company_scale' },
|
||||
{ key: 'province', label: '省份', required: true, max: 50 },
|
||||
{ key: 'city', label: '城市', required: true, max: 50 },
|
||||
{ key: 'district', label: '区县', required: true, max: 50 },
|
||||
{ key: 'address', label: '详细地址', max: 255 }
|
||||
]
|
||||
},
|
||||
{
|
||||
title: '分配信息',
|
||||
fields: [
|
||||
{ key: 'ownerUserId', label: '负责人', type: 'select' },
|
||||
{ key: 'nextTime', label: '下次联系时间', type: 'datetime-local' },
|
||||
{ key: 'remark', label: '备注', type: 'textarea', max: 500 }
|
||||
]
|
||||
}
|
||||
]
|
||||
export const invoiceFields: Field[] = [
|
||||
{ key: 'companyName', label: '单位名称(章)', required: true, max: 200 },
|
||||
{ key: 'taxNo', label: '税号', max: 50 },
|
||||
{ key: 'companyAddress', label: '单位地址', max: 500 },
|
||||
{ key: 'legalRepresentative', label: '法定代表人', max: 100 },
|
||||
{ key: 'agent', label: '代理人', max: 100 },
|
||||
{ key: 'phoneFax', label: '电话/传真', max: 100 },
|
||||
{ key: 'bankName', label: '开户银行', max: 200 },
|
||||
{ key: 'bankAccount', label: '账号', max: 100 },
|
||||
{ key: 'remark', label: '开票备注', type: 'textarea', max: 500 }
|
||||
]
|
||||
export const contactFields: Field[] = [
|
||||
{ key: 'contactName', label: '联系人姓名', required: true, max: 100 },
|
||||
{
|
||||
key: 'gender',
|
||||
label: '性别',
|
||||
options: [
|
||||
{ value: 'male', label: '男' },
|
||||
{ value: 'female', label: '女' }
|
||||
]
|
||||
},
|
||||
{ key: 'mobile', label: '手机号', type: 'tel', required: true, max: 11 },
|
||||
{ key: 'telephone', label: '固定电话', type: 'tel', max: 30 },
|
||||
{ key: 'email', label: '邮箱', type: 'email', max: 100 },
|
||||
{ key: 'wechat', label: '微信号', max: 100 },
|
||||
{ key: 'qq', label: 'QQ号', max: 100 },
|
||||
{ key: 'department', label: '部门', max: 100 },
|
||||
{ key: 'position', label: '职位', max: 100 },
|
||||
{ key: 'role', label: '角色', dict: 'crm_contact_role' },
|
||||
{ key: 'birthday', label: '生日', type: 'date' },
|
||||
{ key: 'address', label: '住址', max: 255 },
|
||||
{
|
||||
key: 'status',
|
||||
label: '状态',
|
||||
options: [
|
||||
{ value: 'active', label: '在职' },
|
||||
{ value: 'leave', label: '离职' }
|
||||
]
|
||||
},
|
||||
{ key: 'isKey', label: '关键决策人', type: 'switch' },
|
||||
{ key: 'isPrimary', label: '主要联系人', type: 'switch' },
|
||||
{ key: 'remark', label: '备注', type: 'textarea', max: 500 }
|
||||
]
|
||||
export const certificateFields = [
|
||||
{ key: 'businessLicenseImages', label: '营业执照', folder: 'license', limit: 5 },
|
||||
{ key: 'businessPermitImages', label: '经营许可证', folder: 'permit', limit: 5 },
|
||||
{ key: 'otherCertImages', label: '其他证件', folder: 'cert', limit: 10 }
|
||||
]
|
||||
export const customerReadFields: Field[] = [
|
||||
{ key: 'customerNo', label: '客户编号' },
|
||||
...customerGroups.flatMap((g) => g.fields).filter((f) => f.key !== 'ownerUserId'),
|
||||
{ key: 'ownerUserName', label: '负责人' },
|
||||
{ key: 'status', label: '客户状态', dict: 'crm_customer_status' },
|
||||
{ key: 'dealStatus', label: '成交状态', dict: 'crm_deal_status' },
|
||||
...Object.entries({
|
||||
lastTime: '最后跟进时间',
|
||||
followCount: '跟进次数',
|
||||
dealTime: '成交时间',
|
||||
dealAmount: '成交金额',
|
||||
contactCount: '联系人数量',
|
||||
opportunityCount: '商机数量',
|
||||
contractCount: '合同数量',
|
||||
intoPoolTime: '进入公海时间',
|
||||
claimTime: '领取时间',
|
||||
protectTime: '保护到期时间',
|
||||
createDeptName: '创建部门',
|
||||
createByName: '创建人',
|
||||
createTime: '创建时间',
|
||||
updateByName: '更新人',
|
||||
updateTime: '更新时间'
|
||||
}).map(([key, label]) => ({ key, label }))
|
||||
]
|
||||
export function unwrapData(value: any): any {
|
||||
return value?.data ?? value ?? {}
|
||||
}
|
||||
export function unwrapRows(value: any): Row[] {
|
||||
const data = unwrapData(value)
|
||||
return Array.isArray(data) ? data : (data.list ?? data.rows ?? [])
|
||||
}
|
||||
export function apiTime(value: string): string {
|
||||
if (!value) return ''
|
||||
const text = value.replace('T', ' ')
|
||||
return text.length === 16 ? `${text}:00` : text
|
||||
}
|
||||
export function customerCardTime(row: Row): string {
|
||||
if (row.nextTime) return `下次联系:${row.nextTime}`
|
||||
if (row.lastTime) return `最后跟进:${row.lastTime}`
|
||||
if (row.createTime) return `创建时间:${row.createTime}`
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
* Web「客户管理」列表全部列(含默认可隐藏),用于移动列表卡。
|
||||
* 客户名称仅作卡片标题,不在此集合。
|
||||
*/
|
||||
export const CUSTOMER_LIST_CARD_FIELDS: Field[] = [
|
||||
{ key: 'customerNo', label: '客户编号' },
|
||||
{ key: 'shortName', label: '客户简称' },
|
||||
{ key: 'customerType', label: '客户类型', dict: 'crm_customer_type' },
|
||||
{ key: 'mobile', label: '手机号' },
|
||||
{ key: 'telephone', label: '固定电话' },
|
||||
{ key: 'email', label: '邮箱' },
|
||||
{ key: 'website', label: '客户网站' },
|
||||
{ key: 'level', label: '客户级别', dict: 'crm_customer_level' },
|
||||
{ key: 'source', label: '客户来源', dict: 'crm_clue_source' },
|
||||
{ key: 'industry', label: '所属行业', dict: 'crm_customer_industry' },
|
||||
{ key: 'parkArea', label: '所在园区', dict: 'crm_customer_park' },
|
||||
{ key: 'scale', label: '企业规模', dict: 'crm_company_scale' },
|
||||
{ key: 'province', label: '省' },
|
||||
{ key: 'city', label: '市' },
|
||||
{ key: 'district', label: '区' },
|
||||
{ key: 'address', label: '详细地址' },
|
||||
{ key: 'status', label: '客户状态', dict: 'crm_customer_status' },
|
||||
{ key: 'dealStatus', label: '成交状态', dict: 'crm_deal_status' },
|
||||
{ key: 'ownerUserName', label: '负责人' },
|
||||
{ key: 'followCount', label: '跟进次数' },
|
||||
{ key: 'lastTime', label: '最后跟进时间' },
|
||||
{ key: 'nextTime', label: '下次联系时间' },
|
||||
{ key: 'dealTime', label: '成交时间' },
|
||||
{ key: 'dealAmount', label: '成交金额' },
|
||||
{ key: 'contactCount', label: '联系人数量' },
|
||||
{ key: 'opportunityCount', label: '商机数量' },
|
||||
{ key: 'contractCount', label: '合同数量' },
|
||||
{ key: 'intoPoolTime', label: '进入公海时间' },
|
||||
{ key: 'claimTime', label: '领取时间' },
|
||||
{ key: 'protectTime', label: '保护到期时间' },
|
||||
{ key: 'createDeptName', label: '创建部门' },
|
||||
{ key: 'createByName', label: '创建人' },
|
||||
{ key: 'createTime', label: '创建时间' },
|
||||
{ key: 'updateByName', label: '更新人' },
|
||||
{ key: 'updateTime', label: '更新时间' },
|
||||
{ key: 'remark', label: '备注' }
|
||||
]
|
||||
|
||||
/** 默认预览行(其余进「更多字段」) */
|
||||
export const CUSTOMER_LIST_CARD_PREVIEW_KEYS = ['shortName', 'mobile'] as const
|
||||
|
||||
export function splitCustomerListFields(
|
||||
fields: Field[] = CUSTOMER_LIST_CARD_FIELDS,
|
||||
options: { previewKeys?: readonly string[] } = {}
|
||||
): { preview: Field[]; extra: Field[] } {
|
||||
const previewKeys = options.previewKeys ?? CUSTOMER_LIST_CARD_PREVIEW_KEYS
|
||||
const byKey = new Map(fields.map((f) => [f.key, f]))
|
||||
const preview = previewKeys
|
||||
.map((key) => byKey.get(key))
|
||||
.filter((f): f is Field => Boolean(f))
|
||||
const previewSet = new Set(preview.map((f) => f.key))
|
||||
const extra = fields.filter((f) => !previewSet.has(f.key))
|
||||
return { preview, extra }
|
||||
}
|
||||
|
||||
export function customerListCardMeta(parts: {
|
||||
statusLabel?: string
|
||||
customerNo?: string
|
||||
createTime?: string
|
||||
}): string {
|
||||
const dash = (v?: string) => {
|
||||
const t = String(v || '').trim()
|
||||
return t || '—'
|
||||
}
|
||||
return [dash(parts.statusLabel), dash(parts.customerNo), dash(parts.createTime)].join(' · ')
|
||||
}
|
||||
export function customerFilterSummaryLabel(
|
||||
value: unknown,
|
||||
resolveLabel: (value: string) => string,
|
||||
fallback: string
|
||||
): string {
|
||||
const values = String(value || '')
|
||||
.split(',')
|
||||
.map((item) => item.trim())
|
||||
.filter(Boolean)
|
||||
if (!values.length) return fallback
|
||||
if (values.length > 1) return `已选${values.length}项`
|
||||
return resolveLabel(values[0])
|
||||
}
|
||||
export function stageSuggestion(stage: string): Row {
|
||||
const values: Record<string, number[]> = {
|
||||
initial: [10, 30],
|
||||
requirement: [30, 50],
|
||||
solution: [50, 60],
|
||||
quote: [60, 65],
|
||||
negotiate: [80, 80],
|
||||
contract: [90, 90],
|
||||
won: [100, 100]
|
||||
}
|
||||
const pair = values[stage]
|
||||
return pair ? { stagePercent: pair[0], winRate: pair[1] } : {}
|
||||
}
|
||||
export function customerForm(row: Row = {}): Row {
|
||||
return {
|
||||
...Object.fromEntries(customerGroups.flatMap((g) => g.fields).map((f) => [f.key, ''])),
|
||||
customerType: '未分类',
|
||||
level: 'normal',
|
||||
paymentTerms: '',
|
||||
clueId: '',
|
||||
...row,
|
||||
businessLicenseImages: row.businessLicenseImages ?? row.businessLicenseImg ?? '',
|
||||
businessPermitImages: row.businessPermitImages ?? '',
|
||||
otherCertImages: row.otherCertImages ?? ''
|
||||
}
|
||||
}
|
||||
export function customerPayload(form: Row): Row {
|
||||
const keys = [
|
||||
...customerGroups.flatMap((g) => g.fields).map((f) => f.key),
|
||||
...certificateFields.map((f) => f.key),
|
||||
'paymentTerms',
|
||||
'clueId'
|
||||
]
|
||||
const data = Object.fromEntries(keys.map((key) => [key, form[key] ?? '']))
|
||||
if (form.id) data.id = String(form.id)
|
||||
data.customerName = String(data.customerName).trim()
|
||||
data.namePinyinAbbr = String(data.namePinyinAbbr).trim()
|
||||
data.ownerUserId = String(data.ownerUserId || '')
|
||||
data.nextTime = apiTime(data.nextTime)
|
||||
return data
|
||||
}
|
||||
export async function saveCustomerAndInvoice(
|
||||
form: Row,
|
||||
invoice: Row,
|
||||
state: { customerId: string },
|
||||
api: {
|
||||
create: (data: Row) => Promise<any>
|
||||
update: (data: Row) => Promise<any>
|
||||
invoice: (data: Row) => Promise<any>
|
||||
}
|
||||
): Promise<string> {
|
||||
if (form.id) {
|
||||
await api.update(customerPayload(form))
|
||||
return String(form.id)
|
||||
}
|
||||
if (!state.customerId) {
|
||||
const created = unwrapData(await api.create(customerPayload(form)))
|
||||
if (!created.id) throw new Error('客户已提交但未返回编号,请返回列表核对后再操作')
|
||||
state.customerId = String(created.id)
|
||||
}
|
||||
if (Object.values(invoice).some((v) => String(v ?? '').trim())) {
|
||||
await api.invoice({ ...invoice, customerId: state.customerId, isDefault: '1' })
|
||||
}
|
||||
return state.customerId
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
:root {
|
||||
--van-primary-color: #0a9f6d;
|
||||
--van-success-color: #0a9f6d;
|
||||
--van-danger-color: #dc2626;
|
||||
--van-warning-color: #d97706;
|
||||
--van-button-primary-background: #0a9f6d;
|
||||
--van-button-primary-border-color: #0a9f6d;
|
||||
--van-dropdown-menu-title-active-text-color: #0a9f6d;
|
||||
--van-dropdown-menu-option-active-color: #0a9f6d;
|
||||
--van-tabs-bottom-bar-color: #0a9f6d;
|
||||
--van-tab-active-text-color: #0a9f6d;
|
||||
--van-nav-bar-icon-color: #0a9f6d;
|
||||
--van-nav-bar-text-color: #0a9f6d;
|
||||
--van-picker-confirm-action-color: #0a9f6d;
|
||||
}
|
||||
|
||||
.mp-quote-page {
|
||||
--van-primary-color: #0a9f6d;
|
||||
--van-success-color: #0a9f6d;
|
||||
--van-button-primary-background: #0a9f6d;
|
||||
--van-button-primary-border-color: #0a9f6d;
|
||||
min-height: 100%;
|
||||
background: #f5f8f7;
|
||||
}
|
||||
|
||||
.mp-quote-loading {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 48px 16px;
|
||||
}
|
||||
|
||||
.mp-quote-content {
|
||||
padding: 12px 12px 24px;
|
||||
}
|
||||
|
||||
.mp-quote-load-hint {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin: 12px 0 24px;
|
||||
font-size: 13px;
|
||||
color: #6b7b74;
|
||||
}
|
||||
|
||||
.mp-quote-load-sentinel {
|
||||
height: 1px;
|
||||
}
|
||||
|
||||
/* 详情:锚点 Tab + 固定底栏 */
|
||||
.mp-quote-detail-page,
|
||||
.mp-quote-form-page {
|
||||
padding-bottom: calc(90px + env(safe-area-inset-bottom));
|
||||
}
|
||||
|
||||
.mp-quote-form-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: calc(100vh - 56px);
|
||||
padding-right: 0;
|
||||
padding-left: 0;
|
||||
background: #f5f8f7;
|
||||
|
||||
/* 与客户新增/编辑一致:字段组不再额外内缩,左右只留壳层 10px */
|
||||
.mp-quote-form-cells.van-cell-group--inset,
|
||||
.mp-quote-products .van-cell-group--inset {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.mp-quote-form-footer {
|
||||
position: fixed;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 40;
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
max-width: min(480px, 100%);
|
||||
margin: 0 auto;
|
||||
padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
|
||||
background: #fff;
|
||||
border-top: 1px solid #dcebe4;
|
||||
box-shadow: 0 -8px 24px rgb(34 64 52 / 12%);
|
||||
|
||||
.van-button {
|
||||
flex: 1 1 0;
|
||||
min-width: 0;
|
||||
height: 36px;
|
||||
}
|
||||
}
|
||||
|
||||
.mp-quote-detail-tabs.van-tabs {
|
||||
position: sticky;
|
||||
top: var(--mp-quote-sticky-top, 56px);
|
||||
z-index: 40;
|
||||
margin: 0 -10px 12px;
|
||||
background: #f5f8f7;
|
||||
|
||||
--van-tabs-line-height: 44px;
|
||||
--van-tabs-nav-background: transparent;
|
||||
--van-tab-text-color: #6b7b74;
|
||||
--van-tab-active-text-color: #087f57;
|
||||
--van-tab-font-size: 13px;
|
||||
--van-tabs-bottom-bar-color: #0a9f6d;
|
||||
--van-tabs-bottom-bar-height: 2px;
|
||||
--van-sticky-z-index: 40;
|
||||
|
||||
.van-tabs__wrap {
|
||||
background: #f5f8f7 !important;
|
||||
border-bottom: 1px solid #dcebe4;
|
||||
}
|
||||
|
||||
.van-tabs__nav {
|
||||
background: #f5f8f7 !important;
|
||||
}
|
||||
|
||||
.van-tab {
|
||||
flex: 1 0 auto;
|
||||
min-width: 72px;
|
||||
min-height: 44px;
|
||||
font-weight: 600;
|
||||
color: #6b7b74;
|
||||
}
|
||||
|
||||
.van-tab--active {
|
||||
font-weight: 700;
|
||||
color: #087f57;
|
||||
}
|
||||
|
||||
.van-tabs__line {
|
||||
background: #0a9f6d !important;
|
||||
}
|
||||
|
||||
.van-tabs__content {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.mp-quote-detail-page .mp-quote-detail-card {
|
||||
scroll-margin-top: var(--mp-quote-anchor-offset, 108px);
|
||||
}
|
||||
|
||||
.mp-quote-approve-sheet.van-popup {
|
||||
position: fixed !important;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
height: min(55%, 420px) !important;
|
||||
max-height: 70vh;
|
||||
}
|
||||
|
||||
.mp-quote-approve-sheet.mp-customer-vant-popup {
|
||||
--van-primary-color: #0a9f6d;
|
||||
--van-button-primary-background: #0a9f6d;
|
||||
--van-button-primary-border-color: #0a9f6d;
|
||||
--van-danger-color: #dc2626;
|
||||
--van-button-danger-background: #dc2626;
|
||||
--van-button-danger-border-color: #dc2626;
|
||||
|
||||
.mp-quote-approve-sheet__panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 0;
|
||||
background: #f7faf8;
|
||||
}
|
||||
|
||||
.mp-quote-approve-sheet__body {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
padding: 8px 10px 16px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.mp-quote-approve-sheet__fields.van-cell-group {
|
||||
margin: 0;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.mp-quote-approve-sheet__fields .van-cell {
|
||||
padding-right: 0;
|
||||
padding-left: 0;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.mp-quote-approve-sheet__foot {
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
gap: 8px;
|
||||
padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
|
||||
background: #fff;
|
||||
border-top: 1px solid #dcebe4;
|
||||
}
|
||||
|
||||
.mp-quote-approve-sheet__foot .van-button {
|
||||
flex: 1 1 auto;
|
||||
height: 44px !important;
|
||||
min-height: 44px !important;
|
||||
padding: 0 16px !important;
|
||||
font-size: 15px !important;
|
||||
border-radius: 8px !important;
|
||||
}
|
||||
}
|
||||
|
||||
.mp-quote-detail-page .mp-wv-fab-bar {
|
||||
position: fixed;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 40;
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
max-width: min(480px, 100%);
|
||||
margin: 0 auto;
|
||||
padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
|
||||
background: #fff;
|
||||
border-top: 1px solid #dcebe4;
|
||||
box-shadow: 0 -8px 24px rgb(34 64 52 / 12%);
|
||||
}
|
||||
|
||||
.mp-quote-detail-page .mp-wv-section > h3,
|
||||
.mp-quote-form-page .quote-section-title--bar {
|
||||
position: relative;
|
||||
padding-left: 10px;
|
||||
margin: 0 0 10px;
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
color: #1f2a26;
|
||||
|
||||
&::before {
|
||||
position: absolute;
|
||||
top: 0.15em;
|
||||
bottom: 0.15em;
|
||||
left: 0;
|
||||
width: 3px;
|
||||
content: '';
|
||||
background: #0a9f6d;
|
||||
border-radius: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
.mp-quote-form-page .quote-section-title--bar.quote-section-title--products {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.mp-quote-money {
|
||||
color: #dc2626;
|
||||
font-weight: 600;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<template>
|
||||
<div class="cert-attachments">
|
||||
<AttachmentUploadField
|
||||
ref="field"
|
||||
:model-value="modelValue || ''"
|
||||
:disabled="readonly"
|
||||
folder="pl/plan-cert"
|
||||
:hint="hint"
|
||||
@update:model-value="$emit('update:modelValue', $event)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import AttachmentUploadField from '@/components/business/attachment-upload-field/index.vue'
|
||||
defineProps<{ modelValue?: string; readonly?: boolean; hint?: string }>()
|
||||
defineEmits<{ 'update:modelValue': [string] }>()
|
||||
const field = ref<InstanceType<typeof AttachmentUploadField>>()
|
||||
defineExpose({ hasUploading: () => field.value?.hasUploading() ?? false })
|
||||
</script>
|
||||
<style scoped lang="scss">
|
||||
.cert-attachments {
|
||||
width: 100%;
|
||||
min-width: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,740 @@
|
||||
<template>
|
||||
<div class="cert-module cert-detail-shell">
|
||||
<MpStructSkeleton v-if="loading" kind="detail" caption="正在加载计划详情" />
|
||||
<p v-if="error" class="cert-error" role="alert">{{ error }}</p
|
||||
><button v-if="error" class="cert-btn" @click="reload">重试</button>
|
||||
<template v-if="plan && plan.id === planId && !loading">
|
||||
<van-tabs
|
||||
v-model:active="activeTab"
|
||||
class="mp-customer-detail-tabs"
|
||||
shrink
|
||||
sticky
|
||||
:offset-top="stickyOffset"
|
||||
:ellipsis="false"
|
||||
line-width="28px"
|
||||
line-height="2px"
|
||||
title-active-color="#087f57"
|
||||
title-inactive-color="#6b7b74"
|
||||
aria-label="计划详情分类"
|
||||
@click-tab="onAnchorTab"
|
||||
>
|
||||
<van-tab
|
||||
v-for="item in detailTabs"
|
||||
:key="item.value"
|
||||
:name="item.value"
|
||||
:title="item.label"
|
||||
/>
|
||||
</van-tabs>
|
||||
<p v-if="permissionError" class="cert-hint cert-detail-notice" role="alert">
|
||||
操作权限读取失败,暂不可上传或确认齐备。
|
||||
<button class="cert-link" @click="$emit('retryPermissions')">重试权限</button>
|
||||
</p>
|
||||
<p
|
||||
v-else-if="permissionsLoaded && !canUpload && !canReady"
|
||||
class="cert-hint cert-detail-notice"
|
||||
>
|
||||
当前仅有查看权限
|
||||
</p>
|
||||
<div class="cert-detail-scroll">
|
||||
<div id="cert-sec-base" class="detail-pane active mp-h5-anchor">
|
||||
<section class="detail-info-card">
|
||||
<div class="adv-field"
|
||||
><span class="adv-field__label">计划编号</span
|
||||
><span class="adv-field__value">{{ plan.planNo || '—' }}</span></div
|
||||
><div class="adv-field"
|
||||
><span class="adv-field__label">计划类型</span
|
||||
><span class="adv-field__value">{{ getPlPlanTypeLabel(plan.planType) }}</span></div
|
||||
><div class="adv-field"
|
||||
><span class="adv-field__label">跟进状态</span
|
||||
><span class="adv-field__value"
|
||||
><el-tag :type="getPlPlanFollowStatusTagType(plan.followStatus) as any">{{
|
||||
getPlPlanFollowStatusLabel(plan.followStatus)
|
||||
}}</el-tag></span
|
||||
></div
|
||||
><div class="adv-field"
|
||||
><span class="adv-field__label">证书状态</span
|
||||
><span class="adv-field__value"
|
||||
><el-tag :type="isHazardCertReady(plan) ? 'success' : 'warning'">{{
|
||||
isHazardCertReady(plan) ? '证书已齐备' : '证书待确认'
|
||||
}}</el-tag></span
|
||||
></div
|
||||
><div class="adv-field"
|
||||
><span class="adv-field__label">计划日期</span
|
||||
><span class="adv-field__value">{{ plan.planDate || '—' }}</span></div
|
||||
><div class="adv-field"
|
||||
><span class="adv-field__label">归属公司</span
|
||||
><span class="adv-field__value">{{
|
||||
getPlPlanCompanyLabel(plan.belongsCompany)
|
||||
}}</span></div
|
||||
><div class="adv-field"
|
||||
><span class="adv-field__label">跟进人</span
|
||||
><span class="adv-field__value">{{ plan.followUserName || '—' }}</span></div
|
||||
><div class="adv-field"
|
||||
><span class="adv-field__label">送货时间</span
|
||||
><span class="adv-field__value">{{
|
||||
(plan.deliveryTimes || []).join(' / ') || '—'
|
||||
}}</span></div
|
||||
><div class="adv-field"
|
||||
><span class="adv-field__label">备注</span
|
||||
><span class="adv-field__value">{{ plan.remark || '—' }}</span></div
|
||||
>
|
||||
</section>
|
||||
</div>
|
||||
<div id="cert-sec-transport" class="detail-pane active mp-h5-anchor">
|
||||
<p v-if="plan.transportId && !transport" class="cert-error" role="alert"
|
||||
>运输信息暂不可用,请刷新重试。</p
|
||||
>
|
||||
<section v-if="showArrangeActions" class="cert-section"
|
||||
><h3>运输链接</h3
|
||||
><div class="cert-actions"
|
||||
><button class="cert-btn" :disabled="copying" @click="copyAction(copyPlanSummary)"
|
||||
>复制给司机</button
|
||||
><button
|
||||
v-if="hasSiteInventoryRecords"
|
||||
class="cert-btn"
|
||||
:disabled="copying"
|
||||
@click="copyAction(copySiteSummary)"
|
||||
>复制给现场</button
|
||||
><button
|
||||
v-if="hasDibangInventoryRecords"
|
||||
class="cert-btn"
|
||||
:disabled="copying"
|
||||
@click="copyAction(copyPoundSlipQrcode)"
|
||||
>复制磅单二维码</button
|
||||
></div
|
||||
><div v-if="driverUrl" class="cert-link-block"
|
||||
><label>司机链接<input class="cert-input" :value="driverUrl" readonly /></label
|
||||
><button class="cert-btn" @click="copyLink(driverUrl)">复制司机链接</button></div
|
||||
><div v-for="site in siteRecords" :key="site.siteLinkId" class="cert-link-block"
|
||||
><label
|
||||
>现场链接 · {{ site.productName
|
||||
}}<input class="cert-input" :value="site.siteUrl || ''" readonly /></label
|
||||
><button class="cert-btn" @click="copyLink(site.siteUrl || '')"
|
||||
>复制现场链接</button
|
||||
></div
|
||||
></section
|
||||
>
|
||||
<CertTransport
|
||||
:plan="plan"
|
||||
:transport="transport"
|
||||
:bundle="vehicleBundle"
|
||||
:settlement="freightSettlement"
|
||||
/>
|
||||
<CertStop
|
||||
:stop="stops.load"
|
||||
label="装货"
|
||||
kind="load"
|
||||
:products="products"
|
||||
:transport="transport"
|
||||
:dibang-rows="dibangRows"
|
||||
:show-feedback="showFeedback"
|
||||
@contract="openContract"
|
||||
/>
|
||||
<CertStop
|
||||
v-for="(stop, i) in stops.deliveries"
|
||||
:key="stop.id || i"
|
||||
:stop="stop"
|
||||
:label="`送货 #${stop.seq || i + 1}`"
|
||||
kind="delivery"
|
||||
:products="products"
|
||||
:transport="transport"
|
||||
:dibang-rows="dibangRows"
|
||||
:show-feedback="showFeedback"
|
||||
@contract="openContract"
|
||||
/>
|
||||
<section v-if="ioOrder" class="cert-section"
|
||||
><h3>出入库现场回传</h3><p>{{ ioOrder.orderNo }}</p
|
||||
><p>时间:{{ ioOrder.siteFeedbackTime || '—' }}</p
|
||||
><p>{{ ioOrder.siteFeedbackRemark || '暂无备注' }}</p
|
||||
><CertAttachments :model-value="(ioOrder.siteFeedbackImages || []).join(',')" readonly
|
||||
/></section>
|
||||
</div>
|
||||
<div id="cert-sec-attachments" class="detail-pane active mp-h5-anchor">
|
||||
<section class="detail-info-card"
|
||||
><h3 class="detail-info-card__title">危化品证书信息</h3
|
||||
><p v-if="!hazardProducts.length">暂无危化品</p
|
||||
><div v-for="p in hazardProducts" :key="p.id" class="cert-product"
|
||||
><h4>{{ p.productName }}</h4
|
||||
><el-tag v-if="p.isToxic" type="warning">易制毒</el-tag
|
||||
><el-tag v-if="p.isExplosive" type="danger">易制爆</el-tag
|
||||
><div v-for="slot in getRequiredCertSlots(p)" :key="slot.key"
|
||||
><h4>{{ slot.label }}</h4
|
||||
><CertAttachments v-if="p[slot.key]" :model-value="p[slot.key]" readonly /><p v-else
|
||||
>未上传</p
|
||||
></div
|
||||
></div
|
||||
></section
|
||||
>
|
||||
<section class="detail-info-card"
|
||||
><h3 class="detail-info-card__title">计划附件</h3
|
||||
><CertAttachments
|
||||
v-if="plan.documentAttachments?.length"
|
||||
:model-value="plan.documentAttachments.map((a) => a.url).join(',')"
|
||||
readonly
|
||||
/><p v-else>暂无附件</p></section
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="canUpload || canReady" class="cert-detail-actions cert-actions">
|
||||
<button
|
||||
v-if="canUpload"
|
||||
class="cert-btn cert-btn--primary"
|
||||
:disabled="busy || !canEdit(plan)"
|
||||
@click="$emit('upload', plan)"
|
||||
>上传证书</button
|
||||
><button
|
||||
v-if="canReady"
|
||||
class="cert-btn"
|
||||
:disabled="busy || !canEdit(plan) || !planHasHazardProducts(plan.products)"
|
||||
@click="$emit('ready', plan, !isHazardCertReady(plan))"
|
||||
>{{ isHazardCertReady(plan) ? '取消齐备' : '证书齐备' }}</button
|
||||
>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
<MpBottomSheet v-model="poundQrcodePickVisible" title="选择磅单二维码"
|
||||
><div class="cert-module cert-sheet-content"
|
||||
><button
|
||||
v-for="record in poundQrcodePickRecords"
|
||||
:key="record.dbInventoryId"
|
||||
class="cert-btn"
|
||||
@click="handlePoundQrcodePickPreview(record)"
|
||||
>{{ record.productName || record.dbInventoryId }} · 预览二维码</button
|
||||
></div
|
||||
></MpBottomSheet
|
||||
>
|
||||
<DbPoundSlipQrcodeDialog
|
||||
ref="qrcodeDialogRef"
|
||||
v-model:visible="qrcodeVisible"
|
||||
:inventory-id="selectedInventoryId"
|
||||
:quantity-unit="selectedInventoryUnit"
|
||||
/>
|
||||
<MpBottomSheet v-model="contractOpen" title="合同详情(只读)"
|
||||
><div class="cert-module cert-sheet-content"
|
||||
><MpStructSkeleton v-if="contractLoading" kind="detail" caption="正在加载合同" />
|
||||
<p v-else-if="contractError" role="alert">{{ contractError }}</p
|
||||
><template v-else-if="contract"
|
||||
><p v-if="contractWarning" class="cert-error" role="alert">{{ contractWarning }}</p
|
||||
><section class="cert-section"
|
||||
><h3>{{ contract.contractNo }}</h3
|
||||
><div v-for="f in contractFields" :key="f.key" class="cert-kv"
|
||||
><span>{{ f.label }}</span
|
||||
><el-tag v-if="f.tag" :type="contractTagType(f.key, contract[f.key])">{{
|
||||
contractLabel(f.key, contract[f.key])
|
||||
}}</el-tag
|
||||
><span v-else>{{ contract[f.key] ?? '—' }}</span></div
|
||||
></section
|
||||
><section class="cert-section"
|
||||
><h3>产品明细</h3
|
||||
><div v-for="(p, i) in contract.products || []" :key="p.id || i" class="cert-product"
|
||||
><h4>{{ p.standardProductName || p.productName }}</h4
|
||||
><p
|
||||
>别名 {{ p.aliasName || '—' }} · 品牌
|
||||
{{ formatBrandConstraintLabel(p.brandMode, p.brandName) }}</p
|
||||
>
|
||||
<p
|
||||
>型号/规格 {{ p.model || p.productModel || '—' }} · 分类
|
||||
{{ p.categoryName || '—' }}</p
|
||||
>
|
||||
<p
|
||||
>数量
|
||||
{{ displayFrameworkQuantity(p, isFrameworkContractType(contract.contractType)) }}
|
||||
{{ resolveMpProductUnitLabel(p.unit) }} · 税率 {{ p.taxRate || 0 }}%</p
|
||||
>
|
||||
<p
|
||||
>包装 {{ formatPackageSpecsJoin(p) || '—' }} · 送货方式
|
||||
{{ p.deliveryMethod || '—' }}</p
|
||||
>
|
||||
<template v-if="canPrice"
|
||||
><p
|
||||
>含税单价:{{
|
||||
displayFrameworkMoney(p, 'price', isFrameworkContractType(contract.contractType))
|
||||
}}
|
||||
· 含税总价:{{
|
||||
displayFrameworkMoney(
|
||||
p,
|
||||
'subtotal',
|
||||
isFrameworkContractType(contract.contractType)
|
||||
)
|
||||
}}
|
||||
· 税费:{{
|
||||
displayFrameworkMoney(
|
||||
p,
|
||||
'taxAmount',
|
||||
isFrameworkContractType(contract.contractType)
|
||||
)
|
||||
}}</p
|
||||
>
|
||||
<div v-for="(tier, ti) in p.priceTiers || []" :key="ti"
|
||||
><p>调价 {{ tier.startDate }} 至 {{ tier.endDate }} · 含税单价 {{ tier.price }}</p
|
||||
><CertAttachments
|
||||
:model-value="
|
||||
attachmentCsv(tier.letterOssIds || tier.letterOssId || tier.attachmentFiles)
|
||||
"
|
||||
readonly
|
||||
/></div>
|
||||
</template>
|
||||
<div
|
||||
v-for="q in p.packageQtyBreakdown?.length > 1 ? p.packageQtyBreakdown : [p]"
|
||||
:key="q.packageSpec || 'all'"
|
||||
><p
|
||||
>{{ q.packageSpec || '' }} · 已归档 {{ q.archivedQty ?? '—' }} · 未归档已安排
|
||||
{{ q.arrangedUnarchivedQty ?? '—' }} · 已安排合计 {{ q.arrangedTotalQty ?? '—' }}</p
|
||||
></div
|
||||
>
|
||||
<p>剩余数量 {{ formatRemainingQtyLabel(resolveLineRemainingQty(p)) }}</p
|
||||
><p>备注:{{ p.remark || '—' }}</p></div
|
||||
></section
|
||||
><section v-if="canPrice" class="cert-section"
|
||||
><h3>金额统计</h3
|
||||
><div v-for="f in contractMoneyFields" :key="f.label" class="cert-kv"
|
||||
><span>{{ f.label }}</span
|
||||
><span>{{ f.value }}</span></div
|
||||
></section
|
||||
>
|
||||
<section class="cert-section"
|
||||
><h3>审批流程</h3><p v-if="approvalError" role="alert">审批记录读取失败</p
|
||||
><p v-else-if="!approvals.length">暂无审批记录</p
|
||||
><div v-for="(a, i) in approvals" :key="a.id || i" class="cert-product"
|
||||
><p>第 {{ a.step || i + 1 }} 步 · {{ a.approverName }}</p
|
||||
><el-tag :type="contractTagType('approvalStatus', a.approvalResult)">{{
|
||||
contractLabel('approvalStatus', a.approvalResult)
|
||||
}}</el-tag
|
||||
><p>意见:{{ a.approvalOpinion || '—' }}</p
|
||||
><p>时间:{{ a.approvalTime || a.createTime || '—' }}</p
|
||||
><p v-if="a.remark">备注:{{ a.remark }}</p></div
|
||||
></section
|
||||
>
|
||||
<section class="cert-section"
|
||||
><h3>操作记录</h3
|
||||
><div v-for="f in contractOperationFields" :key="f.key" class="cert-kv"
|
||||
><span>{{ f.label }}</span
|
||||
><span>{{ contract[f.key] || '—' }}</span></div
|
||||
></section
|
||||
>
|
||||
<section class="cert-section"
|
||||
><h3>关联运输计划</h3><p v-if="linkedError" role="alert">关联计划读取失败</p
|
||||
><button
|
||||
v-if="linkedError"
|
||||
class="cert-btn"
|
||||
:disabled="linkedLoading"
|
||||
@click="loadLinkedPlans(linkedFailedMore)"
|
||||
>重试关联计划</button
|
||||
><p v-if="!linkedPlans.length && !linkedError">暂无关联计划</p
|
||||
><div v-for="p in linkedPlans" :key="p.id" class="cert-product"
|
||||
><button class="cert-link" @click="viewLinkedPlan(p.id)">{{ p.planNo }}</button
|
||||
><p>{{ p.planDate || '—' }} · {{ p.customerName || '—' }}</p
|
||||
><el-tag :type="getPlPlanFollowStatusTagType(p.followStatus) as any">{{
|
||||
getPlPlanFollowStatusLabel(p.followStatus)
|
||||
}}</el-tag></div
|
||||
><button
|
||||
v-if="linkedPlans.length < linkedTotal && !linkedError"
|
||||
class="cert-btn"
|
||||
:disabled="linkedLoading"
|
||||
@click="loadLinkedPlans(true)"
|
||||
>加载更多关联计划</button
|
||||
></section
|
||||
>
|
||||
<section class="cert-section"
|
||||
><h3>条款与附件</h3><p>付款条件:{{ contract.paymentTerms || '—' }}</p
|
||||
><p>交货条件:{{ contract.deliveryTerms || '—' }}</p
|
||||
><p>合同条款:{{ contract.contractTerms || '—' }}</p
|
||||
><p>备注:{{ contract.remark || '—' }}</p
|
||||
><CertAttachments :model-value="attachmentCsv(contract.contractFile)" readonly />
|
||||
<div v-for="(a, i) in parseCrmAttachmentField(contract.attachmentFiles)" :key="i"
|
||||
><p>{{ getCrmAttachmentCategoryLabel(a.category) }}</p
|
||||
><CertAttachments :model-value="a.ossId" readonly /></div></section></template></div
|
||||
></MpBottomSheet>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import MpBottomSheet from '@/components/mp/MpBottomSheet.vue'
|
||||
import MpStructSkeleton from '@/components/mp/MpStructSkeleton.vue'
|
||||
import DbPoundSlipQrcodeDialog from '@/components/business/db/DbPoundSlipQrcodeDialog.vue'
|
||||
import { usePlPlanViewDetail, mapPlanProductToFormRow } from '@/composables/usePlPlanViewDetail'
|
||||
import { usePlPlanArrangeActions } from '@/composables/usePlPlanArrangeActions'
|
||||
import {
|
||||
getRequiredCertSlots,
|
||||
isHazardProduct,
|
||||
isHazardCertReady,
|
||||
planHasHazardProducts
|
||||
} from '@/composables/usePlToxicProductCertCheck'
|
||||
import {
|
||||
getPlPlanCompanyLabel,
|
||||
getPlPlanFollowStatusLabel,
|
||||
getPlPlanFollowStatusTagType,
|
||||
getPlPlanTypeLabel
|
||||
} from '@/utils/pl-display'
|
||||
import { resolvePlanStopsForList } from '@/utils/pl-plan-list-display-rows'
|
||||
import {
|
||||
mapLoadFromApi,
|
||||
mapDeliveriesFromApi,
|
||||
resolveLoadViewAddress,
|
||||
resolveDeliveryViewAddress,
|
||||
resolveStopProductsForView
|
||||
} from '@/utils/pl-plan-stop-form'
|
||||
import { copyTextToClipboard } from '@/utils/clipboard'
|
||||
import { getContract, listContractApproval } from '@/api/crm/contract'
|
||||
import { getOpportunity } from '@/api/crm/opportunity'
|
||||
import { getQuote } from '@/api/crm/quote'
|
||||
import { fetchProductDetail } from '@/api/crm/product'
|
||||
import { planApi, type Plan } from '@/api/pl'
|
||||
import { useDictStore } from '@/store/modules/dict'
|
||||
import { parseCrmAttachmentField, getCrmAttachmentCategoryLabel } from '@/utils/crm-attachment'
|
||||
import { formatBrandConstraintLabel } from '@/utils/crm-product-brand'
|
||||
import { resolveMpProductUnitLabel } from '@/utils/mp-pl-plan-display'
|
||||
import { isFrameworkContractType } from '@/views/crm/contract/contractType'
|
||||
import {
|
||||
displayFrameworkQuantity,
|
||||
displayFrameworkMoney
|
||||
} from '@/views/crm/contract/frameworkProductPricing'
|
||||
import {
|
||||
formatPackageSpecsJoin,
|
||||
resolveLineRemainingQty,
|
||||
formatRemainingQtyLabel
|
||||
} from '@/utils/crm-package-spec'
|
||||
import CertAttachments from './CertAttachments.vue'
|
||||
import CertTransport from './CertTransport.vue'
|
||||
import CertStop from './CertStop.vue'
|
||||
import { canEdit, enrichContractReadFields } from './model'
|
||||
const props = defineProps<{
|
||||
planId: string
|
||||
canUpload: boolean
|
||||
canReady: boolean
|
||||
canPrice: boolean
|
||||
busy: boolean
|
||||
permissionError: boolean
|
||||
permissionsLoaded: boolean
|
||||
}>()
|
||||
const emit = defineEmits<{
|
||||
upload: [Plan]
|
||||
ready: [Plan, boolean]
|
||||
view: [string]
|
||||
retryPermissions: []
|
||||
}>()
|
||||
const {
|
||||
loading,
|
||||
plan,
|
||||
products,
|
||||
transport,
|
||||
freightSettlement,
|
||||
vehicleBundle,
|
||||
dibangRows,
|
||||
ioOrder,
|
||||
loadDetail,
|
||||
resetDetail
|
||||
} = usePlPlanViewDetail()
|
||||
const {
|
||||
showArrangeActions,
|
||||
hasSiteInventoryRecords,
|
||||
hasDibangInventoryRecords,
|
||||
driverUrl,
|
||||
siteRecords,
|
||||
qrcodeVisible,
|
||||
selectedInventoryId,
|
||||
selectedInventoryUnit,
|
||||
qrcodeDialogRef,
|
||||
poundQrcodePickVisible,
|
||||
poundQrcodePickRecords,
|
||||
loadArrangeActions,
|
||||
resetArrangeActions,
|
||||
copyPlanSummary,
|
||||
copySiteSummary,
|
||||
copyPoundSlipQrcode,
|
||||
handlePoundQrcodePickPreview
|
||||
} = usePlPlanArrangeActions()
|
||||
const stops = computed(() => {
|
||||
const data = plan.value || ({} as Plan)
|
||||
const base = resolvePlanStopsForList(data)
|
||||
const rows = products.value.map(mapPlanProductToFormRow)
|
||||
const load = mapLoadFromApi(base.load)
|
||||
return {
|
||||
load: {
|
||||
...base.load,
|
||||
...load,
|
||||
address: resolveLoadViewAddress(data, load),
|
||||
products: resolveStopProductsForView(load.products, rows)
|
||||
},
|
||||
deliveries: mapDeliveriesFromApi(base.deliveries).map((stop, i) => ({
|
||||
...base.deliveries[i],
|
||||
...stop,
|
||||
address: resolveDeliveryViewAddress(data, stop, i),
|
||||
products: resolveStopProductsForView(stop.products, rows)
|
||||
}))
|
||||
}
|
||||
})
|
||||
const hazardProducts = computed(() => products.value.filter(isHazardProduct))
|
||||
const detailTabs = [
|
||||
{ value: 'base', label: '基础信息', anchor: 'cert-sec-base' },
|
||||
{ value: 'transport', label: '运输与段次', anchor: 'cert-sec-transport' },
|
||||
{ value: 'attachments', label: '证书与附件', anchor: 'cert-sec-attachments' }
|
||||
]
|
||||
function onAnchorTab({ name }: { name: string | number }) {
|
||||
const tab = detailTabs.find((item) => item.value === String(name))
|
||||
const el = tab ? document.getElementById(tab.anchor) : null
|
||||
el?.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||
}
|
||||
const activeTab = ref('base')
|
||||
const stickyOffset = ref(0)
|
||||
function syncStickyOffset() {
|
||||
if (typeof document === 'undefined') return
|
||||
const header = document.querySelector('.cert-detail-page > .mp-wv-header') as HTMLElement | null
|
||||
stickyOffset.value = Math.ceil(header?.getBoundingClientRect().height || 0)
|
||||
}
|
||||
onMounted(() => {
|
||||
syncStickyOffset()
|
||||
window.addEventListener('resize', syncStickyOffset)
|
||||
})
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', syncStickyOffset)
|
||||
})
|
||||
const showFeedback = computed(
|
||||
() => plan.value?.transportStatus === 'arranged' && plan.value?.followStatus !== 'cancelled'
|
||||
)
|
||||
const error = ref('')
|
||||
const copying = ref(false)
|
||||
let currentLoad: Promise<void> | null = null
|
||||
async function reload() {
|
||||
if (currentLoad) await currentLoad
|
||||
if (!props.planId) return
|
||||
const id = props.planId
|
||||
error.value = ''
|
||||
currentLoad = (async () => {
|
||||
try {
|
||||
await loadDetail(id)
|
||||
if (id !== props.planId) return
|
||||
if (!plan.value) throw new Error('empty')
|
||||
await loadArrangeActions(id, plan.value)
|
||||
} catch {
|
||||
error.value = '详情部分数据读取失败,请刷新重试'
|
||||
}
|
||||
})()
|
||||
await currentLoad
|
||||
currentLoad = null
|
||||
}
|
||||
async function copyAction(fn: () => Promise<void>) {
|
||||
if (copying.value) return
|
||||
copying.value = true
|
||||
try {
|
||||
await fn()
|
||||
} catch {
|
||||
ElMessage.error('复制失败,请重试')
|
||||
} finally {
|
||||
copying.value = false
|
||||
}
|
||||
}
|
||||
async function copyLink(url: string) {
|
||||
if (!url) return
|
||||
const ok = await copyTextToClipboard(url)
|
||||
if (ok) ElMessage.success('已复制链接')
|
||||
else ElMessage.error('复制失败')
|
||||
}
|
||||
watch(
|
||||
() => props.planId,
|
||||
(id) => {
|
||||
if (id) {
|
||||
activeTab.value = 'base'
|
||||
void reload()
|
||||
} else {
|
||||
resetArrangeActions()
|
||||
resetDetail()
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
const contractOpen = ref(false)
|
||||
const contractLoading = ref(false)
|
||||
const contractError = ref('')
|
||||
const contractWarning = ref('')
|
||||
const contract = ref<any>(null)
|
||||
const approvals = ref<any[]>([])
|
||||
const approvalError = ref(false)
|
||||
const linkedPlans = ref<Plan[]>([])
|
||||
const linkedTotal = ref(0)
|
||||
const linkedPage = ref(1)
|
||||
const linkedLoading = ref(false)
|
||||
const linkedError = ref(false)
|
||||
const linkedFailedMore = ref(false)
|
||||
const dictStore = useDictStore()
|
||||
const contractDicts: Record<string, string> = {
|
||||
status: 'crm_contract_status',
|
||||
contractType: 'crm_contract_type',
|
||||
contractTemplate: 'crm_contract_template',
|
||||
settlementMethod: 'crm_settlement_method'
|
||||
}
|
||||
function contractLabel(key: string, value: string) {
|
||||
if (!value) return '—'
|
||||
if (key === 'approvalStatus')
|
||||
return (
|
||||
(
|
||||
{
|
||||
pending: '待审批',
|
||||
approving: '审批中',
|
||||
approved: '已通过',
|
||||
rejected: '已拒绝',
|
||||
draft: '草稿'
|
||||
} as Record<string, string>
|
||||
)[value] || value
|
||||
)
|
||||
return dictStore.getLabel(contractDicts[key] || '', value) || value
|
||||
}
|
||||
function contractTagType(key: string, value: string): 'success' | 'danger' | 'warning' | 'info' {
|
||||
if (['approved', 'finished', 'executing'].includes(value)) return 'success'
|
||||
if (['rejected', 'invalid'].includes(value)) return 'danger'
|
||||
if (['pending', 'approving'].includes(value)) return 'warning'
|
||||
return 'info'
|
||||
}
|
||||
function attachmentCsv(value: unknown) {
|
||||
return parseCrmAttachmentField(
|
||||
Array.isArray(value) ? JSON.stringify(value) : String(value || '')
|
||||
)
|
||||
.map((a) => a.ossId)
|
||||
.join(',')
|
||||
}
|
||||
const contractMoneyFields = computed(() => {
|
||||
const c = contract.value || {}
|
||||
const amount = Number(c.amount || 0),
|
||||
received = Number(c.receivedAmount || 0),
|
||||
invoiced = Number(c.invoicedAmount || 0)
|
||||
return [
|
||||
{ label: '合计金额(元)', value: amount },
|
||||
{ label: '运费(元)', value: c.freight ?? 0 },
|
||||
{ label: '桶押金(元)', value: c.barrelDeposit ?? 0 },
|
||||
{
|
||||
label: '合计总金额(元)',
|
||||
value: amount + Number(c.freight || 0) + Number(c.barrelDeposit || 0)
|
||||
},
|
||||
{ label: '已回款', value: received },
|
||||
{ label: '未回款', value: amount - received },
|
||||
{ label: '回款进度', value: `${amount > 0 ? ((received / amount) * 100).toFixed(1) : 0}%` },
|
||||
{ label: '已开票', value: invoiced },
|
||||
{ label: '未开票', value: amount - invoiced },
|
||||
{ label: '开票进度', value: `${amount > 0 ? ((invoiced / amount) * 100).toFixed(1) : 0}%` }
|
||||
]
|
||||
})
|
||||
const contractOperationFields = [
|
||||
{ key: 'invalidReason', label: '作废原因' },
|
||||
{ key: 'invalidTime', label: '作废时间' },
|
||||
{ key: 'invalidBy', label: '作废操作人' },
|
||||
{ key: 'executeStartDate', label: '执行开始日期' },
|
||||
{ key: 'expectedEndDate', label: '预计完成日期' },
|
||||
{ key: 'executeRemark', label: '执行说明' }
|
||||
]
|
||||
function viewLinkedPlan(id: string) {
|
||||
contractOpen.value = false
|
||||
emit('view', id)
|
||||
}
|
||||
async function loadLinkedPlans(more = false) {
|
||||
if (linkedLoading.value || !contract.value?.id) return
|
||||
const id = contract.value.id,
|
||||
v = contractVersion,
|
||||
next = more ? linkedPage.value + 1 : 1
|
||||
linkedLoading.value = true
|
||||
linkedError.value = false
|
||||
linkedFailedMore.value = more
|
||||
try {
|
||||
const res = await planApi.list({ contractId: id, page: next, pageSize: 20 })
|
||||
const data = (res.data ?? res) as any
|
||||
if (v !== contractVersion) return
|
||||
linkedPlans.value = more ? [...linkedPlans.value, ...(data.list || [])] : data.list || []
|
||||
linkedTotal.value = data.total || 0
|
||||
linkedPage.value = next
|
||||
} catch {
|
||||
if (v === contractVersion) linkedError.value = true
|
||||
} finally {
|
||||
if (v === contractVersion) linkedLoading.value = false
|
||||
}
|
||||
}
|
||||
let contractVersion = 0
|
||||
async function openContract(id: string) {
|
||||
if (!id) return
|
||||
const v = ++contractVersion
|
||||
contractOpen.value = true
|
||||
contractLoading.value = true
|
||||
contractError.value = ''
|
||||
contractWarning.value = ''
|
||||
contract.value = null
|
||||
approvals.value = []
|
||||
approvalError.value = false
|
||||
linkedPlans.value = []
|
||||
linkedTotal.value = 0
|
||||
linkedPage.value = 1
|
||||
linkedLoading.value = false
|
||||
linkedError.value = false
|
||||
linkedFailedMore.value = false
|
||||
try {
|
||||
const res = await getContract(id)
|
||||
if (v !== contractVersion) return
|
||||
const enriched = await enrichContractReadFields(res.data ?? res, {
|
||||
product: async (id) => {
|
||||
const res = await fetchProductDetail({ id })
|
||||
return (res.data ?? res) as any
|
||||
},
|
||||
opportunity: async (id) => {
|
||||
const res = await getOpportunity(id)
|
||||
return (res.data ?? res) as any
|
||||
},
|
||||
quote: async (id) => {
|
||||
const res = await getQuote(id)
|
||||
return (res.data ?? res) as any
|
||||
}
|
||||
})
|
||||
if (v !== contractVersion) return
|
||||
contract.value = enriched.contract
|
||||
contractWarning.value = enriched.warnings.length
|
||||
? `${enriched.warnings.join('、')}读取失败,当前显示已保存内容。关闭后重新打开可重试。`
|
||||
: ''
|
||||
await Promise.allSettled([
|
||||
loadLinkedPlans(),
|
||||
(async () => {
|
||||
try {
|
||||
const res = await listContractApproval(id)
|
||||
if (v === contractVersion) approvals.value = (res.data ?? res) as any[]
|
||||
} catch {
|
||||
if (v === contractVersion) approvalError.value = true
|
||||
}
|
||||
})()
|
||||
])
|
||||
} catch {
|
||||
if (v === contractVersion) contractError.value = '合同读取失败,请关闭后重试'
|
||||
} finally {
|
||||
if (v === contractVersion) contractLoading.value = false
|
||||
}
|
||||
}
|
||||
const contractFields = [
|
||||
{ key: 'contractName', label: '合同名称' },
|
||||
{ key: 'contractType', label: '合同类型', tag: true },
|
||||
{ key: 'contractTemplate', label: '合同模板', tag: true },
|
||||
{ key: 'status', label: '合同状态', tag: true },
|
||||
{ key: 'approvalStatus', label: '审批状态', tag: true },
|
||||
{ key: 'customerName', label: '客户' },
|
||||
{ key: 'opportunityName', label: '关联商机' },
|
||||
{ key: 'quoteNo', label: '关联报价单' },
|
||||
{ key: 'supplierName', label: '交易主体' },
|
||||
{ key: 'settlementMethod', label: '结算方式', tag: true },
|
||||
{ key: 'contactName', label: '联系人' },
|
||||
{ key: 'contactMobile', label: '联系电话' },
|
||||
{ key: 'signDate', label: '签订日期' },
|
||||
{ key: 'startDate', label: '开始日期' },
|
||||
{ key: 'endDate', label: '结束日期' },
|
||||
{ key: 'ownerUserName', label: '负责人' },
|
||||
{ key: 'partyA', label: '甲方' },
|
||||
{ key: 'partyAAddress', label: '甲方地址' },
|
||||
{ key: 'partyAContact', label: '甲方联系人' },
|
||||
{ key: 'partyAMobile', label: '甲方电话' },
|
||||
{ key: 'partyALegalPerson', label: '甲方法定代表人' },
|
||||
{ key: 'partyAAgent', label: '甲方代理人' },
|
||||
{ key: 'partyAPhoneFax', label: '甲方电话/传真' },
|
||||
{ key: 'partyABank', label: '甲方开户银行' },
|
||||
{ key: 'partyAAccount', label: '甲方账号' },
|
||||
{ key: 'partyB', label: '乙方' },
|
||||
{ key: 'partyBAddress', label: '乙方地址' },
|
||||
{ key: 'partyBContact', label: '乙方联系人' },
|
||||
{ key: 'partyBMobile', label: '乙方电话' },
|
||||
{ key: 'partyBLegalPerson', label: '乙方法定代表人' },
|
||||
{ key: 'partyBAgent', label: '乙方代理人' },
|
||||
{ key: 'partyBPhoneFax', label: '乙方电话/传真' },
|
||||
{ key: 'partyBBank', label: '乙方开户银行' },
|
||||
{ key: 'partyBAccount', label: '乙方账号' }
|
||||
]
|
||||
defineExpose({ reload, openContract })
|
||||
</script>
|
||||
@@ -0,0 +1,306 @@
|
||||
<template>
|
||||
<van-popup
|
||||
:show="modelValue"
|
||||
position="bottom" teleport="body"
|
||||
round
|
||||
class="mp-customer-vant-popup"
|
||||
:style="{ height: '82%' }"
|
||||
@update:show="$emit('update:modelValue', $event)"
|
||||
>
|
||||
<div class="mp-customer-filter-vant">
|
||||
<van-nav-bar title="更多筛选" left-text="关闭" @click-left="$emit('update:modelValue', false)" />
|
||||
<div class="mp-customer-filter-vant__body cert-module cert-sheet-content">
|
||||
<el-form label-position="top" @submit.prevent>
|
||||
<el-form-item v-for="def in defs" :key="def.prop" :label="def.label">
|
||||
<div v-if="def.type === 'enum' && def.enumOptions?.length" class="filter-chips">
|
||||
<button
|
||||
v-for="option in def.enumOptions"
|
||||
:key="String(option.value)"
|
||||
type="button"
|
||||
class="filter-chip"
|
||||
:class="{ on: enumSelected(def.prop, String(option.value)) }"
|
||||
:aria-pressed="enumSelected(def.prop, String(option.value))"
|
||||
@click="toggleEnum(def.prop, String(option.value))"
|
||||
>{{ option.label }}</button
|
||||
>
|
||||
</div>
|
||||
<el-select
|
||||
v-else-if="def.type === 'enum'"
|
||||
:model-value="draft[def.prop]?.selected || []"
|
||||
multiple
|
||||
filterable
|
||||
clearable
|
||||
:placeholder="`请选择${def.label}`"
|
||||
@visible-change="(open) => open && facet.onFilterOpen(def.prop)"
|
||||
@update:model-value="(value) => (draft[def.prop] = { text: '', selected: value })"
|
||||
>
|
||||
<el-option
|
||||
v-for="o in options(def.prop)"
|
||||
:key="String(o.value)"
|
||||
:label="o.label"
|
||||
:value="String(o.value)"
|
||||
/>
|
||||
</el-select>
|
||||
<div v-else-if="def.type === 'datetime'" class="cert-range">
|
||||
<label
|
||||
>开始<input
|
||||
class="cert-input"
|
||||
:value="localInput(draft[def.prop]?.from)"
|
||||
type="date"
|
||||
@input="setDate(def.prop, 'from', $event)"
|
||||
/></label>
|
||||
<label
|
||||
>结束<input
|
||||
class="cert-input"
|
||||
:value="localInput(draft[def.prop]?.to)"
|
||||
type="date"
|
||||
@input="setDate(def.prop, 'to', $event)"
|
||||
/></label>
|
||||
</div>
|
||||
<div v-else-if="def.type === 'number'" class="cert-number">
|
||||
<el-select
|
||||
:model-value="draft[def.prop]?.op || 'between'"
|
||||
@update:model-value="(op) => (draft[def.prop] = { ...draft[def.prop], op })"
|
||||
>
|
||||
<el-option
|
||||
v-for="op in numberOps"
|
||||
:key="op.value"
|
||||
:label="op.label"
|
||||
:value="op.value"
|
||||
/>
|
||||
</el-select>
|
||||
<template v-if="!draft[def.prop]?.op || draft[def.prop]?.op === 'between'">
|
||||
<input
|
||||
class="cert-input"
|
||||
type="number"
|
||||
:aria-label="`${def.label}最小值`"
|
||||
placeholder="最小值"
|
||||
:value="draft[def.prop]?.min"
|
||||
@input="setNumber(def.prop, 'min', $event)"
|
||||
/>
|
||||
<input
|
||||
class="cert-input"
|
||||
type="number"
|
||||
:aria-label="`${def.label}最大值`"
|
||||
placeholder="最大值"
|
||||
:value="draft[def.prop]?.max"
|
||||
@input="setNumber(def.prop, 'max', $event)"
|
||||
/>
|
||||
</template>
|
||||
<input
|
||||
class="cert-input"
|
||||
v-else
|
||||
type="number"
|
||||
:aria-label="def.label"
|
||||
:value="draft[def.prop]?.value"
|
||||
@input="setNumber(def.prop, 'value', $event)"
|
||||
/>
|
||||
</div>
|
||||
<el-input
|
||||
v-else
|
||||
:model-value="draft[def.prop]?.text || ''"
|
||||
clearable
|
||||
:placeholder="`请输入${def.label}`"
|
||||
@update:model-value="(text) => (draft[def.prop] = { text, selected: [] })"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="排序字段">
|
||||
<el-select v-model="sortField" clearable placeholder="默认排序(创建时间倒序)"
|
||||
><el-option
|
||||
v-for="d in defs.filter((item) => item.type === 'datetime')"
|
||||
:key="d.prop"
|
||||
:label="d.label"
|
||||
:value="d.prop"
|
||||
/></el-select>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="sortField" label="排序方式"
|
||||
><el-select v-model="sortOrder"
|
||||
><el-option label="升序" value="asc" /><el-option
|
||||
label="降序"
|
||||
value="desc" /></el-select
|
||||
></el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<div class="mp-customer-filter-vant__foot">
|
||||
<button class="mp-wv-btn" type="button" @click="resetAndApply">重置</button>
|
||||
<button class="mp-wv-btn mp-wv-btn--primary" type="button" @click="apply">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</van-popup>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { plPlanCertColumnFilterDefs as defs } from '@/views/pl/plan-cert/columnFilterDefs'
|
||||
import '@/styles/mp-webview.scss'
|
||||
import '../../crm/customer/customer.scss'
|
||||
import { useServerColumnFilters } from '@/composables/useServerColumnFilters'
|
||||
import { useColumnFacetOptions } from '@/composables/useColumnFacetOptions'
|
||||
import { fetchPlanColumnFacetValues } from '@/api/pl'
|
||||
import {
|
||||
withPlanContractIoFacetOptions,
|
||||
PL_PLAN_CONTRACT_SIDE_FILTER_OPTIONS
|
||||
} from '@/utils/pl-plan-contract-display'
|
||||
import {
|
||||
applyMergedCustomerQueryParams,
|
||||
applyContractSideQueryParams
|
||||
} from '@/utils/pl-plan-pair-list-query'
|
||||
import { PL_PLAN_DEFAULT_FOLLOW_STATUSES } from '@/utils/pl-display'
|
||||
import { facetPlanDateParams } from './model'
|
||||
const props = defineProps<{
|
||||
modelValue: boolean
|
||||
filters: Record<string, any>
|
||||
sort: { sortField: string; sortOrder: string }
|
||||
context: Record<string, any>
|
||||
}>()
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [boolean]
|
||||
apply: [Record<string, any>, { sortField: string; sortOrder: string }, boolean]
|
||||
}>()
|
||||
const { filters: filterDraft, toQueryParams } = useServerColumnFilters(defs)
|
||||
const draft = filterDraft as Record<string, any>
|
||||
const sortField = ref('')
|
||||
const sortOrder = ref('desc')
|
||||
const resetAll = ref(false)
|
||||
const numberOps = [
|
||||
{ value: 'between', label: '区间' },
|
||||
{ value: 'eq', label: '等于' },
|
||||
{ value: 'gt', label: '大于' },
|
||||
{ value: 'gte', label: '大于等于' },
|
||||
{ value: 'lt', label: '小于' },
|
||||
{ value: 'lte', label: '小于等于' }
|
||||
]
|
||||
const facet = useColumnFacetOptions({
|
||||
facetFields: defs.filter((d) => d.type === 'enum' && !d.enumOptions?.length).map((d) => d.prop),
|
||||
columnFilterDefs: defs,
|
||||
getContextParams: () => {
|
||||
const q = { ...props.context }
|
||||
for (const def of defs) {
|
||||
const key = def.queryKey || def.prop
|
||||
const prefix = def.queryKeyPrefix || key
|
||||
for (const k of [
|
||||
key,
|
||||
`${key}In`,
|
||||
def.queryKeyFrom || `${key}From`,
|
||||
def.queryKeyTo || `${key}To`,
|
||||
`${prefix}Op`,
|
||||
`${prefix}Min`,
|
||||
`${prefix}Max`,
|
||||
prefix
|
||||
])
|
||||
delete q[k]
|
||||
}
|
||||
delete q.stopCustomers
|
||||
delete q.stopKindIn
|
||||
Object.assign(q, toQueryParams())
|
||||
Object.assign(q, facetPlanDateParams(props.context, draft.planDate, props.filters.planDate))
|
||||
for (const key of ['loadCustomers', 'deliveryCustomers']) {
|
||||
if (q[`${key}In`]) {
|
||||
q[key] = q[`${key}In`].split(',')
|
||||
delete q[`${key}In`]
|
||||
}
|
||||
}
|
||||
applyMergedCustomerQueryParams(q)
|
||||
applyContractSideQueryParams(q, draft.productContract)
|
||||
if (q.followStatusIn) {
|
||||
q.followStatus = q.followStatusIn
|
||||
delete q.followStatusIn
|
||||
}
|
||||
if (props.context.certUploadStatus === 'incomplete') {
|
||||
q.hazardCertReady = 0
|
||||
delete q.hazardCertReadyIn
|
||||
}
|
||||
if (props.context.planType) {
|
||||
q.planType = props.context.planType
|
||||
delete q.planTypeIn
|
||||
}
|
||||
return q
|
||||
},
|
||||
fetchFacet: fetchPlanColumnFacetValues
|
||||
})
|
||||
function options(prop: string) {
|
||||
const items = facet.enumOptionsFor(prop)
|
||||
return prop === 'productContract'
|
||||
? [...PL_PLAN_CONTRACT_SIDE_FILTER_OPTIONS, ...withPlanContractIoFacetOptions(items)]
|
||||
: items
|
||||
}
|
||||
function enumSelected(prop: string, value: string) {
|
||||
return ((draft[prop]?.selected || []) as string[]).map(String).includes(value)
|
||||
}
|
||||
function toggleEnum(prop: string, value: string) {
|
||||
const current = ((draft[prop]?.selected || []) as string[]).map(String)
|
||||
draft[prop] = {
|
||||
text: '',
|
||||
selected: current.includes(value)
|
||||
? current.filter((item) => item !== value)
|
||||
: [...current, value]
|
||||
}
|
||||
}
|
||||
function localInput(value: string) {
|
||||
return (value || '').replace(' ', 'T')
|
||||
}
|
||||
function setDate(prop: string, key: string, event: Event) {
|
||||
draft[prop] = {
|
||||
...draft[prop],
|
||||
[key]: (event.target as HTMLInputElement).value.replace('T', ' ')
|
||||
} as any
|
||||
}
|
||||
function setNumber(prop: string, key: string, event: Event) {
|
||||
draft[prop] = {
|
||||
op: 'between',
|
||||
...draft[prop],
|
||||
[key]: (event.target as HTMLInputElement).value
|
||||
} as any
|
||||
}
|
||||
function reset() {
|
||||
Object.keys(draft).forEach((k) => delete draft[k])
|
||||
draft.followStatus = { text: '', selected: [...PL_PLAN_DEFAULT_FOLLOW_STATUSES] }
|
||||
sortField.value = ''
|
||||
sortOrder.value = 'desc'
|
||||
resetAll.value = true
|
||||
}
|
||||
function resetAndApply() {
|
||||
reset()
|
||||
apply()
|
||||
}
|
||||
function apply() {
|
||||
for (const def of defs) {
|
||||
const state = draft[def.prop]
|
||||
if (def.type === 'datetime' && state?.from && state?.to && state.from > state.to) {
|
||||
ElMessage.warning(`${def.label}开始不能晚于结束`)
|
||||
return
|
||||
}
|
||||
if (
|
||||
def.type === 'number' &&
|
||||
state?.op === 'between' &&
|
||||
state.min !== '' &&
|
||||
state.max !== '' &&
|
||||
state.min != null &&
|
||||
state.max != null &&
|
||||
Number(state.min) > Number(state.max)
|
||||
) {
|
||||
ElMessage.warning(`${def.label}最小值不能大于最大值`)
|
||||
return
|
||||
}
|
||||
}
|
||||
emit(
|
||||
'apply',
|
||||
JSON.parse(JSON.stringify(draft)),
|
||||
{
|
||||
sortField: sortField.value,
|
||||
sortOrder: sortOrder.value
|
||||
},
|
||||
resetAll.value
|
||||
)
|
||||
emit('update:modelValue', false)
|
||||
}
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(open) => {
|
||||
if (!open) return
|
||||
Object.keys(draft).forEach((k) => delete draft[k])
|
||||
Object.assign(draft, JSON.parse(JSON.stringify(props.filters)))
|
||||
sortField.value = props.sort.sortField
|
||||
sortOrder.value = props.sort.sortOrder
|
||||
resetAll.value = false
|
||||
}
|
||||
)
|
||||
</script>
|
||||
@@ -0,0 +1,189 @@
|
||||
<template>
|
||||
<section class="cert-section">
|
||||
<h3>{{ label }} · {{ stop.customerName || '—' }}</h3>
|
||||
<div class="cert-kv"
|
||||
><span>时间</span
|
||||
><span>{{
|
||||
kind === 'load'
|
||||
? (stop as PlanLoad).loadTime || '—'
|
||||
: (stop as PlanDelivery).deliveryTime || '—'
|
||||
}}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>地址</span><span>{{ stop.address || '—' }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>联系方式</span><span>{{ stop.contact || '—' }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>注意事项</span><span>{{ stop.notes || '—' }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>地磅单</span><el-tag type="info">{{ formatMpStopDibangText(stop) }}</el-tag></div
|
||||
>
|
||||
<div v-for="(c, i) in stop.contracts || []" :key="i" class="cert-contract"
|
||||
><span>合同:</span
|
||||
><button class="cert-link" @click="$emit('contract', c.contractId)">{{
|
||||
c.contractNo || c.contractId
|
||||
}}</button></div
|
||||
>
|
||||
<div v-for="(p, i) in displayProducts" :key="p.id || i" class="cert-product">
|
||||
<h4>{{ p.productName }}</h4>
|
||||
<div class="cert-kv"
|
||||
><span>别名</span><span>{{ p.aliasName || '—' }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>品牌</span
|
||||
><span>{{ formatBrandConstraintLabel(p.brandMode, p.brandName) }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>型号/规格</span><span>{{ p.model || '—' }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>单位 / 包装</span
|
||||
><span
|
||||
>{{ resolveMpProductUnitLabel(p.unit) }} /
|
||||
{{ resolveMpPackageSpecLabel(p.packageSpec) }}</span
|
||||
></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>送货方式</span><span>{{ resolveMpDeliveryMethodLabel(p.deliveryMethod) }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>计划量</span><span>{{ p.planQty ?? '—' }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>入库量</span><span>{{ p.inboundQty ?? '—' }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>出库量</span><span>{{ p.outboundQty ?? '—' }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>合同</span
|
||||
><button v-if="p.contractId" class="cert-link" @click="$emit('contract', p.contractId)">{{
|
||||
p.contractNo || p.contractId
|
||||
}}</button
|
||||
><span v-else>{{ p.contractNo || '—' }}</span></div
|
||||
>
|
||||
<p v-if="p.remark">备注:{{ p.remark }}</p
|
||||
><p v-if="p.archiveRemark">归档备注:{{ p.archiveRemark }}</p>
|
||||
</div>
|
||||
<p v-if="!stop.products?.length">暂无产品</p>
|
||||
<PlPlanStopFeedbackPanel
|
||||
v-if="showFeedback"
|
||||
:stop-label="label"
|
||||
:customer-name="stop.customerName"
|
||||
:generate-dibang="stop.generateDibang"
|
||||
:dibang-rows="stopDibangRows"
|
||||
:plan-product-rows="productRows"
|
||||
:driver-feedback="driverFeedback"
|
||||
:site-feedback="siteFeedback"
|
||||
:fallback-remark="transport?.feedbackRemark"
|
||||
/>
|
||||
</section>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import type { PlanLoad, PlanDelivery, PlanProduct, Transport } from '@/api/pl'
|
||||
import PlPlanStopFeedbackPanel from '@/components/business/pl-plan-stop-feedback-panel/index.vue'
|
||||
import { formatBrandConstraintLabel } from '@/utils/crm-product-brand'
|
||||
import { stopProductMeta } from './model'
|
||||
import {
|
||||
mapPlanProductToFormRow,
|
||||
type PlPlanTransportDibangRow
|
||||
} from '@/composables/usePlPlanViewDetail'
|
||||
import {
|
||||
formatMpStopDibangText,
|
||||
resolveMpProductUnitLabel,
|
||||
resolveMpPackageSpecLabel,
|
||||
resolveMpDeliveryMethodLabel
|
||||
} from '@/utils/mp-pl-plan-display'
|
||||
const props = defineProps<{
|
||||
stop: PlanLoad | PlanDelivery
|
||||
label: string
|
||||
kind: 'load' | 'delivery'
|
||||
products: PlanProduct[]
|
||||
transport: Transport | null
|
||||
dibangRows: PlPlanTransportDibangRow[]
|
||||
showFeedback: boolean
|
||||
}>()
|
||||
defineEmits<{ contract: [string] }>()
|
||||
const displayProducts = computed(() =>
|
||||
(props.stop.products || []).map((p) => ({ ...p, ...stopProductMeta(p, props.products) }))
|
||||
)
|
||||
const productRows = computed(() => props.products.map(mapPlanProductToFormRow))
|
||||
const driverFeedback = computed(
|
||||
() =>
|
||||
props.transport?.driverStopFeedbacks?.find(
|
||||
(f) => f.stopType === props.kind && f.stopId === props.stop.id
|
||||
) || null
|
||||
)
|
||||
const siteFeedback = computed(
|
||||
() =>
|
||||
props.transport?.siteStopFeedbacks?.find(
|
||||
(f) => f.stopType === props.kind && f.stopId === props.stop.id
|
||||
) || null
|
||||
)
|
||||
const stopDibangRows = computed(() =>
|
||||
props.dibangRows.filter((row) =>
|
||||
row.link.stopType && row.link.stopId
|
||||
? row.link.stopType === props.kind && row.link.stopId === props.stop.id
|
||||
: (props.stop.products || []).some((p) => p.planProductId === row.link.planProductId)
|
||||
)
|
||||
)
|
||||
</script>
|
||||
<style scoped lang="scss">
|
||||
:deep(.pl-stop-feedback-cards) {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
:deep(.pl-stop-feedback-ticket__row) {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
:deep(.pl-stop-feedback-ticket__line) {
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
:deep(.pl-stop-feedback-ticket__text) {
|
||||
overflow-wrap: anywhere;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
:deep(.pl-stop-feedback-ticket__foot) {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.cert-section :deep(.attachment-upload--compact.attachment-upload--readonly .attachment-list) {
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.cert-section :deep(.attachment-upload--compact.attachment-upload--readonly .attachment-item) {
|
||||
width: 88px;
|
||||
min-width: 88px;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.cert-section :deep(.attachment-upload--compact.attachment-upload--readonly .attachment-preview) {
|
||||
width: 100%;
|
||||
height: 66px;
|
||||
min-height: 44px;
|
||||
}
|
||||
|
||||
.cert-section
|
||||
:deep(.attachment-upload--compact.attachment-upload--readonly .attachment-compact-download) {
|
||||
position: static;
|
||||
inset: auto;
|
||||
width: 100%;
|
||||
min-width: 44px;
|
||||
height: 44px;
|
||||
min-height: 44px;
|
||||
color: #087f57;
|
||||
background: #e9f9f2;
|
||||
border-top: 1px solid #dcebe4;
|
||||
border-radius: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,179 @@
|
||||
<template>
|
||||
<section class="cert-section">
|
||||
<h3>运输信息</h3>
|
||||
<div class="cert-kv"
|
||||
><span>车牌 / 挂车</span
|
||||
><span
|
||||
>{{ plan.licensePlate || vehicle?.licensePlate || '—' }} /
|
||||
{{ plan.trailerNo || vehicle?.trailerNo || '—' }}</span
|
||||
></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>本次司机</span
|
||||
><span
|
||||
>{{ transport?.driverName || plan.driverName || '—' }}
|
||||
{{ transport?.driverPhone || '' }}</span
|
||||
></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>本次押运员</span
|
||||
><span
|
||||
>{{ transport?.escortName || plan.escortName || '—' }}
|
||||
{{ transport?.escortPhone || plan.escortPhone || '' }}</span
|
||||
></div
|
||||
>
|
||||
<details v-if="vehicle" class="cert-expand"
|
||||
><summary>查看车辆详情</summary>
|
||||
<div class="cert-kv"
|
||||
><span>车辆类型</span
|
||||
><el-tag type="info">{{ getPlVehicleTypeLabel(vehicle.vehicleType) }}</el-tag></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>车辆状态</span
|
||||
><el-tag :type="getPlVehicleStatusTagType(vehicle.vehicleStatus) as any">{{
|
||||
getPlVehicleStatusLabel(vehicle.vehicleStatus)
|
||||
}}</el-tag></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>承运商</span
|
||||
><span>{{ transport?.carrierName || vehicle.carrierName || '—' }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>载重(吨)</span><span>{{ vehicle.loadCapacity ?? '—' }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>创建时间</span><span>{{ vehicle.createTime || '—' }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>关联人员</span
|
||||
><span>{{ normalizePlPersonnelSummaryDisplay(vehicle.personnelSummary) || '—' }}</span></div
|
||||
>
|
||||
<p>备注:{{ vehicle.remark || '—' }}</p>
|
||||
<CertAttachments v-if="vehicle.photoUrls" :model-value="vehicle.photoUrls" readonly />
|
||||
<section v-for="c in vehicle.certList || []" :key="c.id" class="cert-product"
|
||||
><h4>{{ c.certName }}</h4
|
||||
><p>{{ c.vehiclePart || '' }} · {{ c.certNo || '—' }}</p
|
||||
><p>有效期 {{ c.expireDate || '—' }} · 提前 {{ c.remindDays ?? '—' }} 天提醒</p
|
||||
><el-tag type="info">{{ certStatus(c.status) }}</el-tag
|
||||
><CertAttachments :model-value="c.attachmentUrls || ''" readonly
|
||||
/></section>
|
||||
<section
|
||||
v-for="(person, i) in bundle?.personnelList || []"
|
||||
:key="person.personnelId || i"
|
||||
class="cert-product"
|
||||
><h4>{{ person.personnelName }} {{ person.phoneNo }}</h4
|
||||
><el-tag type="info">{{
|
||||
person.role === 'driver' ? '司机' : person.role === 'escort' ? '押运员' : person.role
|
||||
}}</el-tag
|
||||
><p>年龄 {{ person.age ?? '—' }} · 默认人员 {{ person.isDefault ? '是' : '否' }}</p
|
||||
><p>{{ person.remark }}</p
|
||||
><div v-for="c in person.certList || []" :key="c.id"
|
||||
><h4>{{ c.certName }}</h4
|
||||
><p>{{ c.certNo || '—' }} · 有效期 {{ c.expireDate || '—' }}</p
|
||||
><el-tag type="info">{{ certStatus(c.status) }}</el-tag
|
||||
><CertAttachments :model-value="c.attachmentUrls || ''" readonly /></div
|
||||
></section>
|
||||
</details>
|
||||
<p v-else-if="plan.vehicleId">车辆详情暂不可用,请刷新重试。</p>
|
||||
<section
|
||||
v-if="transport?.feedbackTime || transport?.feedbackRemark || transport?.feedbackImages"
|
||||
class="cert-product"
|
||||
><h4>司机回传汇总</h4><p>时间:{{ transport.feedbackTime || '—' }}</p
|
||||
><p>数量:{{ transport.feedbackQty ?? '—' }}</p
|
||||
><p>{{ transport.feedbackRemark }}</p
|
||||
><CertAttachments :model-value="feedbackCsv(transport.feedbackImages)" readonly
|
||||
/></section>
|
||||
</section>
|
||||
<section class="cert-section"
|
||||
><h3>运费信息</h3>
|
||||
<div class="cert-kv"
|
||||
><span>是否有运输费用</span
|
||||
><el-tag type="info">{{ plan.hasFreight ? '是' : '否' }}</el-tag></div
|
||||
>
|
||||
<template v-if="plan.hasFreight">
|
||||
<div class="cert-kv"
|
||||
><span>运输公里数</span><span>{{ transport?.distanceKm ?? '—' }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>计算方式</span
|
||||
><el-tag type="info">{{
|
||||
getPlFreightTypeLabel(transport?.freightType || 'by_weight')
|
||||
}}</el-tag></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>运输量({{ unit }})</span
|
||||
><span>{{
|
||||
transport?.freightType === 'by_trip'
|
||||
? '—'
|
||||
: (transport?.transportQty ??
|
||||
plan.products?.reduce((n, p) => n + Number(p.actualQty ?? p.quantity ?? 0), 0) ??
|
||||
'—')
|
||||
}}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>运输单价(元/{{ unit }})</span
|
||||
><span>{{ transport?.freightPrice ?? '—' }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>运费金额(元)</span
|
||||
><span>{{ plan.freightAmount ?? transport?.freightAmount ?? '—' }}</span></div
|
||||
>
|
||||
<div class="cert-kv"
|
||||
><span>是否开票</span
|
||||
><el-tag type="info">{{
|
||||
transport?.hasInvoice != null
|
||||
? transport.hasInvoice
|
||||
? '是'
|
||||
: '否'
|
||||
: getPlHasInvoiceLabelFromSettlement(settlement)
|
||||
}}</el-tag></div
|
||||
>
|
||||
<p>运费备注:{{ plan.freightRemark || '—' }}</p>
|
||||
</template>
|
||||
</section>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import type { Plan, Transport, FreightSettlementBrief } from '@/api/pl'
|
||||
import type { VehicleViewBundle } from '@/composables/usePlVehicleViewDetail'
|
||||
import {
|
||||
getPlVehicleTypeLabel,
|
||||
getPlVehicleStatusLabel,
|
||||
getPlVehicleStatusTagType,
|
||||
normalizePlPersonnelSummaryDisplay,
|
||||
getPlFreightTypeLabel,
|
||||
getPlHasInvoiceLabelFromSettlement
|
||||
} from '@/utils/pl-display'
|
||||
import { resolveMpProductUnitLabel } from '@/utils/mp-pl-plan-display'
|
||||
import CertAttachments from './CertAttachments.vue'
|
||||
const props = defineProps<{
|
||||
plan: Plan
|
||||
transport: Transport | null
|
||||
bundle: VehicleViewBundle | null
|
||||
settlement: FreightSettlementBrief | null
|
||||
}>()
|
||||
const vehicle = computed(() => props.bundle?.detail)
|
||||
const unit = computed(() =>
|
||||
resolveMpProductUnitLabel(props.transport?.unit || props.plan.products?.[0]?.unit || '吨')
|
||||
)
|
||||
function feedbackCsv(raw?: string) {
|
||||
if (!raw) return ''
|
||||
try {
|
||||
const parsed = JSON.parse(raw)
|
||||
return Array.isArray(parsed) ? parsed.join(',') : raw
|
||||
} catch {
|
||||
return raw
|
||||
}
|
||||
}
|
||||
function certStatus(status: string) {
|
||||
return (
|
||||
(
|
||||
{ valid: '有效', expired: '已过期', expiring: '即将到期', normal: '正常' } as Record<
|
||||
string,
|
||||
string
|
||||
>
|
||||
)[status] ||
|
||||
status ||
|
||||
'—'
|
||||
)
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,152 @@
|
||||
<template>
|
||||
<van-popup
|
||||
:show="modelValue"
|
||||
position="bottom" teleport="body"
|
||||
round
|
||||
class="mp-customer-vant-popup mp-h5-approve-sheet"
|
||||
:style="{ height: '88%' }"
|
||||
@update:show="close"
|
||||
>
|
||||
<div class="mp-customer-filter-vant">
|
||||
<van-nav-bar title="上传证书" left-text="关闭" @click-left="close(false)" />
|
||||
<div class="mp-customer-filter-vant__body cert-module cert-sheet-content">
|
||||
<MpStructSkeleton
|
||||
v-if="loading"
|
||||
kind="sheet"
|
||||
caption="正在加载计划与危化品属性"
|
||||
:count="3"
|
||||
/>
|
||||
<p v-if="error" class="cert-error" role="alert">{{ error }}</p>
|
||||
<button v-if="error && !products.length" class="cert-btn" @click="load">重试</button>
|
||||
<template v-if="plan && !loading">
|
||||
<h3>{{ plan.planNo }}</h3>
|
||||
<p class="cert-hint"
|
||||
>{{ HAZARD_CERT_READY_CONFIRM_HINT }}可按需上传,先确认齐备后仍可补充附件。</p
|
||||
>
|
||||
<p v-if="!allowed" role="alert">该计划已归档、已取消或您无上传权限,仅可查看。</p>
|
||||
<p v-if="!products.length">暂无易制毒/易制爆产品</p>
|
||||
<section v-for="p in products" :key="p.id" class="cert-section">
|
||||
<h3>{{ p.productName }}</h3>
|
||||
<el-tag v-if="p.isToxic" type="warning">易制毒</el-tag>
|
||||
<el-tag v-if="p.isExplosive" type="danger">易制爆</el-tag>
|
||||
<el-form label-position="top" @submit.prevent>
|
||||
<el-form-item
|
||||
v-for="slot in getRequiredCertSlots(p)"
|
||||
:key="slot.key"
|
||||
:label="slot.label"
|
||||
>
|
||||
<CertAttachments
|
||||
:ref="(el) => setUploadRef(`${p.id}-${slot.key}`, el)"
|
||||
v-model="p[slot.key]"
|
||||
:readonly="!allowed || saving"
|
||||
:hint="`支持图片、PDF 等,可上传多个${slot.label}`"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</section>
|
||||
</template>
|
||||
</div>
|
||||
<div class="mp-customer-filter-vant__foot">
|
||||
<van-button
|
||||
block
|
||||
type="primary"
|
||||
:disabled="loading || saving || !allowed || !products.length"
|
||||
:loading="saving"
|
||||
@click="save"
|
||||
>保存证书</van-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</van-popup>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import MpStructSkeleton from '@/components/mp/MpStructSkeleton.vue'
|
||||
import { planApi, type Plan, type PlanProduct } from '@/api/pl'
|
||||
import '@/styles/mp-webview.scss'
|
||||
import '../../crm/customer/customer.scss'
|
||||
import {
|
||||
enrichPlanProductsHazardFromCrm,
|
||||
getRequiredCertSlots,
|
||||
isHazardProduct,
|
||||
HAZARD_CERT_READY_CONFIRM_HINT
|
||||
} from '@/composables/usePlToxicProductCertCheck'
|
||||
import CertAttachments from './CertAttachments.vue'
|
||||
import { canEdit, canSave, certPayload } from './model'
|
||||
const props = defineProps<{ modelValue: boolean; planId: string; permitted: boolean }>()
|
||||
const emit = defineEmits<{ 'update:modelValue': [boolean]; success: [string] }>()
|
||||
const plan = ref<Plan | null>(null)
|
||||
const products = ref<PlanProduct[]>([])
|
||||
const loading = ref(false)
|
||||
const saving = ref(false)
|
||||
const error = ref('')
|
||||
const uploads = new Map<string, InstanceType<typeof CertAttachments>>()
|
||||
const allowed = computed(() => props.permitted && canEdit(plan.value))
|
||||
let version = 0
|
||||
function setUploadRef(key: string, el: any) {
|
||||
if (el) uploads.set(key, el)
|
||||
else uploads.delete(key)
|
||||
}
|
||||
function hasUploading() {
|
||||
return [...uploads.values()].some((el) => el.hasUploading())
|
||||
}
|
||||
function close(value: boolean) {
|
||||
if (saving.value || hasUploading()) {
|
||||
ElMessage.warning('正在上传或保存,请完成后再关闭')
|
||||
return
|
||||
}
|
||||
emit('update:modelValue', value)
|
||||
}
|
||||
async function load() {
|
||||
const request = ++version
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
plan.value = null
|
||||
products.value = []
|
||||
uploads.clear()
|
||||
try {
|
||||
const res = await planApi.get(props.planId)
|
||||
const data = (res.data ?? res) as Plan
|
||||
const enriched = await enrichPlanProductsHazardFromCrm(data.products || [])
|
||||
if (request !== version) return
|
||||
plan.value = data
|
||||
products.value = enriched.filter(isHazardProduct).map((p) => ({
|
||||
...p,
|
||||
purchaseCertUrl: p.purchaseCertUrl || '',
|
||||
transportCertUrl: p.transportCertUrl || '',
|
||||
legalUseCertUrl: p.legalUseCertUrl || ''
|
||||
}))
|
||||
} catch {
|
||||
if (request === version) error.value = '读取计划失败,请重试'
|
||||
} finally {
|
||||
if (request === version) loading.value = false
|
||||
}
|
||||
}
|
||||
async function save() {
|
||||
if (hasUploading()) {
|
||||
ElMessage.warning('附件正在上传,请稍候再保存')
|
||||
return
|
||||
}
|
||||
if (!canSave(allowed.value, hasUploading(), saving.value, products.value.length)) return
|
||||
saving.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
await planApi.updateProductCerts(props.planId, certPayload(products.value))
|
||||
ElMessage.success('证书保存成功')
|
||||
emit('update:modelValue', false)
|
||||
emit('success', props.planId)
|
||||
} catch {
|
||||
error.value = '保存失败,已保留填写内容,请重试'
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
watch(
|
||||
() => [props.modelValue, props.planId] as const,
|
||||
([open, id]) => {
|
||||
if (open && id) void load()
|
||||
else ++version
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
defineExpose({ hasUploading })
|
||||
</script>
|
||||
@@ -0,0 +1,300 @@
|
||||
<template>
|
||||
<article
|
||||
class="mp-wv-card mp-wv-flat-card"
|
||||
:data-plan-id="plan.id"
|
||||
@click="$emit('view', plan.id)"
|
||||
>
|
||||
<div class="mp-wv-card__head">
|
||||
<div class="mp-wv-flat-card__head-main">
|
||||
<van-checkbox
|
||||
class="mp-wv-flat-card__check"
|
||||
:model-value="selected"
|
||||
:aria-label="`选择 ${plan.planNo}`"
|
||||
@click.stop
|
||||
@update:model-value="$emit('select', plan.id)"
|
||||
/>
|
||||
<div class="mp-wv-flat-card__titles">
|
||||
<div class="mp-wv-card__no">{{ plan.planNo }}</div>
|
||||
<div class="mp-wv-flat-card__meta">{{ metaLine }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<span class="status-tag" :class="followStatusClass">{{
|
||||
getPlPlanFollowStatusLabel(plan.followStatus)
|
||||
}}</span>
|
||||
</div>
|
||||
|
||||
<div class="mp-wv-flat-card__preview">
|
||||
<div class="mp-wv-flat-card__line">
|
||||
<span>线路</span>
|
||||
<span>{{ routeLabel }}</span>
|
||||
</div>
|
||||
<div class="mp-wv-flat-card__line">
|
||||
<span>证书状态</span>
|
||||
<span>{{ isHazardCertReady(plan) ? '已齐备' : certGapLabel }}</span>
|
||||
</div>
|
||||
<div class="mp-wv-flat-card__line">
|
||||
<span>车牌 / 人员</span>
|
||||
<span>{{ platePeople }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="mp-wv-flat-card__toggle"
|
||||
type="button"
|
||||
:aria-expanded="expanded"
|
||||
@click.stop="expanded = !expanded"
|
||||
>
|
||||
{{ expanded ? '收起' : '更多字段' }}
|
||||
<span class="mp-wv-flat-card__toggle-icon" aria-hidden="true">{{
|
||||
expanded ? '▴' : '▾'
|
||||
}}</span>
|
||||
</button>
|
||||
|
||||
<div v-show="expanded" class="mp-wv-flat-card__extra" @click.stop>
|
||||
<div class="mp-wv-flat-card__row">
|
||||
<span>送货时间</span>
|
||||
<span>{{ (plan.deliveryTimes || []).join(' / ') || '—' }}</span>
|
||||
</div>
|
||||
<div class="mp-wv-flat-card__row">
|
||||
<span>跟进人</span>
|
||||
<span>{{ plan.followUserName || '—' }}</span>
|
||||
</div>
|
||||
|
||||
<template v-if="loadStop">
|
||||
<div class="mp-wv-flat-card__row">
|
||||
<span>装货客户</span>
|
||||
<span>{{ loadStop.customerName || '—' }}</span>
|
||||
</div>
|
||||
<div class="mp-wv-flat-card__row">
|
||||
<span>装货时间</span>
|
||||
<span>{{ loadStop.loadTime || '—' }}</span>
|
||||
</div>
|
||||
<div class="mp-wv-flat-card__row">
|
||||
<span>装货地址</span>
|
||||
<span>{{ loadStop.address || '—' }}</span>
|
||||
</div>
|
||||
<div class="mp-wv-flat-card__row">
|
||||
<span>装货合同</span>
|
||||
<span>
|
||||
<template v-if="stopContracts(loadStop).length">
|
||||
<template
|
||||
v-for="(c, i) in stopContracts(loadStop)"
|
||||
:key="c.contractId || c.contractNo || i"
|
||||
>
|
||||
<button
|
||||
v-if="c.contractId"
|
||||
class="cert-link"
|
||||
type="button"
|
||||
@click="$emit('contract', c.contractId)"
|
||||
>{{ c.contractNo || c.contractId }}</button
|
||||
>
|
||||
<span v-else>{{ c.contractNo || '—' }}</span>
|
||||
</template>
|
||||
</template>
|
||||
<template v-else>—</template>
|
||||
</span>
|
||||
</div>
|
||||
<div class="mp-wv-flat-card__row">
|
||||
<span>装货产品</span>
|
||||
<span>{{ productSummary(loadStop.products) }}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template
|
||||
v-for="(delivery, index) in deliveryStops"
|
||||
:key="delivery.id || delivery.seq || index"
|
||||
>
|
||||
<div class="mp-wv-flat-card__row">
|
||||
<span>送货客户 {{ delivery.seq || index + 1 }}</span>
|
||||
<span>{{ delivery.customerName || '—' }}</span>
|
||||
</div>
|
||||
<div class="mp-wv-flat-card__row">
|
||||
<span>送货时间</span>
|
||||
<span>{{ delivery.deliveryTime || '—' }}</span>
|
||||
</div>
|
||||
<div class="mp-wv-flat-card__row">
|
||||
<span>送货地址</span>
|
||||
<span>{{ delivery.address || '—' }}</span>
|
||||
</div>
|
||||
<div class="mp-wv-flat-card__row">
|
||||
<span>送货合同</span>
|
||||
<span>
|
||||
<template v-if="stopContracts(delivery).length">
|
||||
<template
|
||||
v-for="(c, i) in stopContracts(delivery)"
|
||||
:key="c.contractId || c.contractNo || i"
|
||||
>
|
||||
<button
|
||||
v-if="c.contractId"
|
||||
class="cert-link"
|
||||
type="button"
|
||||
@click="$emit('contract', c.contractId)"
|
||||
>{{ c.contractNo || c.contractId }}</button
|
||||
>
|
||||
<span v-else>{{ c.contractNo || '—' }}</span>
|
||||
</template>
|
||||
</template>
|
||||
<template v-else>—</template>
|
||||
</span>
|
||||
</div>
|
||||
<div class="mp-wv-flat-card__row">
|
||||
<span>送货产品</span>
|
||||
<span>{{ productSummary(delivery.products) }}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div v-if="!loadStop && !deliveryStops.length" class="mp-wv-flat-card__row">
|
||||
<span>装送货段次</span>
|
||||
<span>暂无装送货段次</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mp-wv-card-actions" @click.stop>
|
||||
<button class="mp-wv-btn" type="button" @click="$emit('view', plan.id)">查看详情</button>
|
||||
<button
|
||||
v-if="canUpload"
|
||||
class="mp-wv-btn mp-wv-btn--primary"
|
||||
type="button"
|
||||
:disabled="!canEdit(plan) || busy"
|
||||
@click="$emit('upload', plan)"
|
||||
>上传证书</button
|
||||
>
|
||||
<button
|
||||
v-if="canReady"
|
||||
class="mp-wv-btn"
|
||||
type="button"
|
||||
:disabled="!canEdit(plan) || !planHasHazardProducts(plan.products) || busy"
|
||||
@click="$emit('ready', plan, !isHazardCertReady(plan))"
|
||||
>{{ isHazardCertReady(plan) ? '取消齐备' : '证书齐备' }}</button
|
||||
>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import type { Plan, PlanDelivery, PlanLoad, PlanStopProduct } from '@/api/pl'
|
||||
import {
|
||||
getPlPlanCompanyLabel,
|
||||
getPlPlanFollowStatusLabel,
|
||||
getPlPlanTypeLabel,
|
||||
formatPlVehiclePlateDisplay,
|
||||
normalizePlPersonnelSummaryDisplay
|
||||
} from '@/utils/pl-display'
|
||||
import {
|
||||
getDeliveryCustomerNameFromRow,
|
||||
getLoadCustomerNameFromRow,
|
||||
type PlPlanListDisplayRow
|
||||
} from '@/utils/pl-plan-list-display-rows'
|
||||
import {
|
||||
isHazardCertReady,
|
||||
planHasHazardProducts,
|
||||
isHazardProduct,
|
||||
getRequiredCertSlots
|
||||
} from '@/composables/usePlToxicProductCertCheck'
|
||||
import { canEdit } from './model'
|
||||
|
||||
type StopContract = { contractId?: string; contractNo?: string }
|
||||
|
||||
const props = defineProps<{
|
||||
plan: Plan
|
||||
rows: PlPlanListDisplayRow[]
|
||||
selected: boolean
|
||||
canUpload: boolean
|
||||
canReady: boolean
|
||||
busy: boolean
|
||||
}>()
|
||||
defineEmits<{
|
||||
select: [string]
|
||||
view: [string]
|
||||
upload: [Plan]
|
||||
ready: [Plan, boolean]
|
||||
contract: [string]
|
||||
}>()
|
||||
|
||||
const expanded = ref(false)
|
||||
const loadStop = computed(() => props.plan.load || null)
|
||||
const deliveryStops = computed(() => props.plan.deliveries || [])
|
||||
const metaLine = computed(() => {
|
||||
const date = props.plan.planDate || '日期未定'
|
||||
return `${date} · ${getPlPlanTypeLabel(props.plan.planType)} · ${getPlPlanCompanyLabel(props.plan.belongsCompany)}`
|
||||
})
|
||||
const platePeople = computed(
|
||||
() =>
|
||||
`${formatPlVehiclePlateDisplay(props.plan.licensePlate, props.plan.trailerNo)} · ${
|
||||
normalizePlPersonnelSummaryDisplay(props.plan.personnelSummary) || '暂无人员'
|
||||
}`
|
||||
)
|
||||
|
||||
const firstRow = computed(() => props.rows[0])
|
||||
const routeLabel = computed(() => {
|
||||
const row = firstRow.value
|
||||
if (row) {
|
||||
return `${getLoadCustomerNameFromRow(row)} → ${getDeliveryCustomerNameFromRow(row)}`
|
||||
}
|
||||
const loadName = (loadStop.value?.customerName || '').trim()
|
||||
const firstDelivery = deliveryStops.value[0]
|
||||
const deliveryName = (firstDelivery?.customerName || '').trim()
|
||||
if (loadName || deliveryName) {
|
||||
return `${loadName || '—'} → ${deliveryName || '—'}`
|
||||
}
|
||||
return '装送货待补充'
|
||||
})
|
||||
const certGapLabel = computed(() => {
|
||||
const missing = (props.plan.products || []).filter(isHazardProduct).flatMap((product) =>
|
||||
getRequiredCertSlots(product)
|
||||
.filter((slot) => !String((product as any)[slot.key] || '').trim())
|
||||
.map((slot) => slot.label)
|
||||
)
|
||||
return missing.length ? `缺${[...new Set(missing)].join('、')}` : '证书已上传'
|
||||
})
|
||||
const followStatusClass = computed(() => {
|
||||
if (props.plan.followStatus === 'cancelled') return 'status-tag--danger'
|
||||
if (props.plan.followStatus === 'completed') return 'status-tag--success'
|
||||
if (props.plan.followStatus === 'arranged') return 'status-tag--info'
|
||||
return 'status-tag--warning'
|
||||
})
|
||||
|
||||
function productSummary(products?: PlanStopProduct[]) {
|
||||
if (!products?.length) return '暂无产品'
|
||||
return products.map((product) => productLine(product)).join(';')
|
||||
}
|
||||
|
||||
function stopContracts(stop: PlanLoad | PlanDelivery): StopContract[] {
|
||||
const fromStop = (stop.contracts || [])
|
||||
.map((c) => ({
|
||||
contractId: String(c.contractId || '').trim() || undefined,
|
||||
contractNo: String(c.contractNo || '').trim() || undefined
|
||||
}))
|
||||
.filter((c) => c.contractId || c.contractNo)
|
||||
if (fromStop.length) return uniqueContracts(fromStop)
|
||||
const fromProducts = (stop.products || [])
|
||||
.map((p) => ({
|
||||
contractId: String(p.contractId || '').trim() || undefined,
|
||||
contractNo: String(p.contractNo || '').trim() || undefined
|
||||
}))
|
||||
.filter((c) => c.contractId || c.contractNo)
|
||||
return uniqueContracts(fromProducts)
|
||||
}
|
||||
|
||||
function uniqueContracts(list: StopContract[]) {
|
||||
const seen = new Set<string>()
|
||||
const out: StopContract[] = []
|
||||
for (const item of list) {
|
||||
const key = `${item.contractId || ''}::${item.contractNo || ''}`
|
||||
if (seen.has(key)) continue
|
||||
seen.add(key)
|
||||
out.push(item)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function productLine(product: PlanStopProduct) {
|
||||
const name = (product.productName || '—').trim() || '—'
|
||||
const model = (product.model || '').trim()
|
||||
const unit = (product.unit || '').trim()
|
||||
const qty =
|
||||
product.planQty != null && Number.isFinite(Number(product.planQty))
|
||||
? `${product.planQty}${unit ? ` ${unit}` : ''}`
|
||||
: ''
|
||||
return [name, model, qty].filter(Boolean).join(' · ')
|
||||
}
|
||||
</script>
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,148 @@
|
||||
<template>
|
||||
<MpWebviewShell @ready="init">
|
||||
<main class="cert-module cert-detail-page mp-h5-detail-page">
|
||||
<MpBusinessHeader title="危化品证详情" back-label="返回危化品证列表" @back="back" />
|
||||
<CertDetail
|
||||
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-model="uploadOpen" :plan-id="id" :permitted="canUpload" @success="saved" />
|
||||
</main>
|
||||
</MpWebviewShell>
|
||||
</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 { 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 id = computed(() => String(route.params.id || ''))
|
||||
const detailRef = ref<InstanceType<typeof CertDetail>>()
|
||||
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 (!canUpload.value || !canEdit(plan) || acting.value) {
|
||||
ElMessage.warning('无上传权限或该计划不可编辑')
|
||||
return
|
||||
}
|
||||
uploadOpen.value = true
|
||||
}
|
||||
|
||||
async function saved() {
|
||||
await detailRef.value?.reload()
|
||||
}
|
||||
|
||||
async function setReady(plan: Plan, ready: boolean) {
|
||||
if (!canReady.value || acting.value) return
|
||||
acting.value = true
|
||||
try {
|
||||
const result = await planApi.get(plan.id)
|
||||
const fresh = (result.data ?? result) as Plan
|
||||
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 (!canReady.value) return
|
||||
await planApi.setHazardCertReady(fresh.id, ready)
|
||||
ElMessage.success(ready ? '证书已标记齐备' : '已取消证书齐备')
|
||||
await detailRef.value?.reload()
|
||||
} catch {
|
||||
ElMessage.error('操作失败,请重试')
|
||||
} finally {
|
||||
acting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadPermissions() {
|
||||
canUpload.value = false
|
||||
canReady.value = false
|
||||
canPrice.value = false
|
||||
permissionError.value = false
|
||||
try {
|
||||
const permission = await fetchGetMenuCodes()
|
||||
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 {
|
||||
permissionError.value = true
|
||||
} finally {
|
||||
permissionsLoaded.value = true
|
||||
}
|
||||
}
|
||||
|
||||
async function openQueryContract() {
|
||||
const contractId = String(route.query.contractId || '')
|
||||
if (!contractId) return
|
||||
await nextTick()
|
||||
await detailRef.value?.openContract(contractId)
|
||||
}
|
||||
|
||||
async function init() {
|
||||
await loadPermissions()
|
||||
await openQueryContract()
|
||||
}
|
||||
|
||||
watch(
|
||||
() => route.query.contractId,
|
||||
() => void openQueryContract()
|
||||
)
|
||||
</script>
|
||||
@@ -0,0 +1,470 @@
|
||||
<template>
|
||||
<MpWebviewShell @ready="init">
|
||||
<MpListPageSkeleton
|
||||
v-if="loading && !plans.length"
|
||||
class="cert-module cert-page mp-plan-cert-list"
|
||||
variant="full"
|
||||
layout="customer"
|
||||
title="危化品证上传"
|
||||
searchable
|
||||
search-placeholder="计划编号 / 供方 / 需方"
|
||||
:tabs="PL_PLAN_CERT_TABS.map((item) => item.label)"
|
||||
:filters="['全部日期', '全部齐备状态', '更多']"
|
||||
caption="正在加载计划"
|
||||
aria-label="正在加载计划"
|
||||
@back="goToMiniWorkbench"
|
||||
/>
|
||||
<main v-else class="cert-module cert-page mp-plan-cert-list">
|
||||
<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="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="load(failedMore)">重试加载</button>
|
||||
<div v-if="!loading && !error && !visibleCards.length" class="cert-empty"
|
||||
>暂无符合条件的计划</div
|
||||
>
|
||||
<PlanCard
|
||||
v-for="item in visibleCards"
|
||||
:key="item.plan.id"
|
||||
:plan="item.plan"
|
||||
:rows="item.rows"
|
||||
:selected="selected.has(item.plan.id)"
|
||||
:can-upload="canUpload"
|
||||
:can-ready="canReady"
|
||||
:busy="acting"
|
||||
@select="toggle"
|
||||
@view="openDetail"
|
||||
@upload="openUpload"
|
||||
@ready="(p, ready) => setReady([p], ready)"
|
||||
@contract="(id) => openContract(item.plan.id, id)"
|
||||
/>
|
||||
<MpListPageSkeleton
|
||||
v-if="loading && plans.length"
|
||||
variant="body"
|
||||
layout="customer"
|
||||
:card-count="1"
|
||||
caption="正在加载更多"
|
||||
aria-label="正在加载更多"
|
||||
/>
|
||||
<p v-else-if="!error && plans.length" class="cert-total mp-h5-load-hint" role="status">
|
||||
<span>共 {{ total }} 条计划 · 已加载 {{ plans.length }} 条</span>
|
||||
<span v-if="selected.size"> · 已选 {{ selected.size }} 项</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>
|
||||
<div v-if="selected.size" class="cert-batch"
|
||||
><span>已选 {{ selected.size }} 项</span
|
||||
><button class="cert-btn" @click="selected = new Set()">清空</button
|
||||
><button
|
||||
v-if="canReady"
|
||||
class="cert-btn cert-btn--primary"
|
||||
:disabled="acting || !eligible(true).length"
|
||||
@click="setReady(selectedPlans, true)"
|
||||
>证书齐备</button
|
||||
><button
|
||||
v-if="canReady"
|
||||
class="cert-btn"
|
||||
:disabled="acting || !eligible(false).length"
|
||||
@click="setReady(selectedPlans, false)"
|
||||
>取消齐备</button
|
||||
></div
|
||||
>
|
||||
</main>
|
||||
<CertFilters
|
||||
v-model="filtersOpen"
|
||||
:filters="filters"
|
||||
:sort="sort"
|
||||
:context="query()"
|
||||
@apply="applyFilters"
|
||||
/>
|
||||
<CertUpload v-model="uploadOpen" :plan-id="uploadId" :permitted="canUpload" @success="saved" />
|
||||
</MpWebviewShell>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { useDebounceFn } from '@vueuse/core'
|
||||
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 { 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 './cert.scss'
|
||||
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 quickPanel = ref('')
|
||||
const readyKind = ref('all')
|
||||
const dateLabel = computed(
|
||||
() => dateOptions.find((item) => item.value === dateKind.value)?.label || '自定义日期'
|
||||
)
|
||||
const readyLabel = computed(
|
||||
() => readyOptions.find((item) => item.value === readyKind.value)?.label || '全部齐备状态'
|
||||
)
|
||||
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 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 selected = ref(new Set<string>())
|
||||
const loading = ref(true)
|
||||
const error = ref('')
|
||||
const failedMore = ref(false)
|
||||
const acting = ref(false)
|
||||
let requestVersion = 0
|
||||
const selectedPlans = computed(() => plans.value.filter((p) => selected.value.has(p.id)))
|
||||
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
|
||||
)
|
||||
// Enum selectors use `In`; the shared customer merger expects arrays under the base keys.
|
||||
for (const key of ['loadCustomers', 'deliveryCustomers']) {
|
||||
if (q[`${key}In`]) {
|
||||
q[key] = q[`${key}In`].split(',')
|
||||
delete q[`${key}In`]
|
||||
}
|
||||
}
|
||||
applyMergedCustomerQueryParams(q)
|
||||
applyContractSideQueryParams(q, filters.productContract as any)
|
||||
return q
|
||||
}
|
||||
async function load(more = false) {
|
||||
if (more && loading.value) return
|
||||
const v = ++requestVersion
|
||||
const nextPage = more ? page.value + 1 : 1
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
failedMore.value = more
|
||||
if (!more) {
|
||||
page.value = 1
|
||||
plans.value = []
|
||||
selected.value = new Set()
|
||||
}
|
||||
try {
|
||||
const res = await planApi.list({ ...query(), page: nextPage, pageSize: 20 })
|
||||
if (v !== requestVersion) return
|
||||
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
|
||||
} catch {
|
||||
if (v === requestVersion) error.value = '计划加载失败,请重试'
|
||||
} finally {
|
||||
if (v === requestVersion) loading.value = false
|
||||
}
|
||||
}
|
||||
function search() {
|
||||
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 || plans.value.length >= total.value) return
|
||||
void load(true)
|
||||
},
|
||||
{ rootMargin: '160px 0px' }
|
||||
)
|
||||
function toggle(id: string) {
|
||||
const next = new Set(selected.value)
|
||||
if (next.has(id)) next.delete(id)
|
||||
else next.add(id)
|
||||
selected.value = next
|
||||
}
|
||||
function changeTab(value: string) {
|
||||
tab.value = value
|
||||
delete filters.planType
|
||||
if (value === 'cert_incomplete') {
|
||||
delete filters.hazardCertReady
|
||||
readyKind.value = 'all'
|
||||
}
|
||||
quickPanel.value = ''
|
||||
search()
|
||||
}
|
||||
function toggleQuickPanel(panel: string) {
|
||||
quickPanel.value = quickPanel.value === panel ? '' : panel
|
||||
}
|
||||
function openMoreFilters() {
|
||||
quickPanel.value = ''
|
||||
moreDropdown.value?.toggle?.(false)
|
||||
filtersOpen.value = true
|
||||
}
|
||||
function setDate(kind: string) {
|
||||
dateKind.value = kind
|
||||
dates.value = dateShortcut(kind)
|
||||
delete filters.planDate
|
||||
quickPanel.value = ''
|
||||
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
|
||||
quickPanel.value = ''
|
||||
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
|
||||
}
|
||||
uploadId.value = p.id
|
||||
uploadOpen.value = true
|
||||
}
|
||||
function eligible(ready: boolean) {
|
||||
return readyTargets(selectedPlans.value, ready, (p) => planHasHazardProducts(p.products))
|
||||
}
|
||||
async function saved(id: string) {
|
||||
await load()
|
||||
openDetail(id)
|
||||
}
|
||||
async function setReady(rows: Plan[], ready: boolean) {
|
||||
if (!canReady.value || acting.value) return
|
||||
acting.value = true
|
||||
let failed = 0
|
||||
let success = 0
|
||||
let skipped = 0
|
||||
try {
|
||||
const fresh: Plan[] = []
|
||||
for (const row of rows) {
|
||||
try {
|
||||
const res = await planApi.get(row.id)
|
||||
fresh.push((res.data ?? res) as Plan)
|
||||
} catch {
|
||||
failed++
|
||||
}
|
||||
}
|
||||
const targets = readyTargets(fresh, ready, (p) => planHasHazardProducts(p.products))
|
||||
skipped = fresh.length - targets.length
|
||||
if (!targets.length) {
|
||||
ElMessage.warning(`无可操作计划;成功 0 条,失败 ${failed} 条,跳过 ${skipped} 条`)
|
||||
return
|
||||
}
|
||||
const message = `本次将${ready ? '标记证书齐备' : '取消齐备'} ${targets.length} 条计划,跳过 ${skipped} 条,读取失败 ${failed} 条。\n${ready ? `${HAZARD_CERT_READY_CONFIRM_HINT}确认后可安排运输,之后仍可补充附件。` : '取消后将无法安排运输。'}`
|
||||
try {
|
||||
await showCrmConfirmDialog({
|
||||
kind: ready ? 'default' : 'danger',
|
||||
title: ready ? '证书齐备确认' : '取消齐备',
|
||||
message,
|
||||
confirmButtonText: ready ? '确认齐备' : '确认取消'
|
||||
})
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
if (!canReady.value) return
|
||||
for (const row of targets) {
|
||||
try {
|
||||
await planApi.setHazardCertReady(row.id, ready)
|
||||
success++
|
||||
} catch {
|
||||
failed++
|
||||
}
|
||||
}
|
||||
ElMessage({
|
||||
type: failed ? 'warning' : 'success',
|
||||
message: `成功 ${success} 条,失败 ${failed} 条,跳过 ${skipped} 条`
|
||||
})
|
||||
await load()
|
||||
} finally {
|
||||
acting.value = false
|
||||
}
|
||||
}
|
||||
async function loadPermissions() {
|
||||
canUpload.value = false
|
||||
canReady.value = false
|
||||
canPrice.value = false
|
||||
permissionError.value = false
|
||||
try {
|
||||
const p = await fetchGetMenuCodes()
|
||||
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 {
|
||||
permissionError.value = true
|
||||
} finally {
|
||||
permissionsLoaded.value = true
|
||||
}
|
||||
}
|
||||
async function init() {
|
||||
await Promise.allSettled([loadPermissions(), load()])
|
||||
}
|
||||
const router = useRouter()
|
||||
onBeforeUnmount(() => {
|
||||
requestVersion++
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,142 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { test } from 'node:test'
|
||||
import { buildQuery, canEdit, readyTargets, 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.ok(!q.followStatus.includes('cancelled'))
|
||||
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: '' }
|
||||
])
|
||||
assert.equal(canSave(true, false, false, 1), true)
|
||||
assert.equal(canSave(true, true, false, 1), false)
|
||||
assert.equal(canSave(true, false, true, 1), false)
|
||||
assert.equal(canSave(false, false, false, 1), false)
|
||||
})
|
||||
test('date shortcuts use local calendar dates across year boundaries', () => {
|
||||
assert.deepEqual(dateShortcut('tomorrow', new Date(2026, 11, 31, 23)), [
|
||||
'2027-01-01',
|
||||
'2027-01-01'
|
||||
])
|
||||
assert.deepEqual(dateShortcut('week', new Date(2026, 9, 18)), ['2026-10-12', '2026-10-18'])
|
||||
assert.deepEqual(dateShortcut('all'), [])
|
||||
})
|
||||
|
||||
test('facet keeps shortcut dates until a draft date range replaces them', () => {
|
||||
const resolveDates = (model as any).facetPlanDateParams
|
||||
assert.equal(
|
||||
typeof resolveDates,
|
||||
'function',
|
||||
'facet context needs explicit shortcut preservation'
|
||||
)
|
||||
const context = { planDateFrom: '2026-10-12', planDateTo: '2026-10-18' }
|
||||
assert.deepEqual(resolveDates(context, undefined, undefined), context)
|
||||
assert.deepEqual(resolveDates(context, { from: '', to: '' }, undefined), context)
|
||||
assert.deepEqual(resolveDates(context, { from: '2026-10-20', to: '' }, undefined), {
|
||||
planDateFrom: '2026-10-20'
|
||||
})
|
||||
assert.deepEqual(resolveDates(context, { from: '', to: '2026-10-25' }, undefined), {
|
||||
planDateTo: '2026-10-25'
|
||||
})
|
||||
assert.deepEqual(resolveDates(context, undefined, { from: '2026-10-12', to: '2026-10-18' }), {})
|
||||
})
|
||||
|
||||
test('stop product metadata uses the matching plan product snapshot, including aliases', () => {
|
||||
const metadata = (model as any).stopProductMeta
|
||||
assert.equal(typeof metadata, 'function', 'stop cards must preserve brand and alias metadata')
|
||||
const products = [
|
||||
{ id: 'p1', productId: 'crm1', aliasName: '别名一', brandName: '品牌一', brandMode: 'fixed' },
|
||||
{ id: 'p2', productId: 'crm1', aliasName: '别名二', brandName: '品牌二', brandMode: 'any' }
|
||||
]
|
||||
assert.deepEqual(metadata({ planProductId: 'p2', productId: 'crm1' }, products), {
|
||||
aliasName: '别名二',
|
||||
brandName: '品牌二',
|
||||
brandMode: 'any'
|
||||
})
|
||||
assert.deepEqual(metadata({ productId: 'crm1' }, products), {
|
||||
aliasName: '别名一',
|
||||
brandName: '品牌一',
|
||||
brandMode: 'fixed'
|
||||
})
|
||||
assert.deepEqual(
|
||||
metadata({ productId: 'unknown', aliasName: '段次别名', brandName: '段次品牌' }, products),
|
||||
{ aliasName: '段次别名', brandName: '段次品牌', brandMode: undefined }
|
||||
)
|
||||
})
|
||||
|
||||
test('contract reads enrich ids and saved product aliases without changing source records', async () => {
|
||||
const enrich = (model as any).enrichContractReadFields
|
||||
assert.equal(typeof enrich, 'function', 'contract read view needs related master data')
|
||||
const source = {
|
||||
opportunityId: 'o1',
|
||||
quoteId: 'q1',
|
||||
products: [{ productId: 'p1', productName: '工业别名' }]
|
||||
}
|
||||
const { contract, warnings } = await enrich(source, {
|
||||
product: async () => ({ productName: '标准产品', aliases: [{ aliasName: '工业别名' }] }),
|
||||
opportunity: async () => ({ opportunityName: '采购商机' }),
|
||||
quote: async () => ({ quoteNo: 'BJ2026' })
|
||||
})
|
||||
assert.equal(contract.opportunityName, '采购商机')
|
||||
assert.equal(contract.quoteNo, 'BJ2026')
|
||||
assert.equal(contract.products[0].standardProductName, '标准产品')
|
||||
assert.equal(contract.products[0].aliasName, '工业别名')
|
||||
assert.deepEqual(warnings, [])
|
||||
assert.equal((source.products[0] as any).standardProductName, undefined)
|
||||
const failed = await enrich(source, {
|
||||
product: async () => {
|
||||
throw new Error('offline')
|
||||
},
|
||||
opportunity: async () => {
|
||||
throw new Error('offline')
|
||||
},
|
||||
quote: async () => {
|
||||
throw new Error('offline')
|
||||
}
|
||||
})
|
||||
assert.equal(failed.contract.products[0].productName, '工业别名')
|
||||
assert.equal(failed.contract.products[0].standardProductName, '工业别名')
|
||||
assert.equal(failed.warnings.length, 3)
|
||||
})
|
||||
@@ -0,0 +1,171 @@
|
||||
import {
|
||||
PL_PLAN_DEFAULT_FOLLOW_STATUSES,
|
||||
plPlanCertTabToFilters,
|
||||
type PlPlanCertTab
|
||||
} from '../../../../utils/pl-display'
|
||||
import { applyAliasDisplayMeta } from '../../../../utils/crm-product-brand'
|
||||
|
||||
export function buildQuery(
|
||||
tab: string,
|
||||
columns: Record<string, any>,
|
||||
keyword: string,
|
||||
dates: string[] = []
|
||||
) {
|
||||
const q: Record<string, any> = { ...columns, hasHazardProduct: 1 }
|
||||
const scope = plPlanCertTabToFilters(tab as PlPlanCertTab)
|
||||
if (keyword.trim()) q.q = keyword.trim()
|
||||
q.followStatus = q.followStatusIn || q.followStatus || PL_PLAN_DEFAULT_FOLLOW_STATUSES.join(',')
|
||||
delete q.followStatusIn
|
||||
if (scope.certUploadStatus) q.certUploadStatus = scope.certUploadStatus
|
||||
if (scope.hazardCertReady !== undefined && scope.hazardCertReady !== '') {
|
||||
q.hazardCertReady = Number(scope.hazardCertReady)
|
||||
delete q.hazardCertReadyIn
|
||||
} else if (q.hazardCertReadyIn && String(q.hazardCertReadyIn).split(',').length === 1) {
|
||||
q.hazardCertReady = Number(q.hazardCertReadyIn)
|
||||
delete q.hazardCertReadyIn
|
||||
}
|
||||
if (scope.planType) {
|
||||
q.planType = scope.planType
|
||||
delete q.planTypeIn
|
||||
}
|
||||
if (!q.planDateFrom && !q.planDateTo) {
|
||||
if (dates[0]) q.planDateFrom = dates[0]
|
||||
if (dates[1]) q.planDateTo = dates[1]
|
||||
}
|
||||
return q
|
||||
}
|
||||
|
||||
type Editable = { archiveStatus?: string; followStatus?: string; hazardCertReady?: number }
|
||||
export function canEdit(plan: Editable | null | undefined) {
|
||||
return !!plan && plan.archiveStatus !== 'archived' && plan.followStatus !== 'cancelled'
|
||||
}
|
||||
export function readyTargets<T extends Editable>(
|
||||
plans: T[],
|
||||
ready: boolean,
|
||||
hasHazard: (p: T) => boolean
|
||||
): T[] {
|
||||
return plans.filter(
|
||||
(p) => canEdit(p) && hasHazard(p) && (Number(p.hazardCertReady) === 1) !== ready
|
||||
)
|
||||
}
|
||||
export function certPayload(
|
||||
products: Array<{
|
||||
id: string
|
||||
purchaseCertUrl?: string
|
||||
transportCertUrl?: string
|
||||
legalUseCertUrl?: string
|
||||
[key: string]: any
|
||||
}>
|
||||
) {
|
||||
return products.map((p) => ({
|
||||
id: p.id,
|
||||
purchaseCertUrl: p.purchaseCertUrl?.trim() || '',
|
||||
transportCertUrl: p.transportCertUrl?.trim() || '',
|
||||
legalUseCertUrl: p.legalUseCertUrl?.trim() || ''
|
||||
}))
|
||||
}
|
||||
export function canSave(allowed: boolean, uploading: boolean, submitting: boolean, count: number) {
|
||||
return allowed && !uploading && !submitting && count > 0
|
||||
}
|
||||
export function dateShortcut(kind: string, now = new Date()): string[] {
|
||||
if (kind === 'all') return []
|
||||
const a = new Date(now.getFullYear(), now.getMonth(), now.getDate())
|
||||
if (kind === 'tomorrow') a.setDate(a.getDate() + 1)
|
||||
if (kind === 'yesterday') a.setDate(a.getDate() - 1)
|
||||
if (kind === 'week') a.setDate(a.getDate() - ((a.getDay() + 6) % 7))
|
||||
const b = new Date(a)
|
||||
if (kind === 'week') b.setDate(b.getDate() + 6)
|
||||
const fmt = (d: Date) =>
|
||||
`${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
|
||||
return [fmt(a), fmt(b)]
|
||||
}
|
||||
|
||||
/** A draft date bound replaces the whole shortcut range; clearing a column range removes it. */
|
||||
export function facetPlanDateParams(
|
||||
context: Record<string, any>,
|
||||
draft?: { from?: string; to?: string },
|
||||
applied?: { from?: string; to?: string }
|
||||
) {
|
||||
const result: Record<string, string> = {}
|
||||
const hasDraft = Boolean(draft?.from || draft?.to)
|
||||
const hasApplied = Boolean(applied?.from || applied?.to)
|
||||
if (hasDraft) {
|
||||
if (draft?.from) result.planDateFrom = draft.from
|
||||
if (draft?.to) result.planDateTo = draft.to
|
||||
} else if (!hasApplied) {
|
||||
if (context.planDateFrom) result.planDateFrom = context.planDateFrom
|
||||
if (context.planDateTo) result.planDateTo = context.planDateTo
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
type ProductMetadata = {
|
||||
id?: string
|
||||
planProductId?: string
|
||||
productId?: string
|
||||
aliasName?: string
|
||||
brandName?: string
|
||||
brandMode?: string
|
||||
}
|
||||
export function stopProductMeta(stop: ProductMetadata, products: ProductMetadata[]) {
|
||||
const linked =
|
||||
products.find((p) => stop.planProductId && p.id === stop.planProductId) ||
|
||||
products.find((p) => stop.productId && p.productId === stop.productId)
|
||||
return {
|
||||
aliasName: linked?.aliasName ?? stop.aliasName,
|
||||
brandName: linked?.brandName ?? stop.brandName,
|
||||
brandMode: linked?.brandMode ?? stop.brandMode
|
||||
}
|
||||
}
|
||||
|
||||
/** Read-only enrichment; failed lookups keep the saved snapshot and surface a partial-load hint. */
|
||||
export async function enrichContractReadFields(
|
||||
source: Record<string, any>,
|
||||
lookup: {
|
||||
product: (id: string) => Promise<Record<string, any>>
|
||||
opportunity: (id: string) => Promise<Record<string, any>>
|
||||
quote: (id: string) => Promise<Record<string, any>>
|
||||
}
|
||||
) {
|
||||
const contract: Record<string, any> = {
|
||||
...source,
|
||||
products: (source.products || []).map((p: any) => ({ ...p }))
|
||||
}
|
||||
const warnings: string[] = []
|
||||
const tasks = contract.products.map(async (p: any) => {
|
||||
if (!p.productId) {
|
||||
p.standardProductName = p.productName
|
||||
return
|
||||
}
|
||||
try {
|
||||
applyAliasDisplayMeta(p, await lookup.product(String(p.productId)))
|
||||
} catch {
|
||||
p.standardProductName = p.standardProductName || p.productName
|
||||
warnings.push('产品名称/别名')
|
||||
}
|
||||
})
|
||||
if (source.opportunityId)
|
||||
tasks.push(
|
||||
(async () => {
|
||||
try {
|
||||
contract.opportunityName =
|
||||
(await lookup.opportunity(String(source.opportunityId))).opportunityName ||
|
||||
source.opportunityName
|
||||
} catch {
|
||||
warnings.push('关联商机')
|
||||
}
|
||||
})()
|
||||
)
|
||||
if (source.quoteId)
|
||||
tasks.push(
|
||||
(async () => {
|
||||
try {
|
||||
contract.quoteNo = (await lookup.quote(String(source.quoteId))).quoteNo || source.quoteNo
|
||||
} catch {
|
||||
warnings.push('关联报价单')
|
||||
}
|
||||
})()
|
||||
)
|
||||
await Promise.all(tasks)
|
||||
return { contract, warnings: [...new Set(warnings)] }
|
||||
}
|
||||
Reference in new issue
Block a user