weizong song 9 months ago
parent e9f786bb92
commit 977922082d

@ -17,7 +17,6 @@
<el-button v-if="!hasValue" type="primary" size="small" @click="openDialog">合同签订</el-button>
<el-button v-if="hasValue" type="primary" size="small" @click="openDialog">重新签订</el-button>
<el-button v-if="hasValue" size="small" @click="clearValue">清除</el-button>
<el-dialog
title="合同签订"
@ -37,7 +36,7 @@
>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="合同编号" prop="contract_no">
<el-form-item label="合同编号" prop="contract_no_without_prefix">
<el-input v-model="form.contract_no_without_prefix">
<template slot="prepend">CZHT</template>
</el-input>
@ -66,7 +65,7 @@
</el-row>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="合同金额(元)" prop="amount_total">
<el-form-item label="合同金额(元)" prop="amount_total" required>
<el-input-number
v-model="form.amount_total"
:min="0"
@ -222,19 +221,19 @@
/>
</el-select>
</el-form-item>
<el-form-item label="科室" prop="owner_department_ids">
<el-form-item label="科室" prop="owner_department_ids" :required="isEditMode()">
<el-select v-model="form.owner_department_ids_array" multiple placeholder="请选择科室" filterable clearable style="width: 100%">
<el-option v-for="dept in departmentList" :key="dept.id" :label="dept.name" :value="dept.id.toString()" />
</el-select>
</el-form-item>
<el-form-item label="合同签订/变更经办人" prop="handler_admin_ids">
<el-form-item label="合同签订/变更经办人" prop="handler_admin_ids" :required="isEditMode()">
<el-select v-model="form.handler_admin_ids_array" multiple placeholder="请选择经办人" filterable clearable style="width: 100%">
<el-option v-for="user in userList" :key="user.id" :label="user.name" :value="user.id.toString()" />
</el-select>
</el-form-item>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="申请科室经办人" prop="apply_handler_id">
<el-form-item label="申请科室经办人" prop="apply_handler_id" :required="isEditMode()">
<el-select v-model="form.apply_handler_id_array" placeholder="请选择" filterable multiple clearable style="width: 100%">
<el-option v-for="user in userList" :key="user.id" :label="user.name" :value="user.id.toString()" />
</el-select>
@ -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", "");
},
},
};
</script>

Loading…
Cancel
Save