diff --git a/src/components/ContractSignField.vue b/src/components/ContractSignField.vue
index 1977b80..f719d9f 100644
--- a/src/components/ContractSignField.vue
+++ b/src/components/ContractSignField.vue
@@ -17,7 +17,6 @@
合同签订
重新签订
- 清除
-
+
CZHT
@@ -66,7 +65,7 @@
-
+
-
+
-
+
-
+
@@ -329,6 +328,7 @@ import {
getContractByFlowId,
createContract,
getBudgetYearOptions,
+ save,
} from "@/api/flow";
import { userListNoAuth, departmentListNoAuth } from "@/api/common";
@@ -457,14 +457,32 @@ export default {
this.$refs.formRef.validateField('pay_plans', () => {});
}
},
- // 监听金额类型变化,重新校验合同金额和金额说明
+ // 监听金额类型变化,重新校验金额说明
'form.amount_type'() {
if (this.$refs.formRef) {
- this.$refs.formRef.validateField('amount_total', () => {});
this.$refs.formRef.validateField('amount_description', () => {});
}
},
},
+ async mounted() {
+ // 组件初始化时,如果value为空但有flowId,尝试从流程数据恢复合同
+ if (!this.hasValue && this.flowId) {
+ try {
+ const res = await getContractByFlowId(this.flowId);
+ const contractData = res?.data || res;
+
+ if (contractData && contractData.id) {
+ // 找到已创建的合同,自动更新value和display
+ const displayText = contractData.contract_no + (contractData.title ? ` / ${contractData.title}` : "");
+ this.$emit("input", String(contractData.id));
+ this.$emit("update:display", displayText);
+ }
+ } catch (e) {
+ // 静默失败,不影响组件正常使用
+ console.warn("从流程数据恢复合同时出错:", e);
+ }
+ }
+ },
methods: {
openDialog() {
this.dialogVisible = true;
@@ -477,26 +495,12 @@ export default {
initRules() {
// 新建时:只校验到付款方式(包含付款方式)
const baseRules = {
- contract_no: [{ required: true, message: "请填写合同编号", trigger: "blur" }],
+ contract_no_without_prefix: [{ required: true, message: "请填写合同编号", trigger: "blur" }],
title: [{ required: true, message: "请填写合同名称", trigger: "blur" }],
main_content: [{ required: true, message: "请填写合同主要内容", trigger: "blur" }],
party_a: [{ required: true, message: "请填写甲方", trigger: "blur" }],
party_b: [{ required: true, message: "请填写乙方", trigger: "blur" }],
- amount_total: [
- {
- validator: (rule, value, callback) => {
- // 开口合同时,合同金额可以为空
- if (this.form.amount_type === 'open') {
- callback();
- } else if (value === null || value === undefined || value === '') {
- callback(new Error('请填写合同金额'));
- } else {
- callback();
- }
- },
- trigger: ['blur', 'change']
- }
- ],
+ amount_total: [{ required: true, message: "请填写合同金额", trigger: ["blur", "change"] }],
amount_type: [{ required: true, message: "请选择金额类型", trigger: "change" }],
amount_description: [
{
@@ -535,6 +539,7 @@ export default {
is_accepted: [{ required: true, message: "请选择是否验收", trigger: "change" }],
handler_admin_ids: [
{
+ required: true,
validator: (rule, value, callback) => {
const ids = this.form.handler_admin_ids_array;
if (!ids || !Array.isArray(ids) || ids.length === 0) {
@@ -548,6 +553,7 @@ export default {
],
apply_handler_id: [
{
+ required: true,
validator: (rule, value, callback) => {
const ids = this.form.apply_handler_id_array;
if (!ids || !Array.isArray(ids) || ids.length === 0) {
@@ -561,6 +567,7 @@ export default {
],
owner_department_ids: [
{
+ required: true,
validator: (rule, value, callback) => {
const ids = this.form.owner_department_ids_array;
if (!ids || !Array.isArray(ids) || ids.length === 0) {
@@ -805,6 +812,12 @@ export default {
await this.fetchPurchaseMethodOptions();
// 初始化校验规则
this.initRules();
+ // 清除表单校验状态,避免新建时触发校验
+ this.$nextTick(() => {
+ if (this.$refs.formRef) {
+ this.$refs.formRef.clearValidate();
+ }
+ });
// 优先尝试加载已有合同(通过合同ID或flowId)
const contractExists = await this.loadExistingContract();
// 如果找不到已有合同,且提供了flowId,则从流程数据预填
@@ -813,6 +826,12 @@ export default {
}
// 重新初始化校验规则(因为可能已经加载了合同数据,需要区分新建/编辑)
this.initRules();
+ // 再次清除校验状态,确保填充数据后不会触发校验
+ this.$nextTick(() => {
+ if (this.$refs.formRef) {
+ this.$refs.formRef.clearValidate();
+ }
+ });
},
onDialogClose() {
// 关闭时不做处理
@@ -1202,6 +1221,19 @@ export default {
this.$emit("update:display", displayText);
this.dialogVisible = false;
Message.success(contractId ? "合同更新成功" : "合同创建成功");
+
+ // 如果是新建合同(不是更新)且有flowId,自动保存到流程字段
+ if (!contractId && this.flowId && this.fieldName) {
+ try {
+ await save(this.flowId, {
+ [this.fieldName]: String(data.id),
+ });
+ // 静默保存,不显示提示
+ } catch (e) {
+ // 保存失败不影响主流程,只记录错误
+ console.error("保存合同ID到流程字段失败:", e);
+ }
+ }
} else {
Message.error(contractId ? "更新合同失败" : "创建合同失败");
}
@@ -1214,10 +1246,6 @@ export default {
}
});
},
- clearValue() {
- this.$emit("input", "");
- this.$emit("update:display", "");
- },
},
};