罗广聪

select

@@ -19,7 +19,7 @@ export default class Import extends Component { @@ -19,7 +19,7 @@ export default class Import extends Component {
19 this.state = { 19 this.state = {
20 customersList: this.props.navigation.state.params.customersList, 20 customersList: this.props.navigation.state.params.customersList,
21 selected_all: false, 21 selected_all: false,
22 - selected_len: 5 22 + selected_len: 0
23 }; 23 };
24 } 24 }
25 componentWillMount() {} 25 componentWillMount() {}
@@ -32,6 +32,27 @@ export default class Import extends Component { @@ -32,6 +32,27 @@ export default class Import extends Component {
32 post("/test/insurance/article", {}, res => {}, err => {}); 32 post("/test/insurance/article", {}, res => {}, err => {});
33 } 33 }
34 34
  35 + selectItem(index) {
  36 + const { customersList, selected_all, selected_len } = this.state;
  37 + let Temp = customersList;
  38 + console.log(index);
  39 + Temp.splice(index, 1, {
  40 + ...customersList[index],
  41 + selected: !customersList[index].selected
  42 + });
  43 + this.setState({
  44 + customersList: Temp
  45 + });
  46 + }
  47 +
  48 + selectAll() {
  49 + const { customersList, selected_all, selected_len } = this.state;
  50 + let LEN = customersList.length;
  51 + this.setState({
  52 + selected_all: !this.state.selected_all
  53 + });
  54 + }
  55 +
35 render() { 56 render() {
36 const { navigate } = this.props.navigation; 57 const { navigate } = this.props.navigation;
37 const { customersList, selected_all, selected_len } = this.state; 58 const { customersList, selected_all, selected_len } = this.state;
@@ -52,15 +73,7 @@ export default class Import extends Component { @@ -52,15 +73,7 @@ export default class Import extends Component {
52 key={index} 73 key={index}
53 style={styles.CustomerItemContaier} 74 style={styles.CustomerItemContaier}
54 onPress={() => { 75 onPress={() => {
55 - let Temp = customersList; 76 + this.selectItem(index)
56 - console.log(index);  
57 - Temp.splice(index, 1, {  
58 - ...customersList[index],  
59 - selected: !customersList[index].selected  
60 - });  
61 - this.setState({  
62 - customersList: Temp  
63 - });  
64 }} 77 }}
65 > 78 >
66 <View style={styles.itemSelectIconContainer}> 79 <View style={styles.itemSelectIconContainer}>
@@ -86,9 +99,7 @@ export default class Import extends Component { @@ -86,9 +99,7 @@ export default class Import extends Component {
86 <TouchableOpacity 99 <TouchableOpacity
87 style={styles.selectAllContainer} 100 style={styles.selectAllContainer}
88 onPress={() => { 101 onPress={() => {
89 - this.setState({ 102 + this.selectAll();
90 - selected_all: !this.state.selected_all  
91 - });  
92 }} 103 }}
93 > 104 >
94 <View style={styles.selectAllIcon}> 105 <View style={styles.selectAllIcon}>