mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-05 19:41:42 +08:00
[improvement] CouponCell: tsx (#2791)
This commit is contained in:
parent
52a4b7eec9
commit
4e52510f85
@ -2,9 +2,23 @@ import { use } from '../utils';
|
||||
import { inherit } from '../utils/functional';
|
||||
import Cell from '../cell';
|
||||
|
||||
// Types
|
||||
import { CreateElement, RenderContext } from 'vue/types';
|
||||
import { DefaultSlots } from '../utils/use/sfc';
|
||||
import { Coupon } from '../coupon/shared';
|
||||
|
||||
export type CouponCellProps = {
|
||||
title?: string;
|
||||
border: boolean;
|
||||
coupons: Coupon[];
|
||||
currency: string;
|
||||
editable: boolean;
|
||||
chosenCoupon: number;
|
||||
};
|
||||
|
||||
const [sfc, bem, t] = use('coupon-cell');
|
||||
|
||||
function formatValue(props) {
|
||||
function formatValue(props: CouponCellProps) {
|
||||
const { coupons, chosenCoupon, currency } = props;
|
||||
const coupon = coupons[chosenCoupon];
|
||||
|
||||
@ -16,8 +30,13 @@ function formatValue(props) {
|
||||
return coupons.length === 0 ? t('tips') : t('count', coupons.length);
|
||||
}
|
||||
|
||||
function CouponCell(h, props, slots, ctx) {
|
||||
const valueClass = props[props.chosenCoupon]
|
||||
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);
|
||||
@ -60,4 +79,4 @@ CouponCell.props = {
|
||||
}
|
||||
};
|
||||
|
||||
export default sfc(CouponCell);
|
||||
export default sfc<CouponCellProps>(CouponCell);
|
@ -11,7 +11,7 @@ exports[`render coupon cell 1`] = `
|
||||
exports[`render coupon cell with coupon 1`] = `
|
||||
<div class="van-cell van-cell--clickable van-coupon-cell">
|
||||
<div class="van-cell__title"><span>优惠券</span></div>
|
||||
<div class="van-cell__value"><span>-¥1.00</span></div><i class="van-icon van-icon-arrow van-cell__right-icon">
|
||||
<div class="van-cell__value van-coupon-cell--selected"><span>-¥1.00</span></div><i class="van-icon van-icon-arrow van-cell__right-icon">
|
||||
<!----></i>
|
||||
</div>
|
||||
`;
|
||||
|
14
packages/coupon/shared.ts
Normal file
14
packages/coupon/shared.ts
Normal file
@ -0,0 +1,14 @@
|
||||
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;
|
||||
};
|
@ -46,7 +46,7 @@ export default {
|
||||
title2: '监听对应事件',
|
||||
title3: '高级用法',
|
||||
placeholder: '请输入搜索关键词',
|
||||
label: '收货地址'
|
||||
label: '地址'
|
||||
},
|
||||
'en-US': {
|
||||
title2: 'Listen to Events',
|
||||
|
@ -62,14 +62,14 @@ Search support all native properties of input tag,such as `maxlength`、`place
|
||||
|
||||
| Attribute | Description | Type | Default |
|
||||
|------|------|------|------|
|
||||
| label | Search label | `String` | - |
|
||||
| shape | Can be set to `round` | `String` | `square` |
|
||||
| background | Background color | `String` | `#f2f2f2` |
|
||||
| show-action | Whether to show right button | `Boolean` | `false` |
|
||||
| disabled | Whether to disable field | `Boolean` | `false` |
|
||||
| readonly | Whether to be readonly | `Boolean` | `false` |
|
||||
| error | Whether to show error info | `Boolean` | `false` |
|
||||
| input-align | Input text align, can be set to `center` `right` | `String` | `left` |
|
||||
| shape | Can be set to `round` | `String` | `square` |
|
||||
| label | Search label | `String` | - |
|
||||
|
||||
### Event
|
||||
|
||||
|
@ -8,6 +8,7 @@ export default sfc({
|
||||
|
||||
props: {
|
||||
value: String,
|
||||
label: String,
|
||||
showAction: Boolean,
|
||||
shape: {
|
||||
type: String,
|
||||
@ -16,8 +17,7 @@ export default sfc({
|
||||
background: {
|
||||
type: String,
|
||||
default: '#ffffff'
|
||||
},
|
||||
label: String
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
|
@ -36,7 +36,7 @@ exports[`renders demo correctly 1`] = `
|
||||
<div>
|
||||
<div class="van-search van-search--show-action" style="background:#ffffff;">
|
||||
<div class="van-search__content van-search__content--round">
|
||||
<div class="van-search__label">收货地址</div>
|
||||
<div class="van-search__label">地址</div>
|
||||
<div class="van-cell van-cell--borderless van-field">
|
||||
<div class="van-field__left-icon"><i class="van-icon van-icon-search">
|
||||
<!----></i></div>
|
||||
|
@ -54,14 +54,14 @@ Search 默认支持 Input 标签所有的原生属性,比如 `maxlength`、`pl
|
||||
|
||||
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
||||
|------|------|------|------|------|
|
||||
| label | 搜索框左侧文本 | `String` | - | 1.6.6 |
|
||||
| shape | 形状,可选值为 `round` | `String` | `square` | 1.6.6 |
|
||||
| background | 搜索框背景色 | `String` | `#f2f2f2` | - |
|
||||
| show-action | 是否在搜索框右侧显示取消按钮 | `Boolean` | `false` | - |
|
||||
| disabled | 是否禁用输入框 | `Boolean` | `false` | - |
|
||||
| readonly | 是否只读 | `Boolean` | `false` | - |
|
||||
| error | 是否将输入内容标红 | `Boolean` | `false` | - |
|
||||
| input-align | 输入框内容对齐方式,可选值为 `center` `right` | `String` | `left` | - |
|
||||
| shape | 形状,可选值为 `round` | `String` | `square` | - |
|
||||
| label | 搜索框左侧文本 | `String` | - | - |
|
||||
|
||||
### Event
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user