import { cacheFor } from '@/request/api/index'; import type { Dictionaries, Fields, RegisterModel } from '@/request/model'; import { fromRegisterFields, getPath} from '@/request/model'; import { useVisitor } from '@/stores'; import HTTP from '../alova'; export function getCaptchaMethod(mobile: string) { return HTTP.Get(`/fdhb-tablet/sms/sendVerCode`, { params: { phone: mobile }, }); } export function registerFieldsMethod(dictionaries?: Dictionaries) { return HTTP.Post(`/fdhb-tablet/warrantManage/getPageSets`, void 0, { cacheFor, name: `variate:register_fields`, params: { k: 'register_fields' }, transform(data, headers) { const options = data?.tabletFileFields ?? []; return fromRegisterFields(options, dictionaries); }, }); } export function registerVisitorMethod() { return HTTP.Get(`/fdhb-tablet/patientInfoManage/createTourist`, { name: 'register', cacheFor: null, }) } export function registerAccountMethod(params: Partial) { return HTTP.Post(`/fdhb-tablet/patientInfoManage/savePatientInfo`, params, { name: 'register', transform(data) { const Visitor = useVisitor(); Visitor.patientId = data; return data; }, }); } export function searchAccountMethod(params: Partial) { return HTTP.Get(`/fdhb-tablet/patientInfoManage/getPatientInfoDetail`, { hitSource: 'register', params, transform(data: Record, headers) { return Object.fromEntries(Object.entries(data).filter(([ item, value ]) => !!value)) as Partial; }, }); } export function scanAccountMethod(key: string) { return HTTP.Get(`/fdhb-tablet/patientInfoManage/getPatInfoByScanCode`, { hitSource: 'register', params: { scanCode: key }, transform(data: Record, headers) { const { id: patientId, processModule, ..._data } = data; if ( patientId ) useVisitor().patientId = patientId; return { key, patientId, path: getPath(processModule), model: Object.fromEntries(Object.entries(_data).filter(([ item, value ]) => !!value)) as Partial, }; }, }); } export function dictionariesMethod() { return HTTP.Get(`/fdhb-tablet/dict/getDicts`, { cacheFor, name: `variate:dict`, transform(data) { if (!Array.isArray(data)) return void 0; const dictionaries: Dictionaries = new Map(); for (const { dictType, items } of data) dictionaries.set(dictType, items.map((item: any) => ({label: item.dictLabel, value: item.dictValue }))); return dictionaries.size ? dictionaries : void 0; }, }); }