const STATUS_META = {
|
1: { text: '正常', type: 'success', bool: true },
|
0: { text: '冻结', type: 'danger', bool: false }
|
}
|
|
export const COMPANYS_REPORT_TITLE = '往来企业报表'
|
export const COMPANYS_REPORT_STYLE = {
|
titleAlign: 'center',
|
titleLevel: 'strong',
|
orientation: 'landscape',
|
density: 'compact',
|
showSequence: true
|
}
|
|
function normalizeText(value) {
|
return String(value ?? '').trim()
|
}
|
|
function normalizeString(value, fallback = '') {
|
const text = normalizeText(value)
|
return text || fallback
|
}
|
|
export function createCompanysSearchState() {
|
return {
|
condition: '',
|
code: '',
|
name: '',
|
nameEn: '',
|
breifCode: '',
|
type: '',
|
contact: '',
|
tel: '',
|
email: '',
|
pcode: '',
|
province: '',
|
city: '',
|
address: '',
|
status: '',
|
memo: ''
|
}
|
}
|
|
export function createCompanysFormState() {
|
return {
|
id: void 0,
|
code: '',
|
name: '',
|
nameEn: '',
|
breifCode: '',
|
type: '',
|
contact: '',
|
tel: '',
|
email: '',
|
pcode: '',
|
province: '',
|
city: '',
|
address: '',
|
status: 1,
|
memo: ''
|
}
|
}
|
|
export function getCompanysStatusOptions() {
|
return [
|
{ label: '正常', value: 1 },
|
{ label: '冻结', value: 0 }
|
]
|
}
|
|
export function getCompanysPaginationKey() {
|
return {
|
current: 'current',
|
size: 'pageSize'
|
}
|
}
|
|
export function getCompanysStatusMeta(status) {
|
if (status === true || Number(status) === 1) {
|
return STATUS_META[1]
|
}
|
if (status === false || Number(status) === 0) {
|
return STATUS_META[0]
|
}
|
return { text: '未知', type: 'info', bool: false }
|
}
|
|
export function buildCompanysTypeOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
|
return records
|
.map((item) => {
|
if (!item || typeof item !== 'object') {
|
return null
|
}
|
const value = item.value ?? item.id ?? item.dictValue
|
if (value === void 0 || value === null || value === '') {
|
return null
|
}
|
return {
|
value: String(value),
|
label: normalizeText(item.label || item.name || item.dictLabel || item.value || '')
|
}
|
})
|
.filter(Boolean)
|
}
|
|
export function buildCompanysSearchParams(params = {}) {
|
const searchParams = {
|
condition: normalizeText(params.condition),
|
code: normalizeText(params.code),
|
name: normalizeText(params.name),
|
nameEn: normalizeText(params.nameEn),
|
breifCode: normalizeText(params.breifCode),
|
type: normalizeText(params.type),
|
contact: normalizeText(params.contact),
|
tel: normalizeText(params.tel),
|
email: normalizeText(params.email),
|
pcode: normalizeText(params.pcode),
|
province: normalizeText(params.province),
|
city: normalizeText(params.city),
|
address: normalizeText(params.address),
|
status:
|
params.status !== undefined && params.status !== null && params.status !== ''
|
? Number(params.status)
|
: void 0,
|
memo: normalizeText(params.memo)
|
}
|
|
return Object.fromEntries(
|
Object.entries(searchParams).filter(([, value]) => value !== '' && value !== void 0 && value !== null)
|
)
|
}
|
|
export function buildCompanysPageQueryParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...buildCompanysSearchParams(params)
|
}
|
}
|
|
export function buildCompanysSavePayload(formData = {}) {
|
return {
|
...(formData.id !== void 0 && formData.id !== null && formData.id !== ''
|
? { id: Number(formData.id) }
|
: {}),
|
code: normalizeText(formData.code),
|
name: normalizeText(formData.name),
|
nameEn: normalizeText(formData.nameEn),
|
breifCode: normalizeText(formData.breifCode),
|
type: normalizeString(formData.type),
|
contact: normalizeText(formData.contact),
|
tel: normalizeText(formData.tel),
|
email: normalizeText(formData.email),
|
pcode: normalizeText(formData.pcode),
|
province: normalizeText(formData.province),
|
city: normalizeText(formData.city),
|
address: normalizeText(formData.address),
|
status:
|
formData.status !== void 0 && formData.status !== null && formData.status !== ''
|
? Number(formData.status)
|
: 1,
|
memo: normalizeText(formData.memo)
|
}
|
}
|
|
export function buildCompanysDialogModel(record = {}) {
|
return {
|
...createCompanysFormState(),
|
...(record.id !== void 0 && record.id !== null && record.id !== '' ? { id: Number(record.id) } : {}),
|
code: normalizeText(record.code || ''),
|
name: normalizeText(record.name || ''),
|
nameEn: normalizeText(record.nameEn || ''),
|
breifCode: normalizeText(record.breifCode || ''),
|
type: normalizeString(record.type || ''),
|
contact: normalizeText(record.contact || ''),
|
tel: normalizeText(record.tel || ''),
|
email: normalizeText(record.email || ''),
|
pcode: normalizeText(record.pcode || ''),
|
province: normalizeText(record.province || ''),
|
city: normalizeText(record.city || ''),
|
address: normalizeText(record.address || ''),
|
status: record.status !== void 0 && record.status !== null ? Number(record.status) : 1,
|
memo: normalizeText(record.memo || '')
|
}
|
}
|
|
export function normalizeCompanysDetailRecord(record = {}, resolveTypeLabel) {
|
const statusMeta = getCompanysStatusMeta(record.statusBool ?? record.status)
|
const typeValue = record.type ?? ''
|
const typeText =
|
normalizeString(record.companys$ || record.type$ || record.typeText || '') ||
|
normalizeString(typeof resolveTypeLabel === 'function' ? resolveTypeLabel(typeValue) : '') ||
|
normalizeString(typeValue, '--')
|
|
return {
|
...record,
|
code: normalizeText(record.code || ''),
|
name: normalizeText(record.name || ''),
|
nameEn: normalizeText(record.nameEn || ''),
|
breifCode: normalizeText(record.breifCode || ''),
|
type: normalizeString(typeValue),
|
typeText,
|
contact: normalizeText(record.contact || ''),
|
tel: normalizeText(record.tel || ''),
|
email: normalizeText(record.email || ''),
|
pcode: normalizeText(record.pcode || ''),
|
province: normalizeText(record.province || ''),
|
city: normalizeText(record.city || ''),
|
address: normalizeText(record.address || ''),
|
memo: normalizeText(record.memo || ''),
|
statusText: statusMeta.text,
|
statusType: statusMeta.type,
|
statusBool: record.statusBool !== void 0 ? Boolean(record.statusBool) : statusMeta.bool,
|
createByText: normalizeText(record.createBy$ || record.createByText || ''),
|
createTimeText: normalizeText(record.createTime$ || record.createTime || ''),
|
updateByText: normalizeText(record.updateBy$ || record.updateByText || ''),
|
updateTimeText: normalizeText(record.updateTime$ || record.updateTime || '')
|
}
|
}
|
|
export function normalizeCompanysListRow(record = {}, resolveTypeLabel) {
|
return normalizeCompanysDetailRecord(record, resolveTypeLabel)
|
}
|
|
export function buildCompanysPrintRows(records = [], resolveTypeLabel) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((record) => normalizeCompanysListRow(record, resolveTypeLabel))
|
}
|
|
export function buildCompanysReportMeta({
|
previewMeta = {},
|
count = 0,
|
orientation = COMPANYS_REPORT_STYLE.orientation
|
} = {}) {
|
return {
|
reportTitle: COMPANYS_REPORT_TITLE,
|
reportDate: previewMeta.reportDate,
|
printedAt: previewMeta.printedAt,
|
operator: previewMeta.operator,
|
count,
|
reportStyle: {
|
...COMPANYS_REPORT_STYLE,
|
orientation
|
}
|
}
|
}
|