organization.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { sendFetch, PageProps } from './index'
  2. import { ResPage, ResResult } from './type'
  3. import { organizationTypeEnum } from '@/store/organization'
  4. import * as URL from "./URL";
  5. import { ElMessage } from "element-plus";
  6. import { throttle, encodePwd } from "@/util";
  7. const error = throttle((msg: string) => ElMessage.error(msg), 2000);
  8. const success = throttle((msg: string) => ElMessage.success(msg), 2000);
  9. export type OrganizationType = {
  10. ancestors: string
  11. contact: string
  12. orderNum: number
  13. orgId: number
  14. parentId: number
  15. orgName: string
  16. password: string
  17. type: organizationTypeEnum | null
  18. userName: string
  19. confirmPwd?: string,
  20. msgAuthCode?: string
  21. cityId?: number
  22. areaId?: number
  23. provinceId?: number
  24. }
  25. export const addOrgFetch = async (params: Partial<OrganizationType>) => {
  26. const api = await sendFetch<ResResult>(URL.addOrganization, {
  27. method: "post",
  28. body: JSON.stringify(params),
  29. }, {
  30. useResult: true
  31. });
  32. if (api.code === 0) {
  33. success('添加成功')
  34. } else {
  35. if (api.code === 2008) {
  36. success(api.message)
  37. } else {
  38. error(api.message)
  39. throw (api.message)
  40. }
  41. }
  42. }
  43. export const alterOrgFetch = (params: Partial<OrganizationType>) =>
  44. sendFetch<PageProps<OrganizationType>>(URL.alterOrganization, {
  45. method: "post",
  46. body: JSON.stringify(params),
  47. });
  48. export const delOrgFetch = (params: Partial<OrganizationType>) =>
  49. sendFetch<PageProps<OrganizationType>>(URL.delOrganization, {
  50. method: "post",
  51. body: JSON.stringify(params),
  52. });
  53. export const getOrgListFetch = (params: PageProps<Partial<OrganizationType>>) =>
  54. sendFetch<ResPage<PageProps<OrganizationType>>>(URL.organizationPage, {
  55. method: "post",
  56. body: JSON.stringify(params),
  57. });
  58. export const getOrgListFetchList = () =>
  59. sendFetch<ResPage<PageProps<OrganizationType>>>(URL.organizationPageList, {
  60. method: "post",
  61. body: JSON.stringify({}),
  62. });
  63. export const registerOrganization = (params: any) => {
  64. const password = encodePwd(params.password)
  65. return sendFetch<ResResult>(URL.registerOrganization, {
  66. method: "post",
  67. body: JSON.stringify({ ...params, password, confirmPwd: password }),
  68. }, {
  69. noToken: true
  70. });
  71. }
  72. export const getProvinces = () => {
  73. return sendFetch<ResResult>(URL.getProvinces, {
  74. method: "get",
  75. });
  76. }
  77. export const getCities = (provinceCode: string) => {
  78. return sendFetch<ResResult>(URL.getCities + "?provinceCode=" + provinceCode, {
  79. method: "get",
  80. });
  81. }
  82. export const getAreas = (provinceCode: string, cityCode: string, zx?: boolean) => {
  83. const url = zx ? URL.getAreas + `?provinceCode=${provinceCode}&cityCode=${cityCode}` : URL.getAreas + `?provinceCode=${provinceCode}&cityCode=${cityCode}&zx=true`
  84. return sendFetch<ResResult>(url, {
  85. method: "get",
  86. });
  87. }