ToLong.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <Dialog
  3. v-model="dialogVisible"
  4. title="试住转长住"
  5. class="check-in-check"
  6. width="79%"
  7. scroll
  8. noPaddingEL="check-in-check"
  9. @close="handleClosed"
  10. >
  11. <ProcessForm ref="processFormRef" :toggleType="true"/>
  12. <template #footer>
  13. <el-button @click="handleClosed">关闭</el-button>
  14. <el-button v-loading="formLoading" type="primary" @click="submitForm" v-if="!isDetail">提交审核</el-button>
  15. </template>
  16. </Dialog>
  17. </template>
  18. <script setup lang="ts">
  19. import {checkInCreate, renewContractLong} from '@/api/elderly/apply/check-in'
  20. import ProcessForm from './ProcessForm.vue'
  21. defineOptions({ name: 'CheckInForm' })
  22. const message = useMessage() // 消息弹窗
  23. const { t } = useI18n() // 国际化
  24. const dialogVisible = ref(false) // 弹窗
  25. const processFormRef = ref()
  26. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  27. const isDetail = ref(false)
  28. const itemRow = ref({})
  29. /** 打开弹窗 */
  30. const open = async (row, detail=false) => {
  31. dialogVisible.value = true
  32. isDetail.value = detail
  33. itemRow.value = row
  34. nextTick(() => {
  35. processFormRef.value.init(row, detail)
  36. })
  37. }
  38. defineExpose({ open }) // 提供 open 方法,用于打开弹窗
  39. const handleClosed = () => {
  40. processFormRef.value && processFormRef.value.resetForm()
  41. dialogVisible.value = false
  42. }
  43. /** 校验表单数据完整性 */
  44. const validateForm = (dataForm: any): boolean => {
  45. // 校验月度固定费用项目
  46. if (dataForm.expenseBO?.monthlyExpenses?.length > 0) {
  47. for (let i = 0; i < dataForm.expenseBO.monthlyExpenses.length; i++) {
  48. const item = dataForm.expenseBO.monthlyExpenses[i]
  49. if (!item.itemCategoryId) {
  50. message.error(`请选择月度固定项目${i + 1}的项目类别`)
  51. return false
  52. }
  53. if (!item.itemId) {
  54. message.error(`请选择月度固定项目${i + 1}的项目名称`)
  55. return false
  56. }
  57. const actualAmountNum = Number(item.actualAmount)
  58. if (item.actualAmount === '' || item.actualAmount === null || item.actualAmount === undefined || Number.isNaN(actualAmountNum) || actualAmountNum < 0) {
  59. message.error(`请输入月度固定项目${i + 1}的费用金额`)
  60. return false
  61. }
  62. }
  63. }
  64. // 校验一次性收费项目
  65. if (dataForm.expenseBO?.oneTimeExpenses?.length > 0) {
  66. for (let i = 0; i < dataForm.expenseBO.oneTimeExpenses.length; i++) {
  67. const item = dataForm.expenseBO.oneTimeExpenses[i]
  68. if (!item.itemCategoryId) {
  69. message.error(`请选择一次性收费项目${i + 1}的项目类别`)
  70. return false
  71. }
  72. if (!item.itemId) {
  73. message.error(`请选择一次性收费项目${i + 1}的项目名称`)
  74. return false
  75. }
  76. const actualAmountNum2 = Number(item.actualAmount)
  77. if (item.actualAmount === '' || item.actualAmount === null || item.actualAmount === undefined || Number.isNaN(actualAmountNum2) || actualAmountNum2 < 0) {
  78. message.error(`请输入一次性收费项目${i + 1}的费用金额`)
  79. return false
  80. }
  81. }
  82. }
  83. // 校验阶段收费项目
  84. if (dataForm.expenseBO?.stageExpenses?.length > 0) {
  85. for (let i = 0; i < dataForm.expenseBO.stageExpenses.length; i++) {
  86. const item = dataForm.expenseBO.stageExpenses[i]
  87. if (!item.itemCategoryId) {
  88. message.error(`请选择阶段收费项目${i + 1}的项目类别`)
  89. return false
  90. }
  91. if (!item.itemId) {
  92. message.error(`请选择阶段收费项目${i + 1}的项目名称`)
  93. return false
  94. }
  95. // 检查金额:优先检查 actualAmount,如果没有则检查 amount,汇总到一个变量后统一校验
  96. const amount = item.actualAmount !== undefined && item.actualAmount !== null && item.actualAmount !== '' ? item.actualAmount : item.amount
  97. const amountNum = Number(amount)
  98. const isValidAmount = amount !== '' && amount !== null && amount !== undefined && !Number.isNaN(amountNum) && amountNum >= 0
  99. if (!isValidAmount) {
  100. message.error(`请输入阶段收费项目${i + 1}的费用金额,金额不能小于0`)
  101. return false
  102. }
  103. // 同时校验 totalAmount 也不能小于0
  104. const totalAmountNum = Number(item.totalAmount)
  105. if (Number.isNaN(totalAmountNum) || totalAmountNum < 0) {
  106. message.error(`阶段收费项目${i + 1}的单项小计不能小于0`)
  107. return false
  108. }
  109. // 如果选中了分期,分期期数是必选的
  110. if (item.isHirePurchase === 1 && !item.hirePurchaseNumber) {
  111. message.error(`请选择阶段收费项目${i + 1}的分期期数`)
  112. return false
  113. }
  114. // 如果选中了赠送,赠送时间是必选的
  115. if (item.isFreeGift === 1) {
  116. if (!item.freeStartTime) {
  117. message.error(`请选择阶段收费项目${i + 1}的赠送开始时间`)
  118. return false
  119. }
  120. if (!item.freeEndTime) {
  121. message.error(`请选择阶段收费项目${i + 1}的赠送结束时间`)
  122. return false
  123. }
  124. }
  125. }
  126. }
  127. return true
  128. }
  129. /** 提交表单 */
  130. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  131. const submitForm = async () => {
  132. let { valid, dataForm } = await processFormRef.value.submitForm()
  133. if (!valid) {
  134. return
  135. }
  136. // 校验费用数据完整性
  137. if (!validateForm(dataForm)) {
  138. return
  139. }
  140. try {
  141. formLoading.value = true
  142. console.log("是是是:",itemRow.value.toLong,dataForm)
  143. let res = undefined
  144. //if(itemRow.value.toLong==1){ //试住转长住
  145. // res = await renewContractLong(dataForm)
  146. // }else {//入住办理
  147. res = await checkInCreate(dataForm)
  148. // }
  149. if (res) {
  150. message.success(t('common.updateSuccess'))
  151. handleClosed()
  152. // 发送操作成功的事件
  153. emit('success')
  154. }
  155. } finally {
  156. formLoading.value = false
  157. }
  158. }
  159. </script>