const rechargeDialog = { template: /*html*/ `
{{lang.finance_title4}}
{{lang.finance_btn6}}
`, data() { return { isShowCz: false, currency_prefix: "", currency_suffix: "", commonData: {}, amount: undefined, submitLoading: false, rechargeActive: [], coinClientCoupon: {}, }; }, components: { payDialog, }, created() { this.getCommon(); }, filters: { formateTime(time) { if (time && time !== 0) { return formateDate(time * 1000); } else if (time === 0) { return lang.coin_text17; } else { return "--"; } }, }, computed: { rechargeTip() { if (this.rechargeActive.length === 0 || !this.amount) { return []; } const rechargeTipList = []; const maxCoinAward = Number( this.coinClientCoupon.per_recharge_get_coin_max ); this.rechargeActive.forEach((item) => { if (item.type === "proportion") { if (this.amount * 1 >= item.recharge_min * 1) { const award = Number(item.recharge_proportion * 0.01 * this.amount); const tip = `${item.name}:${lang.coin_text18}${Number( award > maxCoinAward ? maxCoinAward : award ).toFixed(2)}${this.coinClientCoupon.name}`; rechargeTipList.push(tip); } else { const tip = `${item.name}:${lang.coin_text19}${Number( item.recharge_min - this.amount ).toFixed(2)}${this.currency_suffix}${lang.coin_text20}${Number( item.recharge_proportion * 0.01 * item.recharge_min ).toFixed(2)}${this.coinClientCoupon.name}`; rechargeTipList.push(tip); } } if (item.type === "gradient") { // 找出最大的阶梯金额 const maxAmount = Math.max( ...item.return.map((items) => items.amount) ); if (this.amount * 1 >= maxAmount * 1) { const maxAward = item.return.find( (items) => items.amount === maxAmount )?.award; const tip = `${item.name}:${lang.coin_text18}${Number( maxAward > maxCoinAward ? maxCoinAward : maxAward ).toFixed(2)}${this.coinClientCoupon.name}`; rechargeTipList.push(tip); } else { // 找出当前充值金额对应的阶梯 和 下一个阶梯 const currentIndex = item.return.findIndex((items, index) => { return ( this.amount * 1 >= items.amount * 1 && this.amount * 1 < item.return[index + 1]?.amount * 1 ); }); const currentAmount = item.return[currentIndex]; const nextAmount = item.return[currentIndex + 1]; if (currentAmount && nextAmount) { const currentAward = currentAmount.award > maxCoinAward ? maxCoinAward : currentAmount.award; const nextAward = nextAmount.award > maxCoinAward ? maxCoinAward : nextAmount.award; const tip = `${item.name}:${lang.coin_text21}${Number( currentAward ).toFixed(2)}${this.coinClientCoupon.name},${ lang.coin_text22 }${Number(nextAmount.amount - this.amount).toFixed(2)}${ this.currency_suffix }${lang.coin_text20}${Number(nextAward).toFixed(2)}${ this.coinClientCoupon.name }`; rechargeTipList.push(tip); } } } }); return rechargeTipList; }, }, methods: { getCoinClientCoupon() { apiCoinClientCoupon().then((res) => { this.coinClientCoupon = res.data.data; }); }, getRechargeDetail() { apiCoinRechargeDetail().then((res) => { this.rechargeActive = res.data.data.coins; }); }, open() { if (havePlugin("Coin")) { this.getRechargeDetail(); this.getCoinClientCoupon(); } this.isShowCz = true; }, czClose() { this.amount = undefined; this.isShowCz = false; }, handleSubmit() { if (!this.amount) { return this.$message.error(lang.finance_text130); } this.submitLoading = true; apiRecharge({amount: this.amount}) .then((res) => { if (res.data.status === 200) { this.isShowCz = false; const orderId = res.data.data.id; this.$refs.payDialog.czPay(orderId); } }) .catch((error) => { this.$message.error(error.data.msg); }) .finally(() => { this.submitLoading = false; }); }, paySuccess() { this.$emit("success"); }, getCommon() { this.commonData = JSON.parse(localStorage.getItem("common_set_before")); this.currency_prefix = this.commonData.currency_prefix; this.currency_suffix = this.commonData.currency_suffix; }, }, };