|
|
|
|
@ -11,7 +11,7 @@
|
|
|
|
|
:width-resize="true"
|
|
|
|
|
:header-row-style="table_header_class"
|
|
|
|
|
:row-style="getRowStyle"
|
|
|
|
|
:cell-style="getColumStyle"
|
|
|
|
|
:merge-cells="mergeCells"
|
|
|
|
|
class="table-class"
|
|
|
|
|
show-overflow="tooltip"
|
|
|
|
|
show-header-overflow="tooltip"
|
|
|
|
|
@ -21,14 +21,22 @@
|
|
|
|
|
>
|
|
|
|
|
<ux-table-column
|
|
|
|
|
v-for="(field, index) in fields"
|
|
|
|
|
:key="index"
|
|
|
|
|
:min-width="field.rowName?200:100"
|
|
|
|
|
:field="field.dataeaseName"
|
|
|
|
|
:key="field.dataeaseName+index"
|
|
|
|
|
:field="field.subFields?'':field.dataeaseName"
|
|
|
|
|
:resizable="true"
|
|
|
|
|
:sortable="!field.rowName"
|
|
|
|
|
:fixed="field.fixed"
|
|
|
|
|
:title="field.rowName?field.name+' \\ '+field.rowName:field.name"
|
|
|
|
|
:title="field.name"
|
|
|
|
|
>
|
|
|
|
|
<template v-if="field.subFields">
|
|
|
|
|
<ux-table-column
|
|
|
|
|
v-for="(subfield) in field.subFields"
|
|
|
|
|
:key="subfield.dataeaseName"
|
|
|
|
|
:field="subfield.dataeaseName"
|
|
|
|
|
:resizable="true"
|
|
|
|
|
:title="subfield.name"
|
|
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
</ux-table-column>
|
|
|
|
|
</ux-grid>
|
|
|
|
|
|
|
|
|
|
<el-row v-show="chart.type === 'table-info'" class="table-page">
|
|
|
|
|
@ -82,6 +90,7 @@ export default {
|
|
|
|
|
return {
|
|
|
|
|
fields: [],
|
|
|
|
|
height: 'auto',
|
|
|
|
|
mergeCells: [],
|
|
|
|
|
title_class: {
|
|
|
|
|
margin: '0 0',
|
|
|
|
|
width: '100%',
|
|
|
|
|
@ -113,6 +122,8 @@ export default {
|
|
|
|
|
background: '#ffffff',
|
|
|
|
|
height: '36px'
|
|
|
|
|
},
|
|
|
|
|
cellDimension: 0,
|
|
|
|
|
tableLength: 0,
|
|
|
|
|
title_show: true,
|
|
|
|
|
borderRadius: '0px',
|
|
|
|
|
currentPage: {
|
|
|
|
|
@ -130,13 +141,9 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
chart: function() {
|
|
|
|
|
this.init()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted() {
|
|
|
|
|
created() {
|
|
|
|
|
this.init()
|
|
|
|
|
console.log('init')
|
|
|
|
|
// 监听元素变动事件
|
|
|
|
|
eventBus.$on('resizing', (componentId) => {
|
|
|
|
|
this.chartResize()
|
|
|
|
|
@ -159,6 +166,26 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
deteleObject(obj) {
|
|
|
|
|
var uniques = []
|
|
|
|
|
var stringify = {}
|
|
|
|
|
for (var i = 0; i < obj.length; i++) {
|
|
|
|
|
var keys = Object.keys(obj[i])
|
|
|
|
|
keys.sort(function(a, b) {
|
|
|
|
|
return (Number(a) - Number(b))
|
|
|
|
|
})
|
|
|
|
|
var str = ''
|
|
|
|
|
for (var j = 0; j < keys.length; j++) {
|
|
|
|
|
str += JSON.stringify(keys[j])
|
|
|
|
|
str += JSON.stringify(obj[i][keys[j]])
|
|
|
|
|
}
|
|
|
|
|
if (!stringify.hasOwnProperty(str)) {
|
|
|
|
|
uniques.push(obj[i])
|
|
|
|
|
stringify[str] = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return uniques
|
|
|
|
|
},
|
|
|
|
|
initData() {
|
|
|
|
|
const that = this
|
|
|
|
|
let datas = []
|
|
|
|
|
@ -167,7 +194,6 @@ export default {
|
|
|
|
|
datas = JSON.parse(JSON.stringify(this.chart.data.tableRow))
|
|
|
|
|
const findRowIndex = this.fields.findIndex(e => e.chartType === 'row')
|
|
|
|
|
const findValueIndex = this.fields.findIndex(e => e.chartType === 'bar')
|
|
|
|
|
const findIndex = this.fields.findIndex(e => e.chartType === null)
|
|
|
|
|
if (this.chart.type === 'table-info') {
|
|
|
|
|
// 计算分页
|
|
|
|
|
this.currentPage.show = datas.length
|
|
|
|
|
@ -176,47 +202,142 @@ export default {
|
|
|
|
|
datas = datas.slice(pageStart, pageEnd)
|
|
|
|
|
} else if (this.chart.type === 'table-normal' && findRowIndex >= 0) {
|
|
|
|
|
// 交叉表数据处理
|
|
|
|
|
this.fields[0].rowName = this.fields[findRowIndex].name
|
|
|
|
|
this.fields[0].fixed = 'left'
|
|
|
|
|
const fieldRowName = this.fields[findRowIndex].dataeaseName
|
|
|
|
|
const xaxis = this.chart.xaxis ? JSON.parse(this.chart.xaxis) : []
|
|
|
|
|
const yaxisExt = this.chart.yaxisExt ? JSON.parse(this.chart.yaxisExt) : []
|
|
|
|
|
const xaxisFieldId = xaxis.map(e => e.dataeaseName)
|
|
|
|
|
const yaxisExtFieldId = yaxisExt.map(e => e.dataeaseName)
|
|
|
|
|
const fieldValueName = this.fields[findValueIndex].dataeaseName
|
|
|
|
|
const fieldName = this.fields[findIndex].dataeaseName
|
|
|
|
|
const fields = [this.fields[0]]
|
|
|
|
|
let name = null
|
|
|
|
|
let flag = true
|
|
|
|
|
this.cellDimension = xaxisFieldId.length
|
|
|
|
|
let fields = this.fields.filter(e => xaxisFieldId.includes(e.dataeaseName))
|
|
|
|
|
console.log(fields)
|
|
|
|
|
let rowSum = 0
|
|
|
|
|
const columnValue = []
|
|
|
|
|
datas.forEach((ele, index) => {
|
|
|
|
|
if (name !== ele[fieldName] && name !== null) {
|
|
|
|
|
flag = false
|
|
|
|
|
let columnValue = []
|
|
|
|
|
let rowName = []
|
|
|
|
|
yaxisExtFieldId.forEach((e, index) => {
|
|
|
|
|
const arr = []
|
|
|
|
|
datas.forEach(ele => {
|
|
|
|
|
if (index > 0) {
|
|
|
|
|
arr.push({
|
|
|
|
|
dataeaseName: e + ele[e] + ',' + yaxisExtFieldId[0] + ele[yaxisExtFieldId[0]],
|
|
|
|
|
name: ele[e]
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
rowName.push({
|
|
|
|
|
dataeaseName: e + ele[e],
|
|
|
|
|
name: ele[e]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if (name !== ele[fieldName]) {
|
|
|
|
|
columnValue.push({
|
|
|
|
|
[fieldName]: ele[fieldName]
|
|
|
|
|
})
|
|
|
|
|
if (index > 0) {
|
|
|
|
|
const copyArr = this.deteleObject(arr)
|
|
|
|
|
rowName.forEach(item => {
|
|
|
|
|
const newArr = []
|
|
|
|
|
copyArr.forEach(sube => {
|
|
|
|
|
if (item.dataeaseName === sube.dataeaseName.split(',')[1]) {
|
|
|
|
|
newArr.push(sube)
|
|
|
|
|
}
|
|
|
|
|
name = ele[fieldName]
|
|
|
|
|
if (name === ele[fieldName] && flag) {
|
|
|
|
|
fields.push({
|
|
|
|
|
dataeaseName: fieldRowName + ele[fieldRowName],
|
|
|
|
|
name: ele[fieldRowName]
|
|
|
|
|
})
|
|
|
|
|
item.subFields = newArr
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
rowName = this.deteleObject(rowName)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
if (xaxisFieldId.length > 1) {
|
|
|
|
|
let arr1 = []
|
|
|
|
|
let arr2 = []
|
|
|
|
|
datas.forEach(obj => {
|
|
|
|
|
for (const key in obj) {
|
|
|
|
|
if (Object.hasOwnProperty.call(obj, key)) {
|
|
|
|
|
const element = obj[key]
|
|
|
|
|
if (xaxisFieldId[0] === key) {
|
|
|
|
|
arr1.push({
|
|
|
|
|
[key]: element
|
|
|
|
|
})
|
|
|
|
|
} else if (xaxisFieldId[1] === key) {
|
|
|
|
|
arr2.push({
|
|
|
|
|
[key]: element
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
arr1 = this.deteleObject(arr1)
|
|
|
|
|
arr2 = this.deteleObject(arr2)
|
|
|
|
|
let rowIndex = 0
|
|
|
|
|
arr1.forEach(e => {
|
|
|
|
|
this.mergeCells.push({
|
|
|
|
|
col: 0,
|
|
|
|
|
row: rowIndex,
|
|
|
|
|
rowspan: arr2.length,
|
|
|
|
|
colspan: 1
|
|
|
|
|
})
|
|
|
|
|
arr2.forEach(item => {
|
|
|
|
|
const obj = {}
|
|
|
|
|
columnValue.push(Object.assign(obj, e, item))
|
|
|
|
|
rowIndex += 1
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
columnValue.forEach(ele => {
|
|
|
|
|
if (yaxisExtFieldId.length > 1) {
|
|
|
|
|
datas.forEach(subEle => {
|
|
|
|
|
if (ele[xaxisFieldId[0]] === subEle[xaxisFieldId[0]] && ele[xaxisFieldId[1]] === subEle[xaxisFieldId[1]]) {
|
|
|
|
|
const key = yaxisExtFieldId[1] + subEle[yaxisExtFieldId[1]] + ',' + yaxisExtFieldId[0] + subEle[yaxisExtFieldId[0]]
|
|
|
|
|
ele[key] = subEle[fieldValueName]
|
|
|
|
|
rowSum += subEle[fieldValueName]
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
datas.forEach(subEle => {
|
|
|
|
|
if (ele[xaxisFieldId[0]] === subEle[xaxisFieldId[0]] && ele[xaxisFieldId[1]] === subEle[xaxisFieldId[1]]) {
|
|
|
|
|
const key = yaxisExtFieldId[0] + subEle[yaxisExtFieldId[0]]
|
|
|
|
|
ele[key] = subEle[fieldValueName]
|
|
|
|
|
rowSum += subEle[fieldValueName]
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
ele.rowTotal = rowSum
|
|
|
|
|
rowSum = 0
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
datas.forEach(obj => {
|
|
|
|
|
for (const key in obj) {
|
|
|
|
|
if (Object.hasOwnProperty.call(obj, key)) {
|
|
|
|
|
const element = obj[key]
|
|
|
|
|
if (xaxisFieldId.includes(key)) {
|
|
|
|
|
columnValue.push({
|
|
|
|
|
[key]: element
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
columnValue = this.deteleObject(columnValue)
|
|
|
|
|
columnValue.forEach(ele => {
|
|
|
|
|
if (yaxisExtFieldId.length > 1) {
|
|
|
|
|
datas.forEach(subEle => {
|
|
|
|
|
if (ele[fieldName] === subEle[fieldName]) {
|
|
|
|
|
const key = fieldRowName + subEle[fieldRowName]
|
|
|
|
|
if (ele[xaxisFieldId[0]] === subEle[xaxisFieldId[0]]) {
|
|
|
|
|
const key = yaxisExtFieldId[1] + subEle[yaxisExtFieldId[1]] + ',' + yaxisExtFieldId[0] + subEle[yaxisExtFieldId[0]]
|
|
|
|
|
ele[key] = subEle[fieldValueName]
|
|
|
|
|
rowSum += subEle[fieldValueName]
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
datas.forEach(subEle => {
|
|
|
|
|
if (ele[xaxisFieldId[0]] === subEle[xaxisFieldId[0]]) {
|
|
|
|
|
const key = yaxisExtFieldId[0] + subEle[yaxisExtFieldId[0]]
|
|
|
|
|
ele[key] = subEle[fieldValueName]
|
|
|
|
|
rowSum += subEle[fieldValueName]
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
ele.rowTotal = rowSum
|
|
|
|
|
rowSum = 0
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
fields = fields.concat(rowName)
|
|
|
|
|
fields.push({
|
|
|
|
|
dataeaseName: 'rowTotal',
|
|
|
|
|
fixed: 'right',
|
|
|
|
|
name: `合计(${this.fields[findValueIndex].name})`
|
|
|
|
|
})
|
|
|
|
|
datas = columnValue
|
|
|
|
|
@ -229,6 +350,7 @@ export default {
|
|
|
|
|
datas = []
|
|
|
|
|
this.resetPage()
|
|
|
|
|
}
|
|
|
|
|
this.tableLength = datas.length
|
|
|
|
|
this.$refs.plxTable.reloadData(datas)
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
this.initStyle()
|
|
|
|
|
@ -251,7 +373,7 @@ export default {
|
|
|
|
|
if (this.chart.type === 'table-info') {
|
|
|
|
|
tableHeight = (this.currentPage.pageSize + 2) * 36 - pageHeight
|
|
|
|
|
} else {
|
|
|
|
|
tableHeight = (this.chart.data.tableRow.length + 2) * 36 - pageHeight
|
|
|
|
|
tableHeight = (this.tableLength + 2) * 36 - pageHeight
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
tableHeight = 0
|
|
|
|
|
@ -333,8 +455,7 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
getColumStyle({ columnIndex }) {
|
|
|
|
|
const findRowIndex = this.fields.findIndex(e => e.rowName)
|
|
|
|
|
if (this.chart.type === 'table-normal' && findRowIndex >= 0 && (columnIndex === 0 || columnIndex === this.fields.length - 1)) {
|
|
|
|
|
if (this.chart.type === 'table-normal' && this.cellDimension > 0 && (columnIndex < this.cellDimension || columnIndex === this.fields.length - 1)) {
|
|
|
|
|
return this.table_header_class
|
|
|
|
|
} else {
|
|
|
|
|
return ''
|
|
|
|
|
@ -343,17 +464,16 @@ export default {
|
|
|
|
|
summaryMethod({ columns, data }) {
|
|
|
|
|
const that = this
|
|
|
|
|
const means = [] // 合计
|
|
|
|
|
const findRowIndex = this.fields.findIndex(e => e.rowName)
|
|
|
|
|
const findValueIndex = this.chart.data.fields.findIndex(e => e.chartType === 'bar')
|
|
|
|
|
columns.forEach((column, columnIndex) => {
|
|
|
|
|
if (columnIndex === 0) {
|
|
|
|
|
if (findRowIndex !== -1 && findValueIndex !== -1) {
|
|
|
|
|
if (this.cellDimension > 0 && findValueIndex !== -1) {
|
|
|
|
|
means.push(`合计(${this.chart.data.fields[findValueIndex].name})`)
|
|
|
|
|
} else {
|
|
|
|
|
means.push('合计')
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (columnIndex >= that.chart.data.fields.length - that.chart.data.series.length || findRowIndex !== -1) {
|
|
|
|
|
if (columnIndex >= that.chart.data.fields.length - that.chart.data.series.length || this.cellDimension > 0) {
|
|
|
|
|
const values = data.map(item => Number(item[column.property]))
|
|
|
|
|
// 合计
|
|
|
|
|
if (!values.every(value => isNaN(value))) {
|
|
|
|
|
|