ReportAnalysisCountEdit.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <script setup lang="ts">
  2. import type { PatientModel } from '@/model';
  3. import { patientAnalysisCountMethod, updatePatientAnalysisCountMethod } from '@/request/api/patient.api';
  4. import { useRequest, useWatcher } from 'alova/client';
  5. import { message as Message } from 'ant-design-vue/es/components';
  6. const props = defineProps<{
  7. patient: Partial<PatientModel>;
  8. }>();
  9. const emits = defineEmits<{
  10. destroy: [];
  11. }>();
  12. const patientId = computed(() => props.patient?.id);
  13. const model = reactive({
  14. total: 0,
  15. count: 0,
  16. })
  17. const { loading } = useWatcher(
  18. () => patientAnalysisCountMethod(patientId.value!),
  19. [ () => props.patient?.id ],
  20. {
  21. initialData: {}, immediate: true,
  22. middleware: (_, next) => { if ( patientId.value ) next(); },
  23. },
  24. ).onSuccess(({data})=>{
  25. model.total = data.total;
  26. model.count = data.count;
  27. });
  28. const { loading: updating, send: updata } = useRequest(
  29. () => updatePatientAnalysisCountMethod(patientId.value!, model.count),
  30. { immediate: false },
  31. ).onSuccess(() => {
  32. Message.success(`充值成功`);
  33. emits('destroy');
  34. });
  35. </script>
  36. <template>
  37. <div id="page-container-scroller" class="page-container flex flex-col">
  38. <a-spin :spinning="loading">
  39. <a-descriptions bordered :column="1">
  40. <a-descriptions-item label="姓名">{{ props.patient.name }}</a-descriptions-item>
  41. <a-descriptions-item label="健康分析次数">
  42. <a-form
  43. ref="formRef" :model="model" :label-col="{span: 12}"
  44. @finish="updata()"
  45. >
  46. <a-form-item label="已用次数">{{ model.total }}</a-form-item>
  47. <a-form-item label="剩余次数" name="count" :rules="[{ required: true, message: '请输入剩余次数' }]">
  48. <a-input-number :min="0" :max="100" v-model:value="model.count" />
  49. </a-form-item>
  50. <a-form-item>
  51. <a-space>
  52. <a-button type="primary" html-type="submit" :loading="updating">保存</a-button>
  53. <a-button type="default" @click="emits('destroy')">取消</a-button>
  54. </a-space>
  55. </a-form-item>
  56. </a-form>
  57. </a-descriptions-item>
  58. </a-descriptions>
  59. </a-spin>
  60. </div>
  61. </template>
  62. <style scoped lang="scss">
  63. @import "@/themes/report-card";
  64. </style>