import type { PageParam, PageResult } from '@vben/request';
|
|
import type { CrmPermissionApi } from '#/api/crm/permission';
|
|
import { requestClient } from '#/api/request';
|
|
export namespace CrmContractApi {
|
/** 合同信息 */
|
export interface Contract {
|
id: number;
|
name: string;
|
no: string;
|
customerId: number;
|
customerName?: string;
|
businessId: number;
|
businessName: string;
|
contactLastTime: Date;
|
ownerUserId: number;
|
ownerUserName?: string;
|
ownerUserDeptName?: string;
|
auditStatus: number;
|
// 以下为审核派生字段,由后端在审核时写入,前端只读展示
|
reviewerId?: number; // 审核人ID(实际执行审核的用户)
|
reviewerName?: string; // 审核人姓名
|
reviewTime?: Date; // 审核时间
|
reviewRemark?: string; // 审核意见(审核通过时的意见 / 审核不通过时的原因)
|
orderDate: Date;
|
startTime: Date;
|
endTime: Date;
|
totalProductPrice: number;
|
discountPercent: number;
|
totalPrice: number;
|
depositPrice?: number; // 定金金额,单位:元
|
totalReceivablePrice: number;
|
totalInvoicePrice?: number; // 已开票金额(含审批中),单位:元
|
unInvoicePrice?: number; // 未开票金额,单位:元
|
signContactId: number;
|
signContactName?: string;
|
signUserId: number;
|
signUserName: string;
|
remark: string;
|
createTime?: Date;
|
creator: string;
|
creatorName: string;
|
updateTime?: Date;
|
products?: ContractProduct[];
|
contactName?: string;
|
orderId?: number; // 关联 ERP 销售订单编号
|
orderNo?: string; // ERP 销售订单单号
|
contractType?: string; // 合同类型(供用电/能源服务等)
|
voltageLevel?: string; // 电压等级
|
electricityType?: string; // 用电类型
|
contractCapacity?: number; // 合同容量(kVA)
|
tariffMode?: string; // 电价模式
|
meterMode?: string; // 计量方式
|
payCycle?: number; // 缴费周期(月)
|
commandCount?: number; // 指令数量
|
}
|
|
/** 合同产品信息 */
|
export interface ContractProduct {
|
id: number;
|
itemId: number;
|
itemName: string;
|
itemCode: string;
|
itemBarCode: string;
|
itemSpecification?: string;
|
itemUnitName: string;
|
itemUnitName2?: string;
|
itemUnitName3?: string;
|
itemPrice: number;
|
contractPrice: number;
|
count: number;
|
totalPrice: number;
|
}
|
|
}
|
|
/** 查询合同列表 */
|
export function getContractPage(params: PageParam) {
|
return requestClient.get<PageResult<CrmContractApi.Contract>>(
|
'/crm/contract/page',
|
{ params },
|
);
|
}
|
|
/** 查询合同列表,基于指定客户 */
|
export function getContractPageByCustomer(params: PageParam) {
|
return requestClient.get<PageResult<CrmContractApi.Contract>>(
|
'/crm/contract/page-by-customer',
|
{ params },
|
);
|
}
|
|
/** 查询合同列表,基于指定商机 */
|
export function getContractPageByBusiness(params: PageParam) {
|
return requestClient.get<PageResult<CrmContractApi.Contract>>(
|
'/crm/contract/page-by-business',
|
{ params },
|
);
|
}
|
|
/** 查询合同详情 */
|
export function getContract(id: number) {
|
return requestClient.get<CrmContractApi.Contract>(
|
`/crm/contract/get?id=${id}`,
|
);
|
}
|
|
/** 查询合同下拉列表 */
|
export function getContractSimpleList(customerId: number) {
|
return requestClient.get<CrmContractApi.Contract[]>(
|
`/crm/contract/simple-list?customerId=${customerId}`,
|
);
|
}
|
|
/** 新增合同 */
|
export function createContract(data: CrmContractApi.Contract) {
|
return requestClient.post('/crm/contract/create', data);
|
}
|
|
/** 修改合同 */
|
export function updateContract(data: CrmContractApi.Contract) {
|
return requestClient.put('/crm/contract/update', data);
|
}
|
|
/** 删除合同 */
|
export function deleteContract(id: number) {
|
return requestClient.delete(`/crm/contract/delete?id=${id}`);
|
}
|
|
/** 导出合同 */
|
export function exportContract(params: any) {
|
return requestClient.download('/crm/contract/export-excel', { params });
|
}
|
|
/**
|
* 提交合同审批(未提交 / 审核不通过 → 审批中)
|
*
|
* 审批人由「系统管理 - 审批配置」按业务类型统一配置,提交时无需指定;
|
* 未启用审批或未配置有效审批人时后端会抛出业务异常。
|
*/
|
export function submitContract(id: number) {
|
return requestClient.put('/crm/contract/submit', null, {
|
params: { id },
|
});
|
}
|
|
/**
|
* 获得合同的审批人编号集合
|
*
|
* 供列表页判断当前登录用户是否应展示「审核 / 审核不通过」按钮;未配置时返回空数组。
|
*/
|
export function getContractApproverIds() {
|
return requestClient.get<number[]>('/crm/contract/approver-ids');
|
}
|
|
/**
|
* 审核合同(审批中 → 审核通过 / 审核不通过)
|
*
|
* 仅审批配置中的审批人可调用(多人时或签);pass=false 时 reviewRemark(不通过原因)必填。
|
*/
|
export function auditContract(
|
id: number,
|
pass: boolean,
|
reviewRemark?: string,
|
) {
|
return requestClient.put('/crm/contract/audit', {
|
id,
|
pass,
|
reviewRemark,
|
});
|
}
|
|
/** 合同转移 */
|
export function transferContract(data: CrmPermissionApi.BusinessTransferReqVO) {
|
return requestClient.put('/crm/contract/transfer', data);
|
}
|
|
/** 获得待审核合同数量 */
|
export function getAuditContractCount() {
|
return requestClient.get<number>('/crm/contract/audit-count');
|
}
|
|
/** 获得即将到期(提醒)的合同数量 */
|
export function getRemindContractCount() {
|
return requestClient.get<number>('/crm/contract/remind-count');
|
}
|
|
/** 根据合同生成销售订单 */
|
export function generateSaleOrder(id: number) {
|
return requestClient.post<number>('/crm/contract/generate-sale-order', null, { params: { id } });
|
}
|