projects/mesxc-dy #363
@ -1,218 +1,341 @@
|
|||||||
<!--
|
<!--
|
||||||
* @Author: Do not edit
|
* @Author: Do not edit
|
||||||
* @Date: 2024-04-22 15:49:56
|
* @Date: 2024-04-22 15:49:56
|
||||||
* @LastEditTime: 2024-04-25 09:10:07
|
* @LastEditTime: 2024-04-25 09:53:41
|
||||||
* @LastEditors: DY
|
* @LastEditors: DY
|
||||||
* @Description:
|
* @Description:
|
||||||
-->
|
-->
|
||||||
<template>
|
<template>
|
||||||
<div class="weekly">
|
<div class="weekly">
|
||||||
<el-form :inline="true" :model="listQuery" class="blueTip">
|
<el-form
|
||||||
<el-form-item label="月" prop="reportTime">
|
:inline="true"
|
||||||
<el-date-picker v-model="listQuery.time" value-format="yyyy-MM-dd HH:mm:ss" type="month" size="small" placeholder="选择月">
|
:model="listQuery"
|
||||||
</el-date-picker>
|
class="blueTip">
|
||||||
</el-form-item>
|
<el-form-item
|
||||||
<el-button v-if="this.$auth.hasPermi('base:report-auto-production:query')" type="primary" size="small" @click="getList">
|
label="月"
|
||||||
查询
|
prop="reportTime">
|
||||||
</el-button>
|
<el-date-picker
|
||||||
<el-button v-if="this.$auth.hasPermiAnd(['base:report-auto-original-glass:export', 'base:report-auto-production:export'])" type="primary" size="small" plain
|
v-model="listQuery.time"
|
||||||
@click="handleExport">导出</el-button>
|
value-format="yyyy-MM-dd HH:mm:ss"
|
||||||
</el-form>
|
type="month"
|
||||||
<base-table
|
size="small"
|
||||||
|
placeholder="选择月"></el-date-picker>
|
||||||
|
</el-form-item>
|
||||||
|
<el-button
|
||||||
|
v-if="this.$auth.hasPermi('base:report-auto-production:query')"
|
||||||
|
type="primary"
|
||||||
|
size="small"
|
||||||
|
@click="getList">
|
||||||
|
查询
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="
|
||||||
|
this.$auth.hasPermiAnd([
|
||||||
|
'base:report-auto-original-glass:export',
|
||||||
|
'base:report-auto-production:export',
|
||||||
|
])
|
||||||
|
"
|
||||||
|
type="primary"
|
||||||
|
size="small"
|
||||||
|
plain
|
||||||
|
@click="handleExport">
|
||||||
|
导出
|
||||||
|
</el-button>
|
||||||
|
</el-form>
|
||||||
|
<base-table
|
||||||
:table-props="tableProps"
|
:table-props="tableProps"
|
||||||
:table-data="tableData"
|
:table-data="tableData"
|
||||||
:span-method="mergeColumnHandler"
|
:span-method="objectSpanMethod1"
|
||||||
|
@emitFun="handleEmitFun"
|
||||||
|
:max-height="tableH" />
|
||||||
|
<base-table
|
||||||
|
:table-props="tableProps1"
|
||||||
|
:table-data="tableData1"
|
||||||
|
:span-method="objectSpanMethod1"
|
||||||
@emitFun="handleEmitFun"
|
@emitFun="handleEmitFun"
|
||||||
:max-height="tableH"
|
:max-height="tableH"
|
||||||
/>
|
style="margin-top: 15px" />
|
||||||
<!-- <monthWeek v-if="glassWeekShow" ref="monthWeek" :product="false" :params="listQuery" />
|
</div>
|
||||||
<proMonth v-if="proWeekShow" ref="proMonth" :product="false" :params="listQuery" /> -->
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// import monthWeek from '../glass/month.vue'
|
|
||||||
// import proMonth from '../productionMonthReport/index.vue'
|
|
||||||
import { productionMonthY, productionMonthD } from '@/api/report/glass';
|
import { productionMonthY, productionMonthD } from '@/api/report/glass';
|
||||||
import { parseTime } from '../../core/mixins/code-filter'
|
import { parseTime } from '../../core/mixins/code-filter';
|
||||||
import FileSaver from 'file-saver'
|
import FileSaver from 'file-saver';
|
||||||
import * as XLSX from 'xlsx/xlsx.mjs'
|
import * as XLSX from 'xlsx/xlsx.mjs';
|
||||||
import tableHeightMixin from '@/mixins/lb/tableHeightMixin';
|
import tableHeightMixin from '@/mixins/lb/tableHeightMixin';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
// components: { monthWeek, proMonth },
|
// components: { monthWeek, proMonth },
|
||||||
mixins: [tableHeightMixin],
|
mixins: [tableHeightMixin],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
heightNum: 240,
|
heightNum: 350,
|
||||||
listQuery: {
|
listQuery: {
|
||||||
time: ''
|
time: '',
|
||||||
},
|
},
|
||||||
// startTimeStamp: '',
|
// startTimeStamp: '',
|
||||||
// endTimeStamp: '',
|
// endTimeStamp: '',
|
||||||
// reportTime: '',
|
// reportTime: '',
|
||||||
// glassWeekShow: false,
|
// glassWeekShow: false,
|
||||||
// proWeekShow: false,
|
// proWeekShow: false,
|
||||||
tableData: [],
|
tableData: [],
|
||||||
tableProps: [
|
tableProps: [],
|
||||||
{
|
tableData1: [],
|
||||||
prop: 'lineName',
|
tableProps1: [],
|
||||||
label: ''
|
resData: [],
|
||||||
},
|
span1: [], //表格1的合并规则
|
||||||
{
|
resData1: [],
|
||||||
prop: 'paramsName',
|
span2: []
|
||||||
label: ''
|
};
|
||||||
}
|
},
|
||||||
],
|
created() {
|
||||||
resData: []
|
let now = new Date()
|
||||||
}
|
|
||||||
},
|
|
||||||
created() {
|
|
||||||
let now = new Date()
|
|
||||||
now.setHours(0, 0, 0, 0)
|
now.setHours(0, 0, 0, 0)
|
||||||
now.setDate(1)
|
now.setDate(1)
|
||||||
let startOfMonth = now.getTime()
|
let startOfMonth = now.getTime()
|
||||||
let firstDayOfMonth = new Date(startOfMonth)
|
let firstDayOfMonth = new Date(startOfMonth)
|
||||||
this.listQuery.time = parseTime(firstDayOfMonth)
|
this.listQuery.time = parseTime(firstDayOfMonth)
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.getList()
|
this.getList();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
/** 合并table列的规则 */
|
async getList() {
|
||||||
mergeColumnHandler({ row, column, rowIndex, columnIndex }) {
|
this.tableData = [];
|
||||||
// if (columnIndex == 0 || columnIndex == 1) {
|
this.tableProps = [
|
||||||
// if (this.spanInfo[rowIndex]) {
|
{
|
||||||
// return [
|
prop: 'lineName',
|
||||||
// this.spanInfo[rowIndex], // row span
|
label: '',
|
||||||
// 1, // col span
|
fixed: true,
|
||||||
// ];
|
},
|
||||||
// } else {
|
{
|
||||||
// return [0, 0];
|
prop: 'paramsName',
|
||||||
// }
|
label: '',
|
||||||
// }
|
fixed: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
this.tableData1 = [];
|
||||||
|
this.tableProps1 = [
|
||||||
|
{
|
||||||
|
prop: 'lineName',
|
||||||
|
label: '',
|
||||||
|
fixed: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
prop: 'paramsName',
|
||||||
|
label: '',
|
||||||
|
fixed: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
await productionMonthY(this.listQuery).then((res) => {
|
||||||
|
this.resData = res.data;
|
||||||
|
// 设置表头
|
||||||
|
Object.keys(this.resData).forEach((item) => {
|
||||||
|
this.tableProps.push({
|
||||||
|
prop: item,
|
||||||
|
label: item,
|
||||||
|
'show-overflow-tooltip': true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.buildTableData(this.resData);
|
||||||
|
});
|
||||||
|
await productionMonthD(this.listQuery).then((res) => {
|
||||||
|
this.resData1 = res.data;
|
||||||
|
// 设置表头
|
||||||
|
Object.keys(this.resData1).forEach((item) => {
|
||||||
|
this.tableProps1.push({
|
||||||
|
prop: item,
|
||||||
|
label: item,
|
||||||
|
'show-overflow-tooltip': true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.buildTableData1(this.resData1);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
async getList() {
|
// 设置表格2数据
|
||||||
this.tableData = []
|
buildTableData1(data) {
|
||||||
this.tableProps = [
|
let keys = Object.keys(data);
|
||||||
{
|
let tempData = [];
|
||||||
prop: 'lineName',
|
let subKeys = Object.keys(data[keys[0]]);
|
||||||
label: ''
|
let sub2Keys = Object.keys(data[keys[0]][subKeys[0]]);
|
||||||
},
|
for (let i = 0; i < keys.length; i++) {
|
||||||
{
|
if (i === 0) {
|
||||||
prop: 'paramsName',
|
for (let j = 0; j < subKeys.length; j++) {
|
||||||
label: ''
|
for (let k = 0; k < sub2Keys.length; k++) {
|
||||||
}
|
let obj = {};
|
||||||
]
|
obj.lineName = subKeys[j];
|
||||||
await productionMonthY(this.listQuery).then(res => {
|
obj.paramsName = sub2Keys[k];
|
||||||
this.resData = res.data
|
obj[keys[0]] = data[keys[0]][subKeys[j]][sub2Keys[k]];
|
||||||
// 设置表头
|
tempData.push(obj);
|
||||||
Object.keys(this.resData).forEach(item => {
|
}
|
||||||
this.tableProps.push({
|
}
|
||||||
prop: item,
|
} else {
|
||||||
label: item,
|
for (let j = 0; j < subKeys.length; j++) {
|
||||||
'show-overflow-tooltip': true
|
for (let k = 0; k < sub2Keys.length; k++) {
|
||||||
})
|
for (let v = 0; v < tempData.length; v++) {
|
||||||
})
|
if (
|
||||||
this.buildTableData()
|
tempData[v].lineName === subKeys[j] &&
|
||||||
})
|
tempData[v].paramsName === sub2Keys[k]
|
||||||
await productionMonthD(this.listQuery).then(res => {
|
) {
|
||||||
console.log('11', res.data)
|
tempData[v][keys[i]] = data[keys[i]][subKeys[j]][sub2Keys[k]];
|
||||||
// this.resData = res.data
|
}
|
||||||
// // 设置表头
|
}
|
||||||
// Object.keys(this.resData).forEach(item => {
|
}
|
||||||
// this.tableProps.push({
|
}
|
||||||
// prop: item,
|
}
|
||||||
// label: item,
|
}
|
||||||
// 'show-overflow-tooltip': true
|
this.tableData1 = tempData;
|
||||||
// })
|
this.getSpanArr1(this.tableData1);
|
||||||
// })
|
},
|
||||||
// this.buildTableData()
|
// 设置表格数据
|
||||||
})
|
buildTableData(data) {
|
||||||
},
|
let keys = Object.keys(data);
|
||||||
// 设置表格数据
|
let tempData = [];
|
||||||
buildTableData() {
|
let subKeys = Object.keys(data[keys[0]]);
|
||||||
const temp = Object.values(this.resData)
|
let sub2Keys = Object.keys(data[keys[0]][subKeys[0]]);
|
||||||
console.log('temp', temp)
|
for (let i = 0; i < keys.length; i++) {
|
||||||
const dataArray = []
|
if (i === 0) {
|
||||||
// Object.entries(this.resData).forEach(en => {
|
for (let j = 0; j < subKeys.length; j++) {
|
||||||
// console.log('你好', en)
|
for (let k = 0; k < sub2Keys.length; k++) {
|
||||||
// const date = en[0]
|
let obj = {};
|
||||||
// let valueArray = []
|
obj.lineName = subKeys[j];
|
||||||
// Object.entries(en[1]).forEach((values, sequence) => {
|
obj.paramsName = sub2Keys[k];
|
||||||
// let yValue = {}
|
obj[keys[0]] = data[keys[0]][subKeys[j]][sub2Keys[k]];
|
||||||
// yValue['line'] = values[0]
|
tempData.push(obj);
|
||||||
// Object.entries(values[1]).forEach((lastV, index) => {
|
}
|
||||||
// console.log(lastV)
|
}
|
||||||
// const tempValue = {}
|
} else {
|
||||||
// if (values[0] === yValue['line']) {
|
for (let j = 0; j < subKeys.length; j++) {
|
||||||
// tempValue[values[0]] = lastV[1]
|
for (let k = 0; k < sub2Keys.length; k++) {
|
||||||
// }
|
for (let v = 0; v < tempData.length; v++) {
|
||||||
// valueArray.push(tempValue)
|
if (
|
||||||
// })
|
tempData[v].lineName === subKeys[j] &&
|
||||||
// yValue[date+'-'+sequence] = valueArray
|
tempData[v].paramsName === sub2Keys[k]
|
||||||
// dataArray.push(yValue)
|
) {
|
||||||
// })
|
tempData[v][keys[i]] = data[keys[i]][subKeys[j]][sub2Keys[k]];
|
||||||
// })
|
}
|
||||||
// for (let key in temp) {
|
}
|
||||||
// console.log('你好', temp[key])
|
}
|
||||||
// }
|
}
|
||||||
// 产线
|
}
|
||||||
Object.keys(temp[0]).forEach(item => {
|
}
|
||||||
// 规格循环
|
this.tableData = tempData;
|
||||||
Object.keys(Object.values(temp[0])[0]).forEach(it => {
|
this.getSpanArr(this.tableData);
|
||||||
const row = {
|
},
|
||||||
lineName: item,
|
getSpanArr1(data) {
|
||||||
paramsName: it
|
this.span2 = [];
|
||||||
}
|
for (var i = 0; i < data.length; i++) {
|
||||||
this.tableData.push(row)
|
if (i === 0) {
|
||||||
})
|
this.span2.push(1);
|
||||||
})
|
this.index1 = 0;
|
||||||
},
|
} else {
|
||||||
handleExport() {
|
if (data[i].lineName === data[i - 1].lineName) {
|
||||||
const xlsxParam = { raw: true }
|
this.span2[this.index1] += 1;
|
||||||
let workbook = XLSX.utils.book_new()
|
this.span2.push(0);
|
||||||
var ws = XLSX.utils.table_to_sheet( document.querySelector('#exportTable'), xlsxParam)
|
} else {
|
||||||
XLSX.utils.book_append_sheet(workbook, ws, '许昌安彩月原片生产汇总')
|
this.span2.push(1);
|
||||||
var prows = XLSX.utils.table_to_sheet( document.querySelector('#exportproductionTable'), xlsxParam)
|
this.index1 = i;
|
||||||
XLSX.utils.book_append_sheet(workbook, prows, '许昌安彩月成品生产汇总')
|
}
|
||||||
let fileName = '生产数据汇总表-月报.xlsx';
|
}
|
||||||
var wbout = XLSX.write(workbook, {
|
}
|
||||||
bookType: 'xlsx',
|
},
|
||||||
bookSST: true,
|
// 获取合并行
|
||||||
type: 'array',
|
getSpanArr(data) {
|
||||||
});
|
this.span1 = [];
|
||||||
try {
|
for (var i = 0; i < data.length; i++) {
|
||||||
FileSaver.saveAs(
|
if (i === 0) {
|
||||||
new Blob([wbout], { type: 'application/octet-stream' }),
|
this.span1.push(1);
|
||||||
fileName
|
this.index = 0;
|
||||||
);
|
} else {
|
||||||
this.$message.success('导出成功');
|
if (data[i].lineName === data[i - 1].lineName) {
|
||||||
} catch (e) {
|
this.span1[this.index] += 1;
|
||||||
if (typeof console !== 'undefined') console.log(e, wbout);
|
this.span1.push(0);
|
||||||
}
|
} else {
|
||||||
return wbout;
|
this.span1.push(1);
|
||||||
},
|
this.index = i;
|
||||||
handleEmitFun(payload) {
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
objectSpanMethod1({ rowIndex, columnIndex }) {
|
||||||
|
if (columnIndex === 0) {
|
||||||
|
const _row = this.span1[rowIndex];
|
||||||
|
return {
|
||||||
|
rowspan: _row,
|
||||||
|
colspan: 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleExport() {
|
||||||
|
const xlsxParam = { raw: true };
|
||||||
|
let tables = document.querySelector('.el-table').cloneNode(true)
|
||||||
|
const fix = tables.querySelector('.el-table__fixed')
|
||||||
|
const fixRight = tables.querySelector('.el-table__fixed-right')
|
||||||
|
if (fix) {
|
||||||
|
tables.removeChild(tables.querySelector('.el-table__fixed'))
|
||||||
|
}
|
||||||
|
if (fixRight) {
|
||||||
|
tables.removeChild(tables.querySelector('.el-table__fixed-right'))
|
||||||
|
}
|
||||||
|
let workbook = XLSX.utils.book_new();
|
||||||
|
var ws = XLSX.utils.table_to_sheet(
|
||||||
|
tables,
|
||||||
|
xlsxParam
|
||||||
|
);
|
||||||
|
XLSX.utils.book_append_sheet(workbook, ws, '许昌安彩月原片生产汇总');
|
||||||
|
|
||||||
|
let tables1 = document.querySelectorAll('.el-table')[1].cloneNode(true)
|
||||||
|
const fix1 = tables1.querySelector('.el-table__fixed')
|
||||||
|
const fixRight1 = tables1.querySelector('.el-table__fixed-right')
|
||||||
|
if (fix1) {
|
||||||
|
tables1.removeChild(fix1)
|
||||||
|
}
|
||||||
|
if (fixRight1) {
|
||||||
|
tables1.removeChild(fixRight1)
|
||||||
|
}
|
||||||
|
var prows = XLSX.utils.table_to_sheet(
|
||||||
|
tables1,
|
||||||
|
xlsxParam
|
||||||
|
);
|
||||||
|
XLSX.utils.book_append_sheet(workbook, prows, '许昌安彩月成品生产汇总');
|
||||||
|
let fileName = '生产数据汇总表-月报.xlsx';
|
||||||
|
var wbout = XLSX.write(workbook, {
|
||||||
|
bookType: 'xlsx',
|
||||||
|
bookSST: true,
|
||||||
|
type: 'array',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
FileSaver.saveAs(
|
||||||
|
new Blob([wbout], { type: 'application/octet-stream' }),
|
||||||
|
fileName
|
||||||
|
);
|
||||||
|
this.$message.success('导出成功');
|
||||||
|
} catch (e) {
|
||||||
|
if (typeof console !== 'undefined') console.log(e, wbout);
|
||||||
|
}
|
||||||
|
return wbout;
|
||||||
|
},
|
||||||
|
handleEmitFun(payload) {
|
||||||
console.log('payload', payload);
|
console.log('payload', payload);
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.weekly {
|
.weekly {
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
}
|
}
|
||||||
.blueTip::before{
|
.blueTip::before {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
content: '';
|
content: '';
|
||||||
width: 4px;
|
width: 4px;
|
||||||
height: 18px;
|
height: 18px;
|
||||||
background: #0B58FF;
|
background: #0b58ff;
|
||||||
border-radius: 1px;
|
border-radius: 1px;
|
||||||
margin-right: 8PX;
|
margin-right: 8px;
|
||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
margin-left: 16px;
|
margin-left: 16px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -1,137 +1,341 @@
|
|||||||
<!--
|
<!--
|
||||||
* @Author: Do not edit
|
* @Author: Do not edit
|
||||||
* @Date: 2024-04-22 15:49:56
|
* @Date: 2024-04-22 15:49:56
|
||||||
* @LastEditTime: 2024-04-24 15:49:32
|
* @LastEditTime: 2024-04-25 09:54:39
|
||||||
* @LastEditors: DY
|
* @LastEditors: DY
|
||||||
* @Description:
|
* @Description:
|
||||||
-->
|
-->
|
||||||
<template>
|
<template>
|
||||||
<div class="weekly">
|
<div class="weekly">
|
||||||
<el-form :inline="true" :model="listQuery" class="blueTip">
|
<el-form
|
||||||
<el-form-item label="年" prop="reportTime">
|
:inline="true"
|
||||||
<el-date-picker v-model="reportTime" type="year" size="small" @change="changeTime"
|
:model="listQuery"
|
||||||
:picker-options="{firstDayOfWeek: 1}" :format="'yyyy 年' + '\u3000' + startTimeStamp + '-' + endTimeStamp"
|
class="blueTip">
|
||||||
style="width: 350px" placeholder="选择年">
|
<el-form-item
|
||||||
</el-date-picker>
|
label="月"
|
||||||
</el-form-item>
|
prop="reportTime">
|
||||||
<el-button v-if="this.$auth.hasPermi('base:report-auto-production:query')" type="primary" size="small" @click="search()">
|
<el-date-picker
|
||||||
查询
|
v-model="listQuery.time"
|
||||||
</el-button>
|
value-format="yyyy-MM-dd HH:mm:ss"
|
||||||
<el-button v-if="this.$auth.hasPermiAnd(['base:report-auto-original-glass:export', 'base:report-auto-production:export'])" type="primary" size="small" plain
|
type="year"
|
||||||
@click="handleExport">导出</el-button>
|
size="small"
|
||||||
</el-form>
|
placeholder="选择年"></el-date-picker>
|
||||||
<glassYear v-if="glassYearShow" ref="glassYear" :product="false" :params="listQuery" />
|
</el-form-item>
|
||||||
<proYear v-if="proYearShow" ref="proYear" :product="false" :params="listQuery" />
|
<el-button
|
||||||
</div>
|
v-if="this.$auth.hasPermi('base:report-auto-production:query')"
|
||||||
|
type="primary"
|
||||||
|
size="small"
|
||||||
|
@click="getList">
|
||||||
|
查询
|
||||||
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="
|
||||||
|
this.$auth.hasPermiAnd([
|
||||||
|
'base:report-auto-original-glass:export',
|
||||||
|
'base:report-auto-production:export',
|
||||||
|
])
|
||||||
|
"
|
||||||
|
type="primary"
|
||||||
|
size="small"
|
||||||
|
plain
|
||||||
|
@click="handleExport">
|
||||||
|
导出
|
||||||
|
</el-button>
|
||||||
|
</el-form>
|
||||||
|
<base-table
|
||||||
|
:table-props="tableProps"
|
||||||
|
:table-data="tableData"
|
||||||
|
:span-method="objectSpanMethod1"
|
||||||
|
@emitFun="handleEmitFun"
|
||||||
|
:max-height="tableH" />
|
||||||
|
<base-table
|
||||||
|
:table-props="tableProps1"
|
||||||
|
:table-data="tableData1"
|
||||||
|
:span-method="objectSpanMethod1"
|
||||||
|
@emitFun="handleEmitFun"
|
||||||
|
:max-height="tableH"
|
||||||
|
style="margin-top: 15px" />
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import glassYear from '../glass/year.vue'
|
import { productionYearY, productionYearD } from '@/api/report/glass';
|
||||||
import proYear from '../productionYearReport/index.vue'
|
import { parseTime } from '../../core/mixins/code-filter';
|
||||||
import { parseTime } from '../../core/mixins/code-filter'
|
import FileSaver from 'file-saver';
|
||||||
import FileSaver from 'file-saver'
|
import * as XLSX from 'xlsx/xlsx.mjs';
|
||||||
import * as XLSX from 'xlsx/xlsx.mjs'
|
import tableHeightMixin from '@/mixins/lb/tableHeightMixin';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: { glassYear, proYear },
|
// components: { monthWeek, proMonth },
|
||||||
data() {
|
mixins: [tableHeightMixin],
|
||||||
return {
|
data() {
|
||||||
listQuery: {
|
return {
|
||||||
// pageSize: 10,
|
heightNum: 350,
|
||||||
// pageNo: 1,
|
listQuery: {
|
||||||
// total: 0,
|
time: '',
|
||||||
reportType: 5,
|
},
|
||||||
reportTime: []
|
// startTimeStamp: '',
|
||||||
},
|
// endTimeStamp: '',
|
||||||
startTimeStamp: '',
|
// reportTime: '',
|
||||||
endTimeStamp: '',
|
// glassWeekShow: false,
|
||||||
reportTime: '',
|
// proWeekShow: false,
|
||||||
glassYearShow: false,
|
tableData: [],
|
||||||
proYearShow: false
|
tableProps: [],
|
||||||
}
|
tableData1: [],
|
||||||
},
|
tableProps1: [],
|
||||||
created() {
|
resData: [],
|
||||||
this.getCurrentYearFirst()
|
span1: [], //表格1的合并规则
|
||||||
this.glassYearShow = true
|
resData1: [],
|
||||||
this.proYearShow = true
|
span2: []
|
||||||
},
|
};
|
||||||
methods: {
|
},
|
||||||
handleExport() {
|
created() {
|
||||||
const xlsxParam = { raw: true }
|
let now = new Date()
|
||||||
let workbook = XLSX.utils.book_new()
|
now.setHours(0, 0, 0, 0)
|
||||||
var ws = XLSX.utils.table_to_sheet( document.querySelector('#exportTable'), xlsxParam)
|
now.setDate(1)
|
||||||
XLSX.utils.book_append_sheet(workbook, ws, '许昌安彩年原片生产汇总')
|
let startOfMonth = now.getTime()
|
||||||
var prows = XLSX.utils.table_to_sheet( document.querySelector('#exportproductionTable'), xlsxParam)
|
let firstDayOfMonth = new Date(startOfMonth)
|
||||||
XLSX.utils.book_append_sheet(workbook, prows, '许昌安彩年成品生产汇总')
|
this.listQuery.time = parseTime(firstDayOfMonth)
|
||||||
let fileName = '生产数据汇总表-年报.xlsx';
|
},
|
||||||
var wbout = XLSX.write(workbook, {
|
mounted() {
|
||||||
bookType: 'xlsx',
|
this.getList();
|
||||||
bookSST: true,
|
},
|
||||||
type: 'array',
|
methods: {
|
||||||
});
|
async getList() {
|
||||||
try {
|
this.tableData = [];
|
||||||
FileSaver.saveAs(
|
this.tableProps = [
|
||||||
new Blob([wbout], { type: 'application/octet-stream' }),
|
{
|
||||||
fileName
|
prop: 'lineName',
|
||||||
);
|
label: '',
|
||||||
this.$message.success('导出成功');
|
fixed: true,
|
||||||
} catch (e) {
|
},
|
||||||
if (typeof console !== 'undefined') console.log(e, wbout);
|
{
|
||||||
}
|
prop: 'paramsName',
|
||||||
return wbout;
|
label: '',
|
||||||
},
|
fixed: true,
|
||||||
search() {
|
},
|
||||||
this.$nextTick(() => {
|
];
|
||||||
this.$refs['glassYear'].getDataList()
|
this.tableData1 = [];
|
||||||
this.$refs['proYear'].getDataList()
|
this.tableProps1 = [
|
||||||
})
|
{
|
||||||
},
|
prop: 'lineName',
|
||||||
changeTime(val) {
|
label: '',
|
||||||
if(val) {
|
fixed: true,
|
||||||
// let timeStamp = val.getTime(); //标准时间转为时间戳,毫秒级别
|
},
|
||||||
this.endTimeStamp = this.timeFun(new Date(val.getFullYear(),11, 31, 7, 0, 0).getTime()); //开始时间
|
{
|
||||||
this.startTimeStamp = this.timeFun(new Date(val.getFullYear(), 0, 1, 7, 0, 1).getTime()); //结束时间
|
prop: 'paramsName',
|
||||||
this.listQuery.reportTime[0] = parseTime(new Date(val.getFullYear(), 0, 1, 7, 0, 1).getTime()) //+ ' 00:00:00' //new Date(this.startTimeStamp + ' 00:00:00').getTime() / 1000
|
label: '',
|
||||||
this.listQuery.reportTime[1] = parseTime(new Date(val.getFullYear(), 11, 31, 7, 0, 0).getTime()) //+ ' 23:59:59' //new Date(this.endTimeStamp + ' 23:59:59').getTime() / 1000
|
fixed: true,
|
||||||
} else {
|
},
|
||||||
this.listQuery.reportTime = []
|
];
|
||||||
|
await productionYearY(this.listQuery).then((res) => {
|
||||||
|
this.resData = res.data;
|
||||||
|
// 设置表头
|
||||||
|
Object.keys(this.resData).forEach((item) => {
|
||||||
|
this.tableProps.push({
|
||||||
|
prop: item,
|
||||||
|
label: item,
|
||||||
|
'show-overflow-tooltip': true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.buildTableData(this.resData);
|
||||||
|
});
|
||||||
|
await productionYearD(this.listQuery).then((res) => {
|
||||||
|
this.resData1 = res.data;
|
||||||
|
// 设置表头
|
||||||
|
Object.keys(this.resData1).forEach((item) => {
|
||||||
|
this.tableProps1.push({
|
||||||
|
prop: item,
|
||||||
|
label: item,
|
||||||
|
'show-overflow-tooltip': true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.buildTableData1(this.resData1);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// 设置表格2数据
|
||||||
|
buildTableData1(data) {
|
||||||
|
let keys = Object.keys(data);
|
||||||
|
let tempData = [];
|
||||||
|
let subKeys = Object.keys(data[keys[0]]);
|
||||||
|
let sub2Keys = Object.keys(data[keys[0]][subKeys[0]]);
|
||||||
|
for (let i = 0; i < keys.length; i++) {
|
||||||
|
if (i === 0) {
|
||||||
|
for (let j = 0; j < subKeys.length; j++) {
|
||||||
|
for (let k = 0; k < sub2Keys.length; k++) {
|
||||||
|
let obj = {};
|
||||||
|
obj.lineName = subKeys[j];
|
||||||
|
obj.paramsName = sub2Keys[k];
|
||||||
|
obj[keys[0]] = data[keys[0]][subKeys[j]][sub2Keys[k]];
|
||||||
|
tempData.push(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (let j = 0; j < subKeys.length; j++) {
|
||||||
|
for (let k = 0; k < sub2Keys.length; k++) {
|
||||||
|
for (let v = 0; v < tempData.length; v++) {
|
||||||
|
if (
|
||||||
|
tempData[v].lineName === subKeys[j] &&
|
||||||
|
tempData[v].paramsName === sub2Keys[k]
|
||||||
|
) {
|
||||||
|
tempData[v][keys[i]] = data[keys[i]][subKeys[j]][sub2Keys[k]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.tableData1 = tempData;
|
||||||
|
this.getSpanArr1(this.tableData1);
|
||||||
|
},
|
||||||
|
// 设置表格数据
|
||||||
|
buildTableData(data) {
|
||||||
|
let keys = Object.keys(data);
|
||||||
|
let tempData = [];
|
||||||
|
let subKeys = Object.keys(data[keys[0]]);
|
||||||
|
let sub2Keys = Object.keys(data[keys[0]][subKeys[0]]);
|
||||||
|
for (let i = 0; i < keys.length; i++) {
|
||||||
|
if (i === 0) {
|
||||||
|
for (let j = 0; j < subKeys.length; j++) {
|
||||||
|
for (let k = 0; k < sub2Keys.length; k++) {
|
||||||
|
let obj = {};
|
||||||
|
obj.lineName = subKeys[j];
|
||||||
|
obj.paramsName = sub2Keys[k];
|
||||||
|
obj[keys[0]] = data[keys[0]][subKeys[j]][sub2Keys[k]];
|
||||||
|
tempData.push(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (let j = 0; j < subKeys.length; j++) {
|
||||||
|
for (let k = 0; k < sub2Keys.length; k++) {
|
||||||
|
for (let v = 0; v < tempData.length; v++) {
|
||||||
|
if (
|
||||||
|
tempData[v].lineName === subKeys[j] &&
|
||||||
|
tempData[v].paramsName === sub2Keys[k]
|
||||||
|
) {
|
||||||
|
tempData[v][keys[i]] = data[keys[i]][subKeys[j]][sub2Keys[k]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.tableData = tempData;
|
||||||
|
this.getSpanArr(this.tableData);
|
||||||
|
},
|
||||||
|
getSpanArr1(data) {
|
||||||
|
this.span2 = [];
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
if (i === 0) {
|
||||||
|
this.span2.push(1);
|
||||||
|
this.index1 = 0;
|
||||||
|
} else {
|
||||||
|
if (data[i].lineName === data[i - 1].lineName) {
|
||||||
|
this.span2[this.index1] += 1;
|
||||||
|
this.span2.push(0);
|
||||||
|
} else {
|
||||||
|
this.span2.push(1);
|
||||||
|
this.index1 = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getCurrentYearFirst() {
|
// 获取合并行
|
||||||
let date = new Date();
|
getSpanArr(data) {
|
||||||
date.setDate(1);
|
this.span1 = [];
|
||||||
date.setMonth(0);
|
for (var i = 0; i < data.length; i++) {
|
||||||
this.reportTime = date;
|
if (i === 0) {
|
||||||
this.startTimeStamp = this.timeFun(new Date(new Date().getFullYear(), 0, 1,7,0,1).getTime()); //开始时间
|
this.span1.push(1);
|
||||||
this.endTimeStamp = this.timeFun(new Date(new Date().getFullYear(), 11, 31, 7, 0, 0).getTime()); //结束时间
|
this.index = 0;
|
||||||
this.listQuery.reportTime[0] = parseTime(new Date(new Date().getFullYear(), 0, 1, 7, 0, 1).getTime()) //+ ' 00:00:00' //new Date(this.startTimeStamp + ' 00:00:00').getTime() / 1000
|
} else {
|
||||||
this.listQuery.reportTime[1] = parseTime(new Date(new Date().getFullYear(), 11, 31, 7, 0, 0).getTime()) //+ ' 23:59:59' //new Date(this.endTimeStamp + ' 23:59:59').getTime() / 100
|
if (data[i].lineName === data[i - 1].lineName) {
|
||||||
},
|
this.span1[this.index] += 1;
|
||||||
//时间戳转为yy-mm-dd hh:mm:ss
|
this.span1.push(0);
|
||||||
timeFun(unixtimestamp) {
|
} else {
|
||||||
var unixtimestamp = new Date(unixtimestamp);
|
this.span1.push(1);
|
||||||
var year = 1900 + unixtimestamp.getYear();
|
this.index = i;
|
||||||
var month = "0" + (unixtimestamp.getMonth() + 1);
|
}
|
||||||
var date = "0" + unixtimestamp.getDate();
|
}
|
||||||
return year + "-" + month.substring(month.length - 2, month.length) + "-" + date.substring(date.length - 2, date.length)
|
}
|
||||||
},
|
},
|
||||||
}
|
objectSpanMethod1({ rowIndex, columnIndex }) {
|
||||||
}
|
if (columnIndex === 0) {
|
||||||
|
const _row = this.span1[rowIndex];
|
||||||
|
return {
|
||||||
|
rowspan: _row,
|
||||||
|
colspan: 1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
},
|
||||||
|
handleExport() {
|
||||||
|
const xlsxParam = { raw: true };
|
||||||
|
let tables = document.querySelector('.el-table').cloneNode(true)
|
||||||
|
const fix = tables.querySelector('.el-table__fixed')
|
||||||
|
const fixRight = tables.querySelector('.el-table__fixed-right')
|
||||||
|
if (fix) {
|
||||||
|
tables.removeChild(tables.querySelector('.el-table__fixed'))
|
||||||
|
}
|
||||||
|
if (fixRight) {
|
||||||
|
tables.removeChild(tables.querySelector('.el-table__fixed-right'))
|
||||||
|
}
|
||||||
|
let workbook = XLSX.utils.book_new();
|
||||||
|
var ws = XLSX.utils.table_to_sheet(
|
||||||
|
tables,
|
||||||
|
xlsxParam
|
||||||
|
);
|
||||||
|
XLSX.utils.book_append_sheet(workbook, ws, '许昌安彩年原片生产汇总');
|
||||||
|
|
||||||
|
let tables1 = document.querySelectorAll('.el-table')[1].cloneNode(true)
|
||||||
|
const fix1 = tables1.querySelector('.el-table__fixed')
|
||||||
|
const fixRight1 = tables1.querySelector('.el-table__fixed-right')
|
||||||
|
if (fix1) {
|
||||||
|
tables1.removeChild(tables1.querySelector('.el-table__fixed'))
|
||||||
|
}
|
||||||
|
if (fixRight1) {
|
||||||
|
tables1.removeChild(tables1.querySelector('.el-table__fixed-right'))
|
||||||
|
}
|
||||||
|
var prows = XLSX.utils.table_to_sheet(
|
||||||
|
tables1,
|
||||||
|
xlsxParam
|
||||||
|
);
|
||||||
|
XLSX.utils.book_append_sheet(workbook, prows, '许昌安彩年成品生产汇总');
|
||||||
|
let fileName = '生产数据汇总表-年报.xlsx';
|
||||||
|
var wbout = XLSX.write(workbook, {
|
||||||
|
bookType: 'xlsx',
|
||||||
|
bookSST: true,
|
||||||
|
type: 'array',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
FileSaver.saveAs(
|
||||||
|
new Blob([wbout], { type: 'application/octet-stream' }),
|
||||||
|
fileName
|
||||||
|
);
|
||||||
|
this.$message.success('导出成功');
|
||||||
|
} catch (e) {
|
||||||
|
if (typeof console !== 'undefined') console.log(e, wbout);
|
||||||
|
}
|
||||||
|
return wbout;
|
||||||
|
},
|
||||||
|
handleEmitFun(payload) {
|
||||||
|
console.log('payload', payload);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.weekly {
|
.weekly {
|
||||||
padding-top: 16px;
|
padding: 16px;
|
||||||
}
|
}
|
||||||
.blueTip::before{
|
.blueTip::before {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
content: '';
|
content: '';
|
||||||
width: 4px;
|
width: 4px;
|
||||||
height: 18px;
|
height: 18px;
|
||||||
background: #0B58FF;
|
background: #0b58ff;
|
||||||
border-radius: 1px;
|
border-radius: 1px;
|
||||||
margin-right: 8PX;
|
margin-right: 8px;
|
||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
margin-left: 16px;
|
margin-left: 16px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
Loading…
Reference in New Issue
Block a user