巴青农资商城

goodsDisplay.js 715B

1234567891011121314151617181920212223242526
  1. import { resolveFileUrl } from '@/utils/image'
  2. import { formatPrice } from '@/utils/format'
  3. const GOODS_PLACEHOLDER = '/static/logo.png'
  4. /** 列表卡片展示模型(首页热销 / 分类商品共用) */
  5. export function mapGoodsCard(row) {
  6. if (!row) return null
  7. return {
  8. goodsId: row.goodsId,
  9. goodsSn: row.goodsSn,
  10. goodsName: row.goodsName,
  11. mainPic: row.mainPic,
  12. displayPic: resolveFileUrl(row.mainPic) || GOODS_PLACEHOLDER,
  13. salePrice: row.salePrice,
  14. priceText: formatPrice(row.salePrice),
  15. shopId: row.shopId,
  16. shopName: row.shopName
  17. }
  18. }
  19. export function mapGoodsCardList(list) {
  20. if (!Array.isArray(list)) return []
  21. return list.map(mapGoodsCard).filter(Boolean)
  22. }