buy.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*
  2. *
  3. */
  4. import React, { Component } from "react";
  5. import {
  6. Platform,
  7. StyleSheet,
  8. Text,
  9. View,
  10. Image,
  11. TouchableOpacity,
  12. FlatList,
  13. TouchableHighlight,
  14. DeviceEventEmitter,
  15. ScrollView,
  16. Modal,
  17. Animated,
  18. } from "react-native";
  19. import BasePage from "../BasePage";
  20. import Dimensions from '../utils/dimensions';
  21. import TopicTitle from '../components/TopicTitle';
  22. import CourseTitle from "../components/CourseTitle";
  23. export default class Buy extends BasePage {
  24. state = {
  25. shopData: [
  26. { title: '1个月', originPrice: '199', price: '49', },
  27. { title: '12个月', originPrice: '499', price: '199' }
  28. ],
  29. currentTapindex: 0,
  30. slideAnim: new Animated.Value(-150),
  31. ifDialogShow: false,
  32. payType: 1
  33. };
  34. itemTap = (index) => {
  35. this.setState({
  36. currentTapindex: index
  37. })
  38. }
  39. renderItem = (item, index) => {
  40. return (
  41. <TouchableOpacity style={this.state.currentTapindex === index ? styles.itemWrapperTap : styles.itemWrapperNormal} onPress={() => { this.itemTap(index) }} key={index}>
  42. <Text style={this.state.currentTapindex === index ? styles.timeLengthTap : styles.timeLength}>{item.title}</Text>
  43. <Text style={this.state.currentTapindex === index ? styles.priceTap : styles.price}>¥{item.price}元</Text>
  44. <Text style={this.state.currentTapindex === index ? styles.originPriceTap : styles.originPrice}>原价:¥{item.originPrice}</Text>
  45. </TouchableOpacity>
  46. )
  47. }
  48. dialogComeout = (index) => {
  49. if (index) {
  50. this.setState({
  51. ifDialogShow: true
  52. }, () => {
  53. Animated.timing(
  54. this.state.slideAnim,
  55. {
  56. toValue: 0,
  57. duration: 300,
  58. }
  59. ).start();
  60. })
  61. } else {
  62. Animated.timing(
  63. this.state.slideAnim,
  64. {
  65. toValue: -150,
  66. duration: 200,
  67. }
  68. ).start();
  69. setTimeout(() => {
  70. this.setState({
  71. ifDialogShow: false
  72. })
  73. }, 210)
  74. }
  75. }
  76. setPayMethod = (type) => {
  77. this.setState({
  78. payType: type
  79. },()=>{
  80. setTimeout(() => {
  81. this.dialogComeout(false)
  82. }, 100)
  83. })
  84. }
  85. render() {
  86. return (
  87. <View style={{ flex: 1 }}>
  88. <View
  89. style={{
  90. height: 30,
  91. marginTop: 30
  92. }}
  93. >
  94. <CourseTitle
  95. width={this.getWindowWidth()}
  96. title="VIP购买"
  97. lefttype={1}
  98. textcolor={"#231F20"}
  99. backPress={() => this.goBack()}
  100. // backPress={() => alert("左侧按钮")}
  101. />
  102. </View>
  103. <View style={styles.top}>
  104. <Text style={styles.title}>套餐选择</Text>
  105. <View>
  106. {this.state.shopData.map((item, index) => this.renderItem(item, index))}
  107. </View>
  108. </View>
  109. <TouchableOpacity style={styles.payment} onPress={() => this.dialogComeout(true)}>
  110. <Text style={styles.left}>支付方式</Text>
  111. <View style={styles.right}>
  112. <Text style={styles.method}>微信支付</Text>
  113. <Image source={require('../images/common/arrowRight.png')} />
  114. </View>
  115. </TouchableOpacity>
  116. <View style={styles.bottom}>
  117. <Text style={styles.bottomLeft}>¥{this.state.shopData[this.state.currentTapindex].price}元</Text>
  118. <TouchableOpacity style={styles.bottomRight}>
  119. <Text style={styles.bottomRightText}>支付</Text>
  120. </TouchableOpacity>
  121. </View>
  122. {
  123. this.state.ifDialogShow
  124. ?
  125. <TouchableHighlight
  126. onPress={() => { this.dialogComeout(false) }}
  127. style={{ ...styles.dialog }}
  128. underlayColor={0.1}
  129. >
  130. <Animated.View
  131. style={{ ...styles.payMethod, bottom: this.state.slideAnim }}
  132. onPress={() => { alert(12311) }}
  133. >
  134. <Text style={styles.payText}>选择支付方式</Text>
  135. <TouchableOpacity activeOpacity={0.9} style={styles.payDialog} onPress={() => this.setPayMethod(1)}>
  136. <View style={styles.dialogRow}>
  137. <Image style={styles.payIcon} source={require('../images/common/wxPay.png')} />
  138. <Text>微信支付</Text>
  139. </View>
  140. {
  141. this.state.payType === 1
  142. ?
  143. <Image source={require('../images/common/check.png')} />
  144. :
  145. null
  146. }
  147. </TouchableOpacity>
  148. <TouchableOpacity activeOpacity={0.9} style={styles.payDialog} onPress={() => this.setPayMethod(2)}>
  149. <View style={styles.dialogRow}>
  150. <Image style={styles.payIcon} source={require('../images/common/aliPay.png')} />
  151. <Text>支付宝支付</Text>
  152. </View>
  153. {
  154. this.state.payType === 2
  155. ?
  156. <Image source={require('../images/common/check.png')} />
  157. :
  158. null
  159. }
  160. </TouchableOpacity>
  161. </Animated.View>
  162. </TouchableHighlight>
  163. :
  164. null
  165. }
  166. {/* <Modal
  167. animationType="none "
  168. transparent={true}
  169. visible={true}
  170. onRequestClose={() => {
  171. alert("Modal has been closed.");
  172. }}
  173. ></Modal> */}
  174. </View>
  175. )
  176. }
  177. }
  178. const styles = StyleSheet.create({
  179. top: {
  180. width: Dimensions.width,
  181. flexDirection: 'column',
  182. alignItems: 'center',
  183. paddingBottom: 20
  184. },
  185. title: {
  186. fontSize: 20,
  187. color: '#a8674d',
  188. marginTop: 22,
  189. },
  190. itemWrapperNormal: {
  191. borderWidth: 1,
  192. borderColor: '#a8674d',
  193. borderRadius: 27,
  194. backgroundColor: '#fff',
  195. flexDirection: 'row',
  196. alignItems: 'center',
  197. justifyContent: 'space-around',
  198. width: '86%',
  199. height: Dimensions.getHeight(53),
  200. marginTop: 20,
  201. },
  202. itemWrapperTap: {
  203. // borderWidth: 1,
  204. // borderColor: '#a8674d',
  205. borderRadius: 27,
  206. backgroundColor: '#ff7525',
  207. flexDirection: 'row',
  208. alignItems: 'center',
  209. justifyContent: 'space-around',
  210. width: '86%',
  211. height: Dimensions.getHeight(53),
  212. marginTop: 20,
  213. },
  214. originPriceTap: {
  215. fontSize: 14,
  216. color: '#fff',
  217. textDecorationLine: 'line-through'
  218. },
  219. originPrice: {
  220. fontSize: 14,
  221. color: '#a8674d',
  222. textDecorationLine: 'line-through'
  223. },
  224. priceTap: {
  225. fontSize: 20,
  226. color: '#fff',
  227. },
  228. price: {
  229. fontSize: 20,
  230. color: '#a8674d',
  231. },
  232. timeLengthTap: {
  233. fontSize: 18,
  234. color: '#fff',
  235. },
  236. timeLength: {
  237. fontSize: 18,
  238. color: '#a8674d',
  239. },
  240. payment: {
  241. flexDirection: 'row',
  242. alignItems: 'center',
  243. width: Dimensions.width,
  244. height: 60,
  245. justifyContent: 'space-between',
  246. alignItems: 'center',
  247. borderColor: '#f3f2f7',
  248. borderTopWidth: 6,
  249. borderBottomWidth: 6,
  250. paddingHorizontal: 33
  251. },
  252. left: {
  253. fontSize: 16
  254. },
  255. right: {
  256. flexDirection: 'row',
  257. alignItems: 'center'
  258. },
  259. method: {
  260. color: '#a8674d',
  261. fontSize: 16,
  262. marginRight: 7
  263. },
  264. bottom: {
  265. width: Dimensions.width,
  266. height: 60,
  267. flexDirection: 'row',
  268. position: 'absolute',
  269. bottom: 0,
  270. },
  271. bottomLeft: {
  272. width: '58%',
  273. textAlign: 'center',
  274. lineHeight: 60,
  275. color: '#a8674d',
  276. fontSize: 20
  277. },
  278. bottomRight: {
  279. width: '42%',
  280. fontSize: 16,
  281. color: '#fff',
  282. backgroundColor: '#f5880d',
  283. alignItems: 'center'
  284. },
  285. bottomRightText: {
  286. fontSize: 20,
  287. color: '#fff',
  288. textAlign: 'center',
  289. lineHeight: 60,
  290. },
  291. dialog: {
  292. width: Dimensions.width,
  293. height: Dimensions.height,
  294. position: 'absolute',
  295. backgroundColor: 'rgba(0,0,0,0.4)',
  296. },
  297. payMethod: {
  298. width: Dimensions.width,
  299. height: 150,
  300. position: 'absolute',
  301. // bottom: 0,
  302. backgroundColor: '#fff',
  303. flexDirection: 'column',
  304. alignItems: 'center',
  305. justifyContent: 'flex-start'
  306. },
  307. payDialog: {
  308. width: '90%',
  309. borderTopWidth: 1,
  310. borderColor: '#e4e4e4',
  311. flexDirection: 'row',
  312. alignItems: 'center',
  313. justifyContent: 'space-between',
  314. flex: 1
  315. },
  316. dialogRow: {
  317. flexDirection: 'row',
  318. alignItems: 'center',
  319. },
  320. payIcon: {
  321. marginRight: 17
  322. },
  323. payText: {
  324. fontSize: 16,
  325. color: '#191919',
  326. alignContent: 'center',
  327. flex: 1,
  328. lineHeight: 50
  329. }
  330. })