ViewCampaign.js 6.6 KB

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