2024-04-09 11:18:52 +08:00

187 lines
6.1 KiB
Vue

<template>
<div class="edit-popup">
<popup ref="popupRef" :title="popupTitle" :async="true" width="550px" @confirm="handleSubmit" @close="handleClose">
<el-form ref="formRef" :model="formData" label-width="140px" :rules="formRules">
<el-form-item label="合同名称" prop="contract_name">
<el-input v-model="formData.contract_name" clearable placeholder="点击选择合同" @click="showDialog = true"
readonly />
</el-form-item>
<el-form-item label="甲方签约单位">
<el-input v-model="formData.part_a" clearable placeholder="系统自动获取" disabled />
</el-form-item>
<el-form-item label="乙方签约单位">
<el-input v-model="formData.part_b" clearable placeholder="系统自动获取" disabled />
</el-form-item>
<el-form-item label="签订金额(元)">
<el-input v-model="formData.sign_money" clearable placeholder="系统自动获取" disabled />
</el-form-item>
<el-form-item label="合同签订日期">
<el-input v-model="formData.sign_time" clearable placeholder="系统自动获取" disabled />
</el-form-item>
<el-form-item label="累计已开票(元)">
<el-input v-model="formData.total_invoice_amount" clearable placeholder="系统自动获取" disabled />
</el-form-item>
<el-form-item label="累计已到账(元)">
<el-input v-model="formData.total_refund_amount" clearable placeholder="系统自动获取" disabled />
</el-form-item>
<el-form-item label="结算金额" prop="amount">
<el-input v-model="formData.amount" clearable placeholder="请输入结算金额" type="number" />
</el-form-item>
<el-form-item label="结算日期" prop="date">
<el-date-picker class="flex-1 !flex" v-model="formData.date" clearable value-format="YYYY-MM-DD"
placeholder="选择结算日期">
</el-date-picker>
</el-form-item>
<el-form-item label="结算备注" prop="remark">
<el-input v-model="formData.remark" clearable placeholder="请输入结算备注" type="textarea" />
</el-form-item>
<el-form-item label="附件" prop="annex">
<uploadAnnex :formData="formData"></uploadAnnex>
</el-form-item>
</el-form>
<el-dialog v-model="showDialog" title="选择合同" width="70%">
<dialogTable :config="cost_approved_projects" @customEvent="customEvent" :query="{ status: 1 }">
</dialogTable>
</el-dialog>
</popup>
</div>
</template>
<script lang="ts" setup name="financialSettlementEdit">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiFinancialSettlementAdd, apiFinancialSettlementEdit, apiFinancialSettlementDetail } from '@/api/financial_settlement'
import { timeFormat } from '@/utils/util'
import type { PropType } from 'vue'
import { cost_approved_projects } from "@/components/dialogTable/dialogTableConfig";
defineProps({
dictData: {
type: Object as PropType<Record<string, any[]>>,
default: () => ({})
}
})
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')
const showDialog = ref(false)
// 弹窗标题
const popupTitle = computed(() => {
return mode.value == 'edit' ? '编辑财务管理--项目结算' : '新增财务管理--项目结算'
})
// 表单数据
const formData = reactive({
id: '',
contract_id: '',
contract_name: '',
amount: '',
date: '',
remark: '',
annex: '',
"contract_type": "",
"part_a": "",
"part_b": "",
"sign_money": "",
"sign_time": "",
"invoice_code": "",
"apply_amount": "",
"total_invoice_amount": 0,
"total_refund_amount": 0
})
const customEvent = (e) => {
formData.contract_id = e.id
formData.contract_name = e.contract_name
formData.contract_type = e.contract_type
formData.part_a = e.part_a
formData.part_b = e.part_b
formData.sign_money = e.money
formData.sign_time = e.sign_date
formData.total_invoice_amount = e.total_invoice_amount
formData.total_refund_amount = e.total_refund_amount
showDialog.value = false
}
// 表单验证
const formRules = reactive<any>({
contract_id: [{
required: true,
message: '请输入合同id',
trigger: ['blur']
}],
amount: [{
required: true,
message: '请输入结算金额',
trigger: ['blur']
}],
date: [{
required: true,
message: '请输入结算日期',
trigger: ['blur']
}],
remark: [{
required: true,
message: '请输入结算备注',
trigger: ['blur']
}]
})
// 获取详情
const setFormData = async (data: Record<any, any>) => {
for (const key in formData) {
if (data[key] != null && data[key] != undefined) {
//@ts-ignore
formData[key] = data[key]
}
}
}
const getDetail = async (row: Record<string, any>) => {
const data = await apiFinancialSettlementDetail({
id: row.id
})
setFormData(data)
}
// 提交按钮
const handleSubmit = async () => {
await formRef.value?.validate()
const data = { ...formData, }
mode.value == 'edit'
? await apiFinancialSettlementEdit(data)
: await apiFinancialSettlementAdd(data)
popupRef.value?.close()
emit('success')
}
//打开弹窗
const open = (type = 'add') => {
mode.value = type
popupRef.value?.open()
}
// 关闭回调
const handleClose = () => {
emit('close')
}
defineExpose({
open,
setFormData,
getDetail
})
</script>