diff --git a/packages/coupon-list/test/__snapshots__/index.spec.js.snap b/packages/coupon-list/test/__snapshots__/index.spec.js.snap index 021657bce..c6cfa051e 100644 --- a/packages/coupon-list/test/__snapshots__/index.spec.js.snap +++ b/packages/coupon-list/test/__snapshots__/index.spec.js.snap @@ -39,11 +39,11 @@ exports[`render coupon list 1`] = `
-

+

无使用门槛

-

+

有效期:2017.03.10 - 2017.12.30

@@ -51,14 +51,14 @@ exports[`render coupon list 1`] = `
-

¥ 1.5

+

¥ 1.5

无使用门槛

-

name

+

name

有效期:2017.03.10 - 2017.12.30

-
+
@@ -68,11 +68,11 @@ exports[`render coupon list 1`] = `
-

¥ 1

+

¥ 1

无使用门槛

-

name

+

name

有效期:2017.03.10 - 2017.12.30

@@ -81,11 +81,11 @@ exports[`render coupon list 1`] = `
-

¥ 1.23

+

¥ 1.23

无使用门槛

-

name

+

name

有效期:2017.03.10 - 2017.12.30

@@ -94,11 +94,11 @@ exports[`render coupon list 1`] = `
-

8.8折

-

满0.50元可用

+

8.8折

+

满0.5元可用

-

name

+

name

有效期:2017.03.10 - 2017.12.30

@@ -106,11 +106,11 @@ exports[`render coupon list 1`] = `
-

9折

-

满0.50元可用

+

9折

+

满0.5元可用

-

name

+

name

有效期:2017.03.10 - 2017.12.30

@@ -129,11 +129,11 @@ exports[`render disabled coupon 1`] = `
-

¥ 1.5

+

¥ 1.5

无使用门槛

-

name

+

name

有效期:2017.03.10 - 2017.12.30

diff --git a/packages/coupon/index.js b/packages/coupon/index.js index 99bd948fa..609703b13 100644 --- a/packages/coupon/index.js +++ b/packages/coupon/index.js @@ -1,4 +1,5 @@ import { use } from '../utils'; +import { RED } from '../utils/color'; import Checkbox from '../checkbox'; const [sfc, bem, t] = use('coupon'); @@ -9,7 +10,9 @@ function padZero(num) { function getDate(timeStamp) { const date = new Date(timeStamp * 1000); - return `${date.getFullYear()}.${padZero(date.getMonth() + 1)}.${padZero(date.getDate())}`; + return `${date.getFullYear()}.${padZero(date.getMonth() + 1)}.${padZero( + date.getDate() + )}`; } function formatDiscount(discount) { @@ -33,25 +36,31 @@ export default sfc({ computed: { validPeriod() { - return `${t('valid')}:${getDate(this.coupon.startAt)} - ${getDate(this.coupon.endAt)}`; + const { startAt, endAt } = this.coupon; + return `${t('valid')}:${getDate(startAt)} - ${getDate(endAt)}`; }, faceAmount() { const { coupon } = this; + if (coupon.valueDesc) { return `${coupon.valueDesc}${coupon.unitDesc || ''}`; } - return coupon.denominations - ? `${this.currency} ${formatAmount(this.coupon.denominations)}` - : coupon.discount - ? t('discount', formatDiscount(this.coupon.discount)) - : ''; + + if (coupon.denominations) { + return `${this.currency} ${formatAmount(this.coupon.denominations)}`; + } + + if (coupon.discount) { + return t('discount', formatDiscount(this.coupon.discount)); + } + + return ''; }, conditionMessage() { - let condition = this.coupon.originCondition; - condition = condition % 100 === 0 ? Math.round(condition / 100) : (condition / 100).toFixed(2); - return condition === 0 ? t('unlimited') : t('condition', condition); + const condition = formatAmount(this.coupon.originCondition); + return condition === '0' ? t('unlimited') : t('condition', condition); } }, @@ -63,13 +72,15 @@ export default sfc({
-

+

{this.coupon.condition || this.conditionMessage}

-

{coupon.name}

+

{coupon.name}

{this.validPeriod}

- {this.chosen && } + {this.chosen && ( + + )}
{description &&

{description}

} diff --git a/packages/coupon/index.less b/packages/coupon/index.less index 361366170..35be4d6f8 100644 --- a/packages/coupon/index.less +++ b/packages/coupon/index.less @@ -2,21 +2,21 @@ @import '../style/mixins/ellipsis'; .van-coupon { - margin: 0 15px 15px; + margin: @coupon-margin; overflow: hidden; - background-color: @white; - border-radius: 4px; - box-shadow: 0 0 4px rgba(0, 0, 0, 0.1); + background-color: @coupon-background-color; + border-radius: @coupon-border-radius; + box-shadow: @coupon-box-shadow; &:active { - background-color: @active-color; + background-color: @coupon-active-background-color; } &__content { display: flex; box-sizing: border-box; - height: 100px; - padding: 24px 0 0 15px; + height: @coupon-content-height; + padding: @coupon-content-padding; } p, @@ -40,67 +40,62 @@ &__head { position: relative; - min-width: 85px; + min-width: @coupon-head-width; padding-right: 10px; - h2 { - color: @red; - font-size: 24px; - - span { - &:not(:empty) { - margin-left: 2px; - } - - font-size: 50%; - } - } - p { white-space: pre-wrap; } } + &__amount { + color: @coupon-amount-color; + font-size: @coupon-amount-font-size; + + span { + font-size: @coupon-currency-font-size; + + &:not(:empty) { + margin-left: 2px; + } + } + } + &__body { position: relative; flex: 1; - border-radius: 0 4px 4px 0; + border-radius: 0 @coupon-border-radius @coupon-border-radius 0; + } - h2 { - font-size: 16px; - } + &__name { + font-size: @coupon-name-font-size; } &__corner { position: absolute; top: 16px; right: 15px; - - .van-icon { - background-color: @red; - border-color: @red; - } } &__description { - padding: 7px 15px; - background-color: @background-color-light; - border-top: 1px dashed @border-color; + padding: @coupon-description-padding; + background-color: @coupon-description-background-color; + border-top: 1px dashed @coupon-description-border-color; } &--disabled { &:active { - background-color: @white; + background-color: @coupon-background-color; } .van-coupon-item__content { - height: 90px; + height: @coupon-content-height - 10px; } p, h2, span { - color: @gray-dark; + color: @coupon-disabled-text-color; } } } diff --git a/packages/style/var.less b/packages/style/var.less index 8e8d40c83..9522a5879 100644 --- a/packages/style/var.less +++ b/packages/style/var.less @@ -166,6 +166,24 @@ @contact-list-add-button-z-index: 9999; @contact-list-item-padding: 15px; +// Coupon +@coupon-margin: 0 15px 15px; +@coupon-content-height: 100px; +@coupon-content-padding: 24px 0 0 15px; +@coupon-background-color: @white; +@coupon-active-background-color: @active-color; +@coupon-border-radius: 4px; +@coupon-box-shadow: 0 0 4px rgba(0, 0, 0, 0.1); +@coupon-head-width: 85px; +@coupon-amount-color: @red; +@coupon-amount-font-size: 24px; +@coupon-currency-font-size: 50%; +@coupon-name-font-size: 16px; +@coupon-disabled-text-color: @gray-dark; +@coupon-description-padding: 7px 15px; +@coupon-description-background-color: @background-color-light; +@coupon-description-border-color: @border-color; + // Dialog @dialog-width: 85%; @dialog-font-size: 16px;