mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-23 09:52:57 +08:00
types(Coupon): use tsx (#8088)
This commit is contained in:
parent
08f032e431
commit
1b75c706ab
@ -26,7 +26,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { computed, reactive, toRefs } from 'vue';
|
import { computed, reactive, toRefs } from 'vue';
|
||||||
import { useTranslate } from '@demo/use-translate';
|
import { useTranslate } from '@demo/use-translate';
|
||||||
import { Coupon } from '../../coupon/shared';
|
import { CouponInfo } from '../../coupon';
|
||||||
import Toast from '../../toast';
|
import Toast from '../../toast';
|
||||||
|
|
||||||
const i18n = {
|
const i18n = {
|
||||||
@ -57,7 +57,7 @@ export default {
|
|||||||
const state = reactive({
|
const state = reactive({
|
||||||
showList: false,
|
showList: false,
|
||||||
chosenCoupon: -1,
|
chosenCoupon: -1,
|
||||||
exchangedCoupons: [] as Coupon[],
|
exchangedCoupons: [] as CouponInfo[],
|
||||||
});
|
});
|
||||||
|
|
||||||
const coupon = computed(() => ({
|
const coupon = computed(() => ({
|
||||||
|
@ -1,22 +1,38 @@
|
|||||||
import { computed } from 'vue';
|
import { computed, PropType } from 'vue';
|
||||||
import { padZero, createNamespace } from '../utils';
|
import { padZero, createNamespace } from '../utils';
|
||||||
import { RED } from '../utils/constant';
|
import { RED } from '../utils/constant';
|
||||||
import Checkbox from '../checkbox';
|
import Checkbox from '../checkbox';
|
||||||
|
|
||||||
|
export type CouponInfo = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
endAt: number;
|
||||||
|
value: number;
|
||||||
|
startAt: number;
|
||||||
|
reason?: string;
|
||||||
|
discount?: number;
|
||||||
|
unitDesc?: string;
|
||||||
|
condition?: string;
|
||||||
|
valueDesc?: string;
|
||||||
|
description: string;
|
||||||
|
denominations?: number;
|
||||||
|
originCondition?: number;
|
||||||
|
};
|
||||||
|
|
||||||
const [createComponent, bem, t] = createNamespace('coupon');
|
const [createComponent, bem, t] = createNamespace('coupon');
|
||||||
|
|
||||||
function getDate(timeStamp) {
|
function getDate(timeStamp: number) {
|
||||||
const date = new Date(timeStamp * 1000);
|
const date = new Date(timeStamp * 1000);
|
||||||
return `${date.getFullYear()}.${padZero(date.getMonth() + 1)}.${padZero(
|
return `${date.getFullYear()}.${padZero(date.getMonth() + 1)}.${padZero(
|
||||||
date.getDate()
|
date.getDate()
|
||||||
)}`;
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatDiscount(discount) {
|
function formatDiscount(discount: number) {
|
||||||
return (discount / 10).toFixed(discount % 10 === 0 ? 0 : 1);
|
return (discount / 10).toFixed(discount % 10 === 0 ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatAmount(amount) {
|
function formatAmount(amount: number) {
|
||||||
return (amount / 100).toFixed(
|
return (amount / 100).toFixed(
|
||||||
amount % 100 === 0 ? 0 : amount % 10 === 0 ? 1 : 2
|
amount % 100 === 0 ? 0 : amount % 10 === 0 ? 1 : 2
|
||||||
);
|
);
|
||||||
@ -24,9 +40,12 @@ function formatAmount(amount) {
|
|||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
props: {
|
props: {
|
||||||
coupon: Object,
|
|
||||||
chosen: Boolean,
|
chosen: Boolean,
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
|
coupon: {
|
||||||
|
type: Object as PropType<CouponInfo>,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
currency: {
|
currency: {
|
||||||
type: String,
|
type: String,
|
||||||
default: '¥',
|
default: '¥',
|
||||||
@ -59,7 +78,7 @@ export default createComponent({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const conditionMessage = computed(() => {
|
const conditionMessage = computed(() => {
|
||||||
const condition = formatAmount(props.coupon.originCondition);
|
const condition = formatAmount(props.coupon.originCondition || 0);
|
||||||
return condition === '0' ? t('unlimited') : t('condition', condition);
|
return condition === '0' ? t('unlimited') : t('condition', condition);
|
||||||
});
|
});
|
||||||
|
|
@ -1,14 +0,0 @@
|
|||||||
export type Coupon = {
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
endAt: number;
|
|
||||||
value: number;
|
|
||||||
startAt: number;
|
|
||||||
reason?: string;
|
|
||||||
discount?: number;
|
|
||||||
unitDesc?: string;
|
|
||||||
condition?: string;
|
|
||||||
valueDesc?: string;
|
|
||||||
description: string;
|
|
||||||
denominations?: number;
|
|
||||||
};
|
|
Loading…
x
Reference in New Issue
Block a user