|
@@ -5,12 +5,15 @@ import { baseURL } from './http'
|
|
|
import { resJiLianFu } from './history'
|
|
|
import {
|
|
|
arrangeImages,
|
|
|
- calculateRowCharLines,
|
|
|
+ calcTablePages,
|
|
|
+ getExcelColumnLetter,
|
|
|
+ ITEMPLATE,
|
|
|
numberToChinese,
|
|
|
removeHtmlTags
|
|
|
} from './exportWordUtils'
|
|
|
import { myTableTransferSize } from '@/components/MyTable'
|
|
|
import dayjs from 'dayjs'
|
|
|
+import { D7CEHCK_COLLECTION_RESULT_OPTIONS } from '@/pages/D_storeManage/D7check/constants'
|
|
|
|
|
|
export enum EXPORT_WORD_ENUM {
|
|
|
/** 借用藏品点交凭证 */
|
|
@@ -27,7 +30,6 @@ export enum EXPORT_WORD_ENUM {
|
|
|
FORM_FOR_DIGITAL = 6,
|
|
|
/** 藏品档案 */
|
|
|
COLLECTION_ARCHIVES = 7,
|
|
|
-
|
|
|
/** 拟征集藏品清单 */
|
|
|
COLLECTION_LIST = 8,
|
|
|
/** 文物鉴定书 */
|
|
@@ -41,18 +43,64 @@ export enum EXPORT_WORD_ENUM {
|
|
|
/** 藏品移库 */
|
|
|
COLLECTION_RELOCATION = 13,
|
|
|
/** 藏品盘点记录单 */
|
|
|
- COLLECTION_INVENTORY = 14
|
|
|
-}
|
|
|
-
|
|
|
-export interface ITEMPLATE {
|
|
|
- fileName: string
|
|
|
- templateName?: string
|
|
|
- options?: Record<string, any>
|
|
|
- perLine?: Record<string, number>
|
|
|
- row?: Record<string, number>
|
|
|
+ COLLECTION_INVENTORY = 14,
|
|
|
+ /** 馆内人员进库申请单 */
|
|
|
+ INSIDER_FORM = 15,
|
|
|
+ /** 文物库房外来人员出入库审批表 */
|
|
|
+ OUTSIDER_FORM = 16,
|
|
|
+ /** 文物修复单 */
|
|
|
+ RELIC_REPAIR_LIST = 17,
|
|
|
+ /** 事故处理凭证 */
|
|
|
+ ACCIDENT_HANDLING_CERTIFICATE = 18,
|
|
|
+ /** 藏品现状登记 */
|
|
|
+ COLLECTION_CURRENT_STATUS = 19,
|
|
|
+ /** 馆内展览借用藏品登记台账 */
|
|
|
+ REGISTER_LEDGER = 20
|
|
|
}
|
|
|
|
|
|
export const EXPORT_TEMPLATE_MAP: Record<EXPORT_WORD_ENUM, ITEMPLATE> = {
|
|
|
+ [EXPORT_WORD_ENUM.COLLECTION_CURRENT_STATUS]: {
|
|
|
+ fileName: '藏品现状登记',
|
|
|
+ templateName: '16.docx'
|
|
|
+ },
|
|
|
+ [EXPORT_WORD_ENUM.ACCIDENT_HANDLING_CERTIFICATE]: {
|
|
|
+ fileName: '藏品事故处理凭证',
|
|
|
+ templateName: '15.docx'
|
|
|
+ },
|
|
|
+ [EXPORT_WORD_ENUM.RELIC_REPAIR_LIST]: {
|
|
|
+ fileName: '义乌市博物馆文物修复单',
|
|
|
+ templateName: '14.docx',
|
|
|
+ // 每个字段单行最大字符数
|
|
|
+ perLine: {
|
|
|
+ name: 9,
|
|
|
+ dictLevel: 24,
|
|
|
+ txt2: 4
|
|
|
+ },
|
|
|
+ row: {
|
|
|
+ // 首页最大行数
|
|
|
+ maxRowFirstPage: 3,
|
|
|
+ // 尾页最大行数
|
|
|
+ maxRowLastPage: 6,
|
|
|
+ // 每页最大行数
|
|
|
+ maxRowPage: 8,
|
|
|
+ // 首页单行最大字符行数
|
|
|
+ maxFirstCharLine: 20,
|
|
|
+ // 尾页单行最大字符行数
|
|
|
+ maxLastCharLine: 18,
|
|
|
+ // 每页最大字符行数
|
|
|
+ maxCharLine: 26,
|
|
|
+ // 表格每行最小字符行数
|
|
|
+ minRowCharLine: 3
|
|
|
+ }
|
|
|
+ },
|
|
|
+ [EXPORT_WORD_ENUM.OUTSIDER_FORM]: {
|
|
|
+ fileName: '文物库房外来人员出入库审批表',
|
|
|
+ templateName: '13.docx'
|
|
|
+ },
|
|
|
+ [EXPORT_WORD_ENUM.INSIDER_FORM]: {
|
|
|
+ fileName: '馆内人员进库申请单',
|
|
|
+ templateName: '12.docx'
|
|
|
+ },
|
|
|
[EXPORT_WORD_ENUM.COLLECTION_INVENTORY]: {
|
|
|
fileName: '义乌市博物馆分库藏品盘点记录单',
|
|
|
templateName: '11.docx'
|
|
@@ -93,6 +141,49 @@ export const EXPORT_TEMPLATE_MAP: Record<EXPORT_WORD_ENUM, ITEMPLATE> = {
|
|
|
columnWidths: [10, 10, 10, 15, 10, 15, 15, 12, 15, 15, 15]
|
|
|
}
|
|
|
},
|
|
|
+ [EXPORT_WORD_ENUM.REGISTER_LEDGER]: {
|
|
|
+ fileName: '义乌市博物馆馆内展览借用藏品登记台账',
|
|
|
+ options: {
|
|
|
+ sheetHeader: [
|
|
|
+ '序号',
|
|
|
+ '年度',
|
|
|
+ '借用部门',
|
|
|
+ '展览名称',
|
|
|
+ '借用文物 实际数量(合计)',
|
|
|
+ ['借用藏品基本情况', '藏品总登记号', '藏品名称'],
|
|
|
+ '出借时间',
|
|
|
+ ['出借经手人', '甲方', '乙方'],
|
|
|
+ '藏品提用审批单号',
|
|
|
+ '馆内提退凭证号',
|
|
|
+ '预计归还日期',
|
|
|
+ '归还时间',
|
|
|
+ ['归还经手人', '甲方', '乙方'],
|
|
|
+ '记录人',
|
|
|
+ '备注'
|
|
|
+ ],
|
|
|
+ sheetFilter: [
|
|
|
+ 'index',
|
|
|
+ 'year',
|
|
|
+ 'sonUnit',
|
|
|
+ 'typeName',
|
|
|
+ 'pcs',
|
|
|
+ 'num',
|
|
|
+ 'name',
|
|
|
+ 'lendDate',
|
|
|
+ 'lenderA',
|
|
|
+ 'lenderb',
|
|
|
+ 'sonNum',
|
|
|
+ 'sonNum2',
|
|
|
+ 'expectedReturnDate',
|
|
|
+ 'returnDate',
|
|
|
+ 'handlerA',
|
|
|
+ 'handlerB',
|
|
|
+ 'recorder',
|
|
|
+ 'remark'
|
|
|
+ ],
|
|
|
+ columnWidths: [5, 5, 12, 15, 12, 10, 15, 12, 10, 10, 15, 15, 15, 15, 10, 10, 10, 15]
|
|
|
+ }
|
|
|
+ },
|
|
|
[EXPORT_WORD_ENUM.CERTIFICATE]: {
|
|
|
fileName: '义乌市博物馆馆藏文物鉴定书',
|
|
|
options: {
|
|
@@ -221,68 +312,6 @@ export const EXPORT_TEMPLATE_MAP: Record<EXPORT_WORD_ENUM, ITEMPLATE> = {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 计算表格数据的分页情况
|
|
|
- */
|
|
|
-const calcTablePages = (rows: any[], config: Required<ITEMPLATE>) => {
|
|
|
- if (rows.length === 0) return 0
|
|
|
-
|
|
|
- let totalPages = 0
|
|
|
- let currentPageRows: any[] = []
|
|
|
- let currentPageCharLines = 0
|
|
|
- let isFirstPage = true
|
|
|
- let isLastPage = false
|
|
|
-
|
|
|
- for (let i = 0; i < rows.length; i++) {
|
|
|
- const row = rows[i]
|
|
|
- const rowCharLines = calculateRowCharLines(row, config.perLine)
|
|
|
-
|
|
|
- currentPageCharLines += Math.max(rowCharLines, config.row.minRowCharLine)
|
|
|
- currentPageRows.push(row)
|
|
|
-
|
|
|
- // 判断是否超出首页
|
|
|
- if (isFirstPage && currentPageCharLines > config.row.maxFirstCharLine) {
|
|
|
- isFirstPage = false
|
|
|
- totalPages++
|
|
|
- currentPageCharLines -= config.row.maxFirstCharLine
|
|
|
-
|
|
|
- // 如果剩下行数还超出尾页最大行数,也先预处理
|
|
|
- if (currentPageCharLines > config.row.maxLastCharLine) {
|
|
|
- totalPages++
|
|
|
- currentPageCharLines -= config.row.maxLastCharLine
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 确定当前页的限制
|
|
|
- const maxRows = isFirstPage
|
|
|
- ? config.row.maxRowFirstPage
|
|
|
- : isLastPage
|
|
|
- ? config.row.maxRowLastPage
|
|
|
- : config.row.maxRowPage
|
|
|
-
|
|
|
- const maxCharLines = isFirstPage
|
|
|
- ? config.row.maxFirstCharLine
|
|
|
- : isLastPage
|
|
|
- ? config.row.maxLastCharLine
|
|
|
- : config.row.maxCharLine
|
|
|
-
|
|
|
- // 检查是否换页
|
|
|
- const isPageFull = currentPageRows.length >= maxRows || currentPageCharLines >= maxCharLines
|
|
|
-
|
|
|
- if (isPageFull || i === rows.length - 1) {
|
|
|
- totalPages +=
|
|
|
- Math.floor(currentPageCharLines / maxCharLines) +
|
|
|
- (currentPageCharLines % maxCharLines > 0 ? 1 : 0)
|
|
|
- currentPageRows = []
|
|
|
- currentPageCharLines = 0
|
|
|
- isFirstPage = false
|
|
|
- isLastPage = i === rows.length - 1
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return totalPages
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
* 根据业务类型导出数据
|
|
|
*/
|
|
|
export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any, any>) => {
|
|
@@ -364,6 +393,22 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
day: date.format('DD')
|
|
|
}
|
|
|
break
|
|
|
+ case EXPORT_WORD_ENUM.COLLECTION_INVENTORY:
|
|
|
+ temp = {
|
|
|
+ ...temp,
|
|
|
+ year: date.format('YYYY'),
|
|
|
+ month: date.format('MM'),
|
|
|
+ day: date.format('DD')
|
|
|
+ }
|
|
|
+ temp.goods.forEach((i: any) => {
|
|
|
+ i.checker = i.cusForm[`${i.id}-checker`]
|
|
|
+ i.remark = i.cusForm[`${i.id}-remark`]
|
|
|
+ i.cusForm[`${i.id}-statusCheck`] &&
|
|
|
+ (i.statusCheck = D7CEHCK_COLLECTION_RESULT_OPTIONS.find(
|
|
|
+ ii => ii.value === i.cusForm[`${i.id}-statusCheck`]
|
|
|
+ )?.label)
|
|
|
+ })
|
|
|
+ break
|
|
|
case EXPORT_WORD_ENUM.VOUCHER:
|
|
|
case EXPORT_WORD_ENUM.STORAGE_VOUCHER:
|
|
|
temp = {
|
|
@@ -402,6 +447,15 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
date: dayjs(temp.date).format('YYYY年MM月DD日')
|
|
|
}
|
|
|
break
|
|
|
+ case EXPORT_WORD_ENUM.ACCIDENT_HANDLING_CERTIFICATE:
|
|
|
+ temp = {
|
|
|
+ ...temp,
|
|
|
+ year: date.format('YYYY'),
|
|
|
+ rtf: removeHtmlTags(JSON.parse(temp.rtf).txtArr[0].txt),
|
|
|
+ authInfoRtf: removeHtmlTags(JSON.parse(temp.authInfoRtf).txtArr[0].txt),
|
|
|
+ authResultRtf: removeHtmlTags(JSON.parse(temp.authResultRtf).txtArr[0].txt)
|
|
|
+ }
|
|
|
+ break
|
|
|
case EXPORT_WORD_ENUM.COLLECTION_CARD:
|
|
|
temp = {
|
|
|
...temp,
|
|
@@ -425,6 +479,22 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
case EXPORT_WORD_ENUM.COLLECTION_ARCHIVES:
|
|
|
temp.imagePages = await arrangeImages(temp.imagePages)
|
|
|
break
|
|
|
+ case EXPORT_WORD_ENUM.OUTSIDER_FORM:
|
|
|
+ const memberss = JSON.parse(temp.memberIds)
|
|
|
+ temp = {
|
|
|
+ ...temp,
|
|
|
+ time: dayjs(temp.date).format('HH:mm:ss'),
|
|
|
+ date: dayjs(temp.date).format('YYYY-MM-DD'),
|
|
|
+ members: memberss.map((i: any) => i.name),
|
|
|
+ companys: memberss.map((i: any) => i.remark || '空'),
|
|
|
+ idCards: memberss.map((i: any) => i.papers || '空'),
|
|
|
+ phones: memberss.map((i: any) => i.phone || '空')
|
|
|
+ }
|
|
|
+ break
|
|
|
+ case EXPORT_WORD_ENUM.RELIC_REPAIR_LIST:
|
|
|
+ case EXPORT_WORD_ENUM.COLLECTION_CURRENT_STATUS:
|
|
|
+ temp.rtf = removeHtmlTags(JSON.parse(temp.rtf).txtArr[0].txt)
|
|
|
+ break
|
|
|
case EXPORT_WORD_ENUM.COLLECTION_LIST:
|
|
|
temp.goods.push({
|
|
|
index: '合计',
|
|
@@ -674,10 +744,74 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
}
|
|
|
}
|
|
|
break
|
|
|
+ case EXPORT_WORD_ENUM.REGISTER_LEDGER:
|
|
|
+ const totalPcs = temp.goods.reduce((sum: number, i: any) => sum + (i._pcs || 0), 0)
|
|
|
+ temp.goods.forEach((i: any) => {
|
|
|
+ i.year = date.format('YYYY') + '年度'
|
|
|
+ i.sonUnit = temp.sonUnit
|
|
|
+ i.typeName = temp.typeName
|
|
|
+ i.lendDate = dayjs(i.cusForm[`${i.id}-lendDate`]).format('YYYY年MM月DD日')
|
|
|
+ i.lenderA = i.cusForm[`${i.id}-lenderA`]
|
|
|
+ i.lenderb = i.cusForm[`${i.id}-lenderb`]
|
|
|
+ i.sonNum = temp.sonNum
|
|
|
+ i.sonNum2 = temp.sonNum2
|
|
|
+ i.handlerA = i.cusForm[`${i.id}-handlerA`]
|
|
|
+ i.handlerB = i.cusForm[`${i.id}-handlerB`]
|
|
|
+ i.recorder = i.cusForm[`${i.id}-recorder`]
|
|
|
+ i.remark = i.cusForm[`${i.id}-remark`]
|
|
|
+ i.pcs = `${i.pcs},计${totalPcs}件`
|
|
|
+ const expectedReturnDate = i.cusForm[`${i.id}-expectedReturnDate`]
|
|
|
+ expectedReturnDate &&
|
|
|
+ (i.expectedReturnDate = dayjs(expectedReturnDate).format('YYYY年MM月DD日'))
|
|
|
+ const returnDate = i.cusForm[`${i.id}-returnDate`]
|
|
|
+ returnDate && (i.returnDate = dayjs(returnDate).format('YYYY年MM月DD日'))
|
|
|
+ })
|
|
|
+
|
|
|
+ excelHandler = worksheet => {
|
|
|
+ const borderStyle: ExcelJS.Border = {
|
|
|
+ style: 'thin',
|
|
|
+ color: { argb: 'FF000000' }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (let row = 1; row <= temp.goods.length + 2; row++) {
|
|
|
+ for (let col = 1; col <= 18; col++) {
|
|
|
+ const cell = worksheet.getCell(row, col)
|
|
|
+ cell.border = {
|
|
|
+ top: borderStyle,
|
|
|
+ left: borderStyle,
|
|
|
+ bottom: borderStyle,
|
|
|
+ right: borderStyle
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ worksheet.eachRow(row => {
|
|
|
+ row.eachCell(cell => {
|
|
|
+ cell.alignment = {
|
|
|
+ vertical: 'middle',
|
|
|
+ horizontal: 'center',
|
|
|
+ wrapText: true
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ break
|
|
|
}
|
|
|
|
|
|
if (!item.templateName) {
|
|
|
// 没有templateName则输出excel
|
|
|
+ let mergeHeadNum = 0
|
|
|
+ let headTemp: string[] = []
|
|
|
+ let fatherHeadTemp: {
|
|
|
+ title: string
|
|
|
+ position: string[]
|
|
|
+ }[] = []
|
|
|
+ // 表头需要占据的行数
|
|
|
+ const headRow = Math.max(
|
|
|
+ ...item.options?.sheetHeader.map((head: string | string[]) =>
|
|
|
+ Array.isArray(head) ? head.length - 1 : 1
|
|
|
+ )
|
|
|
+ )
|
|
|
const workbook = new ExcelJS.Workbook()
|
|
|
const worksheet = workbook.addWorksheet('Sheet1', {
|
|
|
properties: { defaultRowHeight: 30 },
|
|
@@ -689,7 +823,43 @@ export const exportWordHandler = async (type: EXPORT_WORD_ENUM, data: Record<any
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- worksheet.addRow(item.options?.sheetHeader)
|
|
|
+ item.options?.sheetHeader.forEach((head: string | string[], index: number) => {
|
|
|
+ if (Array.isArray(head)) {
|
|
|
+ fatherHeadTemp.push({
|
|
|
+ title: head.shift() || '',
|
|
|
+ position: [
|
|
|
+ `${getExcelColumnLetter(index + mergeHeadNum)}1`,
|
|
|
+ `${getExcelColumnLetter(index + head.length - 1 + mergeHeadNum)}1`
|
|
|
+ ]
|
|
|
+ })
|
|
|
+ headTemp.push(...head)
|
|
|
+ mergeHeadNum++
|
|
|
+ } else {
|
|
|
+ headTemp.push(head)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ worksheet.addRow(headTemp)
|
|
|
+ if (fatherHeadTemp.length) {
|
|
|
+ // 存在需要合并的父级表头
|
|
|
+ worksheet.insertRow(1, [])
|
|
|
+ fatherHeadTemp.forEach(head => {
|
|
|
+ const cell = worksheet.getCell(head.position[0])
|
|
|
+ cell.value = head.title
|
|
|
+ worksheet.mergeCells(`${head.position[0]}:${head.position[1]}`)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (headRow > 1) {
|
|
|
+ // 合并表头列
|
|
|
+ headTemp.forEach((head, index) => {
|
|
|
+ const pos = `${getExcelColumnLetter(index)}1:${getExcelColumnLetter(index)}${headRow}`
|
|
|
+ const cell = worksheet.getCell(`${getExcelColumnLetter(index)}1`)
|
|
|
+ if (!cell.isMerged) {
|
|
|
+ worksheet.mergeCells(pos)
|
|
|
+ cell.value = head
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
temp.goods.forEach((good: Record<string, any>, goodIndex: number) => {
|
|
|
const _temp: string[] = []
|
|
|
item.options?.sheetFilter.forEach((key: string, index: number) => {
|