account.api.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { cacheFor } from '@/request/api/index';
  2. import type { Dictionaries, Fields, RegisterModel } from '@/request/model';
  3. import { fromRegisterFields, getPath} from '@/request/model';
  4. import { useVisitor } from '@/stores';
  5. import HTTP from '../alova';
  6. export function getCaptchaMethod(mobile: string) {
  7. return HTTP.Get<string>(`/fdhb-tablet/sms/sendVerCode`, {
  8. params: { phone: mobile },
  9. });
  10. }
  11. export function registerFieldsMethod(dictionaries?: Dictionaries) {
  12. return HTTP.Post<Fields, { tabletFileFields: string[] }>(`/fdhb-tablet/warrantManage/getPageSets`, void 0, {
  13. cacheFor, name: `variate:register_fields`,
  14. params: { k: 'register_fields' },
  15. transform(data, headers) {
  16. const options = data?.tabletFileFields ?? [];
  17. return fromRegisterFields(options, dictionaries);
  18. },
  19. });
  20. }
  21. export function registerVisitorMethod() {
  22. return HTTP.Get<string, string>(`/fdhb-tablet/patientInfoManage/createTourist`, {
  23. name: 'register',
  24. cacheFor: null,
  25. })
  26. }
  27. export function registerAccountMethod(params: Partial<RegisterModel>) {
  28. return HTTP.Post<string, string>(`/fdhb-tablet/patientInfoManage/savePatientInfo`, params, {
  29. name: 'register',
  30. transform(data) {
  31. const Visitor = useVisitor();
  32. Visitor.patientId = data;
  33. return data;
  34. },
  35. });
  36. }
  37. export function searchAccountMethod(params: Partial<RegisterModel>) {
  38. return HTTP.Get(`/fdhb-tablet/patientInfoManage/getPatientInfoDetail`, {
  39. hitSource: 'register',
  40. params,
  41. transform(data: Record<string, any>, headers) {
  42. return Object.fromEntries(Object.entries(data).filter(([ item, value ]) => !!value)) as Partial<RegisterModel>;
  43. },
  44. });
  45. }
  46. export function scanAccountMethod(key: string) {
  47. return HTTP.Get(`/fdhb-tablet/patientInfoManage/getPatInfoByScanCode`, {
  48. hitSource: 'register',
  49. params: { scanCode: key },
  50. transform(data: Record<string, any>, headers) {
  51. const { id: patientId, processModule, ..._data } = data;
  52. if ( patientId ) useVisitor().patientId = patientId;
  53. return {
  54. key, patientId, path: getPath(processModule),
  55. model: Object.fromEntries(Object.entries(_data).filter(([ item, value ]) => !!value)) as Partial<RegisterModel>,
  56. };
  57. },
  58. });
  59. }
  60. export function dictionariesMethod() {
  61. return HTTP.Get<Dictionaries | void, any>(`/fdhb-tablet/dict/getDicts`, {
  62. cacheFor, name: `variate:dict`,
  63. transform(data) {
  64. if (!Array.isArray(data)) return void 0;
  65. const dictionaries: Dictionaries = new Map();
  66. for (const { dictType, items } of data) dictionaries.set(dictType, items.map((item: any) => ({label: item.dictLabel, value: item.dictValue })));
  67. return dictionaries.size ? dictionaries : void 0;
  68. },
  69. });
  70. }