userCenter.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /*
  2. * 个人中心页面
  3. */
  4. import React, { Component } from "react";
  5. import {
  6. Platform,
  7. StyleSheet,
  8. Text,
  9. View,
  10. Image,
  11. TouchableOpacity,
  12. ImageBackground,
  13. Button,
  14. StatusBar,
  15. Modal,
  16. TouchableHighlight,
  17. DeviceEventEmitter,
  18. ScrollView
  19. } from "react-native";
  20. import BasePage from "./BasePage";
  21. import Dimensions from "./utils/dimensions";
  22. import ShopBox from "./components/ShopBox";
  23. import TopicTitle from "./components/TopicTitle";
  24. import ScrollRow from "./components/ScrollRow";
  25. import CourseTitle from "./components/CourseTitle";
  26. import user from "./services/user";
  27. export default class userCenter extends BasePage {
  28. componentDidMount() {
  29. //触发更新
  30. this.refreshSubScription = DeviceEventEmitter.addListener('infoback', () => {
  31. user.userMember().then(res => {
  32. console.log("个人列表", res);
  33. // 收藏
  34. const favoritesList = res.data.favoritesList;
  35. //观看记录
  36. const playLogList = res.data.playLogList;
  37. // 用户消息
  38. const user = res.data.user;
  39. // VIP
  40. const vip = res.data.vip;
  41. this.setState({
  42. favoritesList,
  43. playLogList,
  44. user,
  45. vip
  46. });
  47. });
  48. })
  49. DeviceEventEmitter.emit('infoback')
  50. }
  51. componentWillUnmount(){
  52. this.refreshSubScription.remove();
  53. }
  54. state = {
  55. nickName: "初始昵称",
  56. user: {},
  57. ifDiscount: true,
  58. isVIP: false,
  59. btnArr: [
  60. {
  61. title: "订单",
  62. icon: require("./images/userCenter/order.png"),
  63. goTo: "Order"
  64. },
  65. {
  66. title: "抵用券",
  67. icon: require("./images/userCenter/discount.png"),
  68. goTo: "Ticket"
  69. },
  70. {
  71. title: "客服",
  72. icon: require("./images/userCenter/service.png"),
  73. goTo: "Order"
  74. }
  75. ],
  76. shopData: [
  77. {
  78. title: "1个月",
  79. originPrice: "199",
  80. price: "49",
  81. background: require("./images/shopBox/left.png")
  82. },
  83. {
  84. title: "12个月",
  85. originPrice: "499",
  86. price: "199",
  87. background: require("./images/shopBox/right.png")
  88. }
  89. ],
  90. discount: {
  91. title: "限时秒杀",
  92. icon: require("./images/shopBox/discount.png")
  93. },
  94. favoritesList: [],
  95. playLogList: [],
  96. vip: false
  97. };
  98. renderBtn = (item, index) => {
  99. return (
  100. <TouchableOpacity
  101. key={index}
  102. onPress={() => this.goTo(`${item.goTo}`)}
  103. style={{ display: "flex", justifyContent: "space-between" }}
  104. >
  105. <View style={styles.btnItem}>
  106. <Image source={item.icon} style={styles.btnIcon} />
  107. <Text style={styles.btnTitle}>{item.title}</Text>
  108. </View>
  109. </TouchableOpacity>
  110. );
  111. };
  112. goBack() {
  113. //返回上一页
  114. this.props.navigation.goBack();
  115. }
  116. render() {
  117. return (
  118. <ScrollView
  119. style={{ height: 1100, overflow: "scroll", backgroundColor: "#fff" }}
  120. >
  121. <View style={styles.topSection}>
  122. <ImageBackground
  123. source={require("./images/userCenter/top-bg.png")}
  124. style={{ width: "100%", height: 203 }}
  125. >
  126. <StatusBar
  127. backgroundColor={"transparent"}
  128. barStyle={"dark-content"}
  129. // backgroundColor={"white"}
  130. translucent={true}
  131. hidden={false}
  132. />
  133. <View
  134. style={{
  135. height: 30,
  136. // backgroundColor: "white"
  137. marginTop: 20
  138. }}
  139. >
  140. <CourseTitle
  141. width={this.getWindowWidth()}
  142. title="个人中心"
  143. lefttype={2}
  144. righttype={2}
  145. textcolor={"#fff"}
  146. backPress={() => this.goBack()}
  147. // backgroundColor={"transparent"}
  148. // rightPress={this.showSharedDialog.bind(this)}
  149. />
  150. </View>
  151. <View style={styles.userInfo}>
  152. <TouchableOpacity onPress={() => this.goTo(`PersonalInfo`)}>
  153. <Image
  154. style={styles.userAvatar}
  155. source={{ uri: this.state.user.avatar }}
  156. />
  157. </TouchableOpacity>
  158. <View style={styles.userRight}>
  159. <View style={styles.userName}>
  160. <Text style={styles.userNameText}>
  161. {this.state.user.nickName}
  162. </Text>
  163. {this.state.vip ? (
  164. <Image
  165. style={styles.vipTag}
  166. source={require("./images/common/vip.png")}
  167. />
  168. ) : null}
  169. </View>
  170. {this.state.vip ? null : (
  171. <View style={styles.userName}>
  172. <Text style={styles.vipSologan}>开通vip</Text>
  173. </View>
  174. )}
  175. </View>
  176. </View>
  177. <View style={styles.btnBoxWrapper}>
  178. <View style={styles.btnBox}>
  179. {this.state.btnArr.map((item, index) =>
  180. this.renderBtn(item, index)
  181. )}
  182. </View>
  183. </View>
  184. </ImageBackground>
  185. </View>
  186. <View style={styles.discountSection}>
  187. <ShopBox
  188. data={this.state.shopData}
  189. discount={this.state.discount}
  190. nav={this.props.navigation.navigate}
  191. />
  192. </View>
  193. <View style={styles.recordSection}>
  194. <TopicTitle title={"观看记录"} ifTubeShow={true} />
  195. <ScrollRow
  196. itemWidth={106}
  197. itemHeight={153}
  198. data={this.state.playLogList}
  199. />
  200. </View>
  201. <View style={styles.collectSection}>
  202. <TopicTitle title={"我的收藏"} ifTubeShow={true} />
  203. <ScrollRow
  204. itemWidth={106}
  205. itemHeight={150}
  206. data={this.state.favoritesList}
  207. />
  208. </View>
  209. </ScrollView>
  210. );
  211. }
  212. goTo(index) {
  213. this.toNextPage(index);
  214. }
  215. }
  216. const styles = StyleSheet.create({
  217. topSection: {
  218. height: 250,
  219. width: Dimensions.width
  220. // backgroundColor: 'red'
  221. },
  222. userInfo: {
  223. width: Dimensions.width,
  224. height: 70,
  225. flexDirection: "row",
  226. justifyContent: "flex-start",
  227. alignItems: "center"
  228. },
  229. userAvatar: {
  230. width: 67,
  231. height: 67,
  232. borderRadius: 55,
  233. marginHorizontal: 12
  234. },
  235. userRight: {
  236. flexDirection: "column"
  237. },
  238. userName: {
  239. flexDirection: "row",
  240. alignItems: "center"
  241. },
  242. userNameText: {
  243. fontSize: 18,
  244. color: "#fff",
  245. fontWeight: "500",
  246. marginRight: 9
  247. },
  248. vipSologan: {
  249. fontSize: 14,
  250. color: "#fff"
  251. },
  252. btnBoxWrapper: {
  253. width: Dimensions.width,
  254. alignItems: "center",
  255. marginTop: 16
  256. },
  257. btnBox: {
  258. width: (Dimensions.width * 343) / 375,
  259. height: 100,
  260. borderRadius: 10,
  261. shadowColor: "#000",
  262. // shadowOffset: 1,
  263. shadowOpacity: 2,
  264. shadowRadius: 5,
  265. elevation: 4,
  266. backgroundColor: "#fff",
  267. justifyContent: "space-around",
  268. flexDirection: "row"
  269. },
  270. btnItem: {
  271. height: "100%",
  272. flexDirection: "column",
  273. justifyContent: "center",
  274. alignItems: "center"
  275. },
  276. btnIcon: {
  277. width: 36,
  278. height: 24,
  279. marginBottom: 7
  280. },
  281. btnTitle: {
  282. color: "#3f3f3f",
  283. fontSize: 16
  284. },
  285. discountSection: {
  286. width: Dimensions.width
  287. // height: 242,
  288. // backgroundColor: 'green'
  289. },
  290. recordSection: {
  291. width: Dimensions.width,
  292. height: 235
  293. // backgroundColor: 'blue'
  294. },
  295. collectSection: {
  296. width: Dimensions.width,
  297. height: 255,
  298. marginBottom: 20
  299. // backgroundColor: 'yellow'
  300. }
  301. });