Эх сурвалжийг харах

建档通过获取患者信息,若字段有值则禁用

cc12458 4 сар өмнө
parent
commit
07af8fc545

+ 31 - 7
src/pages/register.page.vue

@@ -31,15 +31,18 @@ const { loading: submitting, send: submit } = useRequest(registerAccountMethod,
   flow.router.push();
 });
 
+const forbiddenFields = shallowRef<Record<string, boolean>>({});
 const { loading: searching, send: search } = useRequest((data) => searchAccountMethod(data), {
   immediate: false,
 }).onSuccess(({ data }) => {
   if (!fields.value.some(field => field.name === 'phone')) Reflect.deleteProperty(data, 'phone');
   const modelLabel = {} as Record<string, any>;
   const modelValue = {} as Record<string, any>;
+  const forbidden = {} as Record<string, boolean>;
 
   for (const [key, value] of Object.entries(data)) {
     const field = fields.value?.find((field) => field.name === key);
+    if (field) forbidden[key] = !!value && !['phone', 'cardno'].includes(key);
     if (typeof value === 'string' && field?.component?.name === 'picker') {
       const result = value.split(',').map((value) => {
         const [v, l] = value.split(':');
@@ -47,11 +50,14 @@ const { loading: searching, send: search } = useRequest((data) => searchAccountM
       });
       modelValue[key] = result.map((t) => t.value).join(',');
       modelLabel[key] = result.map((t) => t.label).join(',');
+    } else if (typeof value === 'object' && field?.component?.name === 'cascader') {
+      modelLabel[key] = value.map((option) => option.label).join(' / ');
+      modelValue[key] = value;
     } else {
       modelLabel[key] = value;
     }
   }
-
+  forbiddenFields.value = forbidden;
   modelRef.value = { ...modelRef.value, ...modelLabel };
   modelValueRef.value = { ...modelValueRef.value, ...modelValue };
 });
@@ -77,10 +83,18 @@ const getCaptchaHandle = async () => {
 };
 
 const searchHandle = async (key: 'cardno' | 'code') => {
+  const forbidden = { cardno: 'phone', code: 'cardno' }[key];
   try {
     await formRef.value?.validate(key);
-    await search(modelRef.value).catch();
-  } catch ( e: any ) {
+    forbiddenFields.value = {};
+    const { cardno, phone, code } = modelRef.value;
+    await search({ cardno, phone, code })
+      .then((data) => {
+        forbiddenFields.value[forbidden] = !!(data as any)[forbidden];
+        triggerRef(forbiddenFields);
+      })
+      .catch();
+  } catch (e: any) {
     Toast.warning(e?.message);
   }
 };
@@ -145,6 +159,7 @@ const cascaderProps = reactive({
   },
 });
 function onFieldFocus(field: any) {
+  if (forbiddenFields.value[field.name]) return;
   if (field.keyboard) {
     keyboardProps.key = field.name;
     keyboardProps.show = true;
@@ -204,8 +219,8 @@ function onFieldBlur(field: any) {
     <div class="page-header flex py-4 px-4 overflow-hidden">
       <div class="grow shrink-0 h-full min-w-16"></div>
       <div class="grow-[3] shrink mx-2 flex flex-col justify-center overflow-hidden">
-        <div class="font-bold text-3xl text-nowrap text-center tracking-wide overflow-ellipsis overflow-hidden">
-          建档
+        <div class="flex justify-center font-bold text-3xl text-nowrap text-center tracking-wide overflow-ellipsis overflow-hidden">
+          建档 <van-loading v-if="searching" style="margin-left: 4px; color: #38ff6e;"></van-loading>
         </div>
       </div>
       <div class="grow shrink-0 h-full min-w-16 flex items-center justify-end overflow-hidden">
@@ -227,9 +242,10 @@ function onFieldBlur(field: any) {
                          :class="{'no-border': field.control?.border === false}"
                          @focus="onFieldFocus(field)" @blur="onFieldBlur(field)"
                          :readonly="field.control?.readonly" @click="onFieldFocus(field)"
+                         :disabled="forbiddenFields[field.name]"
               >
                 <template #input v-if="field.component?.name === 'radio'">
-                  <van-radio-group v-model="modelRef[field.name]" direction="horizontal" shape="dot">
+                  <van-radio-group v-model="modelRef[field.name]" direction="horizontal" shape="dot" :disabled="forbiddenFields[field.name]">
                     <van-radio v-for="option in field.component?.options" :key="option.value" :name="option.value">
                       {{ option.label }}
                     </van-radio>
@@ -285,6 +301,14 @@ function onFieldBlur(field: any) {
     }
   }
 
+  :deep(.van-field--disabled) {
+    --tw-text-opacity: 0.5;
+    --van-radio-checked-icon-color: rgba(56, 255, 110, var(--tw-text-opacity, 1));
+    .text-primary {
+      --tw-text-opacity: 0.5;
+    }
+  }
+
   :deep(.van-field__label) {
     margin-bottom: 24px;
     padding: 8px 0;
@@ -295,7 +319,7 @@ function onFieldBlur(field: any) {
   :deep(.van-field__control) {
     margin-bottom: 24px;
     padding: 8px;
-    border: 1px solid #38ff6e;
+    border: 1px solid var(--van-radio-checked-icon-color);
     border-radius: 8px;
     text-align: center;
   }

+ 9 - 1
src/request/api/account.api.ts

@@ -55,7 +55,15 @@ export function searchAccountMethod(params: Partial<RegisterModel>) {
     hitSource: 'register',
     params,
     transform(data: Record<string, any>, headers) {
-      return Object.fromEntries(Object.entries(data).filter(([ item, value ]) => !!value)) as Partial<RegisterModel>;
+      if (data) data.address = [];
+      const address = ['province', 'city', 'area'];
+      for (const key of address) {
+        const code = data?.[`${key}Code`];
+        const name = data?.[`${key}Name`];
+        if (name && code) data.address.push({ label: name, value: key === 'province' ? code.slice(0, 2) : code.padEnd(12, '0') });
+        else try { delete data.address; } catch {}
+      }
+      return Object.fromEntries(Object.entries(data).filter(([item, value]) => !!value)) as Partial<RegisterModel>;
     },
   });
 }