366 lines
10 KiB
TypeScript
366 lines
10 KiB
TypeScript
// import { postgrestPost } from "../postgrest-client";
|
|
import { API_BASE_URL } from "../../config/api-config";
|
|
|
|
/**
|
|
* 提出意见的请求参数接口
|
|
*/
|
|
export interface SubmitOpinionRequest {
|
|
reviewPointResultId: string | number;
|
|
documentId: string | number;
|
|
auditPoint: string;
|
|
foundIssue: string;
|
|
auditOpinion: string;
|
|
deductionScore: number;
|
|
}
|
|
|
|
/**
|
|
* 提出意见的响应接口
|
|
*/
|
|
export interface SubmitOpinionResponse {
|
|
success: boolean;
|
|
message: string;
|
|
data?: {
|
|
id: string | number;
|
|
created_at: string;
|
|
};
|
|
}
|
|
|
|
/**
|
|
* 交叉评查意见数据接口
|
|
*/
|
|
export interface CrossCheckingOpinion {
|
|
id: string | number;
|
|
evaluation_point_id: string | number;
|
|
document_id: string | number;
|
|
audit_point: string;
|
|
found_issue: string;
|
|
audit_opinion: string;
|
|
deduction_score: number;
|
|
status: string;
|
|
created_at: string;
|
|
updated_at?: string;
|
|
is_vote: boolean; // 当前用户是否已投票
|
|
voter_count: number; // 投票人数
|
|
proposer_name: string; // 意见发起人姓名
|
|
current_user_is_proposer: boolean; // 当前用户是否为意见发起人
|
|
}
|
|
|
|
/**
|
|
* API响应格式
|
|
*/
|
|
export interface ApiResponse<T> {
|
|
data?: T;
|
|
error?: string;
|
|
status?: number;
|
|
}
|
|
|
|
/**
|
|
* 提交交叉评查意见
|
|
* @param opinionData 意见数据
|
|
* @returns 提交结果
|
|
*/
|
|
export async function submitCrossCheckingOpinion(
|
|
opinionData: SubmitOpinionRequest
|
|
): Promise<ApiResponse<SubmitOpinionResponse>> {
|
|
try {
|
|
const requestData = {
|
|
proposer_user_id: 1,
|
|
evaluation_result_id: opinionData.reviewPointResultId,
|
|
// document_id: opinionData.documentId,
|
|
// audit_point: opinionData.auditPoint,
|
|
// found_issue: opinionData.foundIssue,
|
|
proposed_score: opinionData.deductionScore,
|
|
reason: opinionData.auditOpinion
|
|
};
|
|
|
|
const response = await fetch(`${API_BASE_URL}/admin/cross_review/proposals`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(requestData)
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (!response.ok) {
|
|
throw new Error(data.message || '提交失败');
|
|
}
|
|
|
|
return {
|
|
data: {
|
|
success: true,
|
|
message: '意见提交成功',
|
|
data: data
|
|
}
|
|
};
|
|
} catch (error) {
|
|
console.error('提交交叉评查意见失败:', error);
|
|
return {
|
|
error: error instanceof Error ? error.message : '提交意见失败',
|
|
status: 500
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取交叉评查意见列表(支持分页)
|
|
* @param documentId 文档ID
|
|
* @param page 页码
|
|
* @param pageSize 每页大小
|
|
* @returns 意见列表和总数
|
|
*/
|
|
export async function getCrossCheckingOpinions(
|
|
documentId: string | number,
|
|
page: number = 1,
|
|
pageSize: number = 10
|
|
): Promise<ApiResponse<{ opinions: CrossCheckingOpinion[], total: number }>> {
|
|
try {
|
|
// 模拟数据 - 后续替换为真实API调用
|
|
const mockOpinions: CrossCheckingOpinion[] = [
|
|
{
|
|
id: 1,
|
|
evaluation_point_id: 101,
|
|
document_id: documentId,
|
|
audit_point: "合同主体信息核查",
|
|
found_issue: "合同签署方信息不完整",
|
|
audit_opinion: "合同中缺少乙方的详细联系方式,建议补充完整的地址和联系电话",
|
|
deduction_score: -2,
|
|
status: "pending",
|
|
created_at: "2024-01-15 10:30:00",
|
|
is_vote: false,
|
|
voter_count: 3,
|
|
proposer_name: "张三",
|
|
current_user_is_proposer: false
|
|
},
|
|
{
|
|
id: 2,
|
|
evaluation_point_id: 102,
|
|
document_id: documentId,
|
|
audit_point: "合同金额核查",
|
|
found_issue: "合同金额与预算不符",
|
|
audit_opinion: "合同总金额超出预算范围,需要重新评估或调整预算",
|
|
deduction_score: -5,
|
|
status: "approved",
|
|
created_at: "2024-01-14 14:20:00",
|
|
is_vote: true,
|
|
voter_count: 5,
|
|
proposer_name: "李四",
|
|
current_user_is_proposer: true
|
|
},
|
|
{
|
|
id: 3,
|
|
evaluation_point_id: 103,
|
|
document_id: documentId,
|
|
audit_point: "合同条款审查",
|
|
found_issue: "违约责任条款不明确",
|
|
audit_opinion: "合同中违约责任的具体计算方式和赔偿标准需要进一步明确",
|
|
deduction_score: -3,
|
|
status: "rejected",
|
|
created_at: "2024-01-13 09:15:00",
|
|
is_vote: false,
|
|
voter_count: 2,
|
|
proposer_name: "王五",
|
|
current_user_is_proposer: false
|
|
},
|
|
{
|
|
id: 4,
|
|
evaluation_point_id: 103,
|
|
document_id: documentId,
|
|
audit_point: "合同条款审查",
|
|
found_issue: "违约责任条款不明确",
|
|
audit_opinion: "合同中违约责任的具体计算方式和赔偿标准需要进一步明确",
|
|
deduction_score: -3,
|
|
status: "rejected",
|
|
created_at: "2024-01-13 09:15:00",
|
|
is_vote: false,
|
|
voter_count: 2,
|
|
proposer_name: "王五",
|
|
current_user_is_proposer: false
|
|
},
|
|
{
|
|
id: 5,
|
|
evaluation_point_id: 103,
|
|
document_id: documentId,
|
|
audit_point: "合同条款审查",
|
|
found_issue: "违约责任条款不明确",
|
|
audit_opinion: "合同中违约责任的具体计算方式和赔偿标准需要进一步明确",
|
|
deduction_score: -3,
|
|
status: "rejected",
|
|
created_at: "2024-01-13 09:15:00",
|
|
is_vote: false,
|
|
voter_count: 2,
|
|
proposer_name: "王五",
|
|
current_user_is_proposer: false
|
|
},
|
|
{
|
|
id: 6,
|
|
evaluation_point_id: 103,
|
|
document_id: documentId,
|
|
audit_point: "合同条款审查",
|
|
found_issue: "违约责任条款不明确",
|
|
audit_opinion: "合同中违约责任的具体计算方式和赔偿标准需要进一步明确",
|
|
deduction_score: -3,
|
|
status: "rejected",
|
|
created_at: "2024-01-13 09:15:00",
|
|
is_vote: false,
|
|
voter_count: 2,
|
|
proposer_name: "王五",
|
|
current_user_is_proposer: false
|
|
},
|
|
{
|
|
id: 7,
|
|
evaluation_point_id: 103,
|
|
document_id: documentId,
|
|
audit_point: "合同条款审查",
|
|
found_issue: "违约责任条款不明确",
|
|
audit_opinion: "合同中违约责任的具体计算方式和赔偿标准需要进一步明确",
|
|
deduction_score: -3,
|
|
status: "rejected",
|
|
created_at: "2024-01-13 09:15:00",
|
|
is_vote: false,
|
|
voter_count: 2,
|
|
proposer_name: "王五",
|
|
current_user_is_proposer: false
|
|
},
|
|
{
|
|
id: 8,
|
|
evaluation_point_id: 103,
|
|
document_id: documentId,
|
|
audit_point: "合同条款审查",
|
|
found_issue: "违约责任条款不明确",
|
|
audit_opinion: "合同中违约责任的具体计算方式和赔偿标准需要进一步明确",
|
|
deduction_score: -3,
|
|
status: "rejected",
|
|
created_at: "2024-01-13 09:15:00",
|
|
is_vote: false,
|
|
voter_count: 2,
|
|
proposer_name: "王五",
|
|
current_user_is_proposer: false
|
|
},
|
|
{
|
|
id: 9,
|
|
evaluation_point_id: 103,
|
|
document_id: documentId,
|
|
audit_point: "合同条款审查",
|
|
found_issue: "违约责任条款不明确",
|
|
audit_opinion: "合同中违约责任的具体计算方式和赔偿标准需要进一步明确",
|
|
deduction_score: -3,
|
|
status: "rejected",
|
|
created_at: "2024-01-13 09:15:00",
|
|
is_vote: false,
|
|
voter_count: 2,
|
|
proposer_name: "王五",
|
|
current_user_is_proposer: false
|
|
},
|
|
{
|
|
id: 10,
|
|
evaluation_point_id: 103,
|
|
document_id: documentId,
|
|
audit_point: "合同条款审查",
|
|
found_issue: "违约责任条款不明确",
|
|
audit_opinion: "合同中违约责任的具体计算方式和赔偿标准需要进一步明确",
|
|
deduction_score: -3,
|
|
status: "rejected",
|
|
created_at: "2024-01-13 09:15:00",
|
|
is_vote: false,
|
|
voter_count: 2,
|
|
proposer_name: "王五",
|
|
current_user_is_proposer: false
|
|
},
|
|
{
|
|
id: 11,
|
|
evaluation_point_id: 103,
|
|
document_id: documentId,
|
|
audit_point: "合同条款审查",
|
|
found_issue: "违约责任条款不明确",
|
|
audit_opinion: "合同中违约责任的具体计算方式和赔偿标准需要进一步明确",
|
|
deduction_score: -3,
|
|
status: "rejected",
|
|
created_at: "2024-01-13 09:15:00",
|
|
is_vote: false,
|
|
voter_count: 2,
|
|
proposer_name: "王五",
|
|
current_user_is_proposer: false
|
|
},
|
|
];
|
|
|
|
// 模拟分页
|
|
const total = mockOpinions.length;
|
|
const startIndex = (page - 1) * pageSize;
|
|
const endIndex = startIndex + pageSize;
|
|
const paginatedOpinions = mockOpinions.slice(startIndex, endIndex);
|
|
|
|
return {
|
|
data: {
|
|
opinions: paginatedOpinions,
|
|
total: total
|
|
}
|
|
};
|
|
} catch (error) {
|
|
console.error('获取交叉评查意见失败:', error);
|
|
return {
|
|
error: error instanceof Error ? error.message : '获取意见列表失败',
|
|
status: 500
|
|
};
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 意见操作类型
|
|
*/
|
|
export type OpinionActionType = 'agree' | 'disagree' | 'withdraw_vote' | 'withdraw_opinion';
|
|
|
|
/**
|
|
* 意见操作请求参数
|
|
*/
|
|
export interface OpinionActionRequest {
|
|
opinionId: string | number;
|
|
action: OpinionActionType;
|
|
}
|
|
|
|
/**
|
|
* 执行意见操作(赞同、反对、撤销投票、撤销意见)
|
|
* @param actionData 操作数据
|
|
* @returns 操作结果
|
|
*/
|
|
export async function performOpinionAction(
|
|
actionData: OpinionActionRequest
|
|
): Promise<ApiResponse<{ success: boolean; message: string }>> {
|
|
try {
|
|
// 模拟API调用延迟
|
|
await new Promise(resolve => setTimeout(resolve, 500));
|
|
|
|
let message = '';
|
|
switch (actionData.action) {
|
|
case 'agree':
|
|
message = '已赞同该意见';
|
|
break;
|
|
case 'disagree':
|
|
message = '已反对该意见';
|
|
break;
|
|
case 'withdraw_vote':
|
|
message = '已撤销投票';
|
|
break;
|
|
case 'withdraw_opinion':
|
|
message = '已撤销意见';
|
|
break;
|
|
default:
|
|
throw new Error('无效的操作类型');
|
|
}
|
|
|
|
return {
|
|
data: {
|
|
success: true,
|
|
message: message
|
|
}
|
|
};
|
|
} catch (error) {
|
|
console.error('执行意见操作失败:', error);
|
|
return {
|
|
error: error instanceof Error ? error.message : '操作失败',
|
|
status: 500
|
|
};
|
|
}
|
|
}
|