shimai
1 days ago 6f45735adfdcd973a19f638f9ced9629f79cd6de
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
/**
 * NegotiationProgress 组件 - 协商沟通进度
 * 点线式可视化展示沟通轮次
 */
 
import React, { useMemo } from 'react';
import { useCaseData } from '../../contexts/CaseDataContext';
import './NegotiationProgress.css';
 
/**
 * 计算总轮次和已完成轮次
 */
const calculateRounds = (mediationCount, nodeCount, currentNodeIndex) => {
  const currentRound = mediationCount || 0;
  let totalRounds = nodeCount || 6;
  const isLastNode = currentNodeIndex >= nodeCount - 1;
 
  // 当沟通次数超过总次数但未到最后节点时,总次数 = 沟通次数 + 1
  if (currentRound > totalRounds && !isLastNode) {
    totalRounds = currentRound + 1;
  }
 
  return { currentRound, totalRounds, isLastNode };
};
 
/**
 * 进度点组件
 */
const ProgressDot = ({ isActive, isLast }) => (
  <div className={`progress-dot-wrapper ${isLast ? 'last' : ''}`}>
    <div className={`progress-dot ${isActive ? 'active' : ''}`} />
    {!isLast && <div className={`progress-line ${isActive ? 'active' : ''}`} />}
  </div>
);
 
/**
 * NegotiationProgress 主组件
 */
const NegotiationProgress = () => {
  const { caseData, processNodes } = useCaseData();
  
  // 从数据中获取值
  const mediationCount = caseData?.mediation?.mediation_count || 0;
  const nodeCount = processNodes?.length || 6;
  
  // 计算当前节点索引
  const currentNodeIndex = useMemo(() => {
    if (!processNodes?.length) return 0;
    const activeNode = processNodes.findIndex(n => n.nodeState === 1);
    return activeNode >= 0 ? activeNode : processNodes.length - 1;
  }, [processNodes]);
 
  // 计算轮次数据
  const { currentRound, totalRounds, isLastNode } = useMemo(() => {
    return calculateRounds(mediationCount, nodeCount, currentNodeIndex);
  }, [mediationCount, nodeCount, currentNodeIndex]);
 
  // 生成进度点数据
  const dots = useMemo(() => {
    return Array(totalRounds).fill(false).map((_, index) => {
      // 如果是最后节点,全部显示蓝色
      if (isLastNode) return true;
      return index < currentRound;
    });
  }, [totalRounds, currentRound, isLastNode]);
 
  return (
    <div className="negotiation-progress">
      <div className="negotiation-header">
        <span className="negotiation-title">协商沟通</span>
      </div>
      <div className="negotiation-round">
        <span className="round-text">第{currentRound}轮</span>
      </div>
      <div className="negotiation-dots">
        {dots.map((isActive, index) => (
          <ProgressDot 
            key={index}
            isActive={isActive}
            isLast={index === dots.length - 1}
          />
        ))}
      </div>
    </div>
  );
};
 
export default NegotiationProgress;