request.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { Get, Post } from "../../lib/request/method";
  2. const ref = ['province', 'city', 'area'] as const;
  3. const ref2 = ['womenSpecialPeriod', 'foodAllergy', 'hobbyFlavor', 'job'] as const;
  4. function to(params: App.Patient.Model) {
  5. const { address, ..._data } = params;
  6. const data: Record<string, any> = {}
  7. if (Array.isArray(address)) {
  8. address.forEach(({ name, code }, index) => {
  9. const key = ref[index];
  10. data[`${key}Name`] = name
  11. data[`${key}Code`] = code
  12. })
  13. }
  14. for (const key of ref2) {
  15. if (Array.isArray(_data[key])) _data[key] = _data[key]?.map(item => item?.value || item).join(',') as any;
  16. }
  17. return { ..._data, ...data, }
  18. }
  19. function from(params: Record<string, any>) {
  20. const address = [];
  21. for (const key of ref) {
  22. const name = params[`${key}Name`];
  23. const code = params[`${key}Code`];
  24. if (name && code) {
  25. address[address.length] = { name, code };
  26. delete params[`${key}Name`];
  27. delete params[`${key}Code`];
  28. } else {
  29. break;
  30. }
  31. }
  32. for (const key of ref2) {
  33. if (typeof params[key] === 'string' && params[key]) params[key] = params[key].split(',')
  34. }
  35. return { ...params, address } as App.Patient.Model
  36. }
  37. export function getUserInfoMethod() {
  38. return Post(`/patientInfoManage/getPatientInfoDetail`, {}, {
  39. transform({ data }) {
  40. return from(<any>data)
  41. }
  42. })
  43. }
  44. export function createUserInfoMethod(data: App.Patient.Model) {
  45. return Post(`/patientInfoManage/savePatientInfo`, { ...to(data), mobileAccountId: 0, }, {
  46. transform({ data }) { return { patientId: data } }
  47. });
  48. }
  49. export async function updateUserInfoMethod(data: App.Patient.Model) {
  50. const result = await Post(`/patientInfoManage/updatePatientInfo`, to(data));
  51. }
  52. export function verifyCardnoMethod(value: string) {
  53. return Get(`/patientInfoManage/isExistCardno`, { params: { cardno: value }, transform({ data }) { return data } })
  54. }