buy.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. };
  33. itemTap = (index) => {
  34. this.setState({
  35. currentTapindex: index
  36. })
  37. }
  38. renderItem = (item, index) => {
  39. return (
  40. <TouchableOpacity style={this.state.currentTapindex === index ? styles.itemWrapperTap : styles.itemWrapperNormal} onPress={() => { this.itemTap(index) }} key={index}>
  41. <Text style={this.state.currentTapindex === index ? styles.timeLengthTap : styles.timeLength}>{item.title}</Text>
  42. <Text style={this.state.currentTapindex === index ? styles.priceTap : styles.price}>¥{item.price}元</Text>
  43. <Text style={this.state.currentTapindex === index ? styles.originPriceTap : styles.originPrice}>原价:¥{item.originPrice}</Text>
  44. </TouchableOpacity>
  45. )
  46. }
  47. changeMethod = () => {
  48. this.setState({
  49. ifDialogShow: !this.state.ifDialogShow
  50. }, () => {
  51. Animated.timing(
  52. this.state.slideAnim,
  53. {
  54. toValue: 0,
  55. duration: 300,
  56. }
  57. ).start();
  58. })
  59. }
  60. render() {
  61. return (
  62. <View style={{ flex: 1 }}>
  63. <View
  64. style={{
  65. height: 30,
  66. marginTop: 30
  67. }}
  68. >
  69. <CourseTitle
  70. width={this.getWindowWidth()}
  71. title="VIP购买"
  72. lefttype={1}
  73. textcolor={"#231F20"}
  74. backPress={() => this.goBack()}
  75. // backPress={() => alert("左侧按钮")}
  76. />
  77. </View>
  78. <View style={styles.top}>
  79. <Text style={styles.title}>套餐选择</Text>
  80. <View>
  81. {this.state.shopData.map((item, index) => this.renderItem(item, index))}
  82. </View>
  83. </View>
  84. <TouchableOpacity style={styles.payment} onPress={() => this.changeMethod()}>
  85. <Text style={styles.left}>支付方式</Text>
  86. <View style={styles.right}>
  87. <Text style={styles.method}>微信支付</Text>
  88. <Image source={require('../images/common/arrowRight.png')} />
  89. </View>
  90. </TouchableOpacity>
  91. <View style={styles.bottom}>
  92. <Text style={styles.bottomLeft}>¥{this.state.shopData[this.state.currentTapindex].price}元</Text>
  93. <TouchableOpacity style={styles.bottomRight}>
  94. <Text style={styles.bottomRightText}>支付</Text>
  95. </TouchableOpacity>
  96. </View>
  97. {
  98. this.state.ifDialogShow
  99. ?
  100. <View style={{ ...styles.dialog }}>
  101. <Animated.View style={{ ...styles.payMethod, bottom: this.state.slideAnim }}>
  102. <Text>选择支付方式</Text>
  103. {/* <View> */}
  104. {/* </View> */}
  105. </Animated.View>
  106. </View>
  107. :
  108. null
  109. }
  110. {/* <Modal
  111. animationType="none "
  112. transparent={true}
  113. visible={true}
  114. onRequestClose={() => {
  115. alert("Modal has been closed.");
  116. }}
  117. ></Modal> */}
  118. </View>
  119. )
  120. }
  121. }
  122. const styles = StyleSheet.create({
  123. top: {
  124. width: Dimensions.width,
  125. flexDirection: 'column',
  126. alignItems: 'center',
  127. paddingBottom: 20
  128. },
  129. title: {
  130. fontSize: 20,
  131. color: '#a8674d',
  132. marginTop: 22,
  133. },
  134. itemWrapperNormal: {
  135. borderWidth: 1,
  136. borderColor: '#a8674d',
  137. borderRadius: 27,
  138. backgroundColor: '#fff',
  139. flexDirection: 'row',
  140. alignItems: 'center',
  141. justifyContent: 'space-around',
  142. width: '86%',
  143. height: Dimensions.getHeight(53),
  144. marginTop: 20,
  145. },
  146. itemWrapperTap: {
  147. // borderWidth: 1,
  148. // borderColor: '#a8674d',
  149. borderRadius: 27,
  150. backgroundColor: '#ff7525',
  151. flexDirection: 'row',
  152. alignItems: 'center',
  153. justifyContent: 'space-around',
  154. width: '86%',
  155. height: Dimensions.getHeight(53),
  156. marginTop: 20,
  157. },
  158. originPriceTap: {
  159. fontSize: 14,
  160. color: '#fff',
  161. textDecorationLine: 'line-through'
  162. },
  163. originPrice: {
  164. fontSize: 14,
  165. color: '#a8674d',
  166. textDecorationLine: 'line-through'
  167. },
  168. priceTap: {
  169. fontSize: 20,
  170. color: '#fff',
  171. },
  172. price: {
  173. fontSize: 20,
  174. color: '#a8674d',
  175. },
  176. timeLengthTap: {
  177. fontSize: 18,
  178. color: '#fff',
  179. },
  180. timeLength: {
  181. fontSize: 18,
  182. color: '#a8674d',
  183. },
  184. payment: {
  185. flexDirection: 'row',
  186. alignItems: 'center',
  187. width: Dimensions.width,
  188. height: 60,
  189. justifyContent: 'space-between',
  190. alignItems: 'center',
  191. borderColor: '#f3f2f7',
  192. borderTopWidth: 6,
  193. borderBottomWidth: 6,
  194. paddingHorizontal: 33
  195. },
  196. left: {
  197. fontSize: 16
  198. },
  199. right: {
  200. flexDirection: 'row',
  201. alignItems: 'center'
  202. },
  203. method: {
  204. color: '#a8674d',
  205. fontSize: 16,
  206. marginRight: 7
  207. },
  208. bottom: {
  209. width: Dimensions.width,
  210. height: 60,
  211. flexDirection: 'row',
  212. position: 'absolute',
  213. bottom: 0,
  214. },
  215. bottomLeft: {
  216. width: '58%',
  217. textAlign: 'center',
  218. lineHeight: 60,
  219. color: '#a8674d',
  220. fontSize: 20
  221. },
  222. bottomRight: {
  223. width: '42%',
  224. fontSize: 16,
  225. color: '#fff',
  226. backgroundColor: '#f5880d',
  227. alignItems: 'center'
  228. },
  229. bottomRightText: {
  230. fontSize: 20,
  231. color: '#fff',
  232. textAlign: 'center',
  233. lineHeight: 60,
  234. },
  235. dialog: {
  236. width: Dimensions.width,
  237. height: Dimensions.height,
  238. position: 'absolute',
  239. backgroundColor: '#000',
  240. opacity: 0.4
  241. },
  242. payMethod: {
  243. width: Dimensions.width,
  244. height: 150,
  245. position: 'absolute',
  246. // bottom: 0,
  247. backgroundColor: '#fff'
  248. }
  249. })