index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <demo-section>
  3. <demo-block :title="$t('basicUsage')">
  4. <van-coupon-cell
  5. :coupons="coupons"
  6. :chosen-coupon="chosenCoupon"
  7. @click="showList = true"
  8. />
  9. <van-popup
  10. v-model="showList"
  11. position="bottom"
  12. >
  13. <van-coupon-list
  14. :coupons="coupons"
  15. :chosen-coupon="chosenCoupon"
  16. :disabled-coupons="disabledCoupons"
  17. @change="onChange"
  18. @exchange="onExchange"
  19. />
  20. </van-popup>
  21. </demo-block>
  22. </demo-section>
  23. </template>
  24. <script>
  25. /* eslint-disable camelcase */
  26. export default {
  27. i18n: {
  28. 'zh-CN': {
  29. coupon: {
  30. name: '优惠券名称',
  31. reason: '优惠券不可用原因',
  32. description: '描述信息'
  33. },
  34. exchange: '兑换成功'
  35. },
  36. 'en-US': {
  37. coupon: {
  38. name: 'Coupon name',
  39. reason: 'Coupon unavailable reason',
  40. description: 'Description'
  41. },
  42. exchange: 'Success'
  43. }
  44. },
  45. data() {
  46. return {
  47. showList: false,
  48. chosenCoupon: -1,
  49. exchangedCoupons: []
  50. };
  51. },
  52. computed: {
  53. coupons() {
  54. return [this.coupon, this.discountCoupon, ...this.exchangedCoupons];
  55. },
  56. disabledCoupons() {
  57. return [this.disabledCoupon, this.disabledDiscountCoupon];
  58. },
  59. coupon() {
  60. return {
  61. id: 1,
  62. condition: '无使用门槛\n最多优惠12元',
  63. reason: '',
  64. value: 150,
  65. name: this.$t('coupon.name'),
  66. description: this.$t('coupon.description'),
  67. startAt: 1489104000,
  68. endAt: 1514592000,
  69. valueDesc: '1.5',
  70. unitDesc: '元'
  71. };
  72. },
  73. discountCoupon() {
  74. return {
  75. ...this.coupon,
  76. id: 2,
  77. value: 12,
  78. valueDesc: '8.8',
  79. unitDesc: '折'
  80. };
  81. },
  82. disabledCoupon() {
  83. return {
  84. ...this.coupon,
  85. id: 3,
  86. reason: this.$t('coupon.reason')
  87. };
  88. },
  89. disabledDiscountCoupon() {
  90. return {
  91. ...this.discountCoupon,
  92. valueDesc: '1',
  93. unitDesc: '折',
  94. id: 4,
  95. reason: this.$t('coupon.reason')
  96. };
  97. }
  98. },
  99. methods: {
  100. onChange(index) {
  101. this.showList = false;
  102. this.chosenCoupon = index;
  103. },
  104. onExchange() {
  105. this.$toast(this.$t('exchange'));
  106. this.exchangedCoupons.push({
  107. ...this.coupon,
  108. id: this.randomId()
  109. });
  110. },
  111. randomId(max = 999999) {
  112. return Math.floor(Math.random() * max) + 1;
  113. }
  114. }
  115. };
  116. </script>
  117. <style lang="less">
  118. .demo-coupon-list {
  119. .van-popup {
  120. height: 100%;
  121. }
  122. }
  123. </style>