mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-25 10:56:35 +08:00
feat: migrate CouponCell component
This commit is contained in:
parent
579a9ebb78
commit
832ed6f80f
62
src/coupon-cell/index.js
Normal file
62
src/coupon-cell/index.js
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import { createNamespace } from '../utils';
|
||||||
|
import Cell from '../cell';
|
||||||
|
|
||||||
|
const [createComponent, bem, t] = createNamespace('coupon-cell');
|
||||||
|
|
||||||
|
function formatValue(props) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default createComponent({
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
setup(props) {
|
||||||
|
return () => {
|
||||||
|
const valueClass = props.coupons[+props.chosenCoupon]
|
||||||
|
? bem('selected')
|
||||||
|
: '';
|
||||||
|
const value = formatValue(props);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Cell
|
||||||
|
class={bem()}
|
||||||
|
value={value}
|
||||||
|
title={props.title || t('title')}
|
||||||
|
border={props.border}
|
||||||
|
isLink={props.editable}
|
||||||
|
valueClass={valueClass}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user