onImportReport() {
const changeFile = e => {
let file = e.target.files[0]
excelIo.open(
file,
async json => {
Message.info('开始导入')
this.suspendStart()
spread.fromJSON(json)
activeSheet = spread.getActiveSheet()
const { rowCount, rowPosition } = this.getRowCount(
this.singleLayout
)
const pasteData = ReportUtils.getPasteList(activeSheet, rowCount)
pasteData.param.reportName = [this.baseInfo.reportName]
pasteData.param.reportCode = [this.baseInfo.reportCode]
const res = await API.reportImportCheck(pasteData.param)
const errorCode = res.data.isContainsErrorCode
if (!errorCode) {
const rowParams = res.data.rowParams
activeSheet.setArray(rowCount, rowPosition.col, rowParams)
this.setCheckItem(pasteData.cells, rowCount)
this.setReportTable(this.fillForm)
Message.success('导入成功!')
} else {
const elementRecognition = res.data.elementRecognition
let messages = []
reportInfo.elementSelection.forEach(item => {
const dimensionCode = item.dimensionCode
elementRecognition[dimensionCode].forEach((el, index) => {
Object.keys(el).forEach(key => {
if (!el[key]) {
const col = item.selectionCol
const row = index + rowCount + 1
const msg = `导入表第${row}行第${col}列:${key}未找到主数据信息`
messages.push(msg)
}
})
})
})
Notification({
title: '提示',
message: messages.join('<br/>'),
dangerouslyUseHTMLString: true,
offset: 100,
duration: 5000
})
await this.setReportBaseInfo()
}
this.suspendEnd()
},
function() {
Message.error('导入失败!')
}
)
}
importFile(changeFile)
},
|