diff --git a/miniprogram/api/bx.js b/miniprogram/api/bx.js index 04e9d1c74..cf4aaa182 100644 --- a/miniprogram/api/bx.js +++ b/miniprogram/api/bx.js @@ -1,191 +1,38 @@ -/** - * 报销模块 API(REST,协议 code===0 / msg / data.rows) - * 路径挂在 /api 下:/reimburses、/advances、/expense-items、/attachments - */ -import { request, parseResponseJson } from '@/utils/request' +import { bxRequest, bxUploadFile } from '@/utils/bxRequest' -function unwrap(res) { - const body = parseResponseJson(res) - if (!body || typeof body !== 'object') { - throw new Error('接口响应异常') - } - if (body.code != null && body.code !== 0) { - throw new Error(body.msg || body.message || '请求失败') - } - return body.data != null ? body.data : body +export const advanceApi = { + 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' }), + delete: (id) => bxRequest({ url: `/advances/${id}`, method: 'DELETE' }) } -async function get(url, params = {}) { - const res = await request({ url, method: 'GET', data: params, params }) - return unwrap(res) +/** 附件:Batch2 申请页图片上传所需最小集合 */ +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 + } + }) } -async function post(url, data = {}) { - const res = await request({ url, method: 'POST', data }) - return unwrap(res) -} - -async function put(url, data = {}, params = {}) { - const res = await request({ url, method: 'PUT', data, params }) - return unwrap(res) -} - -function pageParams(query = {}) { - const { pageNum, page, pageSize, ...rest } = query - const params = { - page: pageNum ?? page ?? 1, - pageSize: pageSize ?? 20 - } - Object.keys(rest).forEach((k) => { - if (rest[k] != null && rest[k] !== '') params[k] = rest[k] - }) - return params -} - -function normalizeList(data) { - if (Array.isArray(data)) return { rows: data, total: data.length } - const d = data || {} - return { - rows: d.rows || d.list || [], - total: d.total ?? 0 - } -} - -// ── 费用项目 ── - -export async function getExpenseItemTree() { - const data = await get('/expense-items/tree') - return Array.isArray(data) ? data : [] -} - -/** 展平可选叶子费用项目(供 picker) */ -export function flattenExpenseLeaves(tree, path = []) { - const out = [] - ;(tree || []).forEach((node) => { - const name = node.itemName || node.item_name || '' - const nextPath = path.concat(name) - const children = node.children || [] - if (children.length) { - out.push(...flattenExpenseLeaves(children, nextPath)) - } else { - out.push({ - id: String(node.id), - name, - pathLabel: nextPath.join(' / ') - }) - } - }) - return out -} - -// ── 报销 ── - -export async function listMyReimburse(query = {}) { - return normalizeList(await get('/reimburses/my', pageParams(query))) -} - -export async function listPendingReimburse(query = {}) { - return normalizeList(await get('/reimburses/pending-approval', pageParams(query))) -} - -export async function listApprovedByMeReimburse(query = {}) { - return normalizeList(await get('/reimburses/approved-by-me', pageParams(query))) -} - -export async function getReimburse(id) { - return get(`/reimburses/${String(id)}`) -} - -export async function generateReimburseTitle(reimburseDate) { - const params = {} - if (reimburseDate) params.reimburseDate = reimburseDate - return get('/reimburses/generate-title', params) -} - -export function createReimburse(data) { - return post('/reimburses/', data) -} - -export function updateReimburse(id, data) { - return put(`/reimburses/${String(id)}`, data) -} - -export function submitReimburse(id) { - return post(`/reimburses/${String(id)}/submit`) -} - -export function approveReimburse(id, approvalOpinion = '') { - return post(`/reimburses/${String(id)}/approve`, { approvalOpinion }) -} - -export function rejectReimburse(id, approvalOpinion = '') { - return post(`/reimburses/${String(id)}/reject`, { approvalOpinion }) -} - -export async function getReimburseApprovalHistory(id) { - const data = await get(`/reimburses/${String(id)}/approval-history`) - return Array.isArray(data) ? data : [] -} - -// ── 借款(备用金) ── - -export async function listMyAdvance(query = {}) { - return normalizeList(await get('/advances/my', pageParams(query))) -} - -export async function listPendingAdvance(query = {}) { - return normalizeList(await get('/advances/pending-approval', pageParams(query))) -} - -export async function listApprovedByMeAdvance(query = {}) { - return normalizeList(await get('/advances/approved-by-me', pageParams(query))) -} - -export async function getAdvance(id) { - return get(`/advances/${String(id)}`) -} - -export function createAdvance(data) { - return post('/advances/', data) -} - -export function submitAdvance(id) { - return post(`/advances/${String(id)}/submit`) -} - -export function approveAdvance(id, approvalOpinion = '') { - return post(`/advances/${String(id)}/approve`, { approvalOpinion }) -} - -export function rejectAdvance(id, approvalOpinion = '') { - return post(`/advances/${String(id)}/reject`, { approvalOpinion }) -} - -export async function getAdvanceApprovalHistory(id) { - const data = await get(`/advances/${String(id)}/approval-history`) - return Array.isArray(data) ? data : [] -} - -// ── 附件 ── - -export async function listAttachments(bizType, bizId) { - const data = await get('/attachments/list', { - biz_type: bizType, - biz_id: String(bizId) - }) - return Array.isArray(data) ? data : [] -} - -export async function bindAttachments(ids, bizType, bizId) { - if (!ids?.length) return 0 - const q = [ - `ids=${encodeURIComponent(ids.map(String).join(','))}`, - `biz_type=${encodeURIComponent(bizType)}`, - `biz_id=${encodeURIComponent(String(bizId))}` - ].join('&') - return put(`/attachments/bind-biz?${q}`, {}) -} - -export async function previewAttachment(id) { - return get(`/attachments/preview/${String(id)}`) -} +export default { advanceApi, attachmentApi } diff --git a/miniprogram/config/api.js b/miniprogram/config/api.js index 89a4e7728..e16fcfb98 100644 --- a/miniprogram/config/api.js +++ b/miniprogram/config/api.js @@ -50,6 +50,8 @@ export const PAGE_PATHS = { dbWeighingList: '/pages/db/weighing/list', dbWeighingDetail: '/pages/db/weighing/detail', bxAdvanceApply: '/pages/bx/advance/list', + bxAdvanceApplyForm: '/pages/bx/advance/apply', + bxAdvanceDetail: '/pages/bx/advance/detail', bxReimburseApply: '/pages/bx/reimburse/list', bxMine: '/pages/bx/mine/list', bxAll: '/pages/bx/all/list', diff --git a/miniprogram/pages.json b/miniprogram/pages.json index 1472aba61..b86cbbe3f 100644 --- a/miniprogram/pages.json +++ b/miniprogram/pages.json @@ -84,6 +84,14 @@ "path": "pages/bx/advance/list", "style": { "navigationStyle": "custom", "navigationBarTitleText": "备用金申请" } }, + { + "path": "pages/bx/advance/apply", + "style": { "navigationStyle": "custom", "navigationBarTitleText": "备用金申请" } + }, + { + "path": "pages/bx/advance/detail", + "style": { "navigationStyle": "custom", "navigationBarTitleText": "备用金详情" } + }, { "path": "pages/bx/reimburse/list", "style": { "navigationStyle": "custom", "navigationBarTitleText": "报销申请" } diff --git a/miniprogram/pages/bx/advance/apply.vue b/miniprogram/pages/bx/advance/apply.vue new file mode 100644 index 000000000..7abc4a1b0 --- /dev/null +++ b/miniprogram/pages/bx/advance/apply.vue @@ -0,0 +1,326 @@ +