RadioModal.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /**
  2. * Created by zcy on 2017/4/6.
  3. */
  4. import React, {Component} from 'react'
  5. import {
  6. View,
  7. StyleSheet,
  8. TouchableHighlight,
  9. Text,
  10. Image,
  11. Dimensions,
  12. } from 'react-native'
  13. // var Dimensions = require('Dimensions');
  14. var width = Dimensions.get('window').width;
  15. var height = Dimensions.get('window').height;
  16. class RadioModal extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.state = {
  20. clicked: true,
  21. radioInit: this.props.radioInit,
  22. indexa: this.props.selectedValue === undefined ? '0' : this.props.selectedValue,
  23. }
  24. }
  25. click(id, item, notes) {
  26. this.setState({indexa: id})
  27. this.props.onValueChange(id, item, notes)
  28. }
  29. componentDidMount() {
  30. const indexInit = this.props.selectedValue === undefined ? '0' : this.props.selectedValue;
  31. this.setState({
  32. indexa: indexInit
  33. })
  34. //this.props.onValueChange(indexInit)
  35. }
  36. createInner(child, index, props) {
  37. const disabled = props ? child[this.props.options.disabled] : child.props.disabled;
  38. const childC = props ? child[this.props.options.value] : child.props.children;
  39. const values = props ? child[this.props.options.id] : child.props.value;
  40. const notes = props ? child[this.props.options.note] : child.props.note;
  41. const hightlight = props ? this.state.indexa === child[this.props.options.id] : this.state.indexa === child.props.value;
  42. return <Raio2
  43. child={childC}
  44. index={index}
  45. value={values}
  46. notes={notes}
  47. key={index}
  48. initStyle={this.props.innerStyle}
  49. txtColor={this.props.txtColor}
  50. noneColor={this.props.noneColor}
  51. onclick={this.click.bind(this)}
  52. hightlight={hightlight}
  53. disabled={disabled}
  54. seledImg={this.props.seledImg}
  55. selImg={this.props.selImg}
  56. selnoneImg={this.props.selnoneImg}
  57. />
  58. }
  59. render() {
  60. const that = this;
  61. return (
  62. <View {...this.props.style}>
  63. {
  64. !this.props.dataOption && React.Children.map(this.props.children, (child, index) => this.createInner(child, index))
  65. }
  66. {
  67. this.props.dataOption && this.props.dataOption.map((item, index) => this.createInner(item, index, true))
  68. }
  69. </View>
  70. )
  71. }
  72. }
  73. class Raio2 extends Component {
  74. constructor(props) {
  75. super(props);
  76. }
  77. click(id, item, notes) {
  78. if (this.props.disabled) {
  79. return
  80. } else {
  81. this.props.onclick(id, item, notes);
  82. }
  83. }
  84. render() {
  85. const imgUrl = this.props.hightlight ? this.props.seledImg || require('../../assets/images/selted.png') : this.props.selImg || require('../../assets/images/selt.png');
  86. const imgUrlNone = this.props.selnoneImg || require('../../assets/images/seltnone.png');
  87. return (
  88. <TouchableHighlight
  89. underlayColor='transparent'
  90. style={[{marginRight: 15, width: (width - 80) / 2, height: 24}, this.props.initStyle]}
  91. onPress={this.click.bind(this, this.props.value, this.props.child, this.props.notes)}>
  92. <View style={{flex: 1, flexDirection: 'row', alignItems: 'center'}}>
  93. {this.props.disabled && !this.props.hightlight &&
  94. <Image source={imgUrlNone} style={{width: 14, height: 14, marginRight: 7}}/>}
  95. {this.props.disabled && this.props.hightlight &&
  96. <Image source={imgUrl} style={{width: 14, height: 14, marginRight: 7}}/>}
  97. {!this.props.disabled && <Image source={imgUrl} style={{width: 14, height: 14, marginRight: 7}}/>}
  98. <Text
  99. style={{color: this.props.disabled ? this.props.noneColor || '#dfdfdf' : this.props.txtColor || '#414141'}}>{this.props.child}</Text>
  100. </View>
  101. </TouchableHighlight>
  102. )
  103. }
  104. }
  105. const styles = StyleSheet.create({
  106. titleCom: {
  107. marginBottom: 5,
  108. },
  109. seltedImgs: {
  110. width: 14,
  111. height: 14,
  112. marginRight: 8,
  113. },
  114. emailH: {
  115. height: 28,
  116. textAlignVertical: 'center',
  117. marginRight: 10,
  118. color: '#141414',
  119. fontSize: 12,
  120. },
  121. inputs: {
  122. width: width * 0.5,
  123. borderWidth: 1,
  124. borderColor: '#dfdfdf',
  125. borderRadius: 3,
  126. height: 28,
  127. padding: 0,
  128. paddingLeft: 5,
  129. paddingRight: 5,
  130. marginBottom: 10,
  131. fontSize: 12,
  132. },
  133. closeBtns: {
  134. position: 'absolute',
  135. width: 14,
  136. height: 14,
  137. right: 10,
  138. top: 7,
  139. },
  140. headLog: {
  141. backgroundColor: '#e6454a',
  142. color: '#ffffff',
  143. height: 28,
  144. textAlignVertical: 'center',
  145. textAlign: 'center'
  146. },
  147. border1: {
  148. borderWidth: 1,
  149. borderColor: '#dfdfdf',
  150. },
  151. borderR: {
  152. borderRightWidth: 1,
  153. borderRightColor: '#dfdfdf',
  154. },
  155. borderL: {
  156. borderLeftWidth: 1,
  157. borderLeftColor: '#dfdfdf',
  158. },
  159. eleMess: {
  160. paddingLeft: 10,
  161. paddingRight: 10,
  162. height: 24,
  163. fontSize: 12,
  164. color: '#ffffff',
  165. backgroundColor: '#f8cb43',
  166. borderRadius: 3,
  167. textAlignVertical: 'center',
  168. textAlign: 'center',
  169. width: 80,
  170. },
  171. electronicTip: {
  172. width: (width - 40) / 5,
  173. flexDirection: 'row',
  174. justifyContent: 'center',
  175. paddingTop: 10,
  176. paddingBottom: 10,
  177. },
  178. lineRow: {
  179. backgroundColor: '#ffffff',
  180. borderRadius: 3,
  181. flexDirection: 'row',
  182. flex: 1,
  183. marginBottom: 15,
  184. padding: 10,
  185. alignItems: 'center',
  186. justifyContent: 'space-between',
  187. flexWrap: 'wrap',
  188. },
  189. lineRowB: {
  190. backgroundColor: '#ffffff',
  191. borderRadius: 3,
  192. flexDirection: 'row',
  193. flex: 1,
  194. marginBottom: 15,
  195. paddingLeft: 10,
  196. paddingRight: 10,
  197. alignItems: 'center',
  198. },
  199. inner3: {
  200. width: (width - 40) / 3,
  201. fontSize: 12,
  202. color: '#141414'
  203. },
  204. innerS: {
  205. flexDirection: 'row',
  206. flex: 1,
  207. fontSize: 12,
  208. color: '#141414'
  209. },
  210. flex1: {
  211. flex: 1
  212. },
  213. flexRow: {
  214. flexDirection: 'row',
  215. },
  216. flexVer: {
  217. flexDirection: 'column',
  218. },
  219. Jcenter: {
  220. justifyContent: 'center',
  221. },
  222. Acenter: {
  223. alignItems: 'center',
  224. },
  225. BE: {
  226. justifyContent: 'space-between'
  227. },
  228. Textcenter: {
  229. textAlign: 'center',
  230. },
  231. TextCenterVer: {
  232. textAlignVertical: 'center',
  233. },
  234. backCGray: {
  235. backgroundColor: '#dfdfdf'
  236. },
  237. backWhite: {
  238. backgroundColor: '#ffffff',
  239. },
  240. borderRadius5: {
  241. borderRadius: 5,
  242. },
  243. borderRadius3: {
  244. borderRadius: 3,
  245. },
  246. horLine: {
  247. flexDirection: 'row',
  248. flex: 1,
  249. flexWrap: 'wrap',
  250. alignItems: 'flex-start',
  251. marginBottom: 10,
  252. },
  253. paddlr10: {
  254. paddingLeft: 10,
  255. paddingRight: 10,
  256. },
  257. marginB10: {
  258. marginBottom: 10,
  259. },
  260. colorRed: {
  261. color: '#b40e12',
  262. },
  263. colorBlack: {
  264. color: '#141414',
  265. },
  266. colorYellow: {
  267. color: '#f8cb43',
  268. },
  269. color999: {
  270. color: '#999999',
  271. },
  272. colorWhite: {
  273. color: '#ffffff',
  274. },
  275. })
  276. export default RadioModal