index.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import _mergeJSXProps from "@vue/babel-helper-vue-jsx-merge-props";
  2. import { use, isDef } from '../utils';
  3. import { inherit } from '../utils/functional';
  4. import Tag from '../tag'; // Types
  5. var _use = use('card'),
  6. sfc = _use[0],
  7. bem = _use[1];
  8. function Card(h, props, slots, ctx) {
  9. var thumb = props.thumb;
  10. var showThumb = slots.thumb || thumb;
  11. var showTag = slots.tag || props.tag;
  12. var showNum = slots.num || isDef(props.num);
  13. var showPrice = slots.price || isDef(props.price);
  14. var showOriginPrice = slots['origin-price'] || isDef(props.originPrice);
  15. var showBottom = showNum || showPrice || showOriginPrice;
  16. var Thumb = showThumb && h("a", {
  17. "attrs": {
  18. "href": props.thumbLink
  19. },
  20. "class": bem('thumb')
  21. }, [slots.thumb ? slots.thumb() : props.lazyLoad ? h("img", {
  22. "class": bem('img'),
  23. "directives": [{
  24. name: "lazy",
  25. value: thumb
  26. }]
  27. }) : h("img", {
  28. "class": bem('img'),
  29. "attrs": {
  30. "src": thumb
  31. }
  32. }), showTag && h("div", {
  33. "class": bem('tag')
  34. }, [slots.tag ? slots.tag() : h(Tag, {
  35. "attrs": {
  36. "mark": true,
  37. "type": "danger"
  38. }
  39. }, [props.tag])])]);
  40. var Title = slots.title ? slots.title() : props.title && h("div", {
  41. "class": bem('title')
  42. }, [props.title]);
  43. var Desc = slots.desc ? slots.desc() : props.desc && h("div", {
  44. "class": [bem('desc'), 'van-ellipsis']
  45. }, [props.desc]);
  46. var Price = showPrice && h("div", {
  47. "class": bem('price')
  48. }, [slots.price ? slots.price() : props.currency + " " + props.price]);
  49. var OriginPrice = showOriginPrice && h("div", {
  50. "class": bem('origin-price')
  51. }, [slots['origin-price'] ? slots['origin-price']() : props.currency + " " + props.originPrice]);
  52. var Num = showNum && h("div", {
  53. "class": bem('num')
  54. }, [slots.num ? slots.num() : "x " + props.num]);
  55. var Footer = slots.footer && h("div", {
  56. "class": bem('footer')
  57. }, [slots.footer()]);
  58. return h("div", _mergeJSXProps([{
  59. "class": bem()
  60. }, inherit(ctx, true)]), [h("div", {
  61. "class": bem('header')
  62. }, [Thumb, h("div", {
  63. "class": bem('content', {
  64. centered: props.centered
  65. })
  66. }, [Title, Desc, slots.tags && slots.tags(), showBottom && h("div", {
  67. "class": "van-card__bottom"
  68. }, [Price, OriginPrice, Num])])]), Footer]);
  69. }
  70. Card.props = {
  71. tag: String,
  72. desc: String,
  73. thumb: String,
  74. title: String,
  75. centered: Boolean,
  76. lazyLoad: Boolean,
  77. thumbLink: String,
  78. num: [Number, String],
  79. price: [Number, String],
  80. originPrice: [Number, String],
  81. currency: {
  82. type: String,
  83. "default": '¥'
  84. }
  85. };
  86. export default sfc(Card);