123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286 |
- /**
- * Created by zcy on 2017/4/6.
- */
- import React, {Component} from 'react'
- import {
- View,
- StyleSheet,
- TouchableHighlight,
- Text,
- Image,
- Dimensions,
- } from 'react-native'
- // var Dimensions = require('Dimensions');
- var width = Dimensions.get('window').width;
- var height = Dimensions.get('window').height;
- class RadioModal extends Component {
- constructor(props) {
- super(props);
- this.state = {
- clicked: true,
- radioInit: this.props.radioInit,
- indexa: this.props.selectedValue === undefined ? '0' : this.props.selectedValue,
- }
- }
- click(id, item, notes) {
- this.setState({indexa: id})
- this.props.onValueChange(id, item, notes)
- }
- componentDidMount() {
- const indexInit = this.props.selectedValue === undefined ? '0' : this.props.selectedValue;
- this.setState({
- indexa: indexInit
- })
- //this.props.onValueChange(indexInit)
- }
- createInner(child, index, props) {
- const disabled = props ? child[this.props.options.disabled] : child.props.disabled;
- const childC = props ? child[this.props.options.value] : child.props.children;
- const values = props ? child[this.props.options.id] : child.props.value;
- const notes = props ? child[this.props.options.note] : child.props.note;
- const hightlight = props ? this.state.indexa === child[this.props.options.id] : this.state.indexa === child.props.value;
- return <Raio2
- child={childC}
- index={index}
- value={values}
- notes={notes}
- key={index}
- initStyle={this.props.innerStyle}
- txtColor={this.props.txtColor}
- noneColor={this.props.noneColor}
- onclick={this.click.bind(this)}
- hightlight={hightlight}
- disabled={disabled}
- seledImg={this.props.seledImg}
- selImg={this.props.selImg}
- selnoneImg={this.props.selnoneImg}
- />
- }
- render() {
- const that = this;
- return (
- <View {...this.props.style}>
- {
- !this.props.dataOption && React.Children.map(this.props.children, (child, index) => this.createInner(child, index))
- }
- {
- this.props.dataOption && this.props.dataOption.map((item, index) => this.createInner(item, index, true))
- }
- </View>
- )
- }
- }
- class Raio2 extends Component {
- constructor(props) {
- super(props);
- }
- click(id, item, notes) {
- if (this.props.disabled) {
- return
- } else {
- this.props.onclick(id, item, notes);
- }
- }
- render() {
- const imgUrl = this.props.hightlight ? this.props.seledImg || require('../../assets/images/selted.png') : this.props.selImg || require('../../assets/images/selt.png');
- const imgUrlNone = this.props.selnoneImg || require('../../assets/images/seltnone.png');
- return (
- <TouchableHighlight
- underlayColor='transparent'
- style={[{marginRight: 15, width: (width - 80) / 2, height: 24}, this.props.initStyle]}
- onPress={this.click.bind(this, this.props.value, this.props.child, this.props.notes)}>
- <View style={{flex: 1, flexDirection: 'row', alignItems: 'center'}}>
- {this.props.disabled && !this.props.hightlight &&
- <Image source={imgUrlNone} style={{width: 14, height: 14, marginRight: 7}}/>}
- {this.props.disabled && this.props.hightlight &&
- <Image source={imgUrl} style={{width: 14, height: 14, marginRight: 7}}/>}
- {!this.props.disabled && <Image source={imgUrl} style={{width: 14, height: 14, marginRight: 7}}/>}
- <Text
- style={{color: this.props.disabled ? this.props.noneColor || '#dfdfdf' : this.props.txtColor || '#414141'}}>{this.props.child}</Text>
- </View>
- </TouchableHighlight>
- )
- }
- }
- const styles = StyleSheet.create({
- titleCom: {
- marginBottom: 5,
- },
- seltedImgs: {
- width: 14,
- height: 14,
- marginRight: 8,
- },
- emailH: {
- height: 28,
- textAlignVertical: 'center',
- marginRight: 10,
- color: '#141414',
- fontSize: 12,
- },
- inputs: {
- width: width * 0.5,
- borderWidth: 1,
- borderColor: '#dfdfdf',
- borderRadius: 3,
- height: 28,
- padding: 0,
- paddingLeft: 5,
- paddingRight: 5,
- marginBottom: 10,
- fontSize: 12,
- },
- closeBtns: {
- position: 'absolute',
- width: 14,
- height: 14,
- right: 10,
- top: 7,
- },
- headLog: {
- backgroundColor: '#e6454a',
- color: '#ffffff',
- height: 28,
- textAlignVertical: 'center',
- textAlign: 'center'
- },
- border1: {
- borderWidth: 1,
- borderColor: '#dfdfdf',
- },
- borderR: {
- borderRightWidth: 1,
- borderRightColor: '#dfdfdf',
- },
- borderL: {
- borderLeftWidth: 1,
- borderLeftColor: '#dfdfdf',
- },
- eleMess: {
- paddingLeft: 10,
- paddingRight: 10,
- height: 24,
- fontSize: 12,
- color: '#ffffff',
- backgroundColor: '#f8cb43',
- borderRadius: 3,
- textAlignVertical: 'center',
- textAlign: 'center',
- width: 80,
- },
- electronicTip: {
- width: (width - 40) / 5,
- flexDirection: 'row',
- justifyContent: 'center',
- paddingTop: 10,
- paddingBottom: 10,
- },
- lineRow: {
- backgroundColor: '#ffffff',
- borderRadius: 3,
- flexDirection: 'row',
- flex: 1,
- marginBottom: 15,
- padding: 10,
- alignItems: 'center',
- justifyContent: 'space-between',
- flexWrap: 'wrap',
- },
- lineRowB: {
- backgroundColor: '#ffffff',
- borderRadius: 3,
- flexDirection: 'row',
- flex: 1,
- marginBottom: 15,
- paddingLeft: 10,
- paddingRight: 10,
- alignItems: 'center',
- },
- inner3: {
- width: (width - 40) / 3,
- fontSize: 12,
- color: '#141414'
- },
- innerS: {
- flexDirection: 'row',
- flex: 1,
- fontSize: 12,
- color: '#141414'
- },
- flex1: {
- flex: 1
- },
- flexRow: {
- flexDirection: 'row',
- },
- flexVer: {
- flexDirection: 'column',
- },
- Jcenter: {
- justifyContent: 'center',
- },
- Acenter: {
- alignItems: 'center',
- },
- BE: {
- justifyContent: 'space-between'
- },
- Textcenter: {
- textAlign: 'center',
- },
- TextCenterVer: {
- textAlignVertical: 'center',
- },
- backCGray: {
- backgroundColor: '#dfdfdf'
- },
- backWhite: {
- backgroundColor: '#ffffff',
- },
- borderRadius5: {
- borderRadius: 5,
- },
- borderRadius3: {
- borderRadius: 3,
- },
- horLine: {
- flexDirection: 'row',
- flex: 1,
- flexWrap: 'wrap',
- alignItems: 'flex-start',
- marginBottom: 10,
- },
- paddlr10: {
- paddingLeft: 10,
- paddingRight: 10,
- },
- marginB10: {
- marginBottom: 10,
- },
- colorRed: {
- color: '#b40e12',
- },
- colorBlack: {
- color: '#141414',
- },
- colorYellow: {
- color: '#f8cb43',
- },
- color999: {
- color: '#999999',
- },
- colorWhite: {
- color: '#ffffff',
- },
- })
- export default RadioModal
|