bx.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { bxRequest, bxUploadFile, bxUploadInvoice } from '@/utils/bxRequest'
  2. import { request, parseResponseJson } from '@/utils/request'
  3. export const advanceApi = {
  4. list: (params) => bxRequest({ url: '/advances/', method: 'GET', params }),
  5. my: (params) => bxRequest({ url: '/advances/my', method: 'GET', params }),
  6. getById: (id) => bxRequest({ url: `/advances/${id}`, method: 'GET' }),
  7. getApprovals: (id) => bxRequest({ url: `/advances/${id}/approvals`, method: 'GET' }),
  8. getApprovalHistory: (id) => bxRequest({ url: `/advances/${id}/approval-history`, method: 'GET' }),
  9. create: (data) => bxRequest({ url: '/advances/', method: 'POST', data }),
  10. update: (id, data) => bxRequest({ url: `/advances/${id}`, method: 'PUT', data }),
  11. submit: (id) => bxRequest({ url: `/advances/${id}/submit`, method: 'POST' }),
  12. delete: (id) => bxRequest({ url: `/advances/${id}`, method: 'DELETE' })
  13. }
  14. export const reimburseApi = {
  15. generateTitle: (params) =>
  16. bxRequest({ url: '/reimburses/generate-title', method: 'GET', params }),
  17. list: (params) => bxRequest({ url: '/reimburses/', method: 'GET', params }),
  18. my: (params) => bxRequest({ url: '/reimburses/my', method: 'GET', params }),
  19. getById: (id) => bxRequest({ url: `/reimburses/${id}`, method: 'GET' }),
  20. getApprovals: (id) => bxRequest({ url: `/reimburses/${id}/approvals`, method: 'GET' }),
  21. getApprovalHistory: (id) =>
  22. bxRequest({ url: `/reimburses/${id}/approval-history`, method: 'GET' }),
  23. create: (data) => bxRequest({ url: '/reimburses/', method: 'POST', data }),
  24. update: (id, data) => bxRequest({ url: `/reimburses/${id}`, method: 'PUT', data }),
  25. submit: (id, data) =>
  26. bxRequest({ url: `/reimburses/${id}/submit`, method: 'POST', data }),
  27. delete: (id) => bxRequest({ url: `/reimburses/${id}`, method: 'DELETE' })
  28. }
  29. export const expenseItemApi = {
  30. tree: () => bxRequest({ url: '/expense-items/tree', method: 'GET' }),
  31. create: (data) => bxRequest({ url: '/expense-items/', method: 'POST', data }),
  32. update: (id, data) => bxRequest({ url: `/expense-items/${id}`, method: 'PUT', data }),
  33. delete: (id) => bxRequest({ url: `/expense-items/${id}`, method: 'DELETE' })
  34. }
  35. export const workflowApi = {
  36. getByBizType: (bizType) =>
  37. bxRequest({ url: `/workflows/biz/${bizType}`, method: 'GET' }),
  38. create: (data) => bxRequest({ url: '/workflows/', method: 'POST', data }),
  39. update: (id, data) => bxRequest({ url: `/workflows/${id}`, method: 'PUT', data }),
  40. saveNodes: (id, nodes) =>
  41. bxRequest({ url: `/workflows/${id}/nodes`, method: 'PUT', data: nodes }),
  42. delete: (id) => bxRequest({ url: `/workflows/${id}`, method: 'DELETE' })
  43. }
  44. /**
  45. * 门户用户下拉(code===200 信封,非 bx code===0)
  46. * 对齐 bx-mobile portalAdminApi.userOptions → GET /web/admin/users/options
  47. */
  48. export async function fetchPortalUserOptions() {
  49. const res = await request({
  50. url: '/web/admin/users/options',
  51. method: 'GET'
  52. })
  53. const result = parseResponseJson(res)
  54. if (result && typeof result === 'object' && 'code' in result) {
  55. if (result.code === 200 || result.code === 0) {
  56. const data = result.data !== undefined ? result.data : result
  57. return Array.isArray(data) ? data : []
  58. }
  59. const msg = result.message || result.msg || '加载用户失败'
  60. throw new Error(msg)
  61. }
  62. return Array.isArray(result) ? result : []
  63. }
  64. export const invoiceWalletApi = {
  65. mineSummary: (params) =>
  66. bxRequest({ url: '/invoice-wallets/mine/summary', method: 'GET', params }),
  67. list: (params) => bxRequest({ url: '/invoice-wallets', method: 'GET', params })
  68. }
  69. export const invoiceApi = {
  70. list: (params) => bxRequest({ url: '/invoices', method: 'GET', params }),
  71. /**
  72. * 上传发票(multipart)。uni-app 用 uni.uploadFile,单次一张图。
  73. * @param {{ amount: number|string, remark?: string, filePath: string, targetUserId?: string|number }} opts
  74. */
  75. upload: (opts) => bxUploadInvoice(opts),
  76. delete: (id) => bxRequest({ url: `/invoices/${id}`, method: 'DELETE' }),
  77. ledgers: (params) => bxRequest({ url: '/invoice-ledgers', method: 'GET', params })
  78. }
  79. /** 附件:申请页图片上传所需最小集合 */
  80. export const attachmentApi = {
  81. upload: (filePath, bizType = '', bizId = 0) =>
  82. bxUploadFile(filePath, { bizType, bizId }),
  83. listByBiz: (bizType, bizId) =>
  84. bxRequest({
  85. url: '/attachments/list',
  86. method: 'GET',
  87. params: { biz_type: bizType, biz_id: bizId }
  88. }),
  89. preview: (id) => bxRequest({ url: `/attachments/preview/${id}`, method: 'GET' }),
  90. delete: (id) => bxRequest({ url: `/attachments/${id}`, method: 'DELETE' }),
  91. bindBiz: (ids, bizType, bizId) =>
  92. bxRequest({
  93. url: '/attachments/bind-biz',
  94. method: 'PUT',
  95. params: {
  96. ids: (ids || []).join(','),
  97. biz_type: bizType,
  98. biz_id: bizId
  99. }
  100. })
  101. }
  102. export default {
  103. advanceApi,
  104. reimburseApi,
  105. expenseItemApi,
  106. workflowApi,
  107. invoiceWalletApi,
  108. invoiceApi,
  109. attachmentApi,
  110. fetchPortalUserOptions
  111. }