Form.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <Dialog
  3. v-model="dialogVisible"
  4. :title="titleItem"
  5. class="check-out form-tag-dialog"
  6. width="60%"
  7. :scroll="isDetail ? true : false"
  8. >
  9. <ProcessForm ref="processFormRef" :toggleType="isDetail" />
  10. <template #footer>
  11. <el-button @click="handleClosed">关闭</el-button>
  12. <el-button v-loading="formLoading" type="primary" @click="submitForm">提交审核</el-button>
  13. </template>
  14. </Dialog>
  15. </template>
  16. <script lang="ts" setup>
  17. import { ref } from 'vue'
  18. import ProcessForm from './ProcessForm.vue'
  19. defineOptions({ name: 'BakCheckOutForm' })
  20. const message = useMessage() // 消息弹窗
  21. const { t } = useI18n() // 国际化
  22. import { elderlyBakAdd } from '@/api/elderly/bak/check-out'
  23. const dialogVisible = ref(false) // 弹窗
  24. const processFormRef = ref() // 表单 Ref
  25. const isDetail = ref(false) // 是否详情打开
  26. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  27. const titleItem = ref('新增')
  28. /** 打开弹窗
  29. * @param tId 租户 id(必填)
  30. * @param id 退住申请 id(编辑/重新发起时传入)
  31. * @param detail 是否详情
  32. * @param status 审批状态
  33. * @param elderId 外部带入的长者 id(如从出院小结发起退住申请时预选该长者,新增场景)
  34. * @param retreatDate 外部带入的退住日期(如从出院小结带入的出院日期)
  35. * @param reason 外部带入的退住原因(字典键值,如从出院小结带入的出院原因)
  36. * @param description 外部带入的退住描述(如出院原因=其他时的补充说明)
  37. */
  38. const open = async (tId, id, detail, status, elderId, retreatDate, reason, description) => {
  39. dialogVisible.value = true
  40. isDetail.value = detail
  41. await nextTick()
  42. processFormRef.value.setTenantId(tId)
  43. if (id) {
  44. titleItem.value = '重新发起'
  45. processFormRef.value.init(id, detail, status)
  46. } else if (elderId) {
  47. // 新增且带入长者 id:打开后默认选中该长者(下拉框显示且其证件号/入住日期/床位号自动回填)
  48. processFormRef.value.setElderById(elderId)
  49. }
  50. // 带入退住日期(外部传入时预填)
  51. if (retreatDate) {
  52. processFormRef.value.setRetreatDate(retreatDate)
  53. }
  54. // 带入退住原因 / 退住描述(出院原因=其他时,退住描述取「其他」输入值)
  55. if (reason !== '' && reason !== null && reason !== undefined) {
  56. processFormRef.value.setReason(reason)
  57. }
  58. if (description) {
  59. processFormRef.value.setDescription(description)
  60. }
  61. }
  62. /** 提交表单 */
  63. const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
  64. const submitForm = async () => {
  65. if(formLoading.value){
  66. return
  67. }
  68. formLoading.value = true
  69. try {
  70. let { valid, dataForm } = await processFormRef.value.submitForm()
  71. if(!valid){
  72. return
  73. }
  74. const res = await elderlyBakAdd(dataForm)
  75. if (res) {
  76. message.success(t('common.updateSuccess'))
  77. // 发送操作成功的事件
  78. emit('success')
  79. handleClosed()
  80. }
  81. } finally {
  82. setTimeout(()=>{
  83. formLoading.value = false
  84. },500)
  85. }
  86. }
  87. // 关闭表单
  88. const handleClosed = () => {
  89. processFormRef.value.resetForm()
  90. dialogVisible.value = false
  91. }
  92. defineExpose({ open, isDetail })
  93. </script>
  94. <style lang="scss" scoped>
  95. .check-out {
  96. @media (max-width: 1200) {
  97. :deep(.el-form-item--default .el-form-item__label) {
  98. line-height: 0 !important;
  99. }
  100. }
  101. }
  102. </style>