/** * 购买代金券列表 * @邠心vbe on 2024/04/09 */ import React, { Component } from 'react'; import { View, Text, StyleSheet, RefreshControl, FlatList } from 'react-native'; import ViewRedeem from './ViewRedeem'; import apiVoucher from '../../api/apiVoucher'; import { MyRefreshProps } from '../../components/ThemesConfig'; import TextView from '../../components/TextView'; import Button from '../../components/Button'; import Dialog from '../../components/Dialog'; import VoucherType from './VoucherType'; import app from '../../../app.json'; import VbeSkeleton from '../../components/VbeSkeleton'; export default class ListPoints extends Component { constructor(props) { super(props); this.state = { loading: true, userInfo: {}, dataList: [], voucherType: "", hasMore: true, refreshing: false, loadingList: ["","","",""] }; } componentDidMount() { this.props.navigation.addListener('focus', () => { this.refreshUserInfo(); this.getDataList(); }); } onRefresh() { this.setState({ refreshing: true }) this.refreshUserInfo(); this.getDataList(); } refreshUserInfo() { getUserInfo(info => { this.setState({ userInfo: info }); }, true); } getDataList(lastId="") { apiVoucher.getDealVouchers({ lastVoucherId: lastId, voucherType: this.state.voucherType }).then(res => { if (res.data) { if (lastId) { if (res.data.length > 0) { const list = this.state.dataList; this.setState({ dataList: list.concat(res.data) }); } else { this.setState({ hasMore: false }) } } else { this.setState({ dataList: res.data, hasMore: res.data.length >= 10 }); } } else { this.setState({ dataList: [] }); } }).catch(err => { toastShort(err) }).finally(() => { this.setState({ loading: false, refreshing: false }); }); } getDataListPage() { if (this.state.dataList.length > 0 && this.state.hasMore) { const last = this.state.dataList[this.state.dataList.length-1] this.getDataList(last.voucherId); } } confirmPurchase(item) { let msg = "" + $t("voucher.confirmPurchase"); if (item.purchasePoints) { msg = msg.replace("{value}", item.purchasePoints); } else { msg = msg.replace("{value}", "0"); } Dialog.showDialog({ title: $t("voucher.purchaseVoucher"), message: msg, ok: $t("nav.confirm"), callback: btn => { if (btn == Dialog.BUTTON_OK) { this.onPurchase(item) } } }) } onPurchase(item) { Dialog.showProgressDialog(); apiVoucher.purchaseVoucher({ voucherId: item.voucherId }).then(res => { Dialog.dismissLoading(); if (res.msg) { setTimeout(() => { Dialog.showDialog({ title: $t("voucher.purchaseVoucher"), message: res.msg, showCancel: false }) }, 500); } setTimeout(() => { this.refreshUserInfo(); }, 2000) }).catch(err => { Dialog.dismissLoading(); if (err.err) { setTimeout(() => { Dialog.showDialog({ title: $t("voucher.vouchers"), message: err.err, showCancel: false }) }, 500); } }) } changeType(type) { this.setState({ voucherType: type }); this.getDataList(); } listItem = ({item, index, separators}) => { return ( {item.voucherName} {item.voucherDesc} {$t("voucher.expiresOn") + item.expiresOn} { !app.isLumiWhitelabel && <> } { item.purchasePoints > 0 ? :