index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.default = void 0;
  5. var _babelHelperVueJsxMergeProps = _interopRequireDefault(require("@vue/babel-helper-vue-jsx-merge-props"));
  6. var _utils = require("../utils");
  7. var _functional = require("../utils/functional");
  8. var _tag = _interopRequireDefault(require("../tag"));
  9. var _image = _interopRequireDefault(require("../image"));
  10. // Utils
  11. // Components
  12. var _createNamespace = (0, _utils.createNamespace)('card'),
  13. createComponent = _createNamespace[0],
  14. bem = _createNamespace[1];
  15. function Card(h, props, slots, ctx) {
  16. var _slots$priceTop;
  17. var thumb = props.thumb;
  18. var showNum = slots.num || (0, _utils.isDef)(props.num);
  19. var showPrice = slots.price || (0, _utils.isDef)(props.price);
  20. var showOriginPrice = slots['origin-price'] || (0, _utils.isDef)(props.originPrice);
  21. var showBottom = showNum || showPrice || showOriginPrice || slots.bottom;
  22. function onThumbClick(event) {
  23. (0, _functional.emit)(ctx, 'click-thumb', event);
  24. }
  25. function ThumbTag() {
  26. if (slots.tag || props.tag) {
  27. return h("div", {
  28. "class": bem('tag')
  29. }, [slots.tag ? slots.tag() : h(_tag.default, {
  30. "attrs": {
  31. "mark": true,
  32. "type": "danger"
  33. }
  34. }, [props.tag])]);
  35. }
  36. }
  37. function Thumb() {
  38. if (slots.thumb || thumb) {
  39. return h("a", {
  40. "attrs": {
  41. "href": props.thumbLink
  42. },
  43. "class": bem('thumb'),
  44. "on": {
  45. "click": onThumbClick
  46. }
  47. }, [slots.thumb ? slots.thumb() : h(_image.default, {
  48. "attrs": {
  49. "src": thumb,
  50. "width": "100%",
  51. "height": "100%",
  52. "fit": "cover",
  53. "lazy-load": props.lazyLoad
  54. }
  55. }), ThumbTag()]);
  56. }
  57. }
  58. function Title() {
  59. if (slots.title) {
  60. return slots.title();
  61. }
  62. if (props.title) {
  63. return h("div", {
  64. "class": [bem('title'), 'van-multi-ellipsis--l2']
  65. }, [props.title]);
  66. }
  67. }
  68. function Desc() {
  69. if (slots.desc) {
  70. return slots.desc();
  71. }
  72. if (props.desc) {
  73. return h("div", {
  74. "class": [bem('desc'), 'van-ellipsis']
  75. }, [props.desc]);
  76. }
  77. }
  78. function PriceContent() {
  79. var priceArr = props.price.toString().split('.');
  80. return h("div", [h("span", {
  81. "class": bem('price-currency')
  82. }, [props.currency]), h("span", {
  83. "class": bem('price-integer')
  84. }, [priceArr[0]]), ".", h("span", {
  85. "class": bem('price-decimal')
  86. }, [priceArr[1]])]);
  87. }
  88. function Price() {
  89. if (showPrice) {
  90. return h("div", {
  91. "class": bem('price')
  92. }, [slots.price ? slots.price() : PriceContent()]);
  93. }
  94. }
  95. function OriginPrice() {
  96. if (showOriginPrice) {
  97. var slot = slots['origin-price'];
  98. return h("div", {
  99. "class": bem('origin-price')
  100. }, [slot ? slot() : props.currency + " " + props.originPrice]);
  101. }
  102. }
  103. function Num() {
  104. if (showNum) {
  105. return h("div", {
  106. "class": bem('num')
  107. }, [slots.num ? slots.num() : "x" + props.num]);
  108. }
  109. }
  110. function Footer() {
  111. if (slots.footer) {
  112. return h("div", {
  113. "class": bem('footer')
  114. }, [slots.footer()]);
  115. }
  116. }
  117. return h("div", (0, _babelHelperVueJsxMergeProps.default)([{
  118. "class": bem()
  119. }, (0, _functional.inherit)(ctx, true)]), [h("div", {
  120. "class": bem('header')
  121. }, [Thumb(), h("div", {
  122. "class": bem('content', {
  123. centered: props.centered
  124. })
  125. }, [h("div", [Title(), Desc(), slots.tags == null ? void 0 : slots.tags()]), showBottom && h("div", {
  126. "class": "van-card__bottom"
  127. }, [(_slots$priceTop = slots['price-top']) == null ? void 0 : _slots$priceTop.call(slots), Price(), OriginPrice(), Num(), slots.bottom == null ? void 0 : slots.bottom()])])]), Footer()]);
  128. }
  129. Card.props = {
  130. tag: String,
  131. desc: String,
  132. thumb: String,
  133. title: String,
  134. centered: Boolean,
  135. lazyLoad: Boolean,
  136. thumbLink: String,
  137. num: [Number, String],
  138. price: [Number, String],
  139. originPrice: [Number, String],
  140. currency: {
  141. type: String,
  142. default: '¥'
  143. }
  144. };
  145. var _default = createComponent(Card);
  146. exports.default = _default;