StepBar.js
2.7 KB
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
import React,{PropTypes} from 'react';
import ReactDOM from 'react-dom';
import cx from 'classnames';
import s from './header.scss';
class StepBar extends React.Component {
constructor(props) {
super(props);
this.state={
myCurrentStep:0
}
}
static propTypes = {
currentStep:PropTypes.number,
steps:PropTypes.array,
onChange:PropTypes.func,
headClick:PropTypes.bool
}
static defaultProps={
currentStep:1,
headClick:false,
steps:[
{title:'导入用工成本、社保表'},
{title:'确认优化方案'},
{title:'实施智能薪酬方案'},
{title:'订单支付'}
],
close:()=>{
},
onChange:(step)=>{
console.log(step);
}
}
stepClick(step){
const {onChange,headClick}=this.props;
if(headClick){
const {myCurrentStep}=this.state;
this.setState({
myCurrentStep:step
});
if(myCurrentStep!=step){
onChange(step+1);
}
}
}
componentDidMount(){
const {currentStep}=this.props;
this.setState({
myCurrentStep:currentStep-1
});
}
componentWillReceiveProps(nextProps){
const {currentStep}=nextProps;
if(currentStep!=this.props.currentStep){
this.setState({
myCurrentStep:currentStep-1
});
}
}
componentDidUpdate(prevProps,prevState){
}
componentWillUnmount() {
}
render(){
const {title,steps,headClick}=this.props,self=this;
const {myCurrentStep}=this.state;
let clickStyle={cursor: 'default'};
if(headClick){
clickStyle={cursor: 'pointer'}
}
return (
<div className={cx(s.step_bar_wrap)} >
{steps.map((step,i)=>{
return (
<div key={i} className={cx(s.step_item_wrap,i<=myCurrentStep?s.active:null)}>
<div style={clickStyle} className={cx(s.step_item)} onClick={self.stepClick.bind(self,i)}>
{i+1}
</div>
<div className={cx(s.step_item_content)}>
{step.title}
</div>
{(i+1)!=steps.length&&<div className={cx(s.step_item_line,i<myCurrentStep?s.active:null)}></div>}
</div>
)
})}
</div>
)
}
}
export default StepBar;