forked from youzan/vant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
85 lines (74 loc) · 1.74 KB
/
Copy pathindex.tsx
File metadata and controls
85 lines (74 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { createNamespace } from '../utils';
import { inherit } from '../utils/functional';
import Cell from '../cell';
// Types
import { CreateElement, RenderContext } from 'vue/types';
import { DefaultSlots } from '../utils/types';
import { Coupon } from '../coupon/shared';
export type CouponCellProps = {
title?: string;
border: boolean;
coupons: Coupon[];
currency: string;
editable: boolean;
chosenCoupon: number;
};
const [createComponent, bem, t] = createNamespace('coupon-cell');
function formatValue(props: CouponCellProps) {
const { coupons, chosenCoupon, currency } = props;
const coupon = coupons[chosenCoupon];
if (coupon) {
const value = coupon.denominations || coupon.value;
return `-${currency}${(value / 100).toFixed(2)}`;
}
return coupons.length === 0 ? t('tips') : t('count', coupons.length);
}
function CouponCell(
h: CreateElement,
props: CouponCellProps,
slots: DefaultSlots,
ctx: RenderContext<CouponCellProps>
) {
const valueClass = props.coupons[props.chosenCoupon]
? 'van-coupon-cell--selected'
: '';
const value = formatValue(props);
return (
<Cell
class={bem()}
value={value}
title={props.title || t('title')}
border={props.border}
isLink={props.editable}
valueClass={valueClass}
{...inherit(ctx, true)}
/>
);
}
CouponCell.model = {
prop: 'chosenCoupon'
};
CouponCell.props = {
title: String,
coupons: {
type: Array,
default: () => []
},
currency: {
type: String,
default: '¥'
},
border: {
type: Boolean,
default: true
},
editable: {
type: Boolean,
default: true
},
chosenCoupon: {
type: Number,
default: -1
}
};
export default createComponent<CouponCellProps>(CouponCell);