mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] Coupon: optimize static methods (#2393)
This commit is contained in:
parent
007319d9b2
commit
b1044c6739
@ -28,6 +28,23 @@
|
|||||||
import create from '../utils/create';
|
import create from '../utils/create';
|
||||||
import Checkbox from '../checkbox';
|
import Checkbox from '../checkbox';
|
||||||
|
|
||||||
|
function padZero(num) {
|
||||||
|
return (num < 10 ? '0' : '') + num;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDate(timeStamp) {
|
||||||
|
const date = new Date(timeStamp * 1000);
|
||||||
|
return `${date.getFullYear()}.${padZero(date.getMonth() + 1)}.${padZero(date.getDate())}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDiscount(discount) {
|
||||||
|
return (discount / 10).toFixed(discount % 10 === 0 ? 0 : 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatAmount(amount) {
|
||||||
|
return (amount / 100).toFixed(amount % 100 === 0 ? 0 : amount % 10 === 0 ? 1 : 2);
|
||||||
|
}
|
||||||
|
|
||||||
export default create({
|
export default create({
|
||||||
name: 'coupon-item',
|
name: 'coupon-item',
|
||||||
|
|
||||||
@ -44,14 +61,14 @@ export default create({
|
|||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
validPeriod() {
|
validPeriod() {
|
||||||
return `${this.$t('valid')}:${this.getDate(this.data.startAt)} - ${this.getDate(this.data.endAt)}`;
|
return `${this.$t('valid')}:${getDate(this.data.startAt)} - ${getDate(this.data.endAt)}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
faceAmount() {
|
faceAmount() {
|
||||||
return this.data.denominations !== 0
|
return this.data.denominations !== 0
|
||||||
? `<span>${this.currency}</span> ${this.formatAmount(this.data.denominations)}`
|
? `<span>${this.currency}</span> ${formatAmount(this.data.denominations)}`
|
||||||
: this.data.discount !== 0
|
: this.data.discount !== 0
|
||||||
? this.formatDiscount(this.data.discount)
|
? this.$t('discount', formatDiscount(this.data.discount))
|
||||||
: '';
|
: '';
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -60,25 +77,6 @@ export default create({
|
|||||||
condition = condition % 100 === 0 ? Math.round(condition / 100) : (condition / 100).toFixed(2);
|
condition = condition % 100 === 0 ? Math.round(condition / 100) : (condition / 100).toFixed(2);
|
||||||
return this.data.originCondition === 0 ? this.$t('unlimited') : this.$t('condition', condition);
|
return this.data.originCondition === 0 ? this.$t('unlimited') : this.$t('condition', condition);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
getDate(timeStamp) {
|
|
||||||
const date = new Date(timeStamp * 1000);
|
|
||||||
return `${date.getFullYear()}.${this.padZero(date.getMonth() + 1)}.${this.padZero(date.getDate())}`;
|
|
||||||
},
|
|
||||||
|
|
||||||
padZero(num) {
|
|
||||||
return (num < 10 ? '0' : '') + num;
|
|
||||||
},
|
|
||||||
|
|
||||||
formatDiscount(discount) {
|
|
||||||
return this.$t('discount', `${(discount / 10).toFixed(discount % 10 === 0 ? 0 : 1)}`);
|
|
||||||
},
|
|
||||||
|
|
||||||
formatAmount(amount) {
|
|
||||||
return (amount / 100).toFixed(amount % 100 === 0 ? 0 : amount % 10 === 0 ? 1 : 2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user