备料单导出
This commit is contained in:
13
src/vendor/exportExcel.js
vendored
13
src/vendor/exportExcel.js
vendored
@@ -12,12 +12,6 @@ export function getExplorer() {
|
|||||||
return 'Safari'
|
return 'Safari'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export function method5(tableid) {
|
|
||||||
tableToExcel(tableid)
|
|
||||||
}
|
|
||||||
export function Cleanup() {
|
|
||||||
window.clearInterval(idTmr)
|
|
||||||
}
|
|
||||||
const tableToExcel = (function() {
|
const tableToExcel = (function() {
|
||||||
const uri = 'data:application/vnd.ms-excel;base64,'
|
const uri = 'data:application/vnd.ms-excel;base64,'
|
||||||
const template = `<html xmlns:x="urn:schemas-microsoft-com:office:excel"><head><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><meta charset="UTF-8"><style type="text/css">table td {border: 2px solid #000000;width:100px;text-align: center;color: #000000;}</style></head><body><table>{table}</table></body></html>`
|
const template = `<html xmlns:x="urn:schemas-microsoft-com:office:excel"><head><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><meta charset="UTF-8"><style type="text/css">table td {border: 2px solid #000000;width:100px;text-align: center;color: #000000;}</style></head><body><table>{table}</table></body></html>`
|
||||||
@@ -37,3 +31,10 @@ const tableToExcel = (function() {
|
|||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
export function method5(tableid) {
|
||||||
|
tableToExcel(tableid)
|
||||||
|
}
|
||||||
|
export function Cleanup() {
|
||||||
|
window.clearInterval(idTmr)
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
// 导出Excel方法(表格id,不加扩展名的文件名,sheet名)
|
||||||
|
export function exportExcelMethod(tableId, fileName, sheetName) {
|
||||||
|
tableToExcel(tableId, fileName, sheetName)
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
const tableToExcel = (function() {
|
||||||
|
const uri = 'data:application/vnd.ms-excel;base64,'
|
||||||
|
// 设置导出表格的单元格默认高度/宽度/边框样式/字体颜色/背景颜色/居中,网页显示表格宽度建议1240,tr/td视情况而定
|
||||||
|
const template = `<html xmlns:x="urn:schemas-microsoft-com:office:excel"><head><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><meta charset="UTF-8"><style type="text/css">table td {border: 2px solid #000000;height:40px;text-align: center;color: #000000;}</style></head><body><table>{table}</table></body></html>`
|
||||||
|
const base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
|
||||||
|
const format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p] }) }
|
||||||
|
return function(table, filename, sheetname) {
|
||||||
|
if (!table.nodeType) table = document.getElementById(table)
|
||||||
|
const ctx = { worksheet: sheetname || 'Worksheet', table: table.innerHTML }
|
||||||
|
const aTag = document.createElement('a')
|
||||||
|
aTag.href = uri + base64(format(template, ctx))
|
||||||
|
aTag.download = filename
|
||||||
|
aTag.click()
|
||||||
|
}
|
||||||
|
})()
|
||||||
@@ -6,7 +6,8 @@
|
|||||||
<el-input v-model="partName" placeholder="零件图号" size="small" clearable style="width:200px"/>
|
<el-input v-model="partName" placeholder="零件图号" size="small" clearable style="width:200px"/>
|
||||||
<el-button size="small" icon="el-icon-search" type="success" style="margin-left: 10px" @click="pageSize=10; pageCurrent=1;searchTable()">查询</el-button>
|
<el-button size="small" icon="el-icon-search" type="success" style="margin-left: 10px" @click="pageSize=10; pageCurrent=1;searchTable()">查询</el-button>
|
||||||
<el-checkbox v-model="all" size="mini">查询全部</el-checkbox>
|
<el-checkbox v-model="all" size="mini">查询全部</el-checkbox>
|
||||||
<el-button type="primary" size="small" icon="el-icon-download" style="margin-left:10px" @click="downLoad('BL');edit()">导出备料单</el-button>
|
<el-button type="primary" size="small" icon="el-icon-download" style="margin-left:10px" @click="downLoad('BL')">导出备料单</el-button>
|
||||||
|
<el-button type="primary" size="small" icon="el-icon-success" style="margin-left:10px" @click="edit()">导出完成</el-button>
|
||||||
</el-row>
|
</el-row>
|
||||||
</el-card>
|
</el-card>
|
||||||
|
|
||||||
@@ -78,10 +79,11 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { searchtable, searchtable2, edit } from '@/api/ManufacturingCenter/CreatePreparationBill'
|
import { searchtable, searchtable2, edit } from '@/api/ManufacturingCenter/CreatePreparationBill'
|
||||||
import { getExplorer, method5, Cleanup } from '@/vendor/exportExcel'
|
import { exportExcelMethod } from './exportExcel'
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
a: 0,
|
||||||
tableData2: [],
|
tableData2: [],
|
||||||
partName: '',
|
partName: '',
|
||||||
all: false,
|
all: false,
|
||||||
@@ -118,10 +120,11 @@ export default {
|
|||||||
for (let i = 0; i < this.Data.length; i++) {
|
for (let i = 0; i < this.Data.length; i++) {
|
||||||
searchtable2(this.Data[i].工艺计划流水号).then(response => {
|
searchtable2(this.Data[i].工艺计划流水号).then(response => {
|
||||||
this.tableData.push({
|
this.tableData.push({
|
||||||
|
工艺计划流水号: this.Data[i].工艺计划流水号,
|
||||||
零件名称: this.Data[i].零件名称,
|
零件名称: this.Data[i].零件名称,
|
||||||
零件图号: this.Data[i].零件图号,
|
零件图号: this.Data[i].零件图号,
|
||||||
备料打印: this.Data[i].备料打印,
|
备料打印: this.Data[i].备料打印,
|
||||||
工艺要求: response.data[i].工艺要求
|
工艺要求: response.data[0].工艺要求
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
this.loading = false
|
this.loading = false
|
||||||
@@ -133,18 +136,24 @@ export default {
|
|||||||
this.tableData2 = val
|
this.tableData2 = val
|
||||||
},
|
},
|
||||||
edit() {
|
edit() {
|
||||||
for (let i = 0; i < this.tableData2.length; i++) {
|
if (this.tableData2.length === 0) {
|
||||||
edit(this.tableData2[i].工艺计划流水号)
|
this.$message.warning('暂无数据')
|
||||||
|
} else {
|
||||||
|
this.a = 0
|
||||||
|
for (let i = 0; i < this.tableData2.length; i++) {
|
||||||
|
edit(this.tableData2[i].工艺计划流水号)
|
||||||
|
this.a = this.a + 1
|
||||||
|
}
|
||||||
|
if (this.a === this.tableData2.length) {
|
||||||
|
this.searchTable()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
downLoad(tableid) {
|
downLoad(tableid) {
|
||||||
if (this.tableData2.length === 0) {
|
if (this.tableData2.length === 0) {
|
||||||
this.$message.warning('暂无数据')
|
this.$message.warning('暂无数据')
|
||||||
} else {
|
} else {
|
||||||
this.searchTable()
|
exportExcelMethod(tableid, '123', 'asd')
|
||||||
getExplorer()
|
|
||||||
method5(tableid)
|
|
||||||
Cleanup()
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// 分页
|
// 分页
|
||||||
|
|||||||
Reference in New Issue
Block a user