江河统计导出修改

This commit is contained in:
shixiaoman
2021-12-15 15:15:57 +08:00
parent d9bf82d72a
commit a3f5f6ffe2
10 changed files with 363 additions and 82 deletions

View File

@@ -61,6 +61,7 @@
</template>
<script>
import moment from "moment";
import {
listAvgCompositeIndex,
listTargetInfo,
@@ -183,17 +184,53 @@
},
/* 导出 */
exportFile() {
const columns = this.columns.filter(item => item.dataIndex);
const arr = [];
const th = columns.map((item) => item.title);
arr.push(th);
this.data.forEach((d) => {
const td = columns.map((item) => d[item.dataIndex]);
const th1 = [];
const th2 = [];
const merges = []; // 合并
const columnsTemp = []; // 树形结构整理成list
this.columns.forEach((item, index) => {
if (item.children) {
item.children.forEach((citem) => {
th1.push(item.title)
th2.push(citem.title)
columnsTemp.push(citem)
})
merges.push({
s: {
r: 0,
c: th1.length - item.children.length
},
e: {
r: 0,
c: th1.length - 1
}
})
} else {
th1.push(item.title)
th2.push("")
columnsTemp.push(item)
merges.push({
s: {
r: 0,
c: index
},
e: {
r: 1,
c: index
}
})
}
})
arr.push(th1, th2);
this.momData.forEach((d) => {
const td = columnsTemp.map((item) => d[item.dataIndex]);
arr.push(td);
});
let sheet = XLSX.utils.aoa_to_sheet(arr);
this.$util.exportSheet(XLSX, sheet, new Date().getTime().toString());
sheet['!merges'] = merges;
this.$util.exportSheet(XLSX, sheet, moment(this.where.timeStart).format("YYYY年MM月DD日") + "至" + moment(this.where
.timeEnd).format("YYYY年MM月DD日") + "统计数据");
}
},

View File

@@ -32,7 +32,7 @@
</a-select-option>
</a-select>
</a-form-item>
<a-form-item label="开始时间:">
<a-form-item label="开始时间:">
<a-month-picker valueFormat="YYYY-MM" v-model:value="where.startTime" :disabled-date="disabledDate" />
</a-form-item>
<a-form-item label="结束时间:">
@@ -61,6 +61,7 @@
</template>
<script>
import moment from "moment";
import {
listMonthCompositeIndex,
listTargetInfo,
@@ -131,37 +132,37 @@
rules: {},
waterBodyList: [],
waterSystemList: [],
targetInfo:{},
targetInfoList:[],
targetInfo: {},
targetInfoList: [],
};
},
created() {
listInfo().then((res) => {
if (res.data.code == 0) {
console.log(res.data.data)
this.sectionInfo = res.data.data
res.data.data.forEach((m) => {
this.waterSystemList.push(m.waterBody);
this.waterBodyList.push(m.importWaterBody);
})
this.waterSystemList = [...new Set(this.waterSystemList)];
this.waterBodyList = [...new Set(this.waterBodyList)];
} else {
this.$message.error(res.data.msg);
}
}),
listTargetInfo().then((res) => {
if (res.data.code == 0) {
console.log(res.data.data)
this.targetInfo = res.data.data
res.data.data.forEach((m) => {
this.targetInfoList.push(m.indicatorName);
})
this.targetInfoList = [...new Set(this.targetInfoList)];
} else {
this.$message.error(res.data.msg);
}
})
if (res.data.code == 0) {
console.log(res.data.data)
this.sectionInfo = res.data.data
res.data.data.forEach((m) => {
this.waterSystemList.push(m.waterBody);
this.waterBodyList.push(m.importWaterBody);
})
this.waterSystemList = [...new Set(this.waterSystemList)];
this.waterBodyList = [...new Set(this.waterBodyList)];
} else {
this.$message.error(res.data.msg);
}
}),
listTargetInfo().then((res) => {
if (res.data.code == 0) {
console.log(res.data.data)
this.targetInfo = res.data.data
res.data.data.forEach((m) => {
this.targetInfoList.push(m.indicatorName);
})
this.targetInfoList = [...new Set(this.targetInfoList)];
} else {
this.$message.error(res.data.msg);
}
})
},
methods: {
/* 刷新表格 */
@@ -188,17 +189,54 @@
},
/* 导出 */
exportFile() {
const columns = this.columns.filter(item => item.dataIndex);
const arr = [];
const th = columns.map((item) => item.title);
arr.push(th);
this.data.forEach((d) => {
const td = columns.map((item) => d[item.dataIndex]);
const th1 = [];
const th2 = [];
const merges = []; // 合并
const columnsTemp = []; // 树形结构整理成list
this.columns.forEach((item, index) => {
if (item.children) {
item.children.forEach((citem) => {
th1.push(item.title)
th2.push(citem.title)
columnsTemp.push(citem)
})
merges.push({
s: {
r: 0,
c: th1.length - item.children.length
},
e: {
r: 0,
c: th1.length - 1
}
})
} else {
th1.push(item.title)
th2.push("")
columnsTemp.push(item)
merges.push({
s: {
r: 0,
c: index
},
e: {
r: 1,
c: index
}
})
}
})
arr.push(th1, th2);
this.momData.forEach((d) => {
const td = columnsTemp.map((item) => d[item.dataIndex]);
arr.push(td);
});
let sheet = XLSX.utils.aoa_to_sheet(arr);
this.$util.exportSheet(XLSX, sheet, new Date().getTime().toString());
sheet['!merges'] = merges;
this.$util.exportSheet(XLSX, sheet, moment(this.where.timeStart).format("YYYY年MM月DD日") + "至" + moment(this.where
.timeEnd).format("YYYY年MM月DD日") + "统计数据");
}
},