feat: 员工端二期 7 张单据表单页与通用详情渲染(#46)
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
<template>
|
||||
<view class="form-page">
|
||||
<uni-card :border="false" :padding="'16px'" title="基本信息">
|
||||
<uni-card :border="false" :padding="'16px'" :title="pageTitle + ' — 基本信息'">
|
||||
<view class="auto-row">
|
||||
<text class="label">单据类型</text>
|
||||
<text class="value">{{ pageTitle }}</text>
|
||||
</view>
|
||||
<view class="auto-row">
|
||||
<text class="label">报送人</text>
|
||||
<text class="value">{{ reporterName || '—' }}</text>
|
||||
@@ -110,6 +114,7 @@ import { useUserStore } from '@/store/modules/user';
|
||||
import {
|
||||
getInstance,
|
||||
saveCoordination,
|
||||
saveDocument,
|
||||
submitInstance
|
||||
} from '@/api/approval/instance';
|
||||
import {
|
||||
@@ -132,6 +137,8 @@ const categories = [
|
||||
|
||||
const mode = ref<'create' | 'edit'>('create');
|
||||
const instanceId = ref(0);
|
||||
/** 流程编码:内部 coordination_internal / 外部 coordination_external(ADR 0007) */
|
||||
const flowCode = ref('coordination_internal');
|
||||
const organizations = ref<ApprovalOrganization[]>([]);
|
||||
const orgIndex = ref(0);
|
||||
const form = reactive({
|
||||
@@ -150,6 +157,9 @@ const reporterName = computed(
|
||||
() => userStore.info?.realName || userStore.info?.nickname || ''
|
||||
);
|
||||
const reportOrgName = computed(() => userStore.info?.organizationName || '');
|
||||
const pageTitle = computed(() =>
|
||||
flowCode.value === 'coordination_external' ? '外部协调单' : '内部协调单'
|
||||
);
|
||||
const organizationLabels = computed(() =>
|
||||
organizations.value.map(item => item.organizationName)
|
||||
);
|
||||
@@ -160,6 +170,11 @@ const selectedOrgName = computed(
|
||||
onLoad(options => {
|
||||
mode.value = options?.mode === 'edit' ? 'edit' : 'create';
|
||||
instanceId.value = Number(options?.id) || 0;
|
||||
flowCode.value =
|
||||
options?.flowCode === 'coordination_external'
|
||||
? 'coordination_external'
|
||||
: 'coordination_internal';
|
||||
uni.setNavigationBarTitle({ title: pageTitle.value });
|
||||
loadOrganizations();
|
||||
if (instanceId.value) {
|
||||
loadDetail();
|
||||
@@ -203,10 +218,19 @@ async function loadDetail() {
|
||||
showError('当前状态不可修改', null);
|
||||
return;
|
||||
}
|
||||
// 编辑草稿时以实例上的流程为准,避免参数缺失导致存成另一个流程
|
||||
if (
|
||||
detail.flowCode === 'coordination_external' ||
|
||||
detail.flowCode === 'coordination_internal'
|
||||
) {
|
||||
flowCode.value = detail.flowCode;
|
||||
uni.setNavigationBarTitle({ title: pageTitle.value });
|
||||
}
|
||||
form.acceptOrgId = detail.acceptOrgId || 0;
|
||||
form.title = detail.title || '';
|
||||
form.content = detail.content || '';
|
||||
form.remark = detail.remark || '';
|
||||
const fields = detail.document?.fields || [];
|
||||
form.title = detail.title || fieldValue(fields, 'title');
|
||||
form.content = detail.content || fieldValue(fields, 'content');
|
||||
form.remark = detail.remark || fieldValue(fields, 'remark');
|
||||
attachments.value = detail.attachments || [];
|
||||
syncOrgIndex();
|
||||
} catch (error: any) {
|
||||
@@ -214,6 +238,11 @@ async function loadDetail() {
|
||||
}
|
||||
}
|
||||
|
||||
function fieldValue(fields: Array<{ key: string; value?: string | null }>, key: string) {
|
||||
const field = fields.find(item => item.key === key);
|
||||
return field?.value ? String(field.value) : '';
|
||||
}
|
||||
|
||||
function validate(): string | null {
|
||||
if (!form.acceptOrgId) {
|
||||
return '请选择受理部门';
|
||||
@@ -244,13 +273,18 @@ async function ensureDraft(): Promise<number> {
|
||||
}
|
||||
saving.value = true;
|
||||
try {
|
||||
const id = await saveCoordination({
|
||||
// 内部流程仍走一期端点,外部流程走通用草稿端点(同一张表、同一份表单)
|
||||
const payload = {
|
||||
id: instanceId.value || undefined,
|
||||
acceptOrgId: form.acceptOrgId,
|
||||
title: form.title.trim(),
|
||||
content: form.content.trim(),
|
||||
remark: form.remark.trim() || undefined
|
||||
});
|
||||
};
|
||||
const id =
|
||||
flowCode.value === 'coordination_external'
|
||||
? await saveDocument(flowCode.value, payload)
|
||||
: await saveCoordination(payload);
|
||||
instanceId.value = id;
|
||||
mode.value = 'edit';
|
||||
return id;
|
||||
|
||||
Reference in New Issue
Block a user