MedicalPatientEdit.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <script setup lang="ts">
  2. import type { MedicalData, MedicalString } from '@/request/model/medical-record.model';
  3. import type { RegisterModel } from '@/request/model';
  4. import type RegisterForm from '@/components/RegisterForm.vue';
  5. import { Notify } from '@/platform';
  6. import { useRequest } from 'alova/client';
  7. import { editMedicalRecordMethod } from '@/request/api/medical.api';
  8. import { getMedicalReportData } from '@/request/model/medical-record.model';
  9. import { updateMedicalPatient } from '@/request/model/medical-patient.model';
  10. const props = defineProps<Partial<MedicalString>>();
  11. const emits = defineEmits<{
  12. complete: [MedicalString];
  13. cancel: [];
  14. }>();
  15. const {
  16. data: form,
  17. loading: submitting,
  18. send: submit,
  19. } = useRequest(editMedicalRecordMethod, { initialData: { ...props }, immediate: false }).onSuccess(({ data }) => emits('complete', data));
  20. const formRef = ref<InstanceType<typeof RegisterForm> | null>(null);
  21. const report = computed(() => {
  22. try {
  23. return getMedicalReportData(props.report ?? '');
  24. } catch (e: any) {
  25. Notify.error(e.message);
  26. emits('cancel');
  27. }
  28. });
  29. watch(
  30. () => report.value?.patient,
  31. (value) => {
  32. if (!value) return;
  33. nextTick(() => formRef.value?.setValues(value));
  34. },
  35. { immediate: true, flush: 'post' }
  36. );
  37. function onSubmitFromForm(payload: { model: RegisterModel; modelLabel: Partial<RegisterModel> }) {
  38. submit(updateMedicalPatient(form.value, payload));
  39. }
  40. </script>
  41. <template>
  42. <div class="p-6" style="height: calc(100vh - 30px)">
  43. <RegisterForm ref="formRef" :search-forbidden-field="false" @submit="onSubmitFromForm" />
  44. <van-loading class="flex justify-center" v-if="formRef?.loading" type="spinner" size="64" color="#38ff6e" />
  45. <div v-else class="flex gap-4 mb-6 px-4 py-3">
  46. <van-button block type="primary" plain :disabled="submitting" @click="emits('cancel')">取消</van-button>
  47. <van-button block type="primary" :loading="submitting" @click="formRef?.submit()">保存</van-button>
  48. </div>
  49. </div>
  50. </template>
  51. <style scoped lang="scss"></style>