接入feat(cross-checking): 整合组织架构数据并优化意见列表功能
- 更新 API 配置,使用新的后端服务地址- 移除前端模拟数据,改为从后端获取真实数据- 优化意见列表接口,支持分页和用户身份验证 - 调整前端界面,适应新的数据结构和功能需求
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
// import { postgrestPost } from "../postgrest-client";
|
||||
import { API_BASE_URL } from "../../config/api-config";
|
||||
|
||||
/**
|
||||
* 提出意见的请求参数接口
|
||||
@@ -29,20 +28,32 @@ export interface SubmitOpinionResponse {
|
||||
* 交叉评查意见数据接口
|
||||
*/
|
||||
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;
|
||||
proposal_id: string | number;
|
||||
evaluation_point_name: string;
|
||||
proposed_score: number;
|
||||
reason: string;
|
||||
proposer: string;
|
||||
votes: Array<{ voter: string; vote_type: string }>;
|
||||
agree_voters: string[];
|
||||
disagree_voters: string[];
|
||||
pending_voters: string[];
|
||||
can_vote: boolean;
|
||||
problem_message: string;
|
||||
// 兼容旧字段
|
||||
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; // 当前用户是否为意见发起人
|
||||
is_vote?: boolean;
|
||||
voter_count?: number;
|
||||
proposer_name?: string;
|
||||
current_user_is_proposer?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,191 +121,95 @@ export async function submitCrossCheckingOpinion(
|
||||
* @param pageSize 每页大小
|
||||
* @returns 意见列表和总数
|
||||
*/
|
||||
import { API_BASE_URL } from '../../config/api-config';
|
||||
|
||||
export async function getCrossCheckingOpinions(
|
||||
documentId: string | number,
|
||||
page: number = 1,
|
||||
pageSize: number = 10
|
||||
pageSize: number = 10,
|
||||
userId?: number // 可选,便于后端接口对接
|
||||
): 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
|
||||
// 如果没传userId,默认用1
|
||||
const realUserId = userId ?? 1;
|
||||
// 实际后端API调用,拼接API_BASE_URL
|
||||
const response = await fetch(`${API_BASE_URL}/admin/cross_review/proposals/details`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
{
|
||||
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);
|
||||
|
||||
body: JSON.stringify({
|
||||
user_id: realUserId,
|
||||
document_id: documentId, // 如果后端需要document_id可以加上
|
||||
page,
|
||||
page_size: pageSize
|
||||
})
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('获取意见列表失败');
|
||||
}
|
||||
const data = await response.json();
|
||||
|
||||
// 处理新的数据结构,支持分页
|
||||
const responseData = data.data || data;
|
||||
const pagination = data.pagination;
|
||||
|
||||
// 定义后端返回的数据项类型
|
||||
interface ProposalItem {
|
||||
proposal_id: string | number;
|
||||
evaluation_point_name: string;
|
||||
proposed_score: number;
|
||||
reason: string;
|
||||
proposer: string;
|
||||
votes?: Array<{ voter: string; vote_type: string }>;
|
||||
agree_voters?: string[];
|
||||
disagree_voters?: string[];
|
||||
pending_voters?: string[];
|
||||
can_vote?: boolean;
|
||||
problem_message?: string;
|
||||
evaluation_point_id?: string | number;
|
||||
document_id?: string | number;
|
||||
status?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
is_vote?: boolean;
|
||||
current_user_is_proposer?: boolean;
|
||||
}
|
||||
|
||||
// 适配后端返回结构,使用新字段
|
||||
const opinions: CrossCheckingOpinion[] = Array.isArray(responseData) ? responseData.map((item: ProposalItem) => ({
|
||||
proposal_id: item.proposal_id,
|
||||
evaluation_point_name: item.evaluation_point_name,
|
||||
proposed_score: item.proposed_score,
|
||||
reason: item.reason,
|
||||
proposer: item.proposer,
|
||||
votes: item.votes || [],
|
||||
agree_voters: item.agree_voters || [],
|
||||
disagree_voters: item.disagree_voters || [],
|
||||
pending_voters: item.pending_voters || [],
|
||||
can_vote: item.can_vote ?? false,
|
||||
problem_message: item.problem_message || '',
|
||||
// 兼容旧字段
|
||||
id: item.proposal_id,
|
||||
evaluation_point_id: item.evaluation_point_id,
|
||||
document_id: item.document_id || documentId,
|
||||
audit_point: item.evaluation_point_name,
|
||||
found_issue: item.problem_message || '',
|
||||
audit_opinion: item.reason || '',
|
||||
deduction_score: item.proposed_score,
|
||||
status: item.status || 'pending',
|
||||
created_at: item.created_at || '',
|
||||
updated_at: item.updated_at || '',
|
||||
is_vote: item.is_vote || false,
|
||||
voter_count: (item.agree_voters?.length || 0) + (item.disagree_voters?.length || 0),
|
||||
proposer_name: item.proposer,
|
||||
current_user_is_proposer: item.current_user_is_proposer || false
|
||||
})) : [];
|
||||
|
||||
return {
|
||||
data: {
|
||||
opinions: paginatedOpinions,
|
||||
total: total
|
||||
opinions,
|
||||
total: pagination?.total || opinions.length
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user