diff --git a/src/components/AddPlayerInput.js b/src/components/AddPlayerInput.js
index 5d914d8..5cba264 100755
--- a/src/components/AddPlayerInput.js
+++ b/src/components/AddPlayerInput.js
@@ -6,15 +6,29 @@ import styles from './AddPlayerInput.css';
class AddPlayerInput extends Component {
render() {
return (
-
+
+
+
+
+
+
+
+
+
);
}
@@ -28,13 +42,23 @@ class AddPlayerInput extends Component {
handleChange(e) {
this.setState({ name: e.target.value });
}
+ handleChangePosition(e) {
+ this.setState({ position: e.target.value });
+ }
handleSubmit(e) {
- const name = e.target.value.trim();
- if (e.which === 13) {
- this.props.addPlayer(name);
- this.setState({ name: '' });
+ const name = this.state.name;
+ const position = this.state.position
+ if(!name || !position){
+ alert("name or position don't empty")
+ return false;
}
+
+ this.props.addPlayer({
+ name,position
+ });
+ this.setState({ name: ''});
+
}
}
diff --git a/src/components/PlayerList.js b/src/components/PlayerList.js
index 7b40246..8671663 100755
--- a/src/components/PlayerList.js
+++ b/src/components/PlayerList.js
@@ -2,25 +2,114 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types';
import styles from './PlayerList.css';
import PlayerListItem from './PlayerListItem';
+import { connect } from 'react-redux';
+import Pagination from './pagination';
+import './style.css'
+
+//import {addPlayer, deletePlayer, starPlayer} from "../actions/PlayersActions";
class PlayerList extends Component {
+ constructor(props){
+ super(props)
+
+
+ this.state = {
+ indexList : this.props.players.slice(0,5), //初始化第一页,只取5条
+ totalNum:this.props.players.length,//总记录数
+ totalData:[],
+ current: 1, //当前页码
+ pageSize:5, //每页显示的条数5条
+ totalPage:Math.ceil(this.props.players.length/5),//总页数
+ }
+ }
+ componentWillReceiveProps(nextProps, nextContext) {
+
+ this.setState({
+ totalPage:Math.ceil(nextProps.players.length/5),
+ indexList: nextProps.players.slice(0,5)
+ },()=>{
+ if(this.state.totalPage >= this.state.current){
+ this.pageClick(this.state.current)
+ }
+ })
+
+ }
+
+ componentWillMount(){
+
+ }
+ splitPlayersArr(data){
+ let arr = [];
+ for(var i=0;i 0){
+ this.pageClick(cur);
+ }
+ }
+ //下一步
+ goNext(){
+
+ let cur = this.state.current;
+ if(cur < this.state.totalPage){
+ this.pageClick(cur + 1);
+ }
+ }
render() {
return (
-
- {this.props.players.map((player, index) => {
- return (
-
- );
- })}
-
+
+
+ {this.state.indexList.map((player, index) => {
+ return (
+
+ );
+ })}
+
+
+
);
}
}
@@ -31,3 +120,18 @@ PlayerList.propTypes = {
};
export default PlayerList;
+
+
+// function mapStateToProps(state) {
+// return state;
+// }
+// function mapDispatchToProps(dispatch) {
+// return {
+// changePlayerId: (state) => dispatch(state)
+// }
+// }
+//
+// export default connect(
+// mapStateToProps,
+// mapDispatchToProps,
+// )(PlayerList);
diff --git a/src/components/PlayerListItem.js b/src/components/PlayerListItem.js
index ec9758c..5a01303 100755
--- a/src/components/PlayerListItem.js
+++ b/src/components/PlayerListItem.js
@@ -20,7 +20,8 @@ class PlayerListItem extends Component {