VoucherDetails.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /**
  2. * 代金券详情页面
  3. * @邠心vbe on 2024/04/17
  4. */
  5. import React, { Component } from 'react';
  6. import { View, StyleSheet, Text, TouchableOpacity } from 'react-native';
  7. import TextView from '../../components/TextView';
  8. import app from '../../../app.json';
  9. import apiVoucher from '../../api/apiVoucher';
  10. import Dialog from '../../components/Dialog';
  11. import utils from '../../utils/utils';
  12. export default class VoucherDetails extends Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. voucherId: "",
  17. voucherInfo: {}
  18. };
  19. }
  20. componentDidMount() {
  21. const params = this.props.route.params;
  22. if (params.id) {
  23. this.setState({
  24. voucherId: params.id
  25. }, () => {
  26. this.getVoucherDetail();
  27. })
  28. }
  29. }
  30. getVoucherDetail() {
  31. Dialog.showProgressDialog();
  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. Dialog.dismissLoading();
  42. });
  43. }
  44. getDaysText() {
  45. if (this.state.voucherInfo.eligibleForUsageOn) {
  46. if (typeof this.state.voucherInfo.eligibleForUsageOn == 'string') {
  47. this.state.voucherInfo.eligibleForUsageOn = this.state.voucherInfo.eligibleForUsageOn.split(",");
  48. }
  49. return this.state.voucherInfo.eligibleForUsageOn.join(", ");
  50. } else {
  51. return "Every day";
  52. }
  53. }
  54. getTypeText() {
  55. if (this.state.voucherInfo.chargeType) {
  56. return this.state.voucherInfo.chargeType;
  57. } else {
  58. return "AC & DC";
  59. }
  60. }
  61. toSiteDetail(id) {
  62. utils.toChargeDetailPage(id, "view");
  63. }
  64. render() {
  65. return (
  66. <View style={styles.container}>
  67. <TextView style={styles.voucherName}>{this.state.voucherInfo.voucherName}</TextView>
  68. <EndView half/>
  69. <TextView style={styles.labelText}>{$t("voucher.voucherType")}</TextView>
  70. <TextView style={styles.valueText}>{this.state.voucherInfo.voucherType}</TextView>
  71. <TextView style={styles.labelText}>{$t("voucher.description")}</TextView>
  72. <TextView style={styles.valueText}>{this.state.voucherInfo.voucherDesc}</TextView>
  73. <TextView style={styles.labelText}>{$t("voucher.validityPeriod")}</TextView>
  74. <TextView style={styles.valueText}>{this.state.voucherInfo.validityPeriod}</TextView>
  75. <TextView style={styles.labelText}>{$t("voucher.voucherCondition")}</TextView>
  76. <View style={styles.olView}>
  77. <View style={ui.flexc}>
  78. <MaterialIcons
  79. style={styles.circleIcon}
  80. name="circle"
  81. color={textPrimary}
  82. size={6}/>
  83. <TextView style={styles.valueText}>
  84. {$t("voucher.conditionDays")} <Text style={ui.bold}>{this.getDaysText()}</Text>
  85. </TextView>
  86. </View>
  87. <View style={ui.flexc}>
  88. <MaterialIcons
  89. style={styles.circleIcon}
  90. name="circle"
  91. color={textPrimary}
  92. size={6}/>
  93. <TextView style={styles.valueText}>
  94. {$t("voucher.conditionTime")} <Text style={ui.bold}>{this.state.voucherInfo.eligibleForUsageDuring}</Text>
  95. </TextView>
  96. </View>
  97. <View style={ui.flexc}>
  98. <MaterialIcons
  99. style={styles.circleIcon}
  100. name="circle"
  101. color={textPrimary}
  102. size={6}/>
  103. <TextView style={styles.valueText}>
  104. <Text style={ui.bold}>{this.getTypeText()}</Text> {$t("voucher.conditionTypeOnly")}
  105. </TextView>
  106. </View>
  107. <View style={ui.flexc}>
  108. <MaterialIcons
  109. style={styles.circleIcon}
  110. name="circle"
  111. color={textPrimary}
  112. size={6}/>
  113. <TextView style={styles.valueText}>
  114. {$t("voucher.conditionCountry")} <Text style={ui.bold}>{this.state.voucherInfo.country}</Text>
  115. </TextView>
  116. </View>
  117. <View style={ui.flexc}>
  118. <MaterialIcons
  119. style={styles.circleIcon}
  120. name="circle"
  121. color={textPrimary}
  122. size={6}/>
  123. <TextView style={styles.valueText}>
  124. {$t("voucher.conditionMinSpend")} <Text style={ui.bold}>{this.state.voucherInfo.minimumSpend}</Text>
  125. </TextView>
  126. </View>
  127. </View>
  128. <TextView style={styles.labelText}>{$t("voucher.siteEligibility")}</TextView>
  129. <View style={styles.olView}>
  130. { this.state.voucherInfo.siteNames?.map((item, index) => (
  131. <TouchableOpacity
  132. style={styles.siteRow}
  133. onPress={() => this.toSiteDetail(item.sitePk)}
  134. key={index}>
  135. <MaterialIcons
  136. style={styles.circleIcon}
  137. name="circle"
  138. color={textPrimary}
  139. size={6}/>
  140. <TextView style={ui.link}>{item?.siteName}</TextView>
  141. </TouchableOpacity>
  142. ))
  143. }
  144. </View>
  145. </View>
  146. );
  147. }
  148. }
  149. const styles = StyleSheet.create({
  150. container: {
  151. flex: 1,
  152. padding: 16
  153. },
  154. voucherName: {
  155. color: textPrimary,
  156. fontSize: 16,
  157. fontWeight: 'bold',
  158. paddingTop: 4,
  159. paddingBottom: 12,
  160. borderBottomWidth: 2,
  161. borderColor: colorPrimary
  162. },
  163. labelText: {
  164. color: textPrimary,
  165. fontSize: 14,
  166. fontWeight: 'bold',
  167. paddingTop: 16
  168. },
  169. valueText: {
  170. color: textSecondary,
  171. fontSize: 14,
  172. paddingTop: 4
  173. },
  174. olView: {
  175. paddingLeft: 8
  176. },
  177. circleIcon: {
  178. paddingTop: 3,
  179. paddingRight: 8
  180. },
  181. siteRow: {
  182. paddingTop: 4,
  183. paddingBottom: 4,
  184. flexDirection: 'row'
  185. }
  186. })