102 lines
2.6 KiB
TypeScript
102 lines
2.6 KiB
TypeScript
//
|
|
import service, { request } from '@/utils/request'
|
|
import type { ApiResponse } from '@/types/api'
|
|
import type {
|
|
Demand,
|
|
DemandDraftVo,
|
|
DictOption,
|
|
OssUploadVo,
|
|
OssUrlVo,
|
|
SubmissionBizTypeVo,
|
|
} from '@/types/business/demand'
|
|
|
|
export const BIZ_TYPE_DICT = 'vm_biz_type'
|
|
export const BUDGET_RANGE_DICT = 'vm_budget_range'
|
|
|
|
export function getSubmissionBizTypes(): Promise<SubmissionBizTypeVo[]> {
|
|
return request<SubmissionBizTypeVo[]>({
|
|
url: '/web/projectSubmission/list',
|
|
method: 'get',
|
|
})
|
|
}
|
|
|
|
export function getOssUrls(ids: (string | number)[]): Promise<OssUrlVo[]> {
|
|
return request<OssUrlVo[]>({
|
|
url: `/web/resource/oss/listByIds/${ids.join(',')}`,
|
|
method: 'get',
|
|
})
|
|
}
|
|
|
|
export function getBizTypeDict(): Promise<DictOption[]> {
|
|
return request<DictOption[]>({
|
|
url: `/web/system/dict/data/type/${BIZ_TYPE_DICT}`,
|
|
method: 'get',
|
|
})
|
|
}
|
|
|
|
export function getBudgetRangeDict(): Promise<DictOption[]> {
|
|
return request<DictOption[]>({
|
|
url: `/web/system/dict/data/type/${BUDGET_RANGE_DICT}`,
|
|
method: 'get',
|
|
})
|
|
}
|
|
|
|
export async function getDraftDemand(): Promise<DemandDraftVo | null> {
|
|
const resp = await service.request<ApiResponse<DemandDraftVo>>({
|
|
url: '/web/workOrderDraft/getDraft',
|
|
method: 'get',
|
|
})
|
|
if (resp.data?.code !== 200) return null
|
|
return resp.data.data ?? null
|
|
}
|
|
|
|
function toBoPayload(demand: Demand): Record<string, unknown> {
|
|
return {
|
|
id: demand.id,
|
|
userName: demand.userName,
|
|
userPhone: demand.userPhone,
|
|
bizType: demand.bizType,
|
|
budgetRange: demand.budgetRange,
|
|
developmentCycle:
|
|
demand.developmentCycle === '' ? null : demand.developmentCycle,
|
|
supplementaryRemarks: demand.supplementaryRemarks,
|
|
projectName: demand.projectName,
|
|
requirementDesc: demand.requirementDesc,
|
|
attachmentInfo: demand.attachmentInfo,
|
|
}
|
|
}
|
|
|
|
export function saveDraft(demand: Demand): Promise<void> {
|
|
return request<void>({
|
|
url: '/web/workOrderDraft/add',
|
|
method: 'post',
|
|
data: toBoPayload(demand),
|
|
})
|
|
}
|
|
|
|
export function resetDraft(): Promise<void> {
|
|
return request<void>({
|
|
url: '/web/workOrderDraft/reset',
|
|
method: 'post',
|
|
})
|
|
}
|
|
|
|
export function uploadDemandFile(file: File): Promise<OssUploadVo> {
|
|
const data = new FormData()
|
|
data.append('file', file)
|
|
return request<OssUploadVo>({
|
|
url: '/web/workOrderDraft/upload',
|
|
method: 'post',
|
|
data,
|
|
headers: { 'Content-Type': 'multipart/form-data' },
|
|
})
|
|
}
|
|
|
|
export function submitDemand(demand: Demand): Promise<void> {
|
|
return request<void>({
|
|
url: '/web/requirementPool/create',
|
|
method: 'post',
|
|
data: toBoPayload(demand),
|
|
})
|
|
}
|