@tbox.cn/app-module-shopping-guide 0.2.1 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +16 -0
- package/README.md +96 -0
- package/dist/chunk-AYQZO2FV.js +1496 -0
- package/dist/chunk-QDTU2FRN.js +1682 -0
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -8
- package/dist/server/index.d.ts +2512 -608
- package/dist/server/index.js +1 -7
- package/dist/shop-guide-header-art-pea-v2-OME4MKBW.jpg +0 -0
- package/dist/shopping-guide-OQ2SSHXL.css +2593 -0
- package/package.json +25 -16
- package/skills/shopping-guide/SKILL.md +127 -24
- package/src/client/assets/shop-guide-header-art-pea-v2.jpg +0 -0
- package/src/client/assets/shop-guide-header-art.png +0 -0
- package/src/client/assets.d.ts +10 -0
- package/src/client/cards/category-list/index.tsx +113 -0
- package/src/client/cards/human-guide-list/index.tsx +72 -0
- package/src/client/cards/index.ts +14 -0
- package/src/client/cards/location-handoff/index.tsx +52 -0
- package/src/client/cards/mall-directory/index.tsx +77 -0
- package/src/client/cards/nearby-mall-list/index.tsx +40 -0
- package/src/client/cards/product-comparison/index.tsx +100 -0
- package/src/client/cards/product-detail/index.tsx +97 -0
- package/src/client/cards/product-list/index.tsx +223 -0
- package/src/client/cards/recommend-merchants/index.tsx +147 -0
- package/src/client/cards/shop-detail/index.tsx +133 -0
- package/src/client/cards/shop-list/index.tsx +216 -0
- package/src/client/cards/view.ts +147 -0
- package/src/client/categories.ts +38 -0
- package/src/client/components/ImageWithFallback.tsx +34 -0
- package/src/client/components/MerchantRow.tsx +78 -0
- package/src/client/components/ShopDetailSheet.tsx +383 -0
- package/src/client/components/ShopGuideHeader.tsx +24 -0
- package/src/client/components/ShopGuideSectionLabel.tsx +10 -0
- package/src/client/components/ShopListSheet.tsx +293 -0
- package/src/client/index.ts +8 -6
- package/src/client/styles/shopping-guide.css +2593 -0
- package/src/client/types/css.d.ts +2 -0
- package/src/server/cards/category-list/meta.ts +0 -2
- package/src/server/cards/human-guide-list/meta.ts +0 -2
- package/src/server/cards/index.ts +10 -10
- package/src/server/cards/location-handoff/meta.ts +0 -2
- package/src/server/cards/mall-directory/meta.ts +0 -2
- package/src/server/cards/nearby-mall-list/meta.ts +1 -3
- package/src/server/cards/product-comparison/meta.ts +0 -2
- package/src/server/cards/product-detail/meta.ts +0 -2
- package/src/server/cards/product-list/meta.ts +0 -2
- package/src/server/cards/recommend-merchants/meta.ts +37 -0
- package/src/server/cards/recommend-merchants/samples.ts +189 -0
- package/src/server/cards/{merchant-detail → shop-detail}/meta.ts +6 -6
- package/src/server/cards/shop-detail/samples.ts +72 -0
- package/src/server/cards/{merchant-list → shop-list}/meta.ts +9 -9
- package/src/server/cards/shop-list/samples.ts +154 -0
- package/src/server/domain/value-objects.ts +1 -2
- package/src/server/handler.ts +63 -0
- package/src/server/index.ts +161 -101
- package/src/server/ports/index.ts +120 -91
- package/src/server/ports/local-adapters.ts +5 -55
- package/src/server/projections/index.ts +159 -41
- package/src/server/tools/index.ts +590 -315
- package/tbox.module.json +137 -0
- package/tests/cards-render.test.tsx +830 -0
- package/tests/floor-pretool.test.ts +275 -0
- package/tests/handler.test.ts +259 -0
- package/tests/merchant-list-limit.test.ts +53 -0
- package/tests/ports-resolve.test.ts +112 -0
- package/tests/samples.test.ts +71 -0
- package/tests/shopping-guide.test.ts +402 -234
- package/tests/skill.test.ts +86 -0
- package/tests/view.test.ts +42 -0
- package/tsup.config.ts +9 -1
- package/dist/chunk-AGBLC6XI.js +0 -1294
- package/dist/chunk-U4WDS5PQ.js +0 -173
- package/skills/shopping-guide/references/comparison-format.md +0 -5
- package/skills/shopping-guide/references/faq-answers.md +0 -5
- package/skills/shopping-guide/references/floor-directory.md +0 -4
- package/skills/shopping-guide/references/intent-patterns.md +0 -5
- package/skills/shopping-guide/references/location-format.md +0 -5
- package/skills/shopping-guide/references/policy-lookup.md +0 -5
- package/skills/shopping-guide/references/product-search-tips.md +0 -6
- package/skills/shopping-guide/references/recommendation-style.md +0 -5
- package/src/client/cards/index.tsx +0 -267
- package/src/server/cards/customer-service-faq/meta.ts +0 -18
- package/src/server/integrations/joycity/adapter.ts +0 -226
- package/src/server/integrations/joycity/auth-strategy.ts +0 -38
- package/src/server/integrations/joycity/gateway.ts +0 -128
- package/tbox.component.json +0 -48
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* product-comparison 富卡(0.4.0 D6):对比表 + 到期计时器(refreshRequiredAt → stale 全禁)。
|
|
3
|
+
*/
|
|
4
|
+
import { useEffect, useState } from 'react';
|
|
5
|
+
import { ImageWithFallback } from '../../components/ImageWithFallback';
|
|
6
|
+
import type { ProductComparisonCardData } from '@tbox.cn/app-contracts-mall';
|
|
7
|
+
|
|
8
|
+
export function ProductComparisonCard(props: {
|
|
9
|
+
data: ProductComparisonCardData;
|
|
10
|
+
isHistory: boolean;
|
|
11
|
+
}) {
|
|
12
|
+
const { data } = props;
|
|
13
|
+
const [stale, setStale] = useState(false);
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!data.refreshRequiredAt) return;
|
|
17
|
+
const deadline = new Date(data.refreshRequiredAt).getTime();
|
|
18
|
+
const delay = Math.max(0, deadline - Date.now());
|
|
19
|
+
const timer = window.setTimeout(() => setStale(true), delay);
|
|
20
|
+
return () => window.clearTimeout(timer);
|
|
21
|
+
}, [data.refreshRequiredAt]);
|
|
22
|
+
|
|
23
|
+
// 属性行 = 各商品 attributes 按 name 归并(POC 对比表语义)。本卡为只读对比表,无交互元素;
|
|
24
|
+
// isHistory/stale 语义见到期标记(stale 才显示"已过期",isHistory 仅表征历史不可交互)
|
|
25
|
+
const attrNames = Array.from(new Set(data.products.flatMap((p) => p.attributes.map((a) => a.name))));
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<section className={`sg-card sg-product-comparison${stale ? ' sg-product-comparison--stale' : ''}`}>
|
|
29
|
+
<div className="sg-card-title">商品对比</div>
|
|
30
|
+
{stale && (
|
|
31
|
+
<div className="sg-stale-notice">
|
|
32
|
+
<span>对比数据已过期,请重新发起对比</span>
|
|
33
|
+
</div>
|
|
34
|
+
)}
|
|
35
|
+
|
|
36
|
+
<div className="sg-compare-wrap">
|
|
37
|
+
<table className="sg-compare">
|
|
38
|
+
<thead>
|
|
39
|
+
<tr>
|
|
40
|
+
<th scope="col" className="sg-compare__label" />
|
|
41
|
+
{data.products.map((p) => (
|
|
42
|
+
<th key={p.productId} scope="col">
|
|
43
|
+
<ImageWithFallback src={p.imageUrl} alt={p.name} className="sg-compare__img" size={40} />
|
|
44
|
+
<div className="sg-compare__name">{p.name}</div>
|
|
45
|
+
<div className="sg-price-sale">{p.price.sale?.display ?? '—'}</div>
|
|
46
|
+
</th>
|
|
47
|
+
))}
|
|
48
|
+
</tr>
|
|
49
|
+
</thead>
|
|
50
|
+
<tbody>
|
|
51
|
+
<tr>
|
|
52
|
+
<th scope="row" className="sg-compare__label">
|
|
53
|
+
库存
|
|
54
|
+
</th>
|
|
55
|
+
{data.products.map((p) => (
|
|
56
|
+
<td key={p.productId}>
|
|
57
|
+
<span className={`sg-availability sg-availability-${p.availability.status}`}>
|
|
58
|
+
{p.availability.label}
|
|
59
|
+
</span>
|
|
60
|
+
</td>
|
|
61
|
+
))}
|
|
62
|
+
</tr>
|
|
63
|
+
{attrNames.map((name) => (
|
|
64
|
+
<tr key={name}>
|
|
65
|
+
<th scope="row" className="sg-compare__label">
|
|
66
|
+
{name}
|
|
67
|
+
</th>
|
|
68
|
+
{data.products.map((p) => {
|
|
69
|
+
const attr = p.attributes.find((a) => a.name === name);
|
|
70
|
+
return (
|
|
71
|
+
<td key={p.productId} className={attr ? '' : 'sg-compare__cell-empty'}>
|
|
72
|
+
{attr?.value ?? '—'}
|
|
73
|
+
</td>
|
|
74
|
+
);
|
|
75
|
+
})}
|
|
76
|
+
</tr>
|
|
77
|
+
))}
|
|
78
|
+
</tbody>
|
|
79
|
+
</table>
|
|
80
|
+
</div>
|
|
81
|
+
|
|
82
|
+
{data.products.some((p) => p.caveats.length > 0) && (
|
|
83
|
+
<div className="sg-item-caveats">
|
|
84
|
+
{data.products.flatMap((p) => p.caveats.map((c, i) => ({ key: `${p.productId}-${i}`, text: c }))).map(({ key, text }) => (
|
|
85
|
+
<div key={key} className="sg-caveat-item">
|
|
86
|
+
⚠️ {text}
|
|
87
|
+
</div>
|
|
88
|
+
))}
|
|
89
|
+
</div>
|
|
90
|
+
)}
|
|
91
|
+
|
|
92
|
+
{/* 到期后整卡降透明(D4:交互全禁)。标记仅 stale 态显示——isHistory 是"历史不可交互"而非"数据过期",两者语义分离 */}
|
|
93
|
+
<span className="sg-compare__stale-marker" hidden={!stale}>
|
|
94
|
+
对比数据可能已过期
|
|
95
|
+
</span>
|
|
96
|
+
</section>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default ProductComparisonCard;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* product-detail 富卡(0.4.0 D6):轮播 + 缩略图 + 属性 + 价格三段 + 促销事实。
|
|
3
|
+
*/
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import { ImageWithFallback } from '../../components/ImageWithFallback';
|
|
6
|
+
import { ItemActionsRow } from '@tbox.cn/app-sdk/client';
|
|
7
|
+
import type { ProductDetailCardData } from '@tbox.cn/app-contracts-mall';
|
|
8
|
+
|
|
9
|
+
export function ProductDetailCard(props: {
|
|
10
|
+
data: ProductDetailCardData;
|
|
11
|
+
cardId: string;
|
|
12
|
+
isHistory: boolean;
|
|
13
|
+
}) {
|
|
14
|
+
const { data, cardId, isHistory } = props;
|
|
15
|
+
const [active, setActive] = useState(0);
|
|
16
|
+
const images = data.imageUrls;
|
|
17
|
+
const current = Math.min(active, Math.max(images.length - 1, 0));
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<section className="sg-card sg-product-detail">
|
|
21
|
+
<div className="sg-card-title">{data.name}</div>
|
|
22
|
+
{data.brand && <div className="sg-card-subtitle">{data.brand}</div>}
|
|
23
|
+
|
|
24
|
+
{images.length > 0 && (
|
|
25
|
+
<div className="sg-carousel">
|
|
26
|
+
<ImageWithFallback src={images[current]} alt={data.name} className="sg-carousel__stage" size={72} />
|
|
27
|
+
{images.length > 1 && (
|
|
28
|
+
<span className="sg-carousel__count">
|
|
29
|
+
{current + 1}/{images.length}
|
|
30
|
+
</span>
|
|
31
|
+
)}
|
|
32
|
+
{images.length > 1 && (
|
|
33
|
+
<div className="sg-carousel__thumbs">
|
|
34
|
+
{images.map((src, i) => (
|
|
35
|
+
<button
|
|
36
|
+
key={i}
|
|
37
|
+
type="button"
|
|
38
|
+
className="sg-carousel__thumb"
|
|
39
|
+
aria-current={i === current}
|
|
40
|
+
aria-label={`查看第 ${i + 1} 张图`}
|
|
41
|
+
onClick={() => setActive(i)}
|
|
42
|
+
>
|
|
43
|
+
<img src={src} alt="" loading="lazy" referrerPolicy="no-referrer" />
|
|
44
|
+
</button>
|
|
45
|
+
))}
|
|
46
|
+
</div>
|
|
47
|
+
)}
|
|
48
|
+
</div>
|
|
49
|
+
)}
|
|
50
|
+
|
|
51
|
+
<div className="sg-price-block sg-price-block--detail">
|
|
52
|
+
{data.price.sale && <span className="sg-price-sale sg-price-sale--lg">{data.price.sale.display}</span>}
|
|
53
|
+
{data.price.original && data.price.sale && (
|
|
54
|
+
<span className="sg-price-original">{data.price.original.display}</span>
|
|
55
|
+
)}
|
|
56
|
+
{data.price.promotion && <span className="sg-price-promotion">{data.price.promotion.display}</span>}
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
<div className={`sg-availability sg-availability-${data.availability.status}`}>
|
|
60
|
+
{data.availability.label}
|
|
61
|
+
{data.humanGuideAvailable && <span className="sg-availability__guide">支持人工导购</span>}
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
{data.description && <div className="sg-product-desc">{data.description}</div>}
|
|
65
|
+
|
|
66
|
+
<dl className="sg-attr-table">
|
|
67
|
+
{data.attributes.map((a) => (
|
|
68
|
+
<div key={a.name} className="sg-attr-row">
|
|
69
|
+
<dt>{a.name}</dt>
|
|
70
|
+
<dd>{a.value}</dd>
|
|
71
|
+
</div>
|
|
72
|
+
))}
|
|
73
|
+
</dl>
|
|
74
|
+
|
|
75
|
+
<div className="sg-product-merchant">
|
|
76
|
+
{data.merchant.name}
|
|
77
|
+
{data.merchant.location?.displayText && (
|
|
78
|
+
<span className="sg-merchant-location"> · {data.merchant.location.displayText}</span>
|
|
79
|
+
)}
|
|
80
|
+
</div>
|
|
81
|
+
|
|
82
|
+
{data.promotionFacts.map((p) => (
|
|
83
|
+
<div key={p} className="sg-promo-fact">
|
|
84
|
+
{p}
|
|
85
|
+
</div>
|
|
86
|
+
))}
|
|
87
|
+
|
|
88
|
+
{data.categoryPath.length > 0 && (
|
|
89
|
+
<div className="sg-category-path">{data.categoryPath.join(' / ')}</div>
|
|
90
|
+
)}
|
|
91
|
+
|
|
92
|
+
<ItemActionsRow actions={data.itemActions} cardId={cardId} isHistory={isHistory} className="sg-item-actions" chipClassName="sg-chip" />
|
|
93
|
+
</section>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export default ProductDetailCard;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* product-list 富卡(0.4.0 D6 → v2:大图列表 + 半屏商品详情)。
|
|
3
|
+
* 点击商品行唤起半屏展示完整信息(portal + sheet 模式,参考 ToolCallDetailOverlay)。
|
|
4
|
+
*/
|
|
5
|
+
import { useState } from 'react';
|
|
6
|
+
import { createPortal } from 'react-dom';
|
|
7
|
+
import { X } from '@phosphor-icons/react';
|
|
8
|
+
import { ItemActionsRow, sendCardAction } from '@tbox.cn/app-sdk/client';
|
|
9
|
+
import { ImageWithFallback } from '../../components/ImageWithFallback';
|
|
10
|
+
import type { ProductListCardData } from '@tbox.cn/app-contracts-mall';
|
|
11
|
+
|
|
12
|
+
type ProductItem = ProductListCardData['items'][number];
|
|
13
|
+
|
|
14
|
+
function ProductDetailSheet({
|
|
15
|
+
item,
|
|
16
|
+
cardId,
|
|
17
|
+
isHistory,
|
|
18
|
+
onClose,
|
|
19
|
+
}: {
|
|
20
|
+
item: ProductItem;
|
|
21
|
+
cardId: string;
|
|
22
|
+
isHistory: boolean;
|
|
23
|
+
onClose: () => void;
|
|
24
|
+
}) {
|
|
25
|
+
return createPortal(
|
|
26
|
+
<div className="sg-product-sheet" role="dialog" aria-modal="true" aria-label={item.name}>
|
|
27
|
+
<div className="sg-product-sheet__mask" onClick={onClose} />
|
|
28
|
+
<div className="sg-product-sheet__panel">
|
|
29
|
+
<div className="sg-product-sheet__header">
|
|
30
|
+
<span className="sg-product-sheet__title">商品详情</span>
|
|
31
|
+
<button type="button" className="sg-product-sheet__close" onClick={onClose} aria-label="关闭">
|
|
32
|
+
<X size={18} />
|
|
33
|
+
</button>
|
|
34
|
+
</div>
|
|
35
|
+
|
|
36
|
+
<div className="sg-product-sheet__body">
|
|
37
|
+
{item.imageUrl && (
|
|
38
|
+
<ImageWithFallback
|
|
39
|
+
src={item.imageUrl}
|
|
40
|
+
alt={item.name}
|
|
41
|
+
className="sg-product-sheet__cover"
|
|
42
|
+
size={240}
|
|
43
|
+
/>
|
|
44
|
+
)}
|
|
45
|
+
|
|
46
|
+
<div className="sg-product-sheet__main">
|
|
47
|
+
{item.badges.length > 0 && (
|
|
48
|
+
<div className="sg-badges">
|
|
49
|
+
{item.badges.map((b) => (
|
|
50
|
+
<span key={b} className="sg-badge">{b}</span>
|
|
51
|
+
))}
|
|
52
|
+
</div>
|
|
53
|
+
)}
|
|
54
|
+
<div className="sg-product-sheet__name">{item.name}</div>
|
|
55
|
+
{item.brand && <div className="sg-product-sheet__brand">{item.brand}</div>}
|
|
56
|
+
|
|
57
|
+
<div className="sg-product-sheet__price-row">
|
|
58
|
+
{item.price.sale && (
|
|
59
|
+
<span className="sg-price-sale">{item.price.sale.display}</span>
|
|
60
|
+
)}
|
|
61
|
+
{item.price.original && item.price.sale && (
|
|
62
|
+
<span className="sg-price-original">{item.price.original.display}</span>
|
|
63
|
+
)}
|
|
64
|
+
{item.price.promotion && (
|
|
65
|
+
<span className="sg-price-promotion">{item.price.promotion.display}</span>
|
|
66
|
+
)}
|
|
67
|
+
{!item.price.sale && !item.price.original && !item.price.promotion && (
|
|
68
|
+
<span className="sg-price-unavailable">价格暂无</span>
|
|
69
|
+
)}
|
|
70
|
+
</div>
|
|
71
|
+
|
|
72
|
+
<div className={`sg-availability sg-availability-${item.availability.status}`}>
|
|
73
|
+
{item.availability.label}
|
|
74
|
+
</div>
|
|
75
|
+
|
|
76
|
+
<div className="sg-product-sheet__merchant">
|
|
77
|
+
<span>{item.merchant.name}</span>
|
|
78
|
+
{item.merchant.location?.displayText && (
|
|
79
|
+
<span className="sg-merchant-location"> · {item.merchant.location.displayText}</span>
|
|
80
|
+
)}
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
{item.reasons && item.reasons.length > 0 && (
|
|
84
|
+
<div className="sg-reasons">
|
|
85
|
+
{item.reasons.map((r) => (
|
|
86
|
+
<span key={r.code} className="sg-reason-tag">{r.label}</span>
|
|
87
|
+
))}
|
|
88
|
+
</div>
|
|
89
|
+
)}
|
|
90
|
+
|
|
91
|
+
{item.caveats.length > 0 && (
|
|
92
|
+
<div className="sg-item-caveats">
|
|
93
|
+
{item.caveats.map((c, i) => (
|
|
94
|
+
<div key={i} className="sg-caveat-item">⚠️ {c}</div>
|
|
95
|
+
))}
|
|
96
|
+
</div>
|
|
97
|
+
)}
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
{item.availability.marketable && (
|
|
101
|
+
<div className="sg-product-sheet__actions">
|
|
102
|
+
<ItemActionsRow
|
|
103
|
+
actions={item.itemActions}
|
|
104
|
+
cardId={cardId}
|
|
105
|
+
isHistory={isHistory}
|
|
106
|
+
className="sg-product-sheet__action-row"
|
|
107
|
+
chipClassName="sg-product-sheet__chip"
|
|
108
|
+
/>
|
|
109
|
+
</div>
|
|
110
|
+
)}
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
</div>,
|
|
114
|
+
document.body,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function ProductListCard(props: {
|
|
119
|
+
data: ProductListCardData;
|
|
120
|
+
cardId: string;
|
|
121
|
+
isHistory: boolean;
|
|
122
|
+
}) {
|
|
123
|
+
const { data, cardId, isHistory } = props;
|
|
124
|
+
const [activeItem, setActiveItem] = useState<ProductItem | null>(null);
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<section className="sg-card sg-product-list">
|
|
128
|
+
{data.summary && <div className="sg-card-summary">{data.summary}</div>}
|
|
129
|
+
|
|
130
|
+
{data.items.length === 0 ? (
|
|
131
|
+
<div className="sg-empty">{data.noResultsReason ?? '暂无相关商品'}</div>
|
|
132
|
+
) : (
|
|
133
|
+
<ul className="sg-product-list-items">
|
|
134
|
+
{data.items.map((item) => (
|
|
135
|
+
<li
|
|
136
|
+
key={item.productId}
|
|
137
|
+
className="sg-product-item sg-product-item--clickable"
|
|
138
|
+
onClick={() => setActiveItem(item)}
|
|
139
|
+
role="button"
|
|
140
|
+
tabIndex={0}
|
|
141
|
+
onKeyDown={(e) => e.key === 'Enter' && setActiveItem(item)}
|
|
142
|
+
>
|
|
143
|
+
<ImageWithFallback
|
|
144
|
+
src={item.imageUrl}
|
|
145
|
+
alt={item.name}
|
|
146
|
+
className="sg-product-image"
|
|
147
|
+
size={44}
|
|
148
|
+
/>
|
|
149
|
+
<div className="sg-product-info">
|
|
150
|
+
{item.badges.length > 0 && (
|
|
151
|
+
<div className="sg-badges">
|
|
152
|
+
{item.badges.map((b) => (
|
|
153
|
+
<span key={b} className="sg-badge">{b}</span>
|
|
154
|
+
))}
|
|
155
|
+
</div>
|
|
156
|
+
)}
|
|
157
|
+
<div className="sg-product-name">{item.name}</div>
|
|
158
|
+
{item.brand && <div className="sg-product-brand">{item.brand}</div>}
|
|
159
|
+
<div className="sg-price-block">
|
|
160
|
+
{item.price.sale && (
|
|
161
|
+
<span className="sg-price-sale">{item.price.sale.display}</span>
|
|
162
|
+
)}
|
|
163
|
+
{item.price.original && item.price.sale && (
|
|
164
|
+
<span className="sg-price-original">{item.price.original.display}</span>
|
|
165
|
+
)}
|
|
166
|
+
{item.price.promotion && (
|
|
167
|
+
<span className="sg-price-promotion">{item.price.promotion.display}</span>
|
|
168
|
+
)}
|
|
169
|
+
{!item.price.sale && !item.price.original && !item.price.promotion && (
|
|
170
|
+
<span className="sg-price-unavailable">价格暂无</span>
|
|
171
|
+
)}
|
|
172
|
+
</div>
|
|
173
|
+
<div className="sg-product-sheet__merchant">
|
|
174
|
+
<span>{item.merchant.name}</span>
|
|
175
|
+
{item.merchant.location?.displayText && (
|
|
176
|
+
<span className="sg-merchant-location"> · {item.merchant.location.displayText}</span>
|
|
177
|
+
)}
|
|
178
|
+
</div>
|
|
179
|
+
</div>
|
|
180
|
+
<div className="sg-product-item__arrow" aria-hidden="true">›</div>
|
|
181
|
+
</li>
|
|
182
|
+
))}
|
|
183
|
+
</ul>
|
|
184
|
+
)}
|
|
185
|
+
|
|
186
|
+
{data.pageInfo?.hasMore && (
|
|
187
|
+
<div className="sg-page-info">
|
|
188
|
+
已展示 {data.items.length} / {data.pageInfo.total} 件商品
|
|
189
|
+
</div>
|
|
190
|
+
)}
|
|
191
|
+
|
|
192
|
+
{data.refinements.length > 0 && (
|
|
193
|
+
<div className="sg-refinements">
|
|
194
|
+
{data.refinements.map((r, i) => (
|
|
195
|
+
<button
|
|
196
|
+
key={i}
|
|
197
|
+
type="button"
|
|
198
|
+
className="sg-refinement-chip"
|
|
199
|
+
disabled={isHistory}
|
|
200
|
+
onClick={() => {
|
|
201
|
+
if (isHistory) return;
|
|
202
|
+
sendCardAction(cardId, { type: 'sendMessage', value: r.queryText || r.label, visible: true });
|
|
203
|
+
}}
|
|
204
|
+
>
|
|
205
|
+
{r.label}
|
|
206
|
+
</button>
|
|
207
|
+
))}
|
|
208
|
+
</div>
|
|
209
|
+
)}
|
|
210
|
+
|
|
211
|
+
{activeItem && (
|
|
212
|
+
<ProductDetailSheet
|
|
213
|
+
item={activeItem}
|
|
214
|
+
cardId={cardId}
|
|
215
|
+
isHistory={isHistory}
|
|
216
|
+
onClose={() => setActiveItem(null)}
|
|
217
|
+
/>
|
|
218
|
+
)}
|
|
219
|
+
</section>
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export default ProductListCard;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* recommend-merchants 富卡:深色门店导览头 + 单行横滑品类筛选 + 三家门店预览。
|
|
3
|
+
* 完整列表和单店详情分别进入半屏浮层,避免聊天流被长列表撑高。
|
|
4
|
+
*/
|
|
5
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
6
|
+
import { CaretRight } from '@phosphor-icons/react';
|
|
7
|
+
import { ShopDetailSheet } from '../../components/ShopDetailSheet';
|
|
8
|
+
import { MerchantRow } from '../../components/MerchantRow';
|
|
9
|
+
import { resolveCategoryTabs } from '../../categories';
|
|
10
|
+
import { ShopGuideHeader } from '../../components/ShopGuideHeader';
|
|
11
|
+
import { ShopGuideSectionLabel } from '../../components/ShopGuideSectionLabel';
|
|
12
|
+
import { ShopListSheet } from '../../components/ShopListSheet';
|
|
13
|
+
import type { RecommendMerchantsCardData } from '@tbox.cn/app-contracts-mall';
|
|
14
|
+
|
|
15
|
+
const PREVIEW_ITEM_COUNT = 3;
|
|
16
|
+
type Merchant = RecommendMerchantsCardData['items'][number];
|
|
17
|
+
type OverlayState =
|
|
18
|
+
| { readonly kind: 'closed' }
|
|
19
|
+
| { readonly kind: 'list' }
|
|
20
|
+
| { readonly kind: 'detail'; readonly merchant: Merchant };
|
|
21
|
+
|
|
22
|
+
export function RecommendMerchantsCard(props: {
|
|
23
|
+
data: RecommendMerchantsCardData;
|
|
24
|
+
cardId: string;
|
|
25
|
+
isHistory: boolean;
|
|
26
|
+
}) {
|
|
27
|
+
const { data, cardId, isHistory } = props;
|
|
28
|
+
const [activeTabCode, setActiveTabCode] = useState<string>('');
|
|
29
|
+
const [overlay, setOverlay] = useState<OverlayState>({ kind: 'closed' });
|
|
30
|
+
// 与半屏同源:契约的 categoryTabs 打底 + 门店实际业态补充,两处因此看到同一份品类。
|
|
31
|
+
const visibleTabs = useMemo(() => resolveCategoryTabs(data.categoryTabs, data.items), [data.categoryTabs, data.items]);
|
|
32
|
+
|
|
33
|
+
function getFilteredItems() {
|
|
34
|
+
if (!activeTabCode) return data.items;
|
|
35
|
+
const activeTab = visibleTabs.find((tab) => tab.code === activeTabCode);
|
|
36
|
+
if (!activeTab) return data.items;
|
|
37
|
+
return data.items.filter((item) => item.businessCategories.includes(activeTab.name));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const filteredItems = getFilteredItems();
|
|
41
|
+
const previewItems = filteredItems.slice(0, PREVIEW_ITEM_COUNT);
|
|
42
|
+
const selectedMerchant = overlay.kind === 'detail' ? overlay.merchant : null;
|
|
43
|
+
const detailData = useMemo(() => selectedMerchant
|
|
44
|
+
? {
|
|
45
|
+
name: selectedMerchant.name,
|
|
46
|
+
logoUrl: selectedMerchant.logoUrl,
|
|
47
|
+
coverUrl: selectedMerchant.coverUrl,
|
|
48
|
+
brand: selectedMerchant.brand,
|
|
49
|
+
businessCategories: selectedMerchant.businessCategories,
|
|
50
|
+
location: selectedMerchant.location,
|
|
51
|
+
status: selectedMerchant.status,
|
|
52
|
+
rating: selectedMerchant.rating,
|
|
53
|
+
avgSpend: selectedMerchant.avgSpend,
|
|
54
|
+
operatingStatus: selectedMerchant.operatingStatus,
|
|
55
|
+
description: selectedMerchant.description,
|
|
56
|
+
contactInfo: selectedMerchant.contactInfo,
|
|
57
|
+
services: selectedMerchant.services,
|
|
58
|
+
itemActions: selectedMerchant.itemActions,
|
|
59
|
+
}
|
|
60
|
+
: null, [selectedMerchant]);
|
|
61
|
+
const closeOverlay = useCallback(() => setOverlay({ kind: 'closed' }), []);
|
|
62
|
+
const openDetail = useCallback((merchant: Merchant) => {
|
|
63
|
+
setOverlay({ kind: 'detail', merchant });
|
|
64
|
+
}, []);
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<>
|
|
68
|
+
<section className="sg-card sg-recommend-merchants">
|
|
69
|
+
<ShopGuideHeader subtitle={data.summary ?? '按品类发现值得逛的门店'} />
|
|
70
|
+
|
|
71
|
+
{visibleTabs.length > 0 && (
|
|
72
|
+
<div className="sg-rm-tabs" aria-label="按门店品类筛选">
|
|
73
|
+
{/* 「全部」承载「未筛选」这个本就存在的状态——此前它只能靠再点一次已选中的 tab
|
|
74
|
+
回到,而 tab 形态下「点选中项取消」并不直观。与浮层的分类导航同一套语义。 */}
|
|
75
|
+
<button
|
|
76
|
+
type="button"
|
|
77
|
+
aria-pressed={!activeTabCode}
|
|
78
|
+
className={`sg-rm-tab${!activeTabCode ? ' sg-rm-tab--active' : ''}`}
|
|
79
|
+
onClick={() => setActiveTabCode('')}
|
|
80
|
+
>
|
|
81
|
+
<span>全部</span>
|
|
82
|
+
</button>
|
|
83
|
+
{visibleTabs.map((tab) => {
|
|
84
|
+
const isActive = tab.code === activeTabCode;
|
|
85
|
+
return (
|
|
86
|
+
<button
|
|
87
|
+
key={tab.code}
|
|
88
|
+
type="button"
|
|
89
|
+
aria-pressed={isActive}
|
|
90
|
+
className={`sg-rm-tab${isActive ? ' sg-rm-tab--active' : ''}`}
|
|
91
|
+
onClick={() => setActiveTabCode(tab.code)}
|
|
92
|
+
>
|
|
93
|
+
<span>{tab.name}</span>
|
|
94
|
+
</button>
|
|
95
|
+
);
|
|
96
|
+
})}
|
|
97
|
+
</div>
|
|
98
|
+
)}
|
|
99
|
+
|
|
100
|
+
{filteredItems.length === 0 ? (
|
|
101
|
+
<div className="sg-empty">{data.noResultsReason ?? '暂时没有符合条件的门店'}</div>
|
|
102
|
+
) : (
|
|
103
|
+
<>
|
|
104
|
+
<ShopGuideSectionLabel />
|
|
105
|
+
<ul className="sg-rm-list">
|
|
106
|
+
{previewItems.map((item) => (
|
|
107
|
+
<li key={item.merchantId} className="sg-rm-item">
|
|
108
|
+
<MerchantRow merchant={item} onSelect={() => openDetail(item)} />
|
|
109
|
+
</li>
|
|
110
|
+
))}
|
|
111
|
+
</ul>
|
|
112
|
+
{filteredItems.length > PREVIEW_ITEM_COUNT && (
|
|
113
|
+
<button
|
|
114
|
+
type="button"
|
|
115
|
+
className="sg-rm-view-all"
|
|
116
|
+
onClick={() => setOverlay({ kind: 'list' })}
|
|
117
|
+
>
|
|
118
|
+
查看全部门店
|
|
119
|
+
<CaretRight size={17} />
|
|
120
|
+
</button>
|
|
121
|
+
)}
|
|
122
|
+
</>
|
|
123
|
+
)}
|
|
124
|
+
</section>
|
|
125
|
+
|
|
126
|
+
<ShopListSheet
|
|
127
|
+
open={overlay.kind === 'list'}
|
|
128
|
+
items={data.items}
|
|
129
|
+
categoryTabs={data.categoryTabs ?? []}
|
|
130
|
+
activeTabCode={activeTabCode}
|
|
131
|
+
isHistory={isHistory}
|
|
132
|
+
onSelect={openDetail}
|
|
133
|
+
onClose={closeOverlay}
|
|
134
|
+
/>
|
|
135
|
+
|
|
136
|
+
<ShopDetailSheet
|
|
137
|
+
open={overlay.kind === 'detail'}
|
|
138
|
+
data={detailData}
|
|
139
|
+
cardId={cardId}
|
|
140
|
+
isHistory={isHistory}
|
|
141
|
+
onClose={closeOverlay}
|
|
142
|
+
/>
|
|
143
|
+
</>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export default RecommendMerchantsCard;
|