SkuHeader.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  7. var _utils = require("../../utils");
  8. var _functional = require("../../utils/functional");
  9. var _constant = require("../../utils/constant");
  10. var _image = _interopRequireDefault(require("../../image"));
  11. // Utils
  12. // Components
  13. var _createNamespace = (0, _utils.createNamespace)('sku-header'),
  14. createComponent = _createNamespace[0],
  15. bem = _createNamespace[1];
  16. function getSkuImgValue(sku, selectedSku) {
  17. var imgValue;
  18. sku.tree.some(function (item) {
  19. var id = selectedSku[item.k_s];
  20. if (id && item.v) {
  21. var matchedSku = item.v.filter(function (skuValue) {
  22. return skuValue.id === id;
  23. })[0] || {};
  24. var img = matchedSku.previewImgUrl || matchedSku.imgUrl || matchedSku.img_url;
  25. if (img) {
  26. imgValue = (0, _extends2.default)({}, matchedSku, {
  27. ks: item.k_s,
  28. imgUrl: img
  29. });
  30. return true;
  31. }
  32. }
  33. return false;
  34. });
  35. return imgValue;
  36. }
  37. function SkuHeader(h, props, slots, ctx) {
  38. var _slots$skuHeaderIma;
  39. var sku = props.sku,
  40. goods = props.goods,
  41. skuEventBus = props.skuEventBus,
  42. selectedSku = props.selectedSku,
  43. _props$showHeaderImag = props.showHeaderImage,
  44. showHeaderImage = _props$showHeaderImag === void 0 ? true : _props$showHeaderImag;
  45. var selectedValue = getSkuImgValue(sku, selectedSku);
  46. var imgUrl = selectedValue ? selectedValue.imgUrl : goods.picture;
  47. var previewImage = function previewImage() {
  48. skuEventBus.$emit('sku:previewImage', selectedValue);
  49. };
  50. return h("div", (0, _babelHelperVueJsxMergeProps.default)([{
  51. "class": [bem(), _constant.BORDER_BOTTOM]
  52. }, (0, _functional.inherit)(ctx)]), [showHeaderImage && h(_image.default, {
  53. "attrs": {
  54. "fit": "cover",
  55. "src": imgUrl
  56. },
  57. "class": bem('img-wrap'),
  58. "on": {
  59. "click": previewImage
  60. }
  61. }, [(_slots$skuHeaderIma = slots['sku-header-image-extra']) == null ? void 0 : _slots$skuHeaderIma.call(slots)]), h("div", {
  62. "class": bem('goods-info')
  63. }, [slots.default == null ? void 0 : slots.default()])]);
  64. }
  65. SkuHeader.props = {
  66. sku: Object,
  67. goods: Object,
  68. skuEventBus: Object,
  69. selectedSku: Object,
  70. showHeaderImage: Boolean
  71. };
  72. var _default = createComponent(SkuHeader);
  73. exports.default = _default;