merge(supplier): add high-cost category detail toggle

This commit is contained in:
WuYongJie 2026-11-24 13:13:36 +08:00
commit 6d291da416
3 changed files with 95 additions and 3 deletions

View File

@ -106,4 +106,55 @@ describe('SupplierManagementClient supply assurance', () => {
expect(await screen.findByRole('button', { name: '能力画像' })).toBeInTheDocument()
expect(screen.queryByRole('button', { name: '风险清单' })).not.toBeInTheDocument()
})
it('collapses and expands the high-cost category details', async () => {
global.fetch = jest.fn().mockResolvedValue({
ok: true,
json: async () => ({
success: true,
data: [{
supplierName: '高成本供应商',
supplierCode: 'SUP-HIGH',
grade: 'D',
gradeLabel: '成本显著偏高',
deviationRate: 0.2,
coverageRate: 1,
productCount: 5,
validPriceCount: 5,
categories: [{
category: '板式 / 书桌',
productCount: 5,
validPriceCount: 5,
supplierMedianPrice: 120,
categoryBenchmarkPrice: 100,
deviationRate: 0.2,
grade: 'D',
}],
}],
}),
}) as Response
const store = createLegacySupplierStore()
store.capabilities = [capability('SUP-HIGH', '高成本供应商', '开料')]
render(
<SupplierManagementClient
initialStore={store}
mode="evaluation"
canEdit={false}
canDownload={false}
/>,
)
fireEvent.click(screen.getByRole('button', { name: '采购成本评估' }))
await waitFor(() => expect(screen.getByRole('button', { name: '收合明细' })).toBeInTheDocument())
expect(document.getElementById('high-cost-category-details')).toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: '收合明细' }))
expect(screen.getByRole('button', { name: '展开明细' })).toHaveAttribute('aria-expanded', 'false')
expect(document.getElementById('high-cost-category-details')).not.toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: '展开明细' }))
expect(screen.getByRole('button', { name: '收合明细' })).toHaveAttribute('aria-expanded', 'true')
expect(document.getElementById('high-cost-category-details')).toBeInTheDocument()
})
})

View File

@ -2,7 +2,7 @@
import { useEffect, useMemo, useRef, useState } from 'react'
import Link from 'next/link'
import { Download, FileUp, Search } from 'lucide-react'
import { ChevronDown, ChevronUp, Download, FileUp, Search } from 'lucide-react'
import type {
LegacySupplierCapabilityRecord,
LegacySupplierEquipmentRecord,
@ -209,6 +209,7 @@ export function SupplierManagementClient({
const [costAssessments, setCostAssessments] = useState<SupplierCostAssessment[]>([])
const [costLoading, setCostLoading] = useState(true)
const [costError, setCostError] = useState('')
const [highCostExpanded, setHighCostExpanded] = useState(true)
const [analysisTab, setAnalysisTab] = useState<AnalysisTab>('capability')
const [query, setQuery] = useState('')
const [category, setCategory] = useState('all')
@ -509,8 +510,30 @@ export function SupplierManagementClient({
<DistributionTable rows={costDistribution} />
</section>
<section className={styles.panel}>
<div className={styles.panelHeader}><div><h2>高成本材质 / 类目</h2><p>优先复核采购价高于同材质、同二级类目基准的产品</p></div><span className={`${styles.status} ${highCostCategories.length ? styles.orange : styles.green}`}>{highCostCategories.length} 项</span></div>
<div className={styles.tableWrap}><table className={styles.table}><thead><tr><th>供应商</th><th>材质 / 二级类目</th><th>采购价中位</th><th>同业基准</th><th>偏差</th><th>等级</th></tr></thead><tbody>{highCostCategories.slice(0, 50).map(({ profile, category }) => <tr key={`${profile.key}-${category.category}`}><td className={styles.primaryCell}>{profile.supplier}</td><td>{category.category}</td><td>{category.supplierMedianPrice?.toFixed(2) || '—'}</td><td>{category.categoryBenchmarkPrice?.toFixed(2) || '—'}</td><td>{costDeviation(category.deviationRate)}</td><td><span className={`${styles.status} ${costGradeClass(category.grade)}`}>{category.grade}</span></td></tr>)}</tbody></table></div>
<div className={styles.panelHeader}>
<div><h2>高成本材质 / 类目</h2><p>优先复核采购价高于同材质、同二级类目基准的产品</p></div>
<div className={styles.panelHeaderActions}>
<span className={`${styles.status} ${highCostCategories.length ? styles.orange : styles.green}`}>{highCostCategories.length} 项</span>
<button
className={styles.compactButton}
type="button"
aria-controls="high-cost-category-details"
aria-expanded={highCostExpanded}
onClick={() => setHighCostExpanded((expanded) => !expanded)}
>
{highCostExpanded ? <ChevronUp size={13} /> : <ChevronDown size={13} />}
{highCostExpanded ? '收合明细' : '展开明细'}
</button>
</div>
</div>
{highCostExpanded ? (
<div className={styles.tableWrap} id="high-cost-category-details">
<table className={styles.table}>
<thead><tr><th>供应商</th><th>材质 / 二级类目</th><th>采购价中位</th><th>同业基准</th><th>偏差</th><th>等级</th></tr></thead>
<tbody>{highCostCategories.slice(0, 50).map(({ profile, category }) => <tr key={`${profile.key}-${category.category}`}><td className={styles.primaryCell}>{profile.supplier}</td><td>{category.category}</td><td>{category.supplierMedianPrice?.toFixed(2) || '—'}</td><td>{category.categoryBenchmarkPrice?.toFixed(2) || '—'}</td><td>{costDeviation(category.deviationRate)}</td><td><span className={`${styles.status} ${costGradeClass(category.grade)}`}>{category.grade}</span></td></tr>)}</tbody>
</table>
</div>
) : null}
</section>
</div>
<section className={styles.panel}>

View File

@ -137,6 +137,24 @@
.panelHeader h2 { margin: 0; color: #27272a; font-size: 13px; }
.panelHeader p { margin: 4px 0 0; color: #8b8b92; font-size: 10px; }
.panelHeaderActions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.compactButton {
display: inline-flex;
height: 28px;
align-items: center;
justify-content: center;
gap: 5px;
border: 1px solid #d4d4d8;
border-radius: 6px;
background: #fff;
padding: 0 9px;
color: #3f3f46;
font: inherit;
font-size: 11px;
font-weight: 600;
cursor: pointer;
}
.compactButton:hover { border-color: #a1a1aa; background: #fafafa; }
.toolbar {
border-bottom: 1px solid #e4e4e7;