ViewCampaign.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /**
  2. * 活动详情
  3. * @邠心vbe on 2023/08/17
  4. */
  5. import React, { Component } from 'react';
  6. import { View, StyleSheet, Image, ScrollView, Linking } from 'react-native';
  7. import Swiper from 'react-native-swiper';
  8. import apiArticle from '../../api/apiArticle';
  9. import { ElevationObject } from '../../components/Button';
  10. import HeaderTitle from '../../components/HeaderTitle';
  11. import TextView from '../../components/TextView';
  12. import utils from '../../utils/utils';
  13. import { PagerView } from './ViewUtil';
  14. import VbeSkeleton from '../../components/VbeSkeleton';
  15. export default class ViewCampaign extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. id: "",
  20. loading: true,
  21. messageInfo: {
  22. articleTypeName: "",
  23. articleTitle: "",
  24. articleContent: ""
  25. }
  26. };
  27. }
  28. componentDidMount() {
  29. if (this.props.route?.params?.id) {
  30. this.setState({
  31. id: this.props.route?.params?.id
  32. }, () => {
  33. this.readMessage();
  34. })
  35. }
  36. }
  37. readMessage() {
  38. apiArticle.readMessage(this.state.id).then(res => {
  39. if (res.data) {
  40. this.setState({
  41. messageInfo: res.data
  42. });
  43. this.setPageTitle();
  44. }
  45. }).catch(err => {
  46. toastShort(err);
  47. });
  48. }
  49. setPageTitle() {
  50. if (this.state.messageInfo.articleTitle) {
  51. this.props.navigation.setOptions({
  52. headerTitle: () => (<HeaderTitle title={this.state.messageInfo.articleTitle}/>)
  53. })
  54. setTimeout(() => {
  55. this.setState({
  56. loading: false
  57. });
  58. }, 300);
  59. }
  60. }
  61. accessLink(url) {
  62. Linking.openURL(utils.getImageUrl(url))
  63. }
  64. getColorByType(type) {
  65. switch (type) {
  66. case "Ended":
  67. return {
  68. backgroundColor: "#E11919"
  69. }
  70. case "Upcoming":
  71. return {
  72. backgroundColor: "#FFAA2C"
  73. }
  74. }
  75. }
  76. render() {
  77. if (this.state.loading) {
  78. return (
  79. <View style={styles.container}>
  80. <VbeSkeleton
  81. style={{width: $width, height: $width}}
  82. layout={[
  83. {width: $width, height: $width}
  84. ]}
  85. animationDirection={"horizontalRight"}/>
  86. <VbeSkeleton
  87. style={styles.loadingView}
  88. layout={[
  89. {width: '90%', height: 20, marginTop: 8},
  90. {width: '50%', height: 12, marginTop: 8},
  91. {width: '100%', height: 15, marginTop: 24},
  92. {width: '100%', height: 15, marginTop: 8},
  93. {width: '100%', height: 15, marginTop: 8},
  94. {width: '100%', height: 15, marginTop: 8},
  95. {width: '30%', height: 15, marginTop: 8}
  96. ]}
  97. animationDirection={"horizontalRight"}/>
  98. </View>
  99. )
  100. }
  101. return (
  102. <ScrollView
  103. style={styles.container}
  104. contentContainerStyle={$padding(0,0,32)}
  105. stickyHeaderIndices={[utils.isNotEmpty(this.state.messageInfo.articleImages) ? 1 : 0]}>
  106. { utils.isNotEmpty(this.state.messageInfo.articleImages) &&
  107. <Swiper
  108. style={{height: $width}}
  109. autoplay={true}
  110. autoplayTimeout={5}
  111. renderPagination={(index,total) => <PagerView index={index+1} total={total}/> }
  112. removeClippedSubviews={false}>
  113. { this.state.messageInfo.articleImages.map((item, index) => {
  114. return (
  115. <Image
  116. key={index}
  117. style={{width: $width, height: $width}}
  118. source={{uri: utils.getImageUrl(item.articleImagePath)}}/>
  119. );
  120. })}
  121. </Swiper>
  122. }
  123. <View style={styles.header}>
  124. <View>
  125. <TextView
  126. style={[styles.labelTypeText, this.getColorByType(this.state.messageInfo.campaignMark)]}
  127. numberOfLines={1}>
  128. {this.state.messageInfo.campaignMark}
  129. </TextView>
  130. <TextView
  131. style={styles.textTitle}
  132. numberOfLines={2}
  133. ellipsizeMode="tail">
  134. <TextView
  135. style={styles.hideText}
  136. numberOfLines={1}>
  137. {this.state.messageInfo.campaignMark}
  138. </TextView>
  139. {this.state.messageInfo.articleTitle}
  140. </TextView>
  141. </View>
  142. <View style={ui.flexc}>
  143. <MaterialCommunityIcons
  144. name="clock-time-four-outline"
  145. color={textSecondary}
  146. size={12}/>
  147. <TextView
  148. style={styles.textDate}
  149. numberOfLines={1}>
  150. {this.state.messageInfo.createTime}
  151. </TextView>
  152. <MaterialCommunityIcons
  153. name="eye-check-outline"
  154. size={12}
  155. color={textPrimary}/>
  156. <TextView
  157. style={styles.textView}
  158. numberOfLines={1}>
  159. {this.state.messageInfo.articleViews}
  160. </TextView>
  161. </View>
  162. </View>
  163. <TextView style={styles.textLinkTitle}>{$t("notification.labelSummary")}</TextView>
  164. <TextView
  165. style={styles.textSummary}>
  166. {$t("notification.startTime")}
  167. {this.state.messageInfo.startTime}
  168. </TextView>
  169. <TextView
  170. style={styles.textSummary}>
  171. {$t("notification.endTime")}
  172. {this.state.messageInfo.endTime}
  173. </TextView>
  174. <TextView style={styles.textLinkTitle}>{$t("notification.labelDetails")}</TextView>
  175. <TextView
  176. style={styles.textMessage}
  177. selectable={true}>
  178. {this.state.messageInfo.articleContent}
  179. </TextView>
  180. { utils.isNotEmpty(this.state.messageInfo.articleLinks) &&
  181. <>
  182. <TextView style={styles.textLinkTitle}>{$t("notification.labelLinks")}</TextView>
  183. { this.state.messageInfo.articleLinks.map((item, index) =>
  184. <View style={styles.itemLink} key={index}>
  185. <TextView style={styles.linkIndex}>{index + 1}.</TextView>
  186. <TextView
  187. style={styles.linkHyper}
  188. onPress={() => this.accessLink(item.articleLink)}>{item.articleLinkName}</TextView>
  189. </View>
  190. )}
  191. </>
  192. }
  193. <EndView/>
  194. </ScrollView>
  195. );
  196. }
  197. }
  198. const styles = StyleSheet.create({
  199. container: {
  200. flex: 1,
  201. backgroundColor: pageBackground
  202. },
  203. loadingView: {
  204. flex: 1,
  205. padding: 16,
  206. justifyContent: 'flex-start',
  207. backgroundColor: pageBackground
  208. },
  209. textTitle: {
  210. color: textPrimary,
  211. fontSize: 18,
  212. fontWeight: 'bold',
  213. paddingBottom: 2
  214. },
  215. textDate: {
  216. flex: 1,
  217. color: textSecondary,
  218. fontSize: 10,
  219. paddingLeft: 2
  220. },
  221. textView: {
  222. color: textSecondary,
  223. fontSize: 10,
  224. paddingLeft: 4
  225. },
  226. header: {
  227. padding: 16,
  228. ...ElevationObject(1),
  229. backgroundColor: pageBackground
  230. },
  231. textSummary: {
  232. color: textPrimary,
  233. fontSize: 14,
  234. ...$padding(0, 16, 8)
  235. },
  236. textMessage: {
  237. color: textPrimary,
  238. fontSize: 14,
  239. ...$padding(0, 16, 16)
  240. },
  241. labelTypeText: {
  242. color: textLight,
  243. height: 16,
  244. fontSize: 10,
  245. borderRadius: 4,
  246. marginTop: 3,
  247. ...$padding(0, 6),
  248. position: 'absolute',
  249. backgroundColor: "#1ABD00"
  250. },
  251. hideText: {
  252. height: 16,
  253. opacity: 0,
  254. fontSize: 10,
  255. ...$padding(2, 8),
  256. },
  257. textLinkTitle: {
  258. color: textPrimary,
  259. fontSize: 16,
  260. fontWeight: 'bold',
  261. padding: 16
  262. },
  263. itemLink: {
  264. ...$padding(0, 16, 8),
  265. flexDirection: 'row'
  266. },
  267. linkIndex: {
  268. fontSize: 14,
  269. paddingRight: 2
  270. },
  271. linkHyper: {
  272. ...ui.link,
  273. fontSize: 14,
  274. textDecorationLine: 'underline'
  275. },
  276. linkActive: {
  277. color: "#FF3B30"
  278. }
  279. })