import { bxRequest, bxUploadFile, bxUploadInvoice } from '@/utils/bxRequest' import { request, parseResponseJson } from '@/utils/request' export const advanceApi = { list: (params) => bxRequest({ url: '/advances/', method: 'GET', params }), my: (params) => bxRequest({ url: '/advances/my', method: 'GET', params }), getById: (id) => bxRequest({ url: `/advances/${id}`, method: 'GET' }), getApprovals: (id) => bxRequest({ url: `/advances/${id}/approvals`, method: 'GET' }), getApprovalHistory: (id) => bxRequest({ url: `/advances/${id}/approval-history`, method: 'GET' }), create: (data) => bxRequest({ url: '/advances/', method: 'POST', data }), update: (id, data) => bxRequest({ url: `/advances/${id}`, method: 'PUT', data }), submit: (id) => bxRequest({ url: `/advances/${id}/submit`, method: 'POST' }), withdraw: (id) => bxRequest({ url: `/advances/${id}/withdraw`, method: 'POST' }), delete: (id) => bxRequest({ url: `/advances/${id}`, method: 'DELETE' }) } export const reimburseApi = { generateTitle: (params) => bxRequest({ url: '/reimburses/generate-title', method: 'GET', params }), list: (params) => bxRequest({ url: '/reimburses/', method: 'GET', params }), my: (params) => bxRequest({ url: '/reimburses/my', method: 'GET', params }), getById: (id) => bxRequest({ url: `/reimburses/${id}`, method: 'GET' }), getApprovals: (id) => bxRequest({ url: `/reimburses/${id}/approvals`, method: 'GET' }), getApprovalHistory: (id) => bxRequest({ url: `/reimburses/${id}/approval-history`, method: 'GET' }), create: (data) => bxRequest({ url: '/reimburses/', method: 'POST', data }), update: (id, data) => bxRequest({ url: `/reimburses/${id}`, method: 'PUT', data }), submit: (id, data) => bxRequest({ url: `/reimburses/${id}/submit`, method: 'POST', data }), withdraw: (id) => bxRequest({ url: `/reimburses/${id}/withdraw`, method: 'POST' }), delete: (id) => bxRequest({ url: `/reimburses/${id}`, method: 'DELETE' }) } export const expenseItemApi = { tree: () => bxRequest({ url: '/expense-items/tree', method: 'GET' }), create: (data) => bxRequest({ url: '/expense-items/', method: 'POST', data }), update: (id, data) => bxRequest({ url: `/expense-items/${id}`, method: 'PUT', data }), delete: (id) => bxRequest({ url: `/expense-items/${id}`, method: 'DELETE' }) } export const workflowApi = { getByBizType: (bizType) => bxRequest({ url: `/workflows/biz/${bizType}`, method: 'GET' }), create: (data) => bxRequest({ url: '/workflows/', method: 'POST', data }), update: (id, data) => bxRequest({ url: `/workflows/${id}`, method: 'PUT', data }), saveNodes: (id, nodes) => bxRequest({ url: `/workflows/${id}/nodes`, method: 'PUT', data: nodes }), delete: (id) => bxRequest({ url: `/workflows/${id}`, method: 'DELETE' }) } /** * 门户用户下拉(code===200 信封,非 bx code===0) * 对齐 bx-mobile portalAdminApi.userOptions → GET /web/admin/users/options */ export async function fetchPortalUserOptions() { const res = await request({ url: '/web/admin/users/options', method: 'GET' }) const result = parseResponseJson(res) if (result && typeof result === 'object' && 'code' in result) { if (result.code === 200 || result.code === 0) { const data = result.data !== undefined ? result.data : result return Array.isArray(data) ? data : [] } const msg = result.message || result.msg || '加载用户失败' throw new Error(msg) } return Array.isArray(result) ? result : [] } export const invoiceWalletApi = { mineSummary: (params) => bxRequest({ url: '/invoice-wallets/mine/summary', method: 'GET', params }), list: (params) => bxRequest({ url: '/invoice-wallets', method: 'GET', params }) } export const invoiceApi = { list: (params) => bxRequest({ url: '/invoices', method: 'GET', params }), /** * 上传发票(multipart)。uni-app 用 uni.uploadFile,单次一张图。 * @param {{ amount: number|string, remark?: string, filePath: string, targetUserId?: string|number }} opts */ upload: (opts) => bxUploadInvoice(opts), delete: (id) => bxRequest({ url: `/invoices/${id}`, method: 'DELETE' }), ledgers: (params) => bxRequest({ url: '/invoice-ledgers', method: 'GET', params }) } /** 附件:申请页图片上传所需最小集合 */ export const attachmentApi = { upload: (filePath, bizType = '', bizId = 0) => bxUploadFile(filePath, { bizType, bizId }), listByBiz: (bizType, bizId) => bxRequest({ url: '/attachments/list', method: 'GET', params: { biz_type: bizType, biz_id: bizId } }), preview: (id) => bxRequest({ url: `/attachments/preview/${id}`, method: 'GET' }), delete: (id) => bxRequest({ url: `/attachments/${id}`, method: 'DELETE' }), bindBiz: (ids, bizType, bizId) => bxRequest({ url: '/attachments/bind-biz', method: 'PUT', params: { ids: (ids || []).join(','), biz_type: bizType, biz_id: bizId } }) } export default { advanceApi, reimburseApi, expenseItemApi, workflowApi, invoiceWalletApi, invoiceApi, attachmentApi, fetchPortalUserOptions }