完成合同编辑功能

master
lynn 12 months ago
parent 82cd17b824
commit a9a320ae89

@ -222,7 +222,7 @@
</Button> </Button>
<template v-if="scope.row.status != 2||hasEdit"> <template v-if="scope.row.status != 2||hasEdit">
<Button class="slot-btns-item" size="small" type="primary" <Button class="slot-btns-item" size="small" type="primary"
@click="$refs['editor'].isShowEditor = true,$refs['editor'].getDetail(scope.row.id)">编辑 @click="handleEdit(scope.row)">编辑
</Button> </Button>
</template> </template>
<template v-if="hasEdit&&scope.row.status === 2"> <template v-if="hasEdit&&scope.row.status === 2">
@ -246,7 +246,7 @@
<!-- 新增合同模态框 --> <!-- 新增合同模态框 -->
<Modal <Modal
v-model="isShowAdd" v-model="isShowAdd"
title="新增合同" :title="isEditMode ? '编辑合同' : '新增合同'"
width="800" width="800"
:mask-closable="false" :mask-closable="false"
:closable="false" :closable="false"
@ -618,7 +618,8 @@ import {
getContract, getContract,
addContrant, addContrant,
delContract, delContract,
checkContractName checkContractName,
editorContract
} from "@/api/contract/contract" } from "@/api/contract/contract"
import { import {
getparameter getparameter
@ -1283,6 +1284,8 @@ export default {
{ label: '服务合同', value: 'service' } { label: '服务合同', value: 'service' }
], ],
plan: [], // plan: [], //
isEditMode: false, //
currentContractId: null, // ID
} }
}, },
methods: { methods: {
@ -1879,8 +1882,8 @@ export default {
this.form.contract_template.template = this.$refs.afterPaymentForm.innerHTML; this.form.contract_template.template = this.$refs.afterPaymentForm.innerHTML;
} }
// //
const res = await addContrant({ const submitData = {
category: this.form.category, category: this.form.category,
work_type: this.form.affairType, work_type: this.form.affairType,
contract_type: this.form.contractType, contract_type: this.form.contractType,
@ -1905,7 +1908,18 @@ export default {
contract_carry_department: this.form.contract_carry_department?.map(i => ({carry_department_id: i})) || [], contract_carry_department: this.form.contract_carry_department?.map(i => ({carry_department_id: i})) || [],
before_contract_template: this.form.before_contract_template, before_contract_template: this.form.before_contract_template,
contract_template: this.form.contract_template contract_template: this.form.contract_template
}); };
//
let res;
if (this.isEditMode) {
//
submitData.id = this.currentContractId;
res = await editorContract(submitData);
} else {
//
res = await addContrant(submitData);
}
this.isShowAdd = false; this.isShowAdd = false;
Message({ Message({
@ -2313,7 +2327,9 @@ export default {
}, },
resetForm() { resetForm() {
this.currentStep = 1 this.currentStep = 1;
this.isEditMode = false;
this.currentContractId = null;
this.form = { this.form = {
category: '', category: '',
affairType: '', affairType: '',
@ -2322,22 +2338,20 @@ export default {
purchaseSubForm: '', purchaseSubForm: '',
purchaseMethod: '', purchaseMethod: '',
name: '', name: '',
type: '', // type: '',
moneyWay: [], moneyWay: [],
plan: [], plan: [],
plan_display: '', // plan_display: '',
price: 0, price: 0,
supply: '', // / supply: '',
// is_simple: 0,
is_simple: 0, // has_charge: 0,
has_charge: 0, // isBudget: 0,
isBudget: 0, // is_substitute: 0,
is_substitute: 0, // request: 0,
// purchaseApproval: 0,
request: 0, // tenderReview: 0,
purchaseApproval: 0, // contractSign: 0,
tenderReview: 0, //
contractSign: 0, //
expenses: [ expenses: [
{ {
content: '', content: '',
@ -2346,15 +2360,15 @@ export default {
payee: '' payee: ''
} }
], ],
showAfterPayment: false, // showAfterPayment: false,
contract_carry_department: [] // contract_carry_department: []
} };
this.affairTypeOptions = [] this.affairTypeOptions = [];
this.contractTypeOptions = [] this.contractTypeOptions = [];
this.purchaseFormOptions = [] this.purchaseFormOptions = [];
this.purchaseSubFormOptions = [] this.purchaseSubFormOptions = [];
this.purchaseMethodOptions = [] this.purchaseMethodOptions = [];
}, },
// //
@ -2601,6 +2615,188 @@ export default {
} }
} }
}, },
//
async handleEdit(row) {
this.isEditMode = true;
this.currentContractId = row.id;
this.isShowAdd = true;
this.currentStep = 1;
try {
// 1.
await this.getCategoryOptions();
// 2.
const res = await getContract({ id: row.id });
if (res && res.list && res.list.data && res.list.data.length > 0) {
const detail = res.list.data[0];
// , 20, .
detail.category = 20;
// 3.
//
if (detail.category) {
this.form.category = detail.category;
this.handleCategoryChange(detail.category);
}
//
if (detail.work_type) {
this.form.affairType = detail.work_type;
this.handleAffairTypeChange(detail.work_type);
}
//
if (detail.contract_type) {
this.form.contractType = detail.contract_type;
this.handleContractTypeChange(detail.contract_type);
}
//
if (detail.purchase_type_id) {
this.form.purchaseForm = detail.purchase_type_id;
this.handlePurchaseFormChange(detail.purchase_type_id);
}
//
if (detail.purchase_way_id) {
this.form.purchaseMethod = detail.purchase_way_id;
}
//
this.form = {
...this.form,
type: detail.type,
isBudget: detail.is_plan,
is_simple: detail.is_simple,
has_charge: detail.has_charge,
is_substitute: detail.is_substitute,
supply: detail.supply,
price: detail.plan_price,
name: detail.name,
moneyWay: detail.money_way_id ? detail.money_way_id.split(',').map(Number) : [],
plan: detail.plans.map(item => {
return {
label: item.name,
value: {
plan_id: item.id,
use_money: detail.plan_link ? detail.plan_link.filter(item1 => {
return item1.plan_id === item.id
})[0]?.use_money : 0,
new_money: item.money
}
}
}),
contract_carry_department: detail.contract_carry_department.map(i => i.carry_department_id),
before_contract_template: detail.before_contract_template,
contract_template: detail.contract_template
};
//
if (this.form.plan && this.form.plan.length > 0) {
this.form.plan_display = this.form.plan.map(item => item.label).join(', ');
}
}
} catch (error) {
console.error('初始化编辑数据失败:', error);
Message({
type: 'error',
message: '初始化编辑数据失败'
});
}
},
//
handleAdd() {
this.isEditMode = false;
this.currentContractId = null;
this.isShowAdd = true;
this.currentStep = 1;
this.form = {
...this.form,
category: '',
affairType: '',
contractType: '',
purchaseForm: '',
purchaseMethod: '',
type: '',
isBudget: false,
is_simple: 0,
has_charge: 0,
is_substitute: 0,
supply: '',
price: '',
name: '',
moneyWay: [],
plan: [],
contract_carry_department: [],
before_contract_template: null,
contract_template: null
};
this.getCategoryOptions();
},
//
async getContractDetail(id) {
try {
const res = await getContract({ id });
if (res && res.list && res.list.data && res.list.data.length > 0) {
const detail = res.list.data[0];
console.log("detail", detail);
//
this.form = {
...this.form,
//
category: detail.category,
affairType: detail.work_type,
contractType: detail.contract_type,
purchaseForm: detail.purchase_type_id, //
purchaseMethod: detail.purchase_way_id, //
//
type: detail.type,
isBudget: detail.is_plan === 1,
is_simple: detail.is_simple,
has_charge: detail.has_charge,
is_substitute: detail.is_substitute,
supply: detail.supply,
price: detail.plan_price,
name: detail.name,
moneyWay: detail.money_way_id ? detail.money_way_id.split(',').map(Number) : [],
plan: detail.plans.map(item => {
return {
label: item.name,
value: {
plan_id: item.id,
use_money: detail.plan_link ? detail.plan_link.filter(item1 => {
return item1.plan_id === item.id
})[0]?.use_money : 0,
new_money: item.money
}
}
}),
contract_carry_department: detail.contract_carry_department.map(i => i.carry_department_id),
before_contract_template: detail.before_contract_template,
contract_template: detail.contract_template
};
//
if (this.form.plan && this.form.plan.length > 0) {
this.form.plan_display = this.form.plan.map(item => item.label).join(', ');
}
//
this.currentStep = 1;
}
} catch (error) {
console.error('获取合同详情失败:', error);
Message({
type: 'error',
message: '获取合同详情失败'
});
}
},
}, },
mounted() { mounted() {
this.window.width = screen.availWidth * 0.95 this.window.width = screen.availWidth * 0.95
@ -3050,3 +3246,17 @@ export default {
} }
} }
</style> </style>
<style scoped lang="scss">
// ... existing styles ...
// require
::v-deep .el-form-item__error {
width: 200px;
white-space: normal;
word-break: break-all;
text-align: right;
right: 0;
left: auto;
}
</style>

Loading…
Cancel
Save