oak-pay-business/es/components/deposit/new/index.js

67 lines
1.9 KiB
JavaScript

import { ToCent, ToYuan } from "oak-domain/lib/utils/money";
export default OakComponent({
properties: {
accountId: '',
depositMinCent: 0,
depositMaxCent: 1000000,
price: 0,
channel: {},
onSetPrice: (price) => undefined,
onSetChannel: (channel) => undefined,
loss: [0, '', {}],
},
data: {
onChooseChannelMp(channel) { this.onChooseChannel(channel); },
},
formData({ data, features }) {
const payChannels = features.pay.getPayChannels('deposit');
const { price, loss, depositMaxCent, depositMinCent } = this.props;
return {
depositMax: ToYuan(depositMaxCent),
depositMin: ToYuan(depositMinCent),
deposit: data,
payChannels,
priceStr: price ? ToYuan(price) : undefined,
lossStr: loss?.[0] ? ToYuan(loss?.[0]) : undefined,
lossReason: loss?.[1] ? this.t(loss[1], loss[2]) : '',
};
},
lifetimes: {
ready() {
const { depositMinCent } = this.props;
if (depositMinCent) {
this.onPriceChange(ToYuan(depositMinCent), true);
}
}
},
listeners: {
price() {
this.reRender();
},
loss() {
this.reRender();
}
},
methods: {
onPriceChange(price2) {
const price = price2 === null ? null : ToCent(price2);
this.props.onSetPrice(price);
},
onDepPriceChangeMp(event) {
const { value } = event.detail;
if (value === null) {
this.onPriceChange(value);
}
else {
const price2 = parseInt(value);
if (!isNaN(price2)) {
this.onPriceChange(price2);
}
}
},
onChooseChannel(channel) {
this.props.onSetChannel(channel);
},
}
});