AddWorkers.js
2.82 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import React from "react"
import {View, StyleSheet, Text, Image, TouchableOpacity, ScrollView,} from "react-native"
import {observer} from 'mobx-react/native'
import {observable} from 'mobx'
import SearchBar from '../components/SearchBar'
import {line} from "./AddChildrenTask";
import BackButton,{AndroidView} from '../components/BackButton';
import addWorkersLogic from '../logic/addWorkersLogic';
import {WorkerItem} from "./AddList";
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#efeff4",
},
content: {
flex: 1,
backgroundColor: 'white'
},
item: {
height: 57.5,
marginLeft: 15,
borderBottomColor: "#999999",
borderBottomWidth: line,
flexDirection: 'row',
alignItems: 'center',
paddingLeft: 2,
paddingRight: 15,
backgroundColor: "white"
},
footer: {
height: 55,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'flex-end',
paddingRight: 16.5,
backgroundColor: "#f5f5f5",
},
footerText: {
color: "#3399ff",
fontSize: 16,
},
icon: {
height: 16,
width: 16,
marginRight: 15,
},
icon1: {
height: 12,
width: 12,
},
nameBg: {
height: 30,
width: 30,
borderRadius: 4,
backgroundColor: "#2c8fff",
alignItems: 'center',
justifyContent: 'center',
overflow: 'hidden',
marginRight: 13.5
},
nameBgText: {
fontSize: 20,
color: 'white',
},
name: {
fontSize: 16,
flex: 1,
},
})
@observer
export default class AddWorkers extends React.Component {
static navigationOptions = ({navigation}) => {
const {state} = navigation
return {
headerTitle: state.title || '分配人员',
headerLeft: <BackButton navigation={navigation}/>,
headerRight:<AndroidView/>,
}
}
logic = new addWorkersLogic()
async componentWillMount() {
const {workers} = this.props.navigation.state.params
this.logic.chooseWorkers.replace(workers)
await this.logic.get()
}
onPress = () => {
const {navigation} = this.props
navigation.state.params.onChange(this.logic.chooseWorkers)
navigation.goBack()
}
onChange = (v) => {
if(!v.userId){
this.logic.chooseWorkers.clear()
return
}
if (this.logic.chooseWorkers.some(z => v.userId === z.userId)){
this.logic.chooseWorkers.clear()
} else {
this.logic.chooseWorkers.clear()
this.logic.chooseWorkers.push(v)
}
}
render() {
return (
<View style={styles.container}>
<SearchBar logic={this.logic} noButton/>
<ScrollView style={styles.content}>
{this.logic.data.map((v, i) => <WorkerItem data={v} key={i} onChange={() => this.onChange(v)}
choose={(this.logic.chooseWorkers.length===0&&i===0)||this.logic.chooseWorkers.some(x => x.userId === v.userId)}/>)}
</ScrollView>
<TouchableOpacity style={styles.footer} onPress={this.onPress}>
<Text style={styles.footerText}>分配</Text>
</TouchableOpacity>
</View>
)
}
}