@fle-ui/plus-goods-detail-drawer
Version:
@fle-ui/plus-goods-detail-drawer
317 lines (316 loc) • 19.2 kB
JavaScript
"use strict";
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _antd = require("antd");
var _icons = require("@ant-design/icons");
var _DescriptionsItem = require("../DescriptionsItem");
var _SkuTable = _interopRequireDefault(require("../SkuTable"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var BasicInfoSection = /*#__PURE__*/_react.default.memo(function (_ref) {
var basicInfo = _ref.basicInfo,
changeContent = _ref.changeContent,
beforeContent = _ref.beforeContent,
isAudit = _ref.isAudit,
hideFields = _ref.hideFields;
if (hideFields.includes('basicInfo')) {
return null;
}
var skuList = basicInfo.skuList,
isExistSpec = basicInfo.isExistSpec;
var _useState = (0, _react.useState)(false),
_useState2 = _slicedToArray(_useState, 2),
videoModalVisible = _useState2[0],
setVideoModalVisible = _useState2[1];
var _useState3 = (0, _react.useState)(null),
_useState4 = _slicedToArray(_useState3, 2),
currentVideo = _useState4[0],
setCurrentVideo = _useState4[1];
if (!basicInfo) return null;
var handleVideoClick = (0, _react.useCallback)(function (video) {
setCurrentVideo(video);
setVideoModalVisible(true);
}, []);
var getVideoContent = (0, _react.useCallback)(function (video) {
return (video === null || video === void 0 ? void 0 : video.url) ? /*#__PURE__*/_react.default.createElement("div", {
className: "goods-video-cover",
onClick: function onClick() {
return video && handleVideoClick(video);
}
}, /*#__PURE__*/_react.default.createElement(_antd.Image, {
width: 90,
height: 90,
src: video.cover,
preview: false,
style: {
objectFit: 'contain',
border: '1px dashed #f5f5f5',
borderRadius: 4
}
}), /*#__PURE__*/_react.default.createElement(_icons.PlayCircleOutlined, null)) : '-';
}, [handleVideoClick]);
var getImagesContent = (0, _react.useCallback)(function (images) {
return /*#__PURE__*/_react.default.createElement(_antd.Space, {
size: "middle",
wrap: true
}, images && images.length > 0 ? images.map(function (image, index) {
return /*#__PURE__*/_react.default.createElement(_antd.Image, {
key: index,
width: 90,
height: 90,
style: {
objectFit: 'contain',
border: '1px dashed #f5f5f5'
},
src: image
});
}) : '-');
}, []);
var getSkuContent = function getSkuContent(isExistSpec, skuArr) {
return isExistSpec && skuArr && skuArr.length > 0 ? /*#__PURE__*/_react.default.createElement(_SkuTable.default, {
skuList: skuArr || [],
thead: [{
name: '规格图片',
key: 'image',
type: 'image',
mergeRowSpan: true
}]
}) : '-';
};
var basicAttributesItems = (0, _react.useMemo)(function () {
var _changeContent$images;
return [(0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.video',
label: '商品视频',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.video),
beforeContent: getVideoContent(beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.video),
children: getVideoContent(basicInfo === null || basicInfo === void 0 ? void 0 : basicInfo.video)
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.images',
label: '商品图片',
tooltipWidth: 106 * ((changeContent === null || changeContent === void 0 ? void 0 : (_changeContent$images = changeContent.images) === null || _changeContent$images === void 0 ? void 0 : _changeContent$images.length) || 0),
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.images),
beforeContent: getImagesContent(beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.images),
children: getImagesContent(basicInfo === null || basicInfo === void 0 ? void 0 : basicInfo.images)
})].filter(Boolean);
}, [isAudit, hideFields, changeContent === null || changeContent === void 0 ? void 0 : changeContent.video, changeContent === null || changeContent === void 0 ? void 0 : changeContent.images, basicInfo === null || basicInfo === void 0 ? void 0 : basicInfo.video, basicInfo === null || basicInfo === void 0 ? void 0 : basicInfo.images, getVideoContent, getImagesContent]);
var basicInfoItems = (0, _react.useMemo)(function () {
return [(0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.name',
label: '商品名称',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.name),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.name,
children: basicInfo.name || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.desc',
label: '商品描述',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.desc),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.desc,
children: basicInfo.desc || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.sellingPoint',
label: '商品卖点',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.sellingPoint),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.sellingPoint,
children: basicInfo.sellingPoint || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.goodsNo',
label: '商品货号',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.goodsNo),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.goodsNo,
children: basicInfo.goodsNo || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.modelNo',
label: '商品型号',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.modelNo),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.modelNo,
children: basicInfo.modelNo || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.taxCode',
label: '税率编码',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.taxCode),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.taxCode,
children: basicInfo.taxCode || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.brand',
label: '商品品牌',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.brand),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.brand,
children: basicInfo.brand || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.unit',
label: '商品单位',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.unit),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.unit,
children: basicInfo.unit || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.supplier',
label: '供应商',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.supplier),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.supplier,
children: basicInfo.supplier || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.category',
label: '商品分类',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.category),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.category,
children: basicInfo.category || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.befitPerson',
label: '适用人群',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.befitPerson),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.befitPerson,
children: basicInfo.befitPerson || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.befitPresent',
label: '适用送礼对象',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.befitPresent),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.befitPresent,
children: basicInfo.befitPresent || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.style',
label: '商品风格',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.style),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.style,
children: basicInfo.style || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.packaging',
label: '商品包装',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.packaging),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.packaging,
children: basicInfo.packaging || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.suit',
label: '商品套装',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.suit),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.suit,
children: basicInfo.suit || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.marketTime',
label: '上市时间',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.marketTime),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.marketTime,
children: basicInfo.marketTime || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.tag',
label: '商品标签',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.tag),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.tag,
children: basicInfo.tag || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.industry',
label: '适用行业',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.industry),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.industry,
children: basicInfo.industry || '-'
}), (0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.scene',
label: '适用场景',
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.scene),
beforeContent: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.scene,
children: basicInfo.scene || '-'
})].filter(Boolean);
}, [isAudit, changeContent, basicInfo, hideFields]);
var skuItems = (0, _react.useMemo)(function () {
return [(0, _DescriptionsItem.formatDescriptionsItem)({
hideFields: hideFields,
key: 'basicInfo.skuList',
label: '商品规格',
labelStyle: {
fontWeight: 'bold',
color: '#1d2531'
},
isChangeRecord: isAudit && (0, _DescriptionsItem.formatValueToBoolean)(changeContent === null || changeContent === void 0 ? void 0 : changeContent.skuList),
beforeContent: getSkuContent(beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.isExistSpec, beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.skuList),
children: getSkuContent(isExistSpec, basicInfo === null || basicInfo === void 0 ? void 0 : basicInfo.skuList),
dynamicWidth: beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.isExistSpec
})].filter(Boolean);
}, [isAudit, changeContent === null || changeContent === void 0 ? void 0 : changeContent.skuList, beforeContent === null || beforeContent === void 0 ? void 0 : beforeContent.isExistSpec, isExistSpec, basicInfo === null || basicInfo === void 0 ? void 0 : basicInfo.skuList, getSkuContent, hideFields]);
return /*#__PURE__*/_react.default.createElement("div", {
id: "basic-info",
className: "goods-detail-drawer-section"
}, /*#__PURE__*/_react.default.createElement("div", {
className: "goods-detail-drawer-section-title"
}, "\u57FA\u672C\u4FE1\u606F"), /*#__PURE__*/_react.default.createElement(_antd.Descriptions, {
column: 1,
colon: false,
size: "small",
title: "\u57FA\u672C\u5C5E\u6027",
items: basicAttributesItems
}), /*#__PURE__*/_react.default.createElement(_antd.Descriptions, {
bordered: true,
size: "small",
column: {
sm: 1,
md: 2,
lg: 3
},
labelStyle: {
width: 100
},
contentStyle: {
maxWidth: 0
} // 设置最大宽度为0,让内容自适应
,
items: basicInfoItems
}), /*#__PURE__*/_react.default.createElement(_antd.Descriptions, {
column: 1,
size: "small",
colon: false,
layout: "vertical",
items: skuItems
}), /*#__PURE__*/_react.default.createElement(_antd.Modal, {
title: "\u5546\u54C1\u89C6\u9891",
open: videoModalVisible,
onCancel: function onCancel() {
return setVideoModalVisible(false);
},
footer: null,
width: 600,
centered: true
}, currentVideo && /*#__PURE__*/_react.default.createElement("div", {
style: {
textAlign: 'center'
}
}, /*#__PURE__*/_react.default.createElement("video", {
controls: true,
width: "100%",
height: "auto",
poster: currentVideo.cover,
src: currentVideo.url
}, "\u60A8\u7684\u6D4F\u89C8\u5668\u4E0D\u652F\u6301\u89C6\u9891\u64AD\u653E\u3002"))));
});
BasicInfoSection.displayName = 'BasicInfoSection';
var _default = exports.default = BasicInfoSection;