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"> <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 type { MessageItemInterface } from '../../types'
import MarkdownRender from '@/components/markdown-render/markdown-render.vue' import MarkdownRender from '@/components/markdown-render/markdown-render.vue'
import type { FormInst, FormRules, FormItemRule } from 'naive-ui' import type { FormInst, FormRules, FormItemRule } from 'naive-ui'
...@@ -8,7 +8,8 @@ import { useSystemLanguageStore } from '@/store/modules/system-language' ...@@ -8,7 +8,8 @@ import { useSystemLanguageStore } from '@/store/modules/system-language'
import MessageBubbleLoading from '../message-bubble-loading.vue' import MessageBubbleLoading from '../message-bubble-loading.vue'
import isEmail from 'validator/es/lib/isEmail' import isEmail from 'validator/es/lib/isEmail'
import type { BusinessTripForm, ResponseBusinessTripForm } from './types' 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 { interface Props {
messageItem: MessageItemInterface messageItem: MessageItemInterface
...@@ -82,6 +83,7 @@ const formModel = ref<BusinessTripForm>({ ...@@ -82,6 +83,7 @@ const formModel = ref<BusinessTripForm>({
generalBudget: '', generalBudget: '',
email: '', email: '',
}) })
const submitFormBtnLoading = ref(false)
const objectiveOptions = readonly([ const objectiveOptions = readonly([
{ {
...@@ -126,10 +128,30 @@ watch( ...@@ -126,10 +128,30 @@ 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() { function handleSubmitForm() {
businessTripFormRef.value?.validate((errors) => { businessTripFormRef.value?.validate((errors) => {
if (!errors) { if (!errors) {
window.$message.success('提交') submitFormBtnLoading.value = true
fetchBusinessTripFormSubmit(businessTripFormReturner(toRaw(formModel.value)))
.then((res) => {
if (res.code !== 0) return ''
updateSpecifyMessageItem(messageItemId, { updateSpecifyMessageItem(messageItemId, {
smartFormInfo: { smartFormInfo: {
...@@ -137,6 +159,10 @@ function handleSubmitForm() { ...@@ -137,6 +159,10 @@ function handleSubmitForm() {
isDisabled: true, isDisabled: true,
}, },
}) })
})
.finally(() => {
submitFormBtnLoading.value = false
})
} }
}) })
} }
...@@ -320,7 +346,12 @@ function handleSubmitForm() { ...@@ -320,7 +346,12 @@ function handleSubmitForm() {
</n-form-item> </n-form-item>
<div class="mt-[46px] text-end"> <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') }} {{ t('smart_forms_module.business_trip_form.confirm_submission') }}
</n-button> </n-button>
</div> </div>
......
...@@ -244,6 +244,8 @@ function onGetMessageRecordList(recordId: string) { ...@@ -244,6 +244,8 @@ function onGetMessageRecordList(recordId: string) {
function onClearSessionReferenceFile() { function onClearSessionReferenceFile() {
footerOperationRef.value && footerOperationRef.value.clearSessionReferenceFile() footerOperationRef.value && footerOperationRef.value.clearSessionReferenceFile()
} }
function onSmartFormsStatusFreeze() {}
</script> </script>
<template> <template>
...@@ -281,6 +283,7 @@ function onClearSessionReferenceFile() { ...@@ -281,6 +283,7 @@ function onClearSessionReferenceFile() {
@delete-message-item="onDeleteMessageItem" @delete-message-item="onDeleteMessageItem"
@create-new-session="onCreateNewSession" @create-new-session="onCreateNewSession"
@history-record-list-update="onHistoryRecordListUpdate" @history-record-list-update="onHistoryRecordListUpdate"
@smart-forms-status-freeze="onSmartFormsStatusFreeze"
/> />
</div> </div>
......
...@@ -28,8 +28,8 @@ export function businessTripFormReturner(form: BusinessTripForm) { ...@@ -28,8 +28,8 @@ export function businessTripFormReturner(form: BusinessTripForm) {
return { return {
purpose: form.objective, purpose: form.objective,
place: form.travelLocation, place: form.travelLocation,
departureDate: form.departureTime, departureDate: form.departureTime ? new Date(form.departureTime).toISOString() : '',
returnDate: form.returnTime, returnDate: form.returnTime ? new Date(form.returnTime).toISOString() : '',
vehicle: form.vehicle, vehicle: form.vehicle,
transportationFee: form.vehicleEstimatedCost, transportationFee: form.vehicleEstimatedCost,
accommodation: form.residence, 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