export const initheaders = [ { label : "序号", width: '160px', prop:'invNo' }, { label : "发票代码", width: '120px', prop: 'inv_code' }, { label : "发票号码", width: '120px', prop:'inv_number' }, { label : "数电票号码", width: '160px', prop: 'inv_number_electionic' }, { label : "销方识别号", width: '160px', prop: 'seller_id' }, { label : "销方名称", width: '120px', prop: 'seller_title' }, { label : "购方识别号", width: '140px', prop: 'buyer_id' }, { label : "购买方名称", width: '140px', prop: 'buyer_title' }, { label : "开票日期", width: '140px', prop: 'open_date' }, { label : "货物或应税劳务名称", width: '140px', prop: 'XMMC' }, { label : "规格型号", width: '140px', prop: 'GGXH' }, { label : "单位", width: '140px', prop: 'DW' }, { label : "数量", width: '140px', prop: 'SPSL' }, { label : "单价", width: '140px', prop: 'DJ' }, { label : "金额", width: '140px', prop: 'JE' }, { label : "税率", width: '140px', prop: 'SL' }, { label : "税额", width: '140px', prop: 'SE' }, { label : "价税合计", width: '140px', prop: 'JSHJ' }, { label : "发票来源", width: '140px', prop: 'source' }, { label : "发票票种", width: '140px', prop: 'inv_type' }, { label : "发票状态", width: '140px', prop: 'status' }, { label : "是否正数发票", width: '140px', prop: 'type' }, { label : "发票风险等级", width: '140px', prop: 'warning' }, { label : "开票人", width: '140px', prop: 'person' }, { label : "备注", width: '140px', prop: 'remark' }, ]; export const mapLabel2Field = initheaders.reduce((previous, current) => ({ ...previous, [current.label]: current.prop }), {}) console.log(mapLabel2Field) export const columns = [ { type: "index", width: "50", fixed: "left", label: "序号" }, ...initheaders ] // 校验数据是否为空 export const isEmpty = (results:any[]) => results.length === 0 // 校验导入模板表头是否一致 export function isHeaderSame(importHeader: any[]){ if(importHeader.length !== initheaders.length){ return false } for(const index in importHeader){ if(initheaders[index] !== importHeader[index]){ return false } } return true } // 生成导入数据 export function generateTableData(results: any[]){ const tableData = [] for (const item of results) { const tableItem = {} const labels = Object.keys(item) for(const label of labels){ const field = mapLabel2Field[label] tableItem[field] = item[label] } tableData.push(tableItem) } console.log(tableData) return tableData }