补齐证书齐备、证件折算、移动用证和合同绑定,并带上报销批量发放、付款备注以及个人开发流程升级,便于继续讨论已安排计划的调整规则。 Co-authored-by: Cursor <cursoragent@cursor.com>
69 lines
2.6 KiB
TypeScript
69 lines
2.6 KiB
TypeScript
import type { CertType, ScopeProduct } from '@/api/pl/quota-cert'
|
|
|
|
export type CertChoice = { id: string; status: string; certNo?: string; productNameOnCert?: string }
|
|
|
|
export function certChoiceState(item: CertChoice, kind: CertType, taken: Set<string>) {
|
|
if (item.status === 'void') return 'void' as const
|
|
if (item.status === 'closed') return 'closed' as const
|
|
if (taken.has(`${kind}:${item.id}`)) return 'taken' as const
|
|
return 'open' as const
|
|
}
|
|
|
|
export function certChoiceLabel(item: CertChoice, kind: CertType, taken: Set<string>) {
|
|
const name = [item.certNo, item.productNameOnCert].filter(Boolean).join(' · ') || '证号未提供'
|
|
const state = certChoiceState(item, kind, taken)
|
|
if (state === 'void') return `${name}(已作废)`
|
|
if (state === 'closed') return `${name}(已核销)`
|
|
if (state === 'taken') return `${name}(已关联)`
|
|
return name
|
|
}
|
|
|
|
export function scopeKey(products: ScopeProduct[]) {
|
|
return products
|
|
.map((product) => `${product.contractProductId}:${product.scopeStatus || 'active'}`)
|
|
.sort()
|
|
.join('\n')
|
|
}
|
|
|
|
export function canSaveNewLink(products: ScopeProduct[]) {
|
|
return products.some((product) => product.scopeStatus !== 'inactive')
|
|
}
|
|
|
|
export function canSaveProductEdit(before: ScopeProduct[], after: ScopeProduct[]) {
|
|
return scopeKey(before) !== scopeKey(after)
|
|
}
|
|
|
|
export function canRestoreProduct(certStatus: string | undefined, scopeStatus?: string | null) {
|
|
return !(scopeStatus === 'inactive' && (certStatus === 'void' || certStatus === 'closed'))
|
|
}
|
|
|
|
export function nextScopeStatus(scopeStatus?: string | null): 'active' | 'inactive' {
|
|
return scopeStatus === 'inactive' ? 'active' : 'inactive'
|
|
}
|
|
|
|
export function applyScopeStatus(
|
|
products: ScopeProduct[],
|
|
contractProductId: string,
|
|
scopeStatus: 'active' | 'inactive'
|
|
) {
|
|
return products.map((product) =>
|
|
product.contractProductId === contractProductId ? { ...product, scopeStatus } : product
|
|
)
|
|
}
|
|
|
|
export function addDraftProducts(current: ScopeProduct[], contractProductIds: string[]) {
|
|
const existing = new Set(current.map((product) => product.contractProductId))
|
|
const added = contractProductIds
|
|
.map((id) => id.trim())
|
|
.filter((id) => id && !existing.has(id))
|
|
.map((contractProductId) => ({ contractProductId, scopeStatus: 'active' as const }))
|
|
return [...current, ...added]
|
|
}
|
|
|
|
/** 已保存的产品行带 id,不能从集合里拿掉。 */
|
|
export function removeDraftProduct(products: ScopeProduct[], contractProductId: string) {
|
|
return products.filter(
|
|
(product) => Boolean(product.id) || product.contractProductId !== contractProductId
|
|
)
|
|
}
|