ViewCampaign.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. { this.state.messageInfo.articleImages.map((item, index) => {
  84. return (
  85. <Image
  86. key={index}
  87. style={{width: $width, height: $width}}
  88. source={{uri: utils.getImageUrl(item.articleImagePath)}}/>
  89. );
  90. })}
  91. </Swiper>
  92. }
  93. <View style={styles.header}>
  94. <View>
  95. <TextView
  96. style={[styles.labelTypeText, this.getColorByType(this.state.messageInfo.campaignMark)]}
  97. numberOfLines={1}>
  98. {this.state.messageInfo.campaignMark}
  99. </TextView>
  100. <TextView
  101. style={styles.textTitle}
  102. numberOfLines={2}
  103. ellipsizeMode="tail">
  104. <TextView
  105. style={styles.hideText}
  106. numberOfLines={1}>
  107. {this.state.messageInfo.campaignMark}
  108. </TextView>
  109. {this.state.messageInfo.articleTitle}
  110. </TextView>
  111. </View>
  112. <View style={ui.flexc}>
  113. <MaterialCommunityIcons
  114. name="clock-time-four-outline"
  115. color={textSecondary}
  116. size={12}/>
  117. <TextView
  118. style={styles.textDate}
  119. numberOfLines={1}>
  120. {this.state.messageInfo.createTime}
  121. </TextView>
  122. <MaterialCommunityIcons
  123. name="eye-check-outline"
  124. size={12}
  125. color={textPrimary}/>
  126. <TextView
  127. style={styles.textView}
  128. numberOfLines={1}>
  129. {this.state.messageInfo.articleViews}
  130. </TextView>
  131. </View>
  132. </View>
  133. <TextView style={styles.textLinkTitle}>{$t("notification.labelSummary")}</TextView>
  134. <TextView
  135. style={styles.textSummary}>
  136. {$t("notification.startTime")}
  137. {this.state.messageInfo.startTime}
  138. </TextView>
  139. <TextView
  140. style={styles.textSummary}>
  141. {$t("notification.endTime")}
  142. {this.state.messageInfo.endTime}
  143. </TextView>
  144. <TextView style={styles.textLinkTitle}>{$t("notification.labelDetails")}</TextView>
  145. <TextView
  146. style={styles.textMessage}>
  147. {this.state.messageInfo.articleContent}
  148. </TextView>
  149. { utils.isNotEmpty(this.state.messageInfo.articleLinks) &&
  150. <>
  151. <TextView style={styles.textLinkTitle}>{$t("notification.labelLinks")}</TextView>
  152. { this.state.messageInfo.articleLinks.map((item, index) =>
  153. <View style={styles.itemLink} key={index}>
  154. <TextView style={styles.linkIndex}>{index + 1}.</TextView>
  155. <TextView
  156. style={styles.linkHyper}
  157. onPress={() => this.accessLink(item.articleLink)}>{item.articleLinkName}</TextView>
  158. </View>
  159. )}
  160. </>
  161. }
  162. <EndView/>
  163. </ScrollView>
  164. );
  165. }
  166. }
  167. const styles = StyleSheet.create({
  168. container: {
  169. flex: 1,
  170. backgroundColor: pageBackground
  171. },
  172. textTitle: {
  173. color: textPrimary,
  174. fontSize: 18,
  175. fontWeight: 'bold',
  176. paddingBottom: 2
  177. },
  178. textDate: {
  179. flex: 1,
  180. color: textSecondary,
  181. fontSize: 10,
  182. paddingLeft: 2
  183. },
  184. textView: {
  185. color: textSecondary,
  186. fontSize: 10,
  187. paddingLeft: 4
  188. },
  189. header: {
  190. padding: 16,
  191. ...ElevationObject(1),
  192. backgroundColor: pageBackground
  193. },
  194. textSummary: {
  195. color: textPrimary,
  196. fontSize: 14,
  197. ...$padding(0, 16, 8)
  198. },
  199. textMessage: {
  200. color: textPrimary,
  201. fontSize: 14,
  202. ...$padding(0, 16, 16)
  203. },
  204. labelTypeText: {
  205. color: textLight,
  206. height: 16,
  207. fontSize: 10,
  208. borderRadius: 4,
  209. marginTop: 3,
  210. ...$padding(0, 6),
  211. position: 'absolute',
  212. backgroundColor: "#1ABD00"
  213. },
  214. hideText: {
  215. height: 16,
  216. opacity: 0,
  217. fontSize: 10,
  218. ...$padding(2, 8),
  219. },
  220. textLinkTitle: {
  221. color: textPrimary,
  222. fontSize: 16,
  223. fontWeight: 'bold',
  224. padding: 16
  225. },
  226. itemLink: {
  227. ...$padding(0, 16, 8),
  228. flexDirection: 'row'
  229. },
  230. linkIndex: {
  231. fontSize: 14,
  232. paddingRight: 2
  233. },
  234. linkHyper: {
  235. ...ui.link,
  236. fontSize: 14,
  237. textDecorationLine: 'underline'
  238. },
  239. linkActive: {
  240. color: "#FF3B30"
  241. }
  242. })