|
@@ -26,7 +26,7 @@
|
|
|
<el-button type="primary" class="btn" @click="onclick">
|
|
|
<i class="el-icon-search"></i>
|
|
|
</el-button>
|
|
|
- <el-button type="primary" @click="exportData()"
|
|
|
+ <el-button type="primary" @click="exportToExcel('零星进厂汽运监控')"
|
|
|
><i class="el-icon-download"></i>Excel</el-button
|
|
|
>
|
|
|
<span style="margin-left: 1rem;">合计净重:</span>
|
|
@@ -43,7 +43,7 @@
|
|
|
></el-input>
|
|
|
</div>
|
|
|
<div class="table">
|
|
|
- <dilTable ref="excelDom" v-bind.sync="option" @func="func"></dilTable>
|
|
|
+ <dilTable id="excelDom" ref="excelDom" v-bind.sync="option" @func="func"></dilTable>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
@@ -51,6 +51,7 @@
|
|
|
<script>
|
|
|
import { sjTime } from "@/utils/sharedJsFile";
|
|
|
import { getCookie } from "@/utils/util.js";
|
|
|
+import FileSaver from "file-saver";
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
@@ -86,6 +87,41 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ exportToExcel(tableTitle="表格标题") {
|
|
|
+ //创建工作簿对象
|
|
|
+ let wb = XLSX.utils.book_new();
|
|
|
+ //查询数据
|
|
|
+ let map={isExcel:1};
|
|
|
+ this.axios.post(this.option.requestUrl,map).then(res=>{
|
|
|
+ let columnData=res.data.data.columnData;
|
|
|
+ let data=[];
|
|
|
+ if(!res.data.data.list || res.data.data.list.length<=0){
|
|
|
+ this.$message({
|
|
|
+ message:"请先查询,再导出!",
|
|
|
+ type:"warning",
|
|
|
+ duration:1000
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }else{
|
|
|
+ //替换表头
|
|
|
+ console.log("columnData",columnData);
|
|
|
+ res.data.data.list.forEach((item,index)=>{
|
|
|
+ let temp={};
|
|
|
+ columnData.forEach((col)=>{
|
|
|
+ temp[col.label] = item[col.prop];
|
|
|
+ });
|
|
|
+ data.push(temp);
|
|
|
+ });
|
|
|
+ console.log("data",data);
|
|
|
+ //将json数组转换成sheet
|
|
|
+ let table_sheet = XLSX.utils.json_to_sheet(data);
|
|
|
+ //为工作簿添加sheet
|
|
|
+ XLSX.utils.book_append_sheet(wb, table_sheet, "第一页");
|
|
|
+ //导出
|
|
|
+ XLSX.writeFile(wb, tableTitle+'.xlsx');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
func(res) {
|
|
|
console.log(res);
|
|
|
var resultNetWeightTotal = 0;
|