- 新增微信小程序胶囊区域避让布局逻辑 - 统一首页导航与标题对齐规则 - 更新多处演示提示文案为正式表述 - 调整个人中心账户状态显示 - 优化产品页分享按钮条件渲染
83 lines
6.0 KiB
Plaintext
83 lines
6.0 KiB
Plaintext
export type AssessmentForm = {
|
|
name: string, idCard: string, phone: string, city: string, maritalStatus: string,
|
|
occupation: string, company: string, monthlyIncome: string, socialSecurity: string,
|
|
housingFund: string, house: string, car: string, savings: string, creditCard: string,
|
|
otherAssets: string, enterpriseName: string, businessCode: string, annualRevenue: string, operatingYears: string
|
|
}
|
|
export type SelectedDocument = { name: string, path: string }
|
|
export type DataAuthorization = { key: string, name: string, selected: boolean }
|
|
|
|
export function emptyAssessmentForm(): AssessmentForm {
|
|
return { name: '', idCard: '', phone: '', city: '', maritalStatus: '', occupation: '', company: '', monthlyIncome: '', socialSecurity: '', housingFund: '', house: '', car: '', savings: '', creditCard: '', otherAssets: '', enterpriseName: '', businessCode: '', annualRevenue: '', operatingYears: '' }
|
|
}
|
|
export function draftText(saved: UTSJSONObject, key: string): string {
|
|
const value = saved[key]
|
|
return typeof value == 'string' ? value as string : ''
|
|
}
|
|
export function activeAssessmentType(): string {
|
|
const type = uni.getStorageSync('assessmentActiveType')
|
|
if (type == 'enterprise' || type == 'personal') return type as string
|
|
const legacy = uni.getStorageSync('assessmentDraft')
|
|
if (legacy != null && typeof legacy == 'object' && draftText(legacy as UTSJSONObject, 'type') == 'enterprise') return 'enterprise'
|
|
return 'personal'
|
|
}
|
|
export function loadAssessmentDraft(type: string): UTSJSONObject | null {
|
|
const scoped = uni.getStorageSync('assessmentDraft:' + type)
|
|
if (scoped != null && typeof scoped == 'object') return scoped as UTSJSONObject
|
|
const legacy = uni.getStorageSync('assessmentDraft')
|
|
if (legacy != null && typeof legacy == 'object') {
|
|
const saved = legacy as UTSJSONObject
|
|
if (draftText(saved, 'type') == type) return saved
|
|
}
|
|
return null
|
|
}
|
|
export function formFromDraft(saved: UTSJSONObject): AssessmentForm {
|
|
return {
|
|
name: draftText(saved, 'name'), idCard: draftText(saved, 'idCard'), phone: draftText(saved, 'phone'), city: draftText(saved, 'city'), maritalStatus: draftText(saved, 'maritalStatus'),
|
|
occupation: draftText(saved, 'occupation'), company: draftText(saved, 'company'), monthlyIncome: draftText(saved, 'monthlyIncome'), socialSecurity: draftText(saved, 'socialSecurity'), housingFund: draftText(saved, 'housingFund'),
|
|
house: draftText(saved, 'house'), car: draftText(saved, 'car'), savings: draftText(saved, 'savings'), creditCard: draftText(saved, 'creditCard'), otherAssets: draftText(saved, 'otherAssets'),
|
|
enterpriseName: draftText(saved, 'enterpriseName'), businessCode: draftText(saved, 'businessCode'), annualRevenue: draftText(saved, 'annualRevenue'), operatingYears: draftText(saved, 'operatingYears')
|
|
}
|
|
}
|
|
export function documentsFromDraft(saved: UTSJSONObject): SelectedDocument[] {
|
|
const results: SelectedDocument[] = []
|
|
const items = saved['documents'] as UTSJSONObject[] | null
|
|
if (items == null) return results
|
|
items.forEach((item) => {
|
|
const name = draftText(item, 'name'); const path = draftText(item, 'path')
|
|
if (name.length > 0 && path.length > 0) { const document: SelectedDocument = { name, path }; results.push(document) }
|
|
})
|
|
return results
|
|
}
|
|
export function saveAssessmentDraft(type: string, step: number, form: AssessmentForm, documents: SelectedDocument[], authorizations: DataAuthorization[], documentConsent: boolean, dataConsent: boolean): void {
|
|
const files: UTSJSONObject[] = documents.map((item): UTSJSONObject => ({ name: item.name, path: item.path }))
|
|
const grants: string[] = authorizations.filter((item) => item.selected).map((item) => item.key)
|
|
const payload: UTSJSONObject = {
|
|
type, step, name: form.name, idCard: form.idCard, phone: form.phone, city: form.city, maritalStatus: form.maritalStatus,
|
|
occupation: form.occupation, company: form.company, monthlyIncome: form.monthlyIncome, socialSecurity: form.socialSecurity, housingFund: form.housingFund,
|
|
house: form.house, car: form.car, savings: form.savings, creditCard: form.creditCard, otherAssets: form.otherAssets,
|
|
enterpriseName: form.enterpriseName, businessCode: form.businessCode, annualRevenue: form.annualRevenue, operatingYears: form.operatingYears,
|
|
documents: files, authorizations: grants, documentConsent, dataConsent
|
|
}
|
|
uni.setStorageSync('assessmentActiveType', type)
|
|
uni.setStorageSync('assessmentDraft:' + type, payload)
|
|
// 保留现有提交与档案入口读取的活动草稿。
|
|
uni.setStorageSync('assessmentDraft', payload)
|
|
}
|
|
export function showAgreementNotice(title: string): void {
|
|
uni.showModal({ title, content: '完整协议将在相关服务开放时提供。当前勾选仅保存您的选择,不会发起实名认证、查询外部数据或上传资料。', showCancel: false, confirmText: '我知道了' })
|
|
}
|
|
|
|
export type AssessmentProgress = { percent: number, basicDone: boolean, incomeDone: boolean, assetsDone: boolean, authorizationSelected: boolean }
|
|
export function assessmentProgress(type: string): AssessmentProgress {
|
|
const saved = loadAssessmentDraft(type)
|
|
if (saved == null) return { percent: 0, basicDone: false, incomeDone: false, assetsDone: false, authorizationSelected: false }
|
|
const basic = type == 'enterprise' ? ['enterpriseName', 'businessCode', 'name', 'phone', 'city'] : ['name', 'idCard', 'phone', 'city', 'maritalStatus']
|
|
const income = type == 'enterprise' ? ['occupation', 'operatingYears', 'annualRevenue'] : ['occupation', 'company', 'monthlyIncome', 'socialSecurity', 'housingFund']
|
|
const assets = ['house', 'car', 'savings', 'creditCard']
|
|
const keys = basic.concat(income).concat(assets)
|
|
const filled = keys.filter((key) => draftText(saved, key).trim().length > 0).length
|
|
const grants = saved['authorizations'] as string[] | null
|
|
return { percent: Math.round(filled / keys.length * 100), basicDone: basic.every((key) => draftText(saved, key).length > 0), incomeDone: income.every((key) => draftText(saved, key).length > 0), assetsDone: assets.every((key) => draftText(saved, key).length > 0), authorizationSelected: documentsFromDraft(saved).length > 0 || (grants != null && grants.length > 0) }
|
|
}
|