Files
tap/components/demand/review.tsx
T

83 lines
9.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use client';
import { useState } from 'react';
import { CheckCircle2, CircleAlert, Send } from 'lucide-react';
import type { Demand } from '@/lib/demand';
import { currentProposal, reviewStage, type ReviewProposal } from '@/lib/demand-review';
import { pendingChange } from '@/lib/workflow';
import { AttachmentList } from './attachments';
import type { SaveInput } from './form';
const date = (value: string) => new Date(value).toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai', hour12: false });
function ProposalContent({ proposal }: { proposal: ReviewProposal }) {
return <>
<div className="detail-field"><span>实施范围与功能说明</span><p>{proposal.scope}</p></div>
<div className="detail-field"><span>范围外事项</span><p>{proposal.outOfScope}</p></div>
{(proposal.businessAttachments?.length??0)>0&&<div className="detail-field"><span>此方案评审时的附件</span><AttachmentList files={proposal.businessAttachments!}/></div>}
<p className="review-meta">由 {proposal.developer.displayName}({proposal.developer.username})提交 · {date(proposal.submittedAt)}</p>
{proposal.decision && <p className="review-meta">{proposal.decision.actor.displayName}({proposal.decision.actor.username})于 {date(proposal.decision.time)} {proposal.decision.result === 'confirmed' ? '确认同意实施' : '退回修改'}{proposal.decision.comment ? `:${proposal.decision.comment}` : ''}</p>}
{proposal.invalidated && <p className="review-invalid">此版本已失效:{proposal.invalidated.reason}({date(proposal.invalidated.time)})</p>}
</>;
}
export function DemandReviewPanel({ d, onAction, busy, onDirtyChange }: { d: Demand; onAction: (body: SaveInput) => Promise<void>; busy: boolean; onDirtyChange: (dirty: boolean) => void }) {
const proposal = currentProposal(d);
const stage = reviewStage(d);
const business = d.access?.business ?? true;
const ready = d.status === '待评审' && d.reviewReady;
const canPropose = ready && d.access?.developer && ['待开发提出方案', '待开发修改方案'].includes(stage);
const canDecide = ready && business && proposal && !proposal.invalidated && !proposal.decision;
const canReopen = ready && business && proposal && !proposal.invalidated && proposal.decision?.result === 'confirmed';
const [scope, setScope] = useState(proposal?.scope ?? d.fields.scope);
const [outOfScope, setOutOfScope] = useState(proposal?.outOfScope ?? d.fields.outOfScope);
const [comment, setComment] = useState('');
const [confirm, setConfirm] = useState(false);
const [takeoverConfirmed, setTakeoverConfirmed] = useState(false);
const [error, setError] = useState('');
function dirty() { onDirtyChange(true); setError(''); }
async function act(action: string) {
setError('');
if (action === 'propose-solution' && (!scope.trim() || !outOfScope.trim())) { setError('请填写实施范围与功能说明、范围外事项;无范围外事项请填“无”。'); return; }
if (action === 'confirm-solution' && !confirm) { setError('请勾选确认同意按当前方案实施。'); return; }
if (action === 'return-solution' && !comment.trim()) { setError('请填写具体的修改意见。'); return; }
if (action === 'take-over-development' && !takeoverConfirmed) { setError('请确认接手后的评审和排期安排。'); return; }
try { await onAction({ action, id: d.id, revision: d.revision, scope, outOfScope, proposalVersion: proposal?.version, confirm: action === 'take-over-development' ? takeoverConfirmed : confirm, comment }); } catch { /* The parent preserves input and displays the API error. */ }
}
return <section className="review-panel">
<div className="review-heading"><h2>需求评审</h2><span className={'status ' + (stage === '方案已确认' ? 'green' : 'neutral')}>{stage}</span></div>
<p className="review-intro">开发责任人提出实施范围与功能说明、范围外事项,业务方核对后确认。每次提交保留独立方案版本。</p>
{error && <div className="error-banner" role="alert"><CircleAlert size={17}/>{error}</div>}
{!d.reviewReady && <p className="info-banner">请先补齐业务材料并提交评审,开发负责人默认由系统管理员担任,无需填写。</p>}
<div className="review-assignment">
<div className="detail-field"><span>开发负责人</span><p>{d.review ? `${d.review.developer.displayName}(${d.review.developer.username})` : '系统管理员'}</p></div>
<p className="review-meta">开发负责人默认由系统管理员担任,无需填写。业务确认由需求登记账号操作;开发负责人负责方案、排期、开发提测、发布与归档。</p>
{d.access?.canTakeOverDevelopment && <fieldset className="review-assignment-form" disabled={busy}>
<p className="info-banner">原开发账号已停用或不可用,你可以使用当前管理员账号接手。接手后回到待评审,重新确认方案和排期,再提测验收;历史记录保留。</p>
{pendingChange(d) ? <p className="review-meta">请先由业务方在“需求变更”中处理或撤回待确认变更,再接手开发职责。</p> : <>
<label className="check-field"><input type="checkbox" checked={takeoverConfirmed} onChange={e => { setTakeoverConfirmed(e.target.checked); dirty(); }}/><span>我确认接手开发职责,并重新进行评审和排期。</span></label>
<button className="btn primary" onClick={() => void act('take-over-development')}>{busy ? '正在接手…' : '接手开发职责'}</button>
</>}
</fieldset>}
</div>
{(d.attachments?.length??0)>0&&<section className="review-proposal"><h3>当前参考附件</h3><AttachmentList files={d.attachments!}/></section>}
{proposal ? <section className="review-proposal"><h3>方案 v{proposal.version}</h3><ProposalContent proposal={proposal}/></section> : (d.fields.scope || d.fields.outOfScope) ? <section className="review-proposal"><h3>原有方案内容</h3><p className="review-meta">历史内容已保留,尚无本次评审确认记录。开发责任人可据此提交正式方案。</p><div className="detail-field"><span>实施范围与功能说明</span><p>{d.fields.scope || '待补充'}</p></div><div className="detail-field"><span>范围外事项</span><p>{d.fields.outOfScope || '待补充'}</p></div></section> : d.review && !canPropose ? <p className="review-intro">等待 {d.review.developer.displayName} 提交方案,提交后业务方可在此确认或退回修改。</p> : null}
{canPropose && <fieldset className="review-editor" disabled={busy}>
<h3>{proposal ? '修改并提交新版本' : '填写评审方案'}</h3>
<label className="form-field"><span>实施范围与功能说明<em>*</em></span><textarea rows={6} maxLength={6000} value={scope} onChange={e => { setScope(e.target.value); dirty(); }} placeholder="F-01:本次支持的功能、操作步骤与业务规则。"/></label>
<label className="form-field"><span>范围外事项<em>*</em></span><textarea rows={3} maxLength={3000} value={outOfScope} onChange={e => { setOutOfScope(e.target.value); dirty(); }} placeholder="明确本次不纳入的内容,无则填“无”。"/></label>
<p className="review-meta">将生成方案 v{(proposal?.version ?? 0) + 1},提交后等待业务方确认。</p>
<button className="btn primary" onClick={() => void act('propose-solution')}><Send size={16}/>{busy ? '提交中…' : '提交方案供业务确认'}</button>
</fieldset>}
{(canDecide || canReopen) && <fieldset className="review-decision" disabled={busy}>
<h3>{canReopen ? '需要调整已确认方案?' : `确认方案 v${proposal!.version}`}</h3>
<label className="form-field"><span>修改意见/确认备注</span><textarea rows={3} maxLength={3000} value={comment} onChange={e => { setComment(e.target.value); dirty(); }} placeholder="退回修改时必填;同意实施时可补充备注。"/></label>
{canDecide && <label className="check-field"><input type="checkbox" checked={confirm} onChange={e => { setConfirm(e.target.checked); dirty(); }}/><span>我已核对方案 v{proposal!.version} 的实施范围、功能说明与范围外事项,同意按此版本实施。</span></label>}
<div className="review-actions"><button className="btn" onClick={() => void act('return-solution')}>{canReopen ? '要求调整方案' : '退回修改'}</button>{canDecide && <button className="btn primary" onClick={() => void act('confirm-solution')}><CheckCircle2 size={16}/>{busy ? '提交中…' : '确认方案'}</button>}</div>
</fieldset>}
{(d.review?.proposals.length ?? 0) > 1 && <details className="review-history"><summary>历史方案({d.review!.proposals.length - 1})</summary>{d.review!.proposals.slice(0, -1).reverse().map(item => <section className="review-proposal" key={item.version}><h3>方案 v{item.version}</h3><ProposalContent proposal={item}/><details className="review-business-snapshot"><summary>当时的业务需求</summary><div className="detail-field"><span>业务背景</span><p>{item.businessFields.background}</p></div><div className="detail-field"><span>预期目标</span><p>{item.businessFields.goal}</p></div><div className="detail-field"><span>验收标准 · 文档 {item.businessFields.version}</span><p>{item.businessFields.criteria}</p></div></details></section>)}</details>}
</section>;
}