加工进度查询

This commit is contained in:
chenjianan
2019-05-16 17:04:11 +08:00
parent 8c4c48bba4
commit 4add252f01
3 changed files with 154 additions and 28 deletions

View File

@@ -60,3 +60,22 @@ export function getTable2(stepNumber) {
}
})
}
export function getExport(num) {
return request({
url: '',
method: 'post',
data: {
type: '3',
name: `select 机床流水号,组件流水号,车间生产管理工艺_零件工艺计划.工艺计划流水号,车间生产管理工艺_零件工艺计划.零件图号_零件工艺计划,车间生产管理工艺_零件工序_视图.零件名称,待加工工序顺序,车间生产管理工艺_零件工序.工序流水号,车间生产管理工艺_零件工序.工艺编号,车间生产管理工艺_基础表_工艺名称.工艺名称,批次数量,材料
from ( select 工艺计划流水号,min(工序顺序) as 待加工工序顺序
from 车间生产管理工艺_零件工序_视图
where 完成日期_短 is null and 考核状态 = 6
group by 工艺计划流水号) as 当前加工工序表
inner join 车间生产管理工艺_零件工艺计划 on 当前加工工序表.工艺计划流水号 = 车间生产管理工艺_零件工艺计划.工艺计划流水号
inner join 车间生产管理工艺_零件工序 on 当前加工工序表.工艺计划流水号 = 车间生产管理工艺_零件工序.工艺计划流水号 and 当前加工工序表.待加工工序顺序 = 车间生产管理工艺_零件工序.工序顺序
inner join 车间生产管理工艺_基础表_工艺名称 on 车间生产管理工艺_基础表_工艺名称.工艺编号 = 车间生产管理工艺_零件工序.工艺编号
inner join 车间生产管理工艺_零件工序_视图 on 车间生产管理工艺_零件工序_视图.工艺计划流水号 = 车间生产管理工艺_零件工艺计划.工艺计划流水号 and 当前加工工序表.待加工工序顺序 = 车间生产管理工艺_零件工序_视图.工序顺序
where 组件流水号 = ${num}`
}
})
}

View File

@@ -1,7 +1,7 @@
/* eslint-disable */
require('script-loader!file-saver');
require('script-loader!@/vendor/Blob');
require('script-loader!xlsx/dist/xlsx.core.min');
import XLSX from 'xlsx'
function generateArray(table) {
var out = [];
var rows = table.querySelectorAll('tr');
@@ -28,15 +28,24 @@ function generateArray(table) {
if (rowspan || colspan) {
rowspan = rowspan || 1;
colspan = colspan || 1;
ranges.push({s: {r: R, c: outRow.length}, e: {r: R + rowspan - 1, c: outRow.length + colspan - 1}});
ranges.push({
s: {
r: R,
c: outRow.length
},
e: {
r: R + rowspan - 1,
c: outRow.length + colspan - 1
}
;
});
};
//Handle Value
outRow.push(cellValue !== "" ? cellValue : null);
//Handle Colspan
if (colspan) for (var k = 0; k < colspan - 1; ++k) outRow.push(null);
if (colspan)
for (var k = 0; k < colspan - 1; ++k) outRow.push(null);
}
out.push(outRow);
}
@@ -51,16 +60,30 @@ function datenum(v, date1904) {
function sheet_from_array_of_arrays(data, opts) {
var ws = {};
var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}};
var range = {
s: {
c: 10000000,
r: 10000000
},
e: {
c: 0,
r: 0
}
};
for (var R = 0; R != data.length; ++R) {
for (var C = 0; C != data[R].length; ++C) {
if (range.s.r > R) range.s.r = R;
if (range.s.c > C) range.s.c = C;
if (range.e.r < R) range.e.r = R;
if (range.e.c < C) range.e.c = C;
var cell = {v: data[R][C]};
var cell = {
v: data[R][C]
};
if (cell.v == null) continue;
var cell_ref = XLSX.utils.encode_cell({c: C, r: R}); // here
var cell_ref = XLSX.utils.encode_cell({
c: C,
r: R
});
if (typeof cell.v === 'number') cell.t = 'n';
else if (typeof cell.v === 'boolean') cell.t = 'b';
@@ -68,8 +91,7 @@ function sheet_from_array_of_arrays(data, opts) {
cell.t = 'n';
cell.z = XLSX.SSF._table[14];
cell.v = datenum(cell.v);
}
else cell.t = 's';
} else cell.t = 's';
ws[cell_ref] = cell;
}
@@ -93,16 +115,15 @@ function s2ab(s) {
export function export_table_to_excel(id) {
var theTable = document.getElementById(id);
console.log('a')
var oo = generateArray(theTable);
var ranges = oo[1];
/* original data */
var data = oo[0];
var ws_name = "SheetJS";
console.log(data);
var wb = new Workbook(), ws = sheet_from_array_of_arrays(data);
var wb = new Workbook(),
ws = sheet_from_array_of_arrays(data);
/* add ranges to worksheet */
// ws['!cols'] = ['apple', 'banan'];
@@ -112,30 +133,88 @@ export function export_table_to_excel(id) {
wb.SheetNames.push(ws_name);
wb.Sheets[ws_name] = ws;
var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
var wbout = XLSX.write(wb, {
bookType: 'xlsx',
bookSST: false,
type: 'binary'
});
saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), "test.xlsx")
saveAs(new Blob([s2ab(wbout)], {
type: "application/octet-stream"
}), "test.xlsx")
}
function formatJson(jsonData) {
console.log(jsonData)
}
export function export_json_to_excel(th, jsonData, defaultTitle) {
export function export_json_to_excel({
multiHeader = [],
header,
data,
filename,
merges = [],
autoWidth = true,
bookType= 'xlsx'
} = {}) {
/* original data */
filename = filename || 'excel-list'
data = [...data]
data.unshift(header);
for (let i = multiHeader.length-1; i > -1; i--) {
data.unshift(multiHeader[i])
}
var data = jsonData;
data.unshift(th);
var ws_name = "SheetJS";
var wb = new Workbook(),
ws = sheet_from_array_of_arrays(data);
var wb = new Workbook(), ws = sheet_from_array_of_arrays(data);
if (merges.length > 0) {
if (!ws['!merges']) ws['!merges'] = [];
merges.forEach(item => {
ws['!merges'].push(XLSX.utils.decode_range(item))
})
}
if (autoWidth) {
/*设置worksheet每列的最大宽度*/
const colWidth = data.map(row => row.map(val => {
/*先判断是否为null/undefined*/
if (val == null) {
return {
'wch': 10
};
}
/*再判断是否为中文*/
else if (val.toString().charCodeAt(0) > 255) {
return {
'wch': val.toString().length * 2
};
} else {
return {
'wch': val.toString().length
};
}
}))
/*以第一行为初始值*/
let result = colWidth[0];
for (let i = 1; i < colWidth.length; i++) {
for (let j = 0; j < colWidth[i].length; j++) {
if (result[j]['wch'] < colWidth[i][j]['wch']) {
result[j]['wch'] = colWidth[i][j]['wch'];
}
}
}
ws['!cols'] = result;
}
/* add worksheet to workbook */
wb.SheetNames.push(ws_name);
wb.Sheets[ws_name] = ws;
var wbout = XLSX.write(wb, {bookType: 'xlsx', bookSST: false, type: 'binary'});
var title = defaultTitle || '列表'
saveAs(new Blob([s2ab(wbout)], {type: "application/octet-stream"}), title + ".xlsx")
var wbout = XLSX.write(wb, {
bookType: bookType,
bookSST: false,
type: 'binary'
});
saveAs(new Blob([s2ab(wbout)], {
type: "application/octet-stream"
}), `${filename}.${bookType}`);
}

View File

@@ -48,6 +48,7 @@
type="date"
placeholder="选择日期"/>
<el-button type="success" class="el-icon-search" size="small" style="margin: 10px 0 0 10px" @click="getTableData();pageCurrent=1;pageSize=10;total = 0">查询</el-button>
<el-button type="warning" class="el-icon-download" size="small" style="margin: 10px 0 0 10px" @click="exportExcel">导出</el-button>
</el-row>
</el-card>
@@ -309,7 +310,7 @@
</div>
</template>
<script>
import { getNames, getMachines, getGroups, getTable, getTable2 } from '@/api/ManufacturingCenter/ProcessingStatus'
import { getNames, getMachines, getGroups, getTable, getTable2, getExport } from '@/api/ManufacturingCenter/ProcessingStatus'
export default {
data() {
@@ -384,6 +385,33 @@ export default {
this.getTableData()
},
methods: {
formatJson(filterVal, jsonData) {
return jsonData.map(v => filterVal.map(j => {
return v[j]
}))
},
exportExcel() {
if (!this.Group) {
this.$message.warning('请选择分组')
return
}
getExport(this.Group).then(res => {
console.log(res.data)
import('@/vendor/Export2Excel').then(excel => {
const tHeader = ['图号及规格', '制品名称', '计划数', '材料', '当前工序名']
const filterVal = ['零件图号_零件工艺计划', '零件名称', '批次数量', '材料', '工艺名称']
const list = res.data
const data = this.formatJson(filterVal, list)
excel.export_json_to_excel({
header: tHeader,
data,
filename: '加工进度表',
autoWidth: true,
bookType: 'xlsx'
})
})
})
},
// 查询供应商名称
fetchData() {
this.projects = []