bx.js 5.0 KB

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