feat(invoice-check): 立账凭证检核增加收件人配置并迁移到chat页面

This commit is contained in:
sophie committed 2026-09-17 13:17:37 +08:00
1 parent 18e957545c
commit 7b80b4c395
72 files changed
+2705 -263

No files matched your search

@@ -0,0 +1,320 @@
<script setup lang="ts">
/**
* shared/components/UserPickerDialog.vue
* 用途:跨业务公共选人弹窗:左侧部门、右侧搜索/勾选、底部已选与确定。
* 依赖:vue-i18n、dialog-overlay / dialog-panel、userPicker.types / userPicker.utils。
* 逻辑:父组件传入候选人并 v-model 控制显隐;确定才回写 selectedIds,取消不改已保存选择。
* 不自行拉用户列表,便于凭证检核、排程告警等各自提供数据源。
*/
import { computed, onBeforeUnmount, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import {
USER_PICKER_ALL_DEPT,
USER_PICKER_NONE_DEPT,
type UserPickerPerson,
} from '@/shared/types/userPicker.types';
import {
filterUserPickerPeople,
listUserPickerDepartments,
userPickerLabel,
} from '@/shared/utils/userPicker.utils';
interface Props {
modelValue: boolean;
users: UserPickerPerson[];
selectedIds: number[];
title?: string;
subtitle?: string;
/** 为 true 强制展示企微标记;为 false 隐藏;缺省时有 wecom_bound 字段才展示 */
showWecomStatus?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
users: () => [],
selectedIds: () => [],
title: '',
subtitle: '',
});
const emit = defineEmits<{
(e: 'update:modelValue', value: boolean): void;
(e: 'confirm', ids: number[]): void;
(e: 'cancel'): void;
}>();
const { t } = useI18n();
const query = ref('');
const departmentKey = ref(USER_PICKER_ALL_DEPT);
const draftIds = ref<number[]>([]);
const userMap = computed(() => {
const next = new Map<number, UserPickerPerson>();
for (const user of props.users) next.set(user.id, user);
return next;
});
const departments = computed(() => listUserPickerDepartments(props.users));
const visibleUsers = computed(() =>
filterUserPickerPeople(props.users, {
departmentKey: departmentKey.value,
query: query.value,
}),
);
const showWecom = computed(() => {
if (props.showWecomStatus === true) return true;
if (props.showWecomStatus === false) return false;
return props.users.some((user) => typeof user.wecom_bound === 'boolean');
});
const resolvedTitle = computed(() => props.title || t('common.userPicker.title'));
const resolvedSubtitle = computed(() => {
if (props.subtitle) return props.subtitle;
return showWecom.value ? t('common.userPicker.subtitleWithWecom') : t('common.userPicker.subtitle');
});
const visibleAllSelected = computed(() => {
const ids = visibleUsers.value.map((user) => user.id);
return ids.length > 0 && ids.every((id) => draftIds.value.includes(id));
});
/**
* 「全部」或有搜索时用「全选当前列表」;点了具体部门且未搜索时用「全选本部门」。
*/
const selectVisibleLabel = computed(() => {
const scopedToDept =
departmentKey.value !== USER_PICKER_ALL_DEPT && !String(query.value || '').trim();
return t(scopedToDept ? 'common.userPicker.selectDepartment' : 'common.userPicker.selectVisible');
});
/**
* 把传入 id 收成去重正整数,打开弹窗时作为草稿。
*/
function normalizeIds(ids: number[]): number[] {
const seen = new Set<number>();
const next: number[] = [];
for (const raw of ids || []) {
const id = Number(raw);
if (!Number.isInteger(id) || id <= 0 || seen.has(id)) continue;
seen.add(id);
next.push(id);
}
return next;
}
/**
* 部门筛选项展示名:全部 / 未分配 / 具名部门。
*/
function departmentLabel(key: string): string {
if (key === USER_PICKER_ALL_DEPT) return t('common.userPicker.allDepartments');
if (key === USER_PICKER_NONE_DEPT) return t('common.userPicker.unknownDepartment');
return key;
}
/**
* 人员第二行:工号 · 部门。
*/
function personMeta(person: UserPickerPerson): string {
const emp = String(person.employee_id || '').trim();
const dept = String(person.department || '').trim() || t('common.userPicker.unknownDepartment');
return [emp, dept].filter(Boolean).join(' · ');
}
/**
* 勾选或取消单个候选人,保留点击顺序。
*/
function toggleUser(userId: number): void {
if (draftIds.value.includes(userId)) {
draftIds.value = draftIds.value.filter((id) => id !== userId);
return;
}
draftIds.value = [...draftIds.value, userId];
}
/**
* 全选或取消当前可见列表(受部门与搜索约束)。
*/
function toggleVisibleSelection(): void {
const ids = visibleUsers.value.map((user) => user.id);
if (!ids.length) return;
if (visibleAllSelected.value) {
const drop = new Set(ids);
draftIds.value = draftIds.value.filter((id) => !drop.has(id));
return;
}
const seen = new Set(draftIds.value);
draftIds.value = [...draftIds.value, ...ids.filter((id) => !seen.has(id))];
}
function closeDialog(): void {
emit('update:modelValue', false);
}
function handleCancel(): void {
emit('cancel');
closeDialog();
}
/**
* 把草稿 id 回写给父组件后再关闭。
*/
function handleConfirm(): void {
emit('confirm', [...draftIds.value]);
closeDialog();
}
function handleEscKey(event: KeyboardEvent): void {
if (event.key === 'Escape' && props.modelValue) handleCancel();
}
watch(
() => props.modelValue,
(visible) => {
if (visible) {
draftIds.value = normalizeIds(props.selectedIds);
departmentKey.value = USER_PICKER_ALL_DEPT;
query.value = '';
document.addEventListener('keydown', handleEscKey);
return;
}
document.removeEventListener('keydown', handleEscKey);
},
{ immediate: true },
);
onBeforeUnmount(() => {
document.removeEventListener('keydown', handleEscKey);
});
</script>
<template>
<Teleport to="body">
<div
v-if="modelValue"
class="dialog-overlay z-[120] items-center"
@click.self="handleCancel"
>
<div
class="dialog-panel flex max-h-[min(620px,calc(100vh-40px))] w-full max-w-[760px] overflow-hidden"
role="dialog"
aria-modal="true"
>
<div class="flex items-start justify-between gap-3 border-b border-default px-5 py-4">
<div class="min-w-0">
<h3 class="text-base font-semibold text-primary">{{ resolvedTitle }}</h3>
<p class="mt-1 text-xs text-muted">{{ resolvedSubtitle }}</p>
</div>
<button
type="button"
class="shrink-0 rounded-lg px-1.5 text-xl leading-none text-muted hover:bg-surface-soft hover:text-primary"
:aria-label="t('common.close')"
@click="handleCancel"
>
×
</button>
</div>
<div class="flex min-h-0 flex-1 flex-col md:flex-row">
<aside class="max-h-40 shrink-0 overflow-auto border-b border-default bg-surface-soft md:max-h-none md:w-[200px] md:border-b-0 md:border-r">
<button
v-for="dept in departments"
:key="dept.key"
type="button"
class="flex w-full items-center justify-between border-l-4 px-3 py-2.5 text-left text-sm text-secondary"
:class="departmentKey === dept.key
? 'border-brand-600 bg-surface font-semibold text-brand-600'
: 'border-transparent hover:bg-surface'"
@click="departmentKey = dept.key"
>
<span>{{ departmentLabel(dept.key) }}</span>
<span class="text-xs font-medium text-muted">{{ dept.count }}</span>
</button>
</aside>
<section class="flex min-h-0 min-w-0 flex-1 flex-col">
<div class="flex items-center gap-2 border-b border-default px-3 py-2.5">
<input
v-model="query"
type="search"
class="input-field min-w-0 flex-1"
:placeholder="t('common.userPicker.searchPlaceholder')"
/>
<button
type="button"
class="shrink-0 whitespace-nowrap text-xs font-semibold text-brand-600 hover:text-brand-700 disabled:opacity-40"
:disabled="visibleUsers.length === 0"
@click="toggleVisibleSelection"
>
{{ selectVisibleLabel }}
</button>
</div>
<div class="min-h-[220px] flex-1 overflow-auto">
<button
v-for="user in visibleUsers"
:key="user.id"
type="button"
class="flex w-full items-center gap-2.5 border-b border-default px-3 py-2.5 text-left hover:bg-surface-soft"
:class="draftIds.includes(user.id) ? 'bg-blue-50/70' : 'bg-surface'"
@click="toggleUser(user.id)"
>
<input
type="checkbox"
class="pointer-events-none h-3.5 w-3.5 rounded text-brand-600"
:checked="draftIds.includes(user.id)"
tabindex="-1"
readonly
/>
<span class="min-w-0 flex-1">
<span class="block text-sm font-medium text-primary">{{ userPickerLabel(user) }}</span>
<span class="block text-xs text-muted">{{ personMeta(user) }}</span>
</span>
<span
v-if="showWecom && user.wecom_bound"
class="shrink-0 text-[11px] font-semibold text-emerald-700"
>
{{ t('common.userPicker.wecomBound') }}
</span>
<span
v-else-if="showWecom"
class="shrink-0 text-[11px] font-semibold text-amber-700"
>
{{ t('common.userPicker.wecomUnbound') }}
</span>
</button>
<div v-if="visibleUsers.length === 0" class="px-3 py-10 text-center text-sm text-muted">
{{ t('common.userPicker.empty') }}
</div>
</div>
</section>
</div>
<div class="flex items-center gap-3 border-t border-default bg-surface-soft px-5 py-3">
<div class="flex min-w-0 flex-1 flex-wrap gap-1.5">
<span
v-for="userId in draftIds"
:key="userId"
class="inline-flex items-center gap-1 rounded-lg bg-blue-50 px-2 py-0.5 text-xs font-medium text-blue-700"
>
{{ userPickerLabel(userMap.get(userId), userId) }}
<button
type="button"
class="text-blue-400 hover:text-blue-600"
@click="toggleUser(userId)"
>✕</button>
</span>
<span v-if="draftIds.length === 0" class="text-sm text-muted">
{{ t('common.userPicker.noneSelected') }}
</span>
</div>
<button type="button" class="btn-secondary btn-sm shrink-0" @click="handleCancel">
{{ t('common.cancel') }}
</button>
<button type="button" class="btn-primary btn-sm shrink-0" @click="handleConfirm">
{{ t('common.userPicker.confirmCount', { count: draftIds.length }) }}
</button>
</div>
</div>
</div>
</Teleport>
</template>
@@ -0,0 +1,17 @@
/**
* shared/types/userPicker.types.ts
* 用途:公共选人弹窗的人员数据结构,供各业务传入自己的候选人列表。
* 依赖:无。
* 逻辑:UserPickerDialog / userPicker.utils 共用;wecom_bound 可选,缺省时不展示企微标记。
*/
export interface UserPickerPerson {
id: number;
username: string;
real_name?: string | null;
employee_id?: string | null;
department?: string | null;
wecom_bound?: boolean;
}
export const USER_PICKER_ALL_DEPT = '__all__';
export const USER_PICKER_NONE_DEPT = '__none__';
@@ -11,6 +11,7 @@ export const AGENT_CODE_SHIPPING_NOTICE = 'shipping_notice';
export const AGENT_CODE_FILE_CHECK = 'file_check';
export const AGENT_CODE_PROCUREMENT_CONTRACT_REVIEW = 'procurement_contract_review';
export const AGENT_CODE_CONTRACT_PAYMENT = 'contract_payment';
export const AGENT_CODE_VOUCHER_CHECK = 'voucher_check';
export const AGENT_CODE_IN_TRANSIT_TRANSFER = 'in_transit_transfer';
export interface AgentRegistryCapabilities {
@@ -243,6 +244,11 @@ export function isContractPaymentAgent(agent: AgentLike): boolean {
return resolveAgentCode(agent) === AGENT_CODE_CONTRACT_PAYMENT;
}
/** 是否为立账凭证检核 Agent(agent_code=voucher_check)。 */
export function isVoucherCheckAgent(agent: AgentLike): boolean {
return resolveAgentCode(agent) === AGENT_CODE_VOUCHER_CHECK;
}
/** 是否启用本地请假表单(后端 leave_feature_enabled)。 */
export function canUseLeaveFeature(agent: AgentLike): boolean {
return Boolean(agent?.leave_feature_enabled);
@@ -0,0 +1,47 @@
/**
* shared/utils/userPicker.utils.test.ts
* 用途:锁定公共选人弹窗的部门分组与筛选规则。
*/
import { describe, expect, it } from 'vitest';
import {
USER_PICKER_ALL_DEPT,
USER_PICKER_NONE_DEPT,
type UserPickerPerson,
} from '@/shared/types/userPicker.types';
import {
filterUserPickerPeople,
listUserPickerDepartments,
userPickerLabel,
} from './userPicker.utils';
const people: UserPickerPerson[] = [
{ id: 1, username: 'a', real_name: '钟淑惠', employee_id: '0100004', department: '财务部' },
{ id: 2, username: 'b', real_name: '成秋兰', employee_id: '0203036', department: '关务部' },
{ id: 3, username: 'c', real_name: '刘江', employee_id: '07090745', department: ' ' },
];
describe('userPickerLabel', () => {
it('prefers real name and appends employee id', () => {
expect(userPickerLabel(people[0])).toBe('钟淑惠(0100004)');
expect(userPickerLabel(undefined, 9)).toBe('9');
});
});
describe('listUserPickerDepartments', () => {
it('puts all first, named departments next, and unnamed last', () => {
expect(listUserPickerDepartments(people)).toEqual([
{ key: USER_PICKER_ALL_DEPT, count: 3 },
{ key: '财务部', count: 1 },
{ key: '关务部', count: 1 },
{ key: USER_PICKER_NONE_DEPT, count: 1 },
]);
});
});
describe('filterUserPickerPeople', () => {
it('filters by department and keyword', () => {
expect(filterUserPickerPeople(people, { departmentKey: '财务部' }).map((row) => row.id)).toEqual([1]);
expect(filterUserPickerPeople(people, { query: '0203' }).map((row) => row.id)).toEqual([2]);
expect(filterUserPickerPeople(people, { departmentKey: USER_PICKER_NONE_DEPT }).map((row) => row.id)).toEqual([3]);
});
});
@@ -0,0 +1,80 @@
/**
* shared/utils/userPicker.utils.ts
* 用途:公共选人弹窗的展示名、部门分组与筛选。
* 依赖:userPicker.types。
* 逻辑:UserPickerDialog 调用;部门为空归入 USER_PICKER_NONE_DEPT。
*/
import {
USER_PICKER_ALL_DEPT,
USER_PICKER_NONE_DEPT,
type UserPickerPerson,
} from '@/shared/types/userPicker.types';
export interface UserPickerDepartment {
key: string;
count: number;
}
/**
* 人员展示名:实名优先,附工号。
*/
export function userPickerLabel(person?: UserPickerPerson | null, fallbackId?: number): string {
if (!person) return String(fallbackId || '');
const name = String(person.real_name || person.username || '').trim();
const emp = String(person.employee_id || '').trim();
return emp ? `${name}(${emp})` : name || String(person.id);
}
/**
* 把用户部门归一成筛选键:空部门用 USER_PICKER_NONE_DEPT。
*/
export function userPickerDepartmentKey(person: UserPickerPerson): string {
return String(person.department || '').trim() || USER_PICKER_NONE_DEPT;
}
/**
* 统计部门列表:全部在前,具名部门按名称排序,未分配部门垫底。
*/
export function listUserPickerDepartments(users: UserPickerPerson[]): UserPickerDepartment[] {
const counts = new Map<string, number>();
for (const user of users) {
const key = userPickerDepartmentKey(user);
counts.set(key, (counts.get(key) || 0) + 1);
}
const named = [...counts.keys()]
.filter((key) => key !== USER_PICKER_NONE_DEPT)
.sort((a, b) => a.localeCompare(b, 'zh-CN'));
const items: UserPickerDepartment[] = [
{ key: USER_PICKER_ALL_DEPT, count: users.length },
...named.map((key) => ({ key, count: counts.get(key) || 0 })),
];
const unnamed = counts.get(USER_PICKER_NONE_DEPT) || 0;
if (unnamed) items.push({ key: USER_PICKER_NONE_DEPT, count: unnamed });
return items;
}
/**
* 按部门与关键字筛选候选人。
* @param options.departmentKey - USER_PICKER_ALL_DEPT 表示不限部门
* @param options.query - 匹配姓名、用户名、工号、部门
*/
export function filterUserPickerPeople(
users: UserPickerPerson[],
options?: { departmentKey?: string; query?: string },
): UserPickerPerson[] {
const departmentKey = options?.departmentKey || USER_PICKER_ALL_DEPT;
const keyword = String(options?.query || '').trim().toLowerCase();
return users.filter((user) => {
if (departmentKey !== USER_PICKER_ALL_DEPT && userPickerDepartmentKey(user) !== departmentKey) {
return false;
}
if (!keyword) return true;
const hay = [
user.real_name,
user.username,
user.employee_id,
user.department,
].join(' ').toLowerCase();
return hay.includes(keyword);
});
}