/** * 代金券详情页面 * @邠心vbe on 2024/04/17 */ import React, { Component } from 'react'; import { View, StyleSheet, Text, TouchableOpacity, ScrollView } from 'react-native'; import TextView from '../../components/TextView'; import apiVoucher from '../../api/apiVoucher'; import Dialog from '../../components/Dialog'; import utils from '../../utils/utils'; import VbeSkeleton from '../../components/VbeSkeleton'; export default class VoucherDetails extends Component { constructor(props) { super(props); this.state = { loading: true, voucherId: "", voucherInfo: {} }; } componentDidMount() { const params = this.props.route.params; if (params.id) { this.setState({ voucherId: params.id }, () => { this.getVoucherDetail(); }) } } getVoucherDetail() { apiVoucher.getVoucherInfo(this.state.voucherId).then(res => { if (res.data) { this.setState({ voucherInfo: res.data }) } }).catch(err => { toastShort(err) }).finally(() => { this.setState({ loading: false }) }); } getDaysText() { if (this.state.voucherInfo.eligibleForUsageOn) { if (typeof this.state.voucherInfo.eligibleForUsageOn == 'string') { this.state.voucherInfo.eligibleForUsageOn = this.state.voucherInfo.eligibleForUsageOn.split(","); } return this.state.voucherInfo.eligibleForUsageOn.join(", "); } else { return "Every day"; } } getTypeText() { if (this.state.voucherInfo.chargeType) { return this.state.voucherInfo.chargeType; } else { return "AC & DC"; } } toSiteDetail(id) { utils.toChargeDetailPage(id, "view"); } render() { if (this.state.loading) { return ( ) } return ( {this.state.voucherInfo.voucherName} {$t("voucher.voucherType")} {this.state.voucherInfo.voucherType} {$t("voucher.description")} {this.state.voucherInfo.voucherDesc} {$t("voucher.validityPeriod")} {this.state.voucherInfo.validityPeriod} {$t("voucher.voucherCondition")} {$t("voucher.conditionDays")} {this.getDaysText()} {$t("voucher.conditionTime")} {this.state.voucherInfo.eligibleForUsageDuring} {this.getTypeText()} {$t("voucher.conditionTypeOnly")} {$t("voucher.conditionCountry")} {this.state.voucherInfo.country} {$t("voucher.conditionMinSpend")} {this.state.voucherInfo.minimumSpend} {$t("voucher.siteEligibility")} { this.state.voucherInfo.siteNames?.map((item, index) => ( this.toSiteDetail(item.sitePk)} key={index}> {item?.siteName} )) } ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: pageBackground }, loadingView: { flex: 1, padding: 16, justifyContent: 'flex-start', backgroundColor: pageBackground }, voucherName: { color: textPrimary, fontSize: 16, fontWeight: 'bold', paddingTop: 4, paddingBottom: 12, borderBottomWidth: 2, borderColor: colorPrimary }, labelText: { color: textPrimary, fontSize: 14, fontWeight: 'bold', paddingTop: 16 }, valueText: { color: textSecondary, fontSize: 14, paddingTop: 6 }, olView: { paddingTop: 6, paddingLeft: 8 }, circleIcon: { paddingTop: 3, paddingRight: 8 }, siteRow: { paddingTop: 4, paddingBottom: 4, flexDirection: 'row' } })