Commit 3618fd7f authored by TerryLan's avatar TerryLan

chore(智能表单): 出差表单功能完善

parent 092f2b8d
import { request } from '@/utils/request'
export function fetchBusinessTripFormSubmit<T>(payload: object) {
return request.post<T>('/bizPluginBusinessRest/submitTravelForm.json', {
fromDataDto: payload,
formType: 'TravelForm',
})
}
<script setup lang="ts">
import { computed, inject, readonly, ref, useTemplateRef, watch } from 'vue'
import { computed, inject, readonly, ref, toRaw, useTemplateRef, watch, watchEffect } from 'vue'
import type { MessageItemInterface } from '../../types'
import MarkdownRender from '@/components/markdown-render/markdown-render.vue'
import type { FormInst, FormRules, FormItemRule } from 'naive-ui'
......@@ -8,7 +8,8 @@ import { useSystemLanguageStore } from '@/store/modules/system-language'
import MessageBubbleLoading from '../message-bubble-loading.vue'
import isEmail from 'validator/es/lib/isEmail'
import type { BusinessTripForm, ResponseBusinessTripForm } from './types'
import { businessTripFormParser } from '../../utils/smart-forms'
import { businessTripFormParser, businessTripFormReturner } from '../../utils/smart-forms'
import { fetchBusinessTripFormSubmit } from '@/apis/smart-forms'
interface Props {
messageItem: MessageItemInterface
......@@ -82,6 +83,7 @@ const formModel = ref<BusinessTripForm>({
generalBudget: '',
email: '',
})
const submitFormBtnLoading = ref(false)
const objectiveOptions = readonly([
{
......@@ -126,17 +128,41 @@ watch(
},
)
watchEffect(() => {
let aggregateAmount = 0
if (formModel.value.vehicleEstimatedCost) {
aggregateAmount += formModel.value.vehicleEstimatedCost
}
if (formModel.value.residenceEstimatedCost) {
aggregateAmount += formModel.value.residenceEstimatedCost
}
if (formModel.value.advancePaymentAmount) {
aggregateAmount += formModel.value.advancePaymentAmount
}
formModel.value.generalBudget = aggregateAmount.toString()
})
function handleSubmitForm() {
businessTripFormRef.value?.validate((errors) => {
if (!errors) {
window.$message.success('提交')
updateSpecifyMessageItem(messageItemId, {
smartFormInfo: {
...(props.messageItem.smartFormInfo || { type: 'BusinessTripForm', params: '' }),
isDisabled: true,
},
})
submitFormBtnLoading.value = true
fetchBusinessTripFormSubmit(businessTripFormReturner(toRaw(formModel.value)))
.then((res) => {
if (res.code !== 0) return ''
updateSpecifyMessageItem(messageItemId, {
smartFormInfo: {
...(props.messageItem.smartFormInfo || { type: 'BusinessTripForm', params: '' }),
isDisabled: true,
},
})
})
.finally(() => {
submitFormBtnLoading.value = false
})
}
})
}
......@@ -320,7 +346,12 @@ function handleSubmitForm() {
</n-form-item>
<div class="mt-[46px] text-end">
<n-button type="primary" :disabled="isDisabledForm" @click="handleSubmitForm">
<n-button
type="primary"
:disabled="isDisabledForm"
:loading="submitFormBtnLoading"
@click="handleSubmitForm"
>
{{ t('smart_forms_module.business_trip_form.confirm_submission') }}
</n-button>
</div>
......
......@@ -244,6 +244,8 @@ function onGetMessageRecordList(recordId: string) {
function onClearSessionReferenceFile() {
footerOperationRef.value && footerOperationRef.value.clearSessionReferenceFile()
}
function onSmartFormsStatusFreeze() {}
</script>
<template>
......@@ -281,6 +283,7 @@ function onClearSessionReferenceFile() {
@delete-message-item="onDeleteMessageItem"
@create-new-session="onCreateNewSession"
@history-record-list-update="onHistoryRecordListUpdate"
@smart-forms-status-freeze="onSmartFormsStatusFreeze"
/>
</div>
......
......@@ -28,8 +28,8 @@ export function businessTripFormReturner(form: BusinessTripForm) {
return {
purpose: form.objective,
place: form.travelLocation,
departureDate: form.departureTime,
returnDate: form.returnTime,
departureDate: form.departureTime ? new Date(form.departureTime).toISOString() : '',
returnDate: form.returnTime ? new Date(form.returnTime).toISOString() : '',
vehicle: form.vehicle,
transportationFee: form.vehicleEstimatedCost,
accommodation: form.residence,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment