import { ToCent, ToYuan } from 'oak-domain/lib/utils/money'; import { PAY_CHANNEL_ACCOUNT_NAME, PAY_CHANNEL_OFFLINE_NAME } from '../../../types/PayConfig'; export default OakComponent({ properties: { depositMinCent: 0, depositMaxCent: 1000000, onSetPrice: (price) => undefined, onSetChannel: (channel) => undefined, onSetMeta: (meta) => undefined, channel: '', meta: {}, }, formData({ data }) { const payConfig2 = this.features.pay.getPayConfigs(); let accountConfig; const payConfig = []; for (const config of payConfig2) { if (config.channel === PAY_CHANNEL_ACCOUNT_NAME) { accountConfig = config; } else if (config.channel !== PAY_CHANNEL_OFFLINE_NAME || config.allowUser) { payConfig.push(config); } } const { depositMaxCent, depositMinCent } = this.props; const depositLoss = accountConfig?.depositLoss; const depositLossRatio = accountConfig?.depositLossRatio; const tips = depositLoss ? depositLossRatio ? this.t('tips.depositLossRatio', { ratio: depositLossRatio }) : this.t('tips.depositLoss') : ''; return { depositMax: ToYuan(depositMaxCent), depositMin: ToYuan(depositMinCent), account: data, payConfig, tips, }; }, features: ['application'], listeners: { price(v) { this.reRender(); } }, methods: { onPriceChange(price2) { if (price2 === null) { this.props.onSetPrice(price2); this.setState({ price: price2, priceStr: '', }); } else { let price = ToCent(price2); this.props.onSetPrice(price); if (this.props.depositMaxCent && price > this.props.depositMaxCent) { price = this.props.depositMaxCent; } this.setState({ price, priceStr: ToYuan(price), }); } }, onDepPriceChangeMp(event) { const { value } = event.detail; if (value === null) { this.onPriceChange(value); } else { const price2 = parseInt(value); if (!isNaN(price2)) { this.onPriceChange(price2); } } }, }, data: { onChannelPickMp(channel) { this.props.onSetChannel(channel); }, onMetaSetMp(meta) { this.props.onSetMeta(meta); }, price: 0, priceStr: '', }, lifetimes: { ready() { const { depositMinCent } = this.props; if (depositMinCent) { this.onPriceChange(ToYuan(depositMinCent)); } } } });