| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <template>
- <Dialog
- v-model="dialogVisible"
- title="试住转长住"
- class="check-in-check"
- width="79%"
- scroll
- noPaddingEL="check-in-check"
- @close="handleClosed"
- >
- <ProcessForm ref="processFormRef" :toggleType="true"/>
- <template #footer>
- <el-button @click="handleClosed">关闭</el-button>
- <el-button v-loading="formLoading" type="primary" @click="submitForm" v-if="!isDetail">提交审核</el-button>
- </template>
- </Dialog>
- </template>
- <script setup lang="ts">
- import {checkInCreate, renewContractLong} from '@/api/elderly/apply/check-in'
- import ProcessForm from './ProcessForm.vue'
- defineOptions({ name: 'CheckInForm' })
- const message = useMessage() // 消息弹窗
- const { t } = useI18n() // 国际化
- const dialogVisible = ref(false) // 弹窗
- const processFormRef = ref()
- const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
- const isDetail = ref(false)
- const itemRow = ref({})
- /** 打开弹窗 */
- const open = async (row, detail=false) => {
- dialogVisible.value = true
- isDetail.value = detail
- itemRow.value = row
- nextTick(() => {
- processFormRef.value.init(row, detail)
- })
- }
- defineExpose({ open }) // 提供 open 方法,用于打开弹窗
- const handleClosed = () => {
- processFormRef.value && processFormRef.value.resetForm()
- dialogVisible.value = false
- }
- /** 校验表单数据完整性 */
- const validateForm = (dataForm: any): boolean => {
- // 校验月度固定费用项目
- if (dataForm.expenseBO?.monthlyExpenses?.length > 0) {
- for (let i = 0; i < dataForm.expenseBO.monthlyExpenses.length; i++) {
- const item = dataForm.expenseBO.monthlyExpenses[i]
- if (!item.itemCategoryId) {
- message.error(`请选择月度固定项目${i + 1}的项目类别`)
- return false
- }
- if (!item.itemId) {
- message.error(`请选择月度固定项目${i + 1}的项目名称`)
- return false
- }
- const actualAmountNum = Number(item.actualAmount)
- if (item.actualAmount === '' || item.actualAmount === null || item.actualAmount === undefined || Number.isNaN(actualAmountNum) || actualAmountNum < 0) {
- message.error(`请输入月度固定项目${i + 1}的费用金额`)
- return false
- }
- }
- }
- // 校验一次性收费项目
- if (dataForm.expenseBO?.oneTimeExpenses?.length > 0) {
- for (let i = 0; i < dataForm.expenseBO.oneTimeExpenses.length; i++) {
- const item = dataForm.expenseBO.oneTimeExpenses[i]
- if (!item.itemCategoryId) {
- message.error(`请选择一次性收费项目${i + 1}的项目类别`)
- return false
- }
- if (!item.itemId) {
- message.error(`请选择一次性收费项目${i + 1}的项目名称`)
- return false
- }
- const actualAmountNum2 = Number(item.actualAmount)
- if (item.actualAmount === '' || item.actualAmount === null || item.actualAmount === undefined || Number.isNaN(actualAmountNum2) || actualAmountNum2 < 0) {
- message.error(`请输入一次性收费项目${i + 1}的费用金额`)
- return false
- }
- }
- }
- // 校验阶段收费项目
- if (dataForm.expenseBO?.stageExpenses?.length > 0) {
- for (let i = 0; i < dataForm.expenseBO.stageExpenses.length; i++) {
- const item = dataForm.expenseBO.stageExpenses[i]
- if (!item.itemCategoryId) {
- message.error(`请选择阶段收费项目${i + 1}的项目类别`)
- return false
- }
- if (!item.itemId) {
- message.error(`请选择阶段收费项目${i + 1}的项目名称`)
- return false
- }
- // 检查金额:优先检查 actualAmount,如果没有则检查 amount,汇总到一个变量后统一校验
- const amount = item.actualAmount !== undefined && item.actualAmount !== null && item.actualAmount !== '' ? item.actualAmount : item.amount
- const amountNum = Number(amount)
- const isValidAmount = amount !== '' && amount !== null && amount !== undefined && !Number.isNaN(amountNum) && amountNum >= 0
- if (!isValidAmount) {
- message.error(`请输入阶段收费项目${i + 1}的费用金额,金额不能小于0`)
- return false
- }
- // 同时校验 totalAmount 也不能小于0
- const totalAmountNum = Number(item.totalAmount)
- if (Number.isNaN(totalAmountNum) || totalAmountNum < 0) {
- message.error(`阶段收费项目${i + 1}的单项小计不能小于0`)
- return false
- }
- // 如果选中了分期,分期期数是必选的
- if (item.isHirePurchase === 1 && !item.hirePurchaseNumber) {
- message.error(`请选择阶段收费项目${i + 1}的分期期数`)
- return false
- }
- // 如果选中了赠送,赠送时间是必选的
- if (item.isFreeGift === 1) {
- if (!item.freeStartTime) {
- message.error(`请选择阶段收费项目${i + 1}的赠送开始时间`)
- return false
- }
- if (!item.freeEndTime) {
- message.error(`请选择阶段收费项目${i + 1}的赠送结束时间`)
- return false
- }
- }
- }
- }
- return true
- }
- /** 提交表单 */
- const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
- const submitForm = async () => {
- let { valid, dataForm } = await processFormRef.value.submitForm()
- if (!valid) {
- return
- }
- // 校验费用数据完整性
- if (!validateForm(dataForm)) {
- return
- }
- try {
- formLoading.value = true
- console.log("是是是:",itemRow.value.toLong,dataForm)
- let res = undefined
- //if(itemRow.value.toLong==1){ //试住转长住
- // res = await renewContractLong(dataForm)
- // }else {//入住办理
- res = await checkInCreate(dataForm)
- // }
- if (res) {
- message.success(t('common.updateSuccess'))
- handleClosed()
- // 发送操作成功的事件
- emit('success')
- }
- } finally {
- formLoading.value = false
- }
- }
- </script>
|