mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat: migrate CouponList component
This commit is contained in:
parent
41796b0616
commit
579a9ebb78
@ -73,4 +73,7 @@ module.exports = [
|
|||||||
'contact-card',
|
'contact-card',
|
||||||
'contact-edit',
|
'contact-edit',
|
||||||
'contact-list',
|
'contact-list',
|
||||||
|
'coupon',
|
||||||
|
'coupon-list',
|
||||||
|
'coupon-cell',
|
||||||
];
|
];
|
||||||
|
@ -66,6 +66,7 @@ Vant 遵循 [Semver](https://semver.org/lang/zh-CN/) 语义化版本规范。
|
|||||||
其他改动:
|
其他改动:
|
||||||
|
|
||||||
- Circle: `v-model` 重命名为 `v-model:currentRate`
|
- Circle: `v-model` 重命名为 `v-model:currentRate`
|
||||||
|
- CouponList: `v-model` 重命名为 `v-model:code`
|
||||||
- List: `v-model` 重命名为 `v-model:loading`,`error.sync` 重命名为 `v-model:error`
|
- List: `v-model` 重命名为 `v-model:loading`,`error.sync` 重命名为 `v-model:error`
|
||||||
- Tabs: `v-model` 重命名为 `v-model:active`
|
- Tabs: `v-model` 重命名为 `v-model:active`
|
||||||
- TreeSelect: `active-id.sync` 重命名为 `v-model:active-id`
|
- TreeSelect: `active-id.sync` 重命名为 `v-model:active-id`
|
||||||
|
@ -1,88 +0,0 @@
|
|||||||
// Utils
|
|
||||||
import { createNamespace } from '../utils';
|
|
||||||
import { inherit } from '../utils/functional';
|
|
||||||
|
|
||||||
// Components
|
|
||||||
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 | string;
|
|
||||||
};
|
|
||||||
|
|
||||||
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.value || coupon.denominations || 0;
|
|
||||||
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, String],
|
|
||||||
default: -1,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default createComponent<CouponCellProps>(CouponCell);
|
|
@ -88,7 +88,7 @@ export default {
|
|||||||
|
|
||||||
| 参数 | 说明 | 类型 | 默认值 |
|
| 参数 | 说明 | 类型 | 默认值 |
|
||||||
| --- | --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| v-model | 当前输入的兑换码 | _string_ | - |
|
| v-model:code | 当前输入的兑换码 | _string_ | - |
|
||||||
| chosen-coupon | 当前选中优惠券的索引 | _number_ | `-1` |
|
| chosen-coupon | 当前选中优惠券的索引 | _number_ | `-1` |
|
||||||
| coupons | 可用优惠券列表 | _Coupon[]_ | `[]` |
|
| coupons | 可用优惠券列表 | _Coupon[]_ | `[]` |
|
||||||
| disabled-coupons | 不可用优惠券列表 | _Coupon[]_ | `[]` |
|
| disabled-coupons | 不可用优惠券列表 | _Coupon[]_ | `[]` |
|
||||||
|
@ -6,9 +6,8 @@
|
|||||||
:chosen-coupon="chosenCoupon"
|
:chosen-coupon="chosenCoupon"
|
||||||
@click="showList = true"
|
@click="showList = true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<van-popup
|
<van-popup
|
||||||
v-model="showList"
|
v-model:show="showList"
|
||||||
round
|
round
|
||||||
position="bottom"
|
position="bottom"
|
||||||
style="height: 90%; padding-top: 4px;"
|
style="height: 90%; padding-top: 4px;"
|
||||||
|
@ -12,16 +12,12 @@ const [createComponent, bem, t] = createNamespace('coupon-list');
|
|||||||
const EMPTY_IMAGE = 'https://img.yzcdn.cn/vant/coupon-empty.png';
|
const EMPTY_IMAGE = 'https://img.yzcdn.cn/vant/coupon-empty.png';
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
model: {
|
|
||||||
prop: 'code',
|
|
||||||
},
|
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
code: String,
|
code: String,
|
||||||
closeButtonText: String,
|
|
||||||
inputPlaceholder: String,
|
|
||||||
enabledTitle: String,
|
enabledTitle: String,
|
||||||
disabledTitle: String,
|
disabledTitle: String,
|
||||||
|
closeButtonText: String,
|
||||||
|
inputPlaceholder: String,
|
||||||
exchangeButtonText: String,
|
exchangeButtonText: String,
|
||||||
exchangeButtonLoading: Boolean,
|
exchangeButtonLoading: Boolean,
|
||||||
exchangeButtonDisabled: Boolean,
|
exchangeButtonDisabled: Boolean,
|
||||||
@ -67,6 +63,8 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
emits: ['change', 'exchange', 'update:code'],
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
tab: 0,
|
tab: 0,
|
||||||
@ -98,7 +96,7 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
currentCode(code) {
|
currentCode(code) {
|
||||||
this.$emit('input', code);
|
this.$emit('update:code', code);
|
||||||
},
|
},
|
||||||
|
|
||||||
displayedCouponIndex: 'scrollToShowCoupon',
|
displayedCouponIndex: 'scrollToShowCoupon',
|
||||||
@ -194,9 +192,9 @@ export default createComponent({
|
|||||||
ref="card"
|
ref="card"
|
||||||
key={coupon.id}
|
key={coupon.id}
|
||||||
coupon={coupon}
|
coupon={coupon}
|
||||||
currency={this.currency}
|
|
||||||
chosen={index === this.chosenCoupon}
|
chosen={index === this.chosenCoupon}
|
||||||
nativeOnClick={onChange(index)}
|
currency={this.currency}
|
||||||
|
onClick={onChange(index)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{!coupons.length && this.genEmpty()}
|
{!coupons.length && this.genEmpty()}
|
||||||
@ -234,8 +232,8 @@ export default createComponent({
|
|||||||
<Button
|
<Button
|
||||||
vShow={this.showCloseButton}
|
vShow={this.showCloseButton}
|
||||||
round
|
round
|
||||||
type="danger"
|
|
||||||
block
|
block
|
||||||
|
type="danger"
|
||||||
class={bem('close')}
|
class={bem('close')}
|
||||||
text={this.closeButtonText || t('close')}
|
text={this.closeButtonText || t('close')}
|
||||||
onClick={onChange(-1)}
|
onClick={onChange(-1)}
|
||||||
|
@ -83,8 +83,8 @@ export default createComponent({
|
|||||||
{!this.disabled && (
|
{!this.disabled && (
|
||||||
<Checkbox
|
<Checkbox
|
||||||
size={18}
|
size={18}
|
||||||
value={this.chosen}
|
|
||||||
class={bem('corner')}
|
class={bem('corner')}
|
||||||
|
modelValue={this.chosen}
|
||||||
checkedColor={RED}
|
checkedColor={RED}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
@ -343,10 +343,10 @@ module.exports = {
|
|||||||
path: 'contact-card',
|
path: 'contact-card',
|
||||||
title: 'Contact 联系人',
|
title: 'Contact 联系人',
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// path: 'coupon-list',
|
path: 'coupon-list',
|
||||||
// title: 'Coupon 优惠券',
|
title: 'Coupon 优惠券',
|
||||||
// },
|
},
|
||||||
// {
|
// {
|
||||||
// path: 'goods-action',
|
// path: 'goods-action',
|
||||||
// title: 'GoodsAction 商品导航',
|
// title: 'GoodsAction 商品导航',
|
||||||
@ -677,10 +677,10 @@ module.exports = {
|
|||||||
path: 'contact-card',
|
path: 'contact-card',
|
||||||
title: 'Contact',
|
title: 'Contact',
|
||||||
},
|
},
|
||||||
// {
|
{
|
||||||
// path: 'coupon-list',
|
path: 'coupon-list',
|
||||||
// title: 'Coupon',
|
title: 'Coupon',
|
||||||
// },
|
},
|
||||||
// {
|
// {
|
||||||
// path: 'goods-action',
|
// path: 'goods-action',
|
||||||
// title: 'GoodsAction',
|
// title: 'GoodsAction',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user