2025-08-26 23:13:34 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<a-modal
|
|
|
|
|
|
:visible="visible"
|
2025-10-12 15:08:29 +08:00
|
|
|
|
title="新增创建合同模板"
|
2025-08-26 23:13:34 +08:00
|
|
|
|
unmount-on-close
|
|
|
|
|
|
@ok="handleSubmit"
|
|
|
|
|
|
@cancel="handleCancel"
|
|
|
|
|
|
>
|
|
|
|
|
|
<a-form
|
|
|
|
|
|
ref="formRef"
|
|
|
|
|
|
:model="form"
|
|
|
|
|
|
:rules="rules"
|
|
|
|
|
|
auto-label-width
|
|
|
|
|
|
layout="vertical"
|
|
|
|
|
|
>
|
|
|
|
|
|
<!-- 模版名称 -->
|
|
|
|
|
|
<a-form-item label="模版名称" field="name" required>
|
|
|
|
|
|
<a-input v-model="form.name" placeholder="请输入模板名称" />
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
<!-- 适用范围(部门) -->
|
|
|
|
|
|
<a-form-item label="适用范围" field="user_id">
|
|
|
|
|
|
<a-tree-select
|
|
|
|
|
|
v-model="form.departmentId"
|
|
|
|
|
|
:data="props.departmentListData"
|
|
|
|
|
|
:field-names="{ key: 'id', title: 'name', children: 'children' }"
|
|
|
|
|
|
placeholder="请选择适用范围"
|
|
|
|
|
|
allow-clear
|
|
|
|
|
|
/>
|
|
|
|
|
|
</a-form-item>
|
|
|
|
|
|
</a-form>
|
|
|
|
|
|
</a-modal>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import { ref, reactive, watch } from 'vue';
|
|
|
|
|
|
import type { FormInstance } from '@arco-design/web-vue';
|
2026-02-01 12:04:08 +08:00
|
|
|
|
import {
|
|
|
|
|
|
createTemplateSetting,
|
|
|
|
|
|
updateTemplateSetting,
|
|
|
|
|
|
} from '@/api/contracts';
|
2025-08-26 23:13:34 +08:00
|
|
|
|
import { DepartmentItem, CreateTemplateSettingParam } from '@/types/setting';
|
|
|
|
|
|
import { Message } from '@arco-design/web-vue';
|
2025-10-12 15:08:29 +08:00
|
|
|
|
import { useRouter } from 'vue-router';
|
2025-08-26 23:13:34 +08:00
|
|
|
|
interface TreeNode {
|
|
|
|
|
|
id: string | number;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
children?: TreeNode[];
|
|
|
|
|
|
}
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
|
visible: boolean;
|
|
|
|
|
|
isEdit: boolean;
|
2025-10-12 15:08:29 +08:00
|
|
|
|
record?: any;
|
2025-08-26 23:13:34 +08:00
|
|
|
|
departmentListData: TreeNode[]; // 修复类型
|
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
|
(e: 'update:visible', val: boolean): void;
|
|
|
|
|
|
(e: 'submitted'): void;
|
|
|
|
|
|
}>();
|
2025-10-12 15:08:29 +08:00
|
|
|
|
const router = useRouter();
|
2025-08-26 23:13:34 +08:00
|
|
|
|
// 表单数据
|
|
|
|
|
|
const formRef = ref<FormInstance>();
|
2025-10-12 15:08:29 +08:00
|
|
|
|
const form = reactive<any>({
|
2025-08-26 23:13:34 +08:00
|
|
|
|
name: '',
|
|
|
|
|
|
departmentId: null,
|
2025-10-12 15:08:29 +08:00
|
|
|
|
id: undefined,
|
2025-08-26 23:13:34 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 校验规则
|
|
|
|
|
|
const rules = {
|
|
|
|
|
|
name: [{ required: true, message: '请输入模板名称' }],
|
|
|
|
|
|
departmentId: [{ required: true, message: '请选择适用范围' }],
|
|
|
|
|
|
};
|
2025-10-12 15:08:29 +08:00
|
|
|
|
// 表单事件
|
|
|
|
|
|
const handleCancel = () => {
|
|
|
|
|
|
emit('update:visible', false);
|
|
|
|
|
|
};
|
2025-08-26 23:13:34 +08:00
|
|
|
|
watch(
|
|
|
|
|
|
() => props.visible,
|
|
|
|
|
|
(val) => {
|
|
|
|
|
|
if (val) {
|
|
|
|
|
|
if (props.record) {
|
2025-10-12 15:08:29 +08:00
|
|
|
|
Object.assign(form, {
|
|
|
|
|
|
...props.record,
|
|
|
|
|
|
});
|
2025-08-26 23:13:34 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
Object.assign(form, {
|
|
|
|
|
|
id: undefined,
|
|
|
|
|
|
name: '',
|
|
|
|
|
|
departmentId: null,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
{ immediate: true }
|
|
|
|
|
|
);
|
|
|
|
|
|
const handleSubmit = async () => {
|
|
|
|
|
|
await formRef.value?.validate();
|
2025-10-12 15:08:29 +08:00
|
|
|
|
if (!form.departmentId || !form.name) return;
|
|
|
|
|
|
if (props.isEdit) {
|
|
|
|
|
|
// saveType 保存类别:1 名称与适用范围数据,2 基础信息数据,3 条款数据)
|
|
|
|
|
|
form.saveType = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
const { code, message, data } = props.isEdit
|
2025-08-26 23:13:34 +08:00
|
|
|
|
? await updateTemplateSetting(form)
|
|
|
|
|
|
: await createTemplateSetting(form);
|
|
|
|
|
|
if (code === 200) {
|
|
|
|
|
|
Message.success(message);
|
2025-10-12 15:08:29 +08:00
|
|
|
|
if (props.isEdit) {
|
|
|
|
|
|
emit('submitted');
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const info = data as any;
|
|
|
|
|
|
const id = info.contractTemplateSettingId;
|
|
|
|
|
|
router.push({
|
|
|
|
|
|
name: 'system-setting-contract-template-edit',
|
|
|
|
|
|
query: { id },
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-08-26 23:13:34 +08:00
|
|
|
|
handleCancel();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
</script>
|