liu
3 天以前 91eff4781fa4142d1f62d30a0fa1de5cae424eaf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
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 } });
}