import{o as s,a as n,y as d}from"./vue-libs.b44bc779.js";const a={class:"van-doc-markdown-body"},e=d(`

Coupon

Intro

Used for redemption and selection of coupons.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

import { createApp } from 'vue';
import { CouponCell, CouponList } from 'vant';

const app = createApp();
app.use(CouponCell);
app.use(CouponList);

Usage

Basic Usage

<!-- Coupon Cell -->
<van-coupon-cell
  :coupons="coupons"
  :chosen-coupon="chosenCoupon"
  @click="showList = true"
/>
<!-- Coupon List -->
<van-popup
  v-model:show="showList"
  round
  position="bottom"
  style="height: 90%; padding-top: 4px;"
>
  <van-coupon-list
    :coupons="coupons"
    :chosen-coupon="chosenCoupon"
    :disabled-coupons="disabledCoupons"
    @change="onChange"
    @exchange="onExchange"
  />
</van-popup>
import { ref } from 'vue';

export default {
  setup() {
    const coupon = {
      available: 1,
      originCondition: 0,
      reason: '',
      value: 150,
      name: 'Coupon name',
      startAt: 1489104000,
      endAt: 1514592000,
      valueDesc: '1.5',
      unitDesc: '\u5143',
    };

    const coupons = ref([coupon]);
    const showList = ref(false);
    const chosenCoupon = ref(-1);

    const onChange = (index) => {
      showList.value = false;
      chosenCoupon.value = index;
    };
    const onExchange = (code) => {
      coupons.value.push(coupon);
    };

    return {
      coupons,
      showList,
      onChange,
      onExchange,
      chosenCoupon,
      disabledCoupons: [coupon],
    };
  },
};

API

CouponCell Props

AttributeDescriptionTypeDefault
titleCell titlestringCoupon
chosen-couponIndex of chosen couponnumber | string-1
couponsCoupon listCoupon[][]
editableCell editablebooleantrue
borderWhether to show inner borderbooleantrue
currencyCurrency symbolstring\xA5

CouponList Props

AttributeDescriptionTypeDefault
v-modelCurrent exchange codestring-
chosen-couponIndex of chosen couponnumber-1
couponsCoupon listCoupon[][]
disabled-couponsDisabled coupon listCoupon[][]
enabled-titleTitle of coupon liststringAvailable
disabled-titleTitle of disabled coupon liststringUnavailable
exchange-button-textExchange button textstringExchange
exchange-button-loadingWhether to show loading in exchange buttonbooleanfalse
exchange-button-disabledWhether to disable exchange buttonbooleanfalse
exchange-min-lengthMin length to enable exchange buttonnumber1
displayed-coupon-indexIndex of displayed couponnumber-
close-button-textClose button textstringClose
input-placeholderInput placeholderstringCoupon code
currencyCurrency symbolstring\xA5
empty-imagePlaceholder image when list is emptystring-
show-countWhether to show coupon count in tab titlebooleantrue

CouponList Events

EventDescriptionArguments
changeEmitted when chosen coupon changedindex: index of chosen coupon
exchangeEmitted when exchanging couponcode: exchange code

CouponList Slots

NameDescription
list-footer v3.0.18Coupon list bottom
disabled-list-footer v3.0.18Unavailable coupons list bottom

Data Structure of Coupon

KeyDescriptionType
idIdstring
nameNamestring
conditionConditionstring
startAtStart time (Timestamp, unit second)number
endAtEnd time (Timestamp, unit second)number
descriptionDescriptionstring
reasonUnavailable reasonstring
valueValuenumber
valueDescValue Textstring
unitDescUnit Textstring

Types

The component exports the following type definitions:

import type { CouponCellProps, CouponListProps } from 'vant';

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-coupon-margin0 var(--van-padding-sm) var(--van-padding-sm)-
--van-coupon-content-height84px-
--van-coupon-content-padding14px 0-
--van-coupon-content-text-colorvar(--van-text-color)-
--van-coupon-background-colorvar(--van-background-color-light)-
--van-coupon-active-background-colorvar(--van-active-color)-
--van-coupon-border-radiusvar(--van-border-radius-lg)-
--van-coupon-box-shadow0 0 4px rgba(0, 0, 0, 0.1)-
--van-coupon-head-width96px-
--van-coupon-amount-colorvar(--van-danger-color)-
--van-coupon-amount-font-size30px-
--van-coupon-currency-font-size40%-
--van-coupon-name-font-sizevar(--van-font-size-md)-
--van-coupon-disabled-text-colorvar(--van-text-color-2)-
--van-coupon-description-paddingvar(--van-padding-xs) var(--van-padding-md)-
--van-coupon-description-border-colorvar(--van-border-color)-
--van-coupon-corner-checkbox-icon-colorvar(--van-danger-color)-
--van-coupon-list-background-colorvar(--van-background-color)-
--van-coupon-list-field-padding5px 0 5px var(--van-padding-md)-
--van-coupon-list-exchange-button-height32px-
--van-coupon-list-close-button-height40px-
--van-coupon-list-empty-tip-colorvar(--van-text-color-2)-
--van-coupon-list-empty-tip-font-sizevar(--van-font-size-md)-
--van-coupon-list-empty-tip-line-heightvar(--van-line-height-md)-
--van-coupon-cell-selected-text-colorvar(--van-text-color)-
`,14),o=[e],h={__name:"README",setup(r,{expose:t}){return t({frontmatter:{}}),(p,c)=>(s(),n("div",a,o))}};export{h as default};