| | |
| | | exportExcel = (data) => { |
| | | const { btn } = this.props |
| | | |
| | | let columns = btn.verify.columns.filter(col => col.output !== 'false') |
| | | let imgCol = false |
| | | let columns = btn.verify.columns.filter(col => { |
| | | if (col.output === 'false') return false |
| | | |
| | | if (col.type === 'image') { |
| | | imgCol = true |
| | | } |
| | | |
| | | if (col.type === 'number' && (col.decimal || col.decimal === 0) ) { |
| | | col.round = Math.pow(10, col.decimal) |
| | | } |
| | | |
| | | return col |
| | | }) |
| | | |
| | | try { |
| | | let imgCol = columns.filter(col => col.type === 'image')[0] |
| | | |
| | | if (imgCol) { |
| | | const column = columns.map(item => { |
| | | let col = { |
| | |
| | | item.$Index = index + 1 + '' |
| | | |
| | | columns.forEach((col, i) => { |
| | | if (item[col.Column] && col.abs === 'true') { |
| | | _row[col.Column] = Math.abs(item[col.Column]) |
| | | } else { |
| | | _row[col.Column] = item[col.Column] |
| | | let val = item[col.Column] |
| | | if (typeof(val) === 'number') { |
| | | if (col.abs === 'true') { |
| | | val = Math.abs(val) |
| | | } |
| | | if (col.round) { |
| | | val = Math.round(val * col.round) / col.round |
| | | val = val.toFixed(col.decimal) |
| | | } |
| | | } |
| | | |
| | | _row[col.Column] = val |
| | | }) |
| | | |
| | | table.push(_row) |
| | |
| | | } else { |
| | | this.execSuccess({ErrCode: 'S', ErrMesg: '导出成功!'}) |
| | | } |
| | | |
| | | } else { |
| | | let _header = [] |
| | | let _topRow = {} |
| | | let colwidth = [] |
| | | let abses = [] |
| | | |
| | | columns.forEach(col => { |
| | | if (_topRow[col.Column]) return |
| | | |
| | | _header.push(col.Column) |
| | | _topRow[col.Column] = col.Text |
| | | |
| | | if (col.abs === 'true') { |
| | | abses.push(col.Column) |
| | | } |
| | | |
| | | colwidth.push({width: col.Width || 20}) |
| | | }) |
| | | |
| | |
| | | |
| | | item.$Index = index + 1 + '' |
| | | |
| | | _header.forEach(field => { |
| | | if (item[field] && abses.includes(field)) { |
| | | _row[field] = Math.abs(item[field]) |
| | | } else { |
| | | _row[field] = item[field] |
| | | columns.forEach((col, i) => { |
| | | let val = item[col.Column] |
| | | |
| | | if (typeof(val) === 'number') { |
| | | if (col.abs === 'true') { |
| | | val = Math.abs(val) |
| | | } |
| | | if (col.round) { |
| | | val = Math.round(val * col.round) / col.round |
| | | val = val.toFixed(col.decimal) |
| | | } |
| | | } |
| | | |
| | | _row[col.Column] = val |
| | | }) |
| | | |
| | | table.push(_row) |