organization.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import {
  2. addTreeitem,
  3. axios,
  4. delTreeitem,
  5. editTreeitem,
  6. getTreeselect,
  7. } from "@/request";
  8. export enum DeptType {
  9. corps = 1,
  10. detachment = 2,
  11. brigade = 3,
  12. }
  13. export type Organization = {
  14. ancestors: string;
  15. children?: Organization[];
  16. deptType: DeptType;
  17. id: string;
  18. leader: string;
  19. level: number;
  20. name: string;
  21. parentId: string;
  22. parentName: string;
  23. phone: string;
  24. remark: string;
  25. };
  26. export const getOrganizationTree = async (type?: string) =>
  27. (await axios.get<Organization[]>(getTreeselect, { params: { type } })).data;
  28. export const addOrganization = async (
  29. dept: Omit<Organization, "id">,
  30. deptIds: string[]
  31. ) => {
  32. await axios.post(addTreeitem, {
  33. superior: "sheq",
  34. ...dept,
  35. deptIdList: deptIds.join(","),
  36. });
  37. };
  38. export const setOrganization = async (
  39. dept: Organization,
  40. deptIds: string[]
  41. ) => {
  42. await axios.post(editTreeitem, {
  43. superior: "sheq",
  44. ...dept,
  45. deptIdList: deptIds.join(","),
  46. });
  47. };
  48. export const delOrganization = async (deptId: string) =>
  49. axios.post(delTreeitem + deptId);