AddWorkers.js 2.82 KB
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>
		)
	}
}