VoucherDetails.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /**
  2. * 代金券详情页面
  3. * @邠心vbe on 2024/04/17
  4. */
  5. import React, { Component } from 'react';
  6. import { View, StyleSheet, Text, TouchableOpacity, ScrollView } from 'react-native';
  7. import TextView from '../../components/TextView';
  8. import apiVoucher from '../../api/apiVoucher';
  9. import Dialog from '../../components/Dialog';
  10. import utils from '../../utils/utils';
  11. import VbeSkeleton from '../../components/VbeSkeleton';
  12. export default class VoucherDetails extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. loading: true,
  17. voucherId: "",
  18. voucherInfo: {}
  19. };
  20. }
  21. componentDidMount() {
  22. const params = this.props.route.params;
  23. if (params.id) {
  24. this.setState({
  25. voucherId: params.id
  26. }, () => {
  27. this.getVoucherDetail();
  28. })
  29. }
  30. }
  31. getVoucherDetail() {
  32. apiVoucher.getVoucherInfo(this.state.voucherId).then(res => {
  33. if (res.data) {
  34. this.setState({
  35. voucherInfo: res.data
  36. })
  37. }
  38. }).catch(err => {
  39. toastShort(err)
  40. }).finally(() => {
  41. this.setState({
  42. loading: false
  43. })
  44. });
  45. }
  46. getDaysText() {
  47. if (this.state.voucherInfo.eligibleForUsageOn) {
  48. if (typeof this.state.voucherInfo.eligibleForUsageOn == 'string') {
  49. this.state.voucherInfo.eligibleForUsageOn = this.state.voucherInfo.eligibleForUsageOn.split(",");
  50. }
  51. return this.state.voucherInfo.eligibleForUsageOn.join(", ");
  52. } else {
  53. return "Every day";
  54. }
  55. }
  56. getTypeText() {
  57. if (this.state.voucherInfo.chargeType) {
  58. return this.state.voucherInfo.chargeType;
  59. } else {
  60. return "AC & DC";
  61. }
  62. }
  63. toSiteDetail(id) {
  64. utils.toChargeDetailPage(id, "view");
  65. }
  66. render() {
  67. if (this.state.loading) {
  68. return (
  69. <VbeSkeleton
  70. style={styles.loadingView}
  71. viewStyle={styles.container}
  72. layout={[
  73. {width: '100%', height: 20},
  74. {width: '50%', height: 20, marginTop: 8},
  75. {width: '30%', height: 18, marginTop: 32},
  76. {width: '100%', height: 15, marginTop: 16},
  77. {width: '100%', height: 15, marginTop: 8},
  78. {width: '60%', height: 15, marginTop: 8},
  79. {width: '30%', height: 18, marginTop: 24},
  80. {width: '100%', height: 15, marginTop: 8},
  81. {width: '100%', height: 15, marginTop: 8},
  82. {width: '60%', height: 15, marginTop: 8},
  83. {width: '30%', height: 18, marginTop: 24},
  84. {width: '100%', height: 15, marginTop: 8},
  85. {width: '100%', height: 15, marginTop: 8},
  86. {width: '60%', height: 15, marginTop: 8},
  87. {width: '30%', height: 18, marginTop: 24},
  88. {width: '100%', height: 15, marginTop: 8},
  89. {width: '100%', height: 15, marginTop: 8},
  90. {width: '60%', height: 15, marginTop: 8},
  91. {width: '30%', height: 18, marginTop: 24},
  92. {width: '100%', height: 15, marginTop: 8},
  93. {width: '100%', height: 15, marginTop: 8},
  94. {width: '60%', height: 15, marginTop: 8}
  95. ]}/>
  96. )
  97. }
  98. return (
  99. <ScrollView
  100. style={styles.container}
  101. contentContainerStyle={$padding(16)}>
  102. <TextView style={styles.voucherName}>{this.state.voucherInfo.voucherName}</TextView>
  103. <EndView half/>
  104. <TextView style={styles.labelText}>{$t("voucher.voucherType")}</TextView>
  105. <TextView style={styles.valueText}>{this.state.voucherInfo.voucherType}</TextView>
  106. <TextView style={styles.labelText}>{$t("voucher.description")}</TextView>
  107. <TextView style={styles.valueText}>{this.state.voucherInfo.voucherDesc}</TextView>
  108. <TextView style={styles.labelText}>{$t("voucher.validityPeriod")}</TextView>
  109. <TextView style={styles.valueText}>{this.state.voucherInfo.validityPeriod}</TextView>
  110. <TextView style={styles.labelText}>{$t("voucher.voucherCondition")}</TextView>
  111. <View style={styles.olView}>
  112. <View style={ui.flexc}>
  113. <MaterialIcons
  114. style={styles.circleIcon}
  115. name="circle"
  116. color={textPrimary}
  117. size={6}/>
  118. <TextView style={styles.valueText}>
  119. {$t("voucher.conditionDays")} <Text style={ui.bold}>{this.getDaysText()}</Text>
  120. </TextView>
  121. </View>
  122. <View style={ui.flexc}>
  123. <MaterialIcons
  124. style={styles.circleIcon}
  125. name="circle"
  126. color={textPrimary}
  127. size={6}/>
  128. <TextView style={styles.valueText}>
  129. {$t("voucher.conditionTime")} <Text style={ui.bold}>{this.state.voucherInfo.eligibleForUsageDuring}</Text>
  130. </TextView>
  131. </View>
  132. <View style={ui.flexc}>
  133. <MaterialIcons
  134. style={styles.circleIcon}
  135. name="circle"
  136. color={textPrimary}
  137. size={6}/>
  138. <TextView style={styles.valueText}>
  139. <Text style={ui.bold}>{this.getTypeText()}</Text> {$t("voucher.conditionTypeOnly")}
  140. </TextView>
  141. </View>
  142. <View style={ui.flexc}>
  143. <MaterialIcons
  144. style={styles.circleIcon}
  145. name="circle"
  146. color={textPrimary}
  147. size={6}/>
  148. <TextView style={styles.valueText}>
  149. {$t("voucher.conditionCountry")} <Text style={ui.bold}>{this.state.voucherInfo.country}</Text>
  150. </TextView>
  151. </View>
  152. <View style={ui.flexc}>
  153. <MaterialIcons
  154. style={styles.circleIcon}
  155. name="circle"
  156. color={textPrimary}
  157. size={6}/>
  158. <TextView style={styles.valueText}>
  159. {$t("voucher.conditionMinSpend")} <Text style={ui.bold}>{this.state.voucherInfo.minimumSpend}</Text>
  160. </TextView>
  161. </View>
  162. </View>
  163. <TextView style={styles.labelText}>{$t("voucher.siteEligibility")}</TextView>
  164. <View style={styles.olView}>
  165. { this.state.voucherInfo.siteNames?.map((item, index) => (
  166. <TouchableOpacity
  167. style={styles.siteRow}
  168. onPress={() => this.toSiteDetail(item.sitePk)}
  169. key={index}>
  170. <MaterialIcons
  171. style={styles.circleIcon}
  172. name="circle"
  173. color={textPrimary}
  174. size={6}/>
  175. <TextView style={ui.link}>{item?.siteName}</TextView>
  176. </TouchableOpacity>
  177. ))
  178. }
  179. </View>
  180. </ScrollView>
  181. );
  182. }
  183. }
  184. const styles = StyleSheet.create({
  185. container: {
  186. flex: 1,
  187. backgroundColor: pageBackground
  188. },
  189. loadingView: {
  190. flex: 1,
  191. padding: 16,
  192. justifyContent: 'flex-start',
  193. backgroundColor: pageBackground
  194. },
  195. voucherName: {
  196. color: textPrimary,
  197. fontSize: 16,
  198. fontWeight: 'bold',
  199. paddingTop: 4,
  200. paddingBottom: 12,
  201. borderBottomWidth: 2,
  202. borderColor: colorPrimary
  203. },
  204. labelText: {
  205. color: textPrimary,
  206. fontSize: 14,
  207. fontWeight: 'bold',
  208. paddingTop: 16
  209. },
  210. valueText: {
  211. color: textSecondary,
  212. fontSize: 14,
  213. paddingTop: 6
  214. },
  215. olView: {
  216. paddingTop: 6,
  217. paddingLeft: 8
  218. },
  219. circleIcon: {
  220. paddingTop: 3,
  221. paddingRight: 8
  222. },
  223. siteRow: {
  224. paddingTop: 4,
  225. paddingBottom: 4,
  226. flexDirection: 'row'
  227. }
  228. })