From 832ed6f80f1aebaf0a3e4e72e9a3bbe232d058e2 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Mon, 17 Aug 2020 19:47:51 +0800 Subject: [PATCH] feat: migrate CouponCell component --- src/coupon-cell/index.js | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/coupon-cell/index.js diff --git a/src/coupon-cell/index.js b/src/coupon-cell/index.js new file mode 100644 index 000000000..346a8ef6a --- /dev/null +++ b/src/coupon-cell/index.js @@ -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 ( + + ); + }; + }, +});