Files
hjc-web/server/api/tender/order.post.ts
T
weicw-dshsa cadb2b837f feat(order): 下单页新增发票类型选择
- BuyDocument.vue:购买页新增「发票类型」单选(VAT_SPECIAL 电子专票 / VAT_NORMAL 电子普票),
  必填,未选时拦在 $fetch 之前并点名提示「请选择发票类型」
- 预选值取企业档案的 invoiceType(走 /api/tender/enterprise,用 useRequestFetch 保证 SSR/CSR 一致);
  取不到或值不在枚举内则不预选,由提交那道兜住
- 建单 body 带上 invoiceType
- order.post.ts 本就把 readBody 结果整体透传给后端,未做字段白名单,无需改动;
  仅更新接口契约注释
2026-10-08 14:54:22 +08:00

42 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { $fetch } from 'ofetch'
import { createError, defineEventHandler, readBody, getHeader, getCookie } from 'h3'
import { useRuntimeConfig } from '#imports'
import { getTenantFromContext } from '../../utils/tenant'
/**
* 创建标书订单
* POST /api/tender/order { projectId, quantity, contactName, contactPhone, contactEmail, invoiceType }
* 代理到后端 /api/hjc/order/create;需登录态(从 cookie hjc_token 或 Authorization 透传)。
*
* `invoiceType`(VAT_SPECIAL 电子专票 / VAT_NORMAL 电子普票)由下单页必选;本代理
* **body 整体透传**(不做字段白名单/裁剪),校验在后端。
*
* 约定:原样透传 ApiResult{code,message,data},由前端按 code 判定
* (401 未登录/token 失效、403 无权限、其余为业务失败)。
*/
export default defineEventHandler(async (event) => {
const config = useRuntimeConfig()
const ctx = getTenantFromContext(event, config)
const body = await readBody(event)
const cookieToken = getCookie(event, 'hjc_token')
const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null)
try {
return await $fetch('/hjc/order/create', {
baseURL: config.public.modulesApiBase,
method: 'POST',
headers: {
TenantId: ctx.tenantId,
...(auth ? { Authorization: auth } : {})
},
query: { TenantId: ctx.tenantId },
body
})
} catch (error: any) {
throw createError({
statusCode: error?.statusCode || error?.response?.status || 502,
statusMessage: error?.statusMessage || 'Failed to create order'
})
}
})