ViewCampaign.js 6.5 KB

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