yudao-init/src/views/produce/data/index.vue

519 lines
18 KiB
Vue
Raw Normal View History

2024-04-17 16:17:07 +08:00
<!--
* @Author: zhp
* @Date: 2024-04-15 10:49:13
2024-06-03 08:37:31 +08:00
* @LastEditTime: 2024-05-31 19:14:05
2024-05-20 14:55:36 +08:00
* @LastEditors: DY
2024-04-17 16:17:07 +08:00
* @Description:
-->
<template>
<div style="display: flex; flex-direction: column; min-height: calc(100vh - 96px - 31px)">
<div class="app-container" style="padding: 16px 24px 0;height: auto; flex-grow: 1;">
<el-form :model="listQuery" :inline="true" ref="dataForm" class="blueTip">
2024-05-20 14:55:36 +08:00
<el-form-item label="时间维度" prop="date">
2024-06-03 08:37:31 +08:00
<el-select size="small" clearable v-model="listQuery.mode" placeholder="请选择">
2024-04-17 16:17:07 +08:00
<el-option v-for="item in timeList" :key="item.value" :label="item.label" :value="item.value">
</el-option>
</el-select>
</el-form-item>
2024-06-03 08:37:31 +08:00
<el-form-item v-show="listQuery.mode === 0 || listQuery.mode === ''" label="时间范围" prop="reportTime">
2024-05-20 14:55:36 +08:00
<el-date-picker size="small" clearable v-model="listQuery.reportTime" type="datetimerange" range-separator=""
2024-06-03 08:37:31 +08:00
start-placeholder="开始日期" value-format="timestamp" format="yyyy-MM-dd" @change="changeDayTime" end-placeholder="结束日期">
2024-04-17 16:17:07 +08:00
</el-date-picker>
</el-form-item>
2024-06-03 08:37:31 +08:00
<el-form-item v-show="listQuery.mode === 1" label="时间范围" prop="reportTime">
2024-05-20 14:55:36 +08:00
<el-date-picker size="small" clearable v-model="listQuery.start" type="week" format="yyyy 第 WW 周" placeholder="选择周"
2024-04-17 16:17:07 +08:00
style="width: 180px" @change="onValueChange">
</el-date-picker>
2024-05-20 14:55:36 +08:00
<el-date-picker size="small" clearable v-model="listQuery.end" type="week" format="yyyy 第 WW 周" placeholder="选择周"
2024-04-17 16:17:07 +08:00
style="width: 180px" @change="onValueChange">
</el-date-picker>
2024-05-20 14:55:36 +08:00
<span v-if="listQuery.start && listQuery.end" style="margin-left: 10px">
2024-04-17 16:17:07 +08:00
{{ date1 }} {{ date2 }} {{ weekNum }}
</span>
</el-form-item>
2024-06-03 08:37:31 +08:00
<el-form-item v-show="listQuery.mode === 2" label="时间范围" prop="reportTime">
2024-05-20 14:55:36 +08:00
<el-date-picker size="small" clearable v-model="listQuery.reportTime" type="monthrange" value-format="timestamp" range-separator=""
2024-04-17 16:17:07 +08:00
start-placeholder="开始月份" end-placeholder="结束月份" @change="changeTime">
</el-date-picker>
</el-form-item>
2024-06-03 08:37:31 +08:00
<el-form-item v-show="listQuery.mode === 3" label="时间范围" prop="reportTime">
2024-05-22 16:28:47 +08:00
<el-date-picker size="small" clearable v-model="listQuery.start" format="yyyy-MM-dd" value-format="timestamp" type="year"
2024-04-17 16:17:07 +08:00
placeholder="开始时间">
</el-date-picker>
~
2024-05-22 16:28:47 +08:00
<el-date-picker size="small" clearable v-model="listQuery.end" format="yyyy-MM-dd" value-format="timestamp" type="year" placeholder="结束时间"
2024-04-17 16:17:07 +08:00
@change="getYear">
</el-date-picker>
</el-form-item>
2024-05-07 10:03:55 +08:00
<el-form-item label="工厂名称" prop="factorys">
2024-05-20 14:55:36 +08:00
<el-select size="small" clearable v-model="listQuery.factorys" placeholder="请选择工厂名称" multiple >
2024-06-03 08:37:31 +08:00
<el-option v-for="item in factoryArray" :key="item.id" :label="item.name" :value="item.id">
2024-04-17 16:17:07 +08:00
</el-option>
</el-select>
</el-form-item>
<!-- <el-form-item label="玻璃类型" prop="type">
<el-select v-model="listQuery.type" placeholder="请选择玻璃类型">
<el-option v-for="item in typeList" :key="item.id" :label="item.name" :value="item.id">
</el-option>
</el-select>
</el-form-item> -->
<el-form-item label="玻璃类型" prop="type">
2024-06-03 08:37:31 +08:00
<el-select size="small" clearable v-model="listQuery.type" multiple placeholder="请选择玻璃类型">
2024-04-17 16:17:07 +08:00
<el-option v-for="item in typeList" :key="item.id" :label="item.name" :value="item.id">
</el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" size="small" @click="getDataList">查询</el-button>
<el-button type="primary" size="small" plain @click="handleExport">导出</el-button>
</el-form-item>
</el-form>
2024-05-20 14:55:36 +08:00
</div>
<div class="app-container" style="margin-top: 8px;padding: 16px; height: auto; flex-grow: 1;">
2024-04-17 16:17:07 +08:00
<!-- <el-row :gutter="24"> -->
<!-- <el-col :span="12" v-for="item in dataList" :key="item.id"> -->
2024-05-20 14:55:36 +08:00
<search-bar :formConfigs="formConfig1" ref="searchBarForm1" style="margin-bottom: 0" />
2024-04-17 16:17:07 +08:00
<line-chart class="yearChart" ref="lineChart" style="height: 40vh;width: 100%"></line-chart>
<!-- </el-col> -->
<!-- <el-col :span="12">
<line-chart :id=" 'second' " class="yearChart" ref="lineChart" style="height: 40vh;width: 100%"></line-chart>
</el-col> -->
</div>
2024-05-20 14:55:36 +08:00
<div class="app-container" style="margin-top: 8px;flex-grow: 1; height: auto; padding: 16px;">
<search-bar :formConfigs="formConfig" ref="searchBarForm" @headBtnClick="buttonClick" style="margin-bottom: 0" />
<base-table :table-props="tableProps" :page="listQuery.current" :limit="listQuery.size"
2024-04-17 16:17:07 +08:00
:table-data="tableData">
<method-btn v-if="tableBtn.length" slot="handleBtn" label="操作" :width="120" fixed="right"
:method-list="tableBtn" @clickBtn="handleClick" />
</base-table>
2024-05-20 14:55:36 +08:00
<pagination
:limit.sync="listQuery.size"
:page.sync="listQuery.current"
:total="listQuery.total"
@pagination="getDataList"
/>
2024-04-17 16:17:07 +08:00
</div>
2024-06-03 08:37:31 +08:00
<add-or-update v-if="detailOrUpdateVisible" ref="detailOrUpdate" :date="listQuery.mode" @refreshDataList="successSubmit" @destroy="detailOrUpdateVisible = false" />
2024-04-17 16:17:07 +08:00
<!-- <inputTable :date="date" :data="tableData" :time="[startTimeStamp, endTimeStamp]" :sum="all"
:type="listQuery.reportType" @refreshDataList="getDataList" /> -->
<!-- <pagination
:limit.sync="listQuery.pageSize"
:page.sync="listQuery.pageNo"
:total="listQuery.total"
@pagination="getDataList" /> -->
</div>
</template>
<script>
// import { parseTime } from '../../core/mixins/code-filter';
2024-06-03 08:37:31 +08:00
import { getProduceDataPage, prodOutputDataList, exportOutPutExcel } from '@/api/produceData';
2024-04-17 16:17:07 +08:00
// import inputTable from './inputTable.vue';
import lineChart from './lineChart';
import moment from 'moment'
import ButtonNav from '@/components/ButtonNav'
import basicPage from '@/mixins/basic-page'
2024-06-03 08:37:31 +08:00
import AddOrUpdate from './add-or-updata'
import { factoryList, factoryArray, factoryArray1 } from "@/utils/constants";
2024-04-17 16:17:07 +08:00
export default {
components: { lineChart, ButtonNav, AddOrUpdate },
mixins: [basicPage],
data() {
return {
2024-06-03 08:37:31 +08:00
factoryList,
factoryArray,
factoryArray1,
2024-04-17 16:17:07 +08:00
listQuery: {
2024-05-20 14:55:36 +08:00
size: 20,
2024-05-07 10:03:55 +08:00
current: 1,
2024-06-03 08:37:31 +08:00
factorys: undefined,
2024-04-17 16:17:07 +08:00
total: 0,
2024-06-03 08:37:31 +08:00
mode: 0,
2024-05-07 10:03:55 +08:00
type:undefined,
2024-04-17 16:17:07 +08:00
// reportType: 2,
2024-05-07 10:03:55 +08:00
beginTime: undefined,
endTime:undefined,
2024-05-22 16:28:47 +08:00
reportTime: [],
start: undefined,
end: undefined
2024-04-17 16:17:07 +08:00
},
detailOrUpdateVisible:false,
date1: undefined,
date2: undefined,
tableBtn: [
{
type: 'detail',
btnName: '详情',
},
// {
// type: 'delete',
// btnName: '删除',
// },
].filter((v) => v),
typeList: [
{
name: '芯片',
id: 0,
},
{
name: '标准组件',
id: 1,
},
{
name: 'BIPV产品',
id: 2,
},
],
2024-05-20 14:55:36 +08:00
formConfig: [
2024-04-17 16:17:07 +08:00
{
2024-05-20 14:55:36 +08:00
type: 'title',
label: '工厂信息',
2024-04-17 16:17:07 +08:00
},
],
2024-05-20 14:55:36 +08:00
formConfig1: [
2024-04-17 16:17:07 +08:00
{
type: 'title',
2024-05-20 14:55:36 +08:00
label: '良品数量',
2024-04-17 16:17:07 +08:00
},
],
timeList: [
{
2024-05-07 10:03:55 +08:00
value: 0,
2024-04-17 16:17:07 +08:00
label: '日'
},
{
2024-05-07 10:03:55 +08:00
value: 1,
2024-04-17 16:17:07 +08:00
label: '周'
},
{
2024-05-07 10:03:55 +08:00
value: 2,
2024-04-17 16:17:07 +08:00
label:'月'
},
{
2024-05-07 10:03:55 +08:00
value: 3,
2024-04-17 16:17:07 +08:00
label: '年'
}
],
tableProps: [
{
2024-05-20 14:55:36 +08:00
prop: 'tableTime',
2024-04-17 16:17:07 +08:00
label: '日期',
2024-05-20 14:55:36 +08:00
minWidth: 100,
showOverflowtooltip: true
2024-04-17 16:17:07 +08:00
},
{
2024-05-07 10:03:55 +08:00
prop: 'factory',
2024-04-17 16:17:07 +08:00
label: '工厂名称',
2024-06-03 08:37:31 +08:00
filter: (val) => factoryList[val],
2024-05-20 14:55:36 +08:00
minWidth: 200,
showOverflowtooltip: true
2024-04-17 16:17:07 +08:00
},
{
2024-05-07 10:03:55 +08:00
prop: 'glassType',
2024-04-17 16:17:07 +08:00
label: '玻璃类型',
2024-05-20 14:55:36 +08:00
filter: (val) => ['玻璃芯片', '标准组件', 'BIPV', '定制组件'][val]
2024-04-17 16:17:07 +08:00
},
{
2024-05-07 10:03:55 +08:00
prop: 'inputNumber',
2024-04-17 16:17:07 +08:00
label: '投入数量',
},
{
2024-05-07 10:03:55 +08:00
prop: 'outputNumber',
2024-04-17 16:17:07 +08:00
label: '产出数量',
},
{
2024-05-07 10:03:55 +08:00
prop: 'goodNumber',
2024-04-17 16:17:07 +08:00
label: '良品数量',
},
{
2024-05-07 10:03:55 +08:00
prop: 'yieldRate',
2024-04-17 16:17:07 +08:00
label: '良品率%',
2024-06-03 08:37:31 +08:00
filter: (val) => val + '%'
2024-04-17 16:17:07 +08:00
},
],
2024-05-07 10:03:55 +08:00
tableData: [],
2024-06-03 08:37:31 +08:00
lineData: [],
chart: null,
seriesList: []
2024-04-17 16:17:07 +08:00
// proLineList: [],
// all: {}
2024-06-03 08:37:31 +08:00
};
2024-04-17 16:17:07 +08:00
},
computed: {
weekNum() {
2024-05-22 16:28:47 +08:00
return Math.round((this.listQuery.end - this.listQuery.start) / (24 * 60 * 60 * 1000 * 7)) + 1
2024-04-17 16:17:07 +08:00
},
},
2024-06-03 08:37:31 +08:00
created() {
const today = new Date()
const sevenDaysAgo = new Date(today.getTime() - (7 * 24 * 60 * 60 * 1000))
this.listQuery.beginTime = sevenDaysAgo.getTime()
this.listQuery.endTime = today.getTime()
this.listQuery.reportTime = [this.listQuery.beginTime, this.listQuery.endTime]
},
2024-04-17 16:17:07 +08:00
mounted() {
},
methods: {
otherMethods(val) {
this.detailOrUpdateVisible = true;
this.addOrEditTitle = "详情";
this.$nextTick(() => {
this.$refs.detailOrUpdate.init(val.data.id);
});
},
getYear(e) {
2024-05-22 16:28:47 +08:00
if (this.listQuery.end - this.listQuery.start > 10*365*24*60*60*1000) {
2024-04-17 16:17:07 +08:00
this.$message({
message: '年份起止时间不能超过十年',
type: 'warning'
});
2024-05-20 14:55:36 +08:00
this.listQuery.reportTime = []
2024-05-22 16:28:47 +08:00
this.listQuery.start = undefined
this.listQuery.end = undefined
2024-04-17 16:17:07 +08:00
// console.log();
2024-05-20 14:55:36 +08:00
} else {
2024-05-22 16:28:47 +08:00
this.listQuery.beginTime = this.listQuery.start
this.listQuery.endTime = this.listQuery.end
2024-04-17 16:17:07 +08:00
}
// console.log(e);
},
onValueChange(picker, k) { // 选中近k周后触发的操作
2024-05-20 14:55:36 +08:00
// console.log(this.listQuery.reportTime[0], this.listQuery.reportTime[1])
2024-05-22 16:28:47 +08:00
if (this.listQuery.start && this.listQuery.end) {
2024-05-20 14:55:36 +08:00
console.log(this.listQuery.reportTime)
2024-05-22 16:28:47 +08:00
this.date1 = moment(this.listQuery.start.getTime() - 24 * 60 * 60 * 1000).format('YYYY-MM-DD HH:mm:ss')
this.date2 = moment(this.listQuery.end.getTime() + 5 * 24 * 60 * 60 * 1000).format('YYYY-MM-DD HH:mm:ss')
2024-05-20 14:55:36 +08:00
const numDays = (new Date(this.date2).getTime() - new Date(this.date1).getTime()) / (24 * 3600 * 1000);
if (numDays > 168) {
2024-04-17 16:17:07 +08:00
console.log(numDays)
this.$message({
message: '周范围不能超过24周',
type: 'warning'
});
2024-05-20 14:55:36 +08:00
} else {
2024-05-22 16:28:47 +08:00
this.listQuery.beginTime = this.listQuery.start.getTime() - 24 * 60 * 60 * 1000
this.listQuery.endTime = this.listQuery.end.getTime() + 5 * 24 * 60 * 60 * 1000
2024-04-17 16:17:07 +08:00
}
2024-05-20 14:55:36 +08:00
}
2024-04-17 16:17:07 +08:00
},
changeDayTime() {
if (this.listQuery.reportTime) {
// this.createStartDate = moment(new Date(this.listQuery.reportTime[0]), 'yyyy-MM-dd hh:mm:ss');
// this.createEndDate = moment(new Date(this.listQuery.reportTime[1]), 'yyyy-MM-dd hh:mm:ss');
console.log(this.listQuery.reportTime[1])
2024-05-20 14:55:36 +08:00
const numDays = (this.listQuery.reportTime[1] - this.listQuery.reportTime[0]) / (24 * 3600 * 1000);
if (numDays > 30) {
2024-04-17 16:17:07 +08:00
this.$message({
message: '时间范围不能超过30天',
type: 'warning'
});
this.listQuery.reportTime = [];
2024-05-20 14:55:36 +08:00
} else {
this.listQuery.beginTime = this.listQuery.reportTime[0]
this.listQuery.endTime = this.listQuery.reportTime[1]
2024-04-17 16:17:07 +08:00
}
} else {
}
},
changeTime(value) {
if (this.listQuery.reportTime) {
2024-05-20 14:55:36 +08:00
const numDays = this.listQuery.reportTime[1] - this.listQuery.reportTime[0];
if (numDays > 2*365*24*60*60*1000) {
2024-04-17 16:17:07 +08:00
this.$message({
message: '时间范围不能超过24个月',
type: 'warning'
});
this.listQuery.reportTime = [];
} else {
2024-05-20 14:55:36 +08:00
this.listQuery.beginTime = this.listQuery.reportTime[0]
this.listQuery.endTime = this.listQuery.reportTime[1]
2024-04-17 16:17:07 +08:00
}
} else {
console.log(this.listQuery.reportTime[0])
}
},
async getDataList() {
2024-06-03 08:37:31 +08:00
// const res = await getProduceDataPage(this.listQuery)
// console.log(res)
// if (res.code === 0) {
// this.tableData = res.data.records
// this.listQuery.total = res.data.total
// if (this.listQuery.total > 0) {
// this.tableData.forEach(item => {
// item.tableTime = item?.reportDate?.length > 0 ? item.reportDate[0] + '-' + item.reportDate[1] + '-' + item.reportDate[2] : '--'
// })
// }
// }
// 图表
await prodOutputDataList({
current: 1,
size: 99,
beginTime: this.listQuery.beginTime,
endTime: this.listQuery.endTime,
factorys: this.listQuery.factorys,
mode: this.listQuery.mode,
type: this.listQuery.type
}).then(resp => {
console.log('Aaa', resp.data)
this.lineData = resp?.data || []
if (this.lineData.length > 0) {
this.buildChart(this.lineData)
}
2024-05-20 14:55:36 +08:00
})
2024-06-03 08:37:31 +08:00
// this.buildChart(this.tableData)
2024-04-17 16:17:07 +08:00
},
2024-05-22 16:28:47 +08:00
buildChart(list) {
2024-06-03 08:37:31 +08:00
let temp = []
let xAxisData = []
list.forEach(item => {
temp.push(item.groupTime)
})
// x轴数据
xAxisData = Array.from(new Set(temp))
2024-05-22 16:28:47 +08:00
// y轴数据
2024-06-03 08:37:31 +08:00
for (const y of this.factoryArray1) {
for (const type of this.typeList) {
const seriesItem = {
name: y.name,
record: type.name,
2024-05-22 16:28:47 +08:00
type: 'bar',
emphasis: {
focus: 'series'
},
2024-06-03 08:37:31 +08:00
data: Array(xAxisData.length).fill(0)
}
list.forEach(data => {
xAxisData.forEach((x, index) => {
if (x === data.groupTime && y.id === data.factory && type.id === data.glassType) {
seriesItem.data[index] = data.goodNumber
2024-05-22 16:28:47 +08:00
}
})
2024-06-03 08:37:31 +08:00
})
this.seriesList.push(seriesItem)
2024-05-22 16:28:47 +08:00
}
}
2024-06-03 08:37:31 +08:00
console.log('啊啊', this.seriesList)
this.$refs.lineChart.initChart(xAxisData, this.seriesList)
// const chartList = Object.groupBy(list, (item) => item.tableTime)
// this.xAxis = []
// this.seriesList = []
// for (const keyIndex in chartList) {
// // X坐标轴数据
// this.xAxis.push(keyIndex)
// }
// // y轴数据
// for (const y of this.factoryArray) {
// // y: {name: , id: }
// const seriesItem = {
// name: y.name,
// type: 'bar',
// emphasis: {
// focus: 'series'
// },
// data: Array(this.xAxis.length).fill(0)
// }
// for (const a in chartList) {
// for (const z of chartList[a]) {
// this.xAxis.forEach((item, index) => {
// if (z.factory === y.id && a === item) {
// seriesItem.data[index] = z.goodNumber
// }
// })
// }
// }
// this.seriesList.push(seriesItem)
// }
// this.$refs.lineChart.initChart(this.xAxis, this.seriesList)
2024-04-17 16:17:07 +08:00
},
buttonClick(val) {
this.listQuery.reportTime = val.reportTime ? val.reportTime : undefined;
switch (val.btnName) {
case 'search':
2024-05-20 14:55:36 +08:00
this.listQuery.current = 1;
this.listQuery.size = 20;
2024-04-17 16:17:07 +08:00
this.getDataList();
break;
case 'export':
this.handleExport();
break;
default:
console.log(val);
}
},
/** 导出按钮操作 */
handleExport() {
2024-05-20 14:55:36 +08:00
this.$modal.confirm('是否确认导出生产数据?').then(() => {
// 处理查询参数
let params = {...this.listQuery};
params.current = 1;
params.size = 999;
this.exportLoading = true;
return exportOutPutExcel(params);
}).then(response => {
this.$download.excel(response, '生产数据.xls');
this.exportLoading = false;
}).catch(() => {});
2024-04-17 16:17:07 +08:00
// 处理查询参数
// var xlsxParam = { raw: true };
// /* 从表生成工作簿对象 */
// import('xlsx').then(excel => {
// var wb = excel.utils.table_to_book(
// document.querySelector("#exportTable"),
// xlsxParam
// );
// /* 获取二进制字符串作为输出 */
// var wbout = excel.write(wb, {
// bookType: "xlsx",
// bookSST: true,
// type: "array",
// });
// try {
// FileSaver.saveAs(
// //Blob 对象表示一个不可变、原始数据的类文件对象。
// //Blob 表示的不一定是JavaScript原生格式的数据。
// //File 接口基于Blob继承了 blob 的功能并将其扩展使其支持用户系统上的文件。
// //返回一个新创建的 Blob 对象,其内容由参数中给定的数组串联组成。
// new Blob([wbout], { type: "application/octet-stream" }),
// //设置导出文件名称
// "许昌安彩日原片生产汇总.xlsx"
// );
// } catch (e) {
// if (typeof console !== "undefined") console.log(e, wbout);
// }
// return wbout;
// //do something......
// })
},
},
};
</script>
<style scoped>
/* .blueTip { */
/* padding-bottom: 10px; */
/* } */
/* .blueTi */
.blueTip::before{
display: inline-block;
content: '';
width: 4px;
height: 18px;
background: #0B58FF;
border-radius: 1px;
margin-right: 8PX;
margin-top: 8px;
}
.app-container {
2024-05-20 14:55:36 +08:00
margin: 0 0px 0;
2024-04-17 16:17:07 +08:00
background-color: #fff;
border-radius: 4px;
padding: 16px 16px 0;
height: calc(100vh - 134px);
overflow: auto;
}
</style>