yudao-dev/src/views/core/analysis/yieldAnalysis/index.vue
2023-11-16 13:57:21 +08:00

233 lines
6.2 KiB
Vue

<template>
<div class="app-container">
<search-bar :formConfigs="formConfig" ref="searchBarForm" @headBtnClick="buttonClick" />
<div v-if="tableData.length">
<base-table v-loading="dataListLoading" :table-props="tableProps" :table-data="tableData" />
<SearchBar :formConfigs="[{ label: '产品产量对比图', type: 'title' }]" />
<line-chart ref="lineChart" />
</div>
<div v-else class="no-data-bg"></div>
<!-- <pagination
:limit.sync="listQuery.pageSize"
:page.sync="listQuery.pageNo"
:total="listQuery.total"
@pagination="getDataList" /> -->
</div>
</template>
<script>
// import basicPage from '../../mixins/basic-page';
import { parseTime } from '../../mixins/code-filter';
import { getYieldAnalysisPageData } from '@/api/core/analysis/index';
// import { getProductionLinePage } from '@/api/core/base/productionLine';
import lineChart from '../LineChart'
import moment from 'moment';
// import { getWorkshopSectionPage } from '@/api/core/base/workshopSection';
// const tableProps = [
// // {
// // prop: 'lineName',
// // label: '产线',
// // align: 'center',
// // },
// // {
// // prop: 'sum',
// // label: '合计',
// // align: 'center',
// // },
// // {
// // prop: 'dynamicValue',
// // label: 'dynamicName',
// // align: 'center',
// // children:[
// // ]
// // }
// ];
export default {
components: {
lineChart,
},
// mixins: [basicPage],
data() {
return {
urlOptions: {
getDataListURL: getYieldAnalysisPageData,
},
tableProps:[],
dataListLoading:false,
tableData: [],
listQuery: {
// lineIds: [],
recordTime: []
},
dateLabelList: [],
tempTtime: '',
day: 0,
xData: [],
formConfig: [
// {
// type: 'select',
// label: '产线',
// selectOptions: [],
// param: 'lineIds',
// defaultSelect: '',
// multiple:true,
// filterable: true,
// },
{
type: 'datePicker',
label: '时间',
dateType: 'month',
format: 'yyyy-MM',
valueFormat: 'yyyy-MM-dd HH:mm:ss',
rangeSeparator: '-',
startPlaceholder: '开始时间',
endPlaceholder: '结束时间',
param: 'time',
},
{
type: 'button',
btnName: '查询',
name: 'search',
color: 'primary',
}
],
};
},
created() {
// this.getArr();
},
methods: {
// getArr() {
// const params = {
// page: 1,
// limit: 500,
// };
// this.optionArrUrl.forEach((item, index) => {
// item(params).then((response) => {
// this.formConfig[index].selectOptions = response.data.list
// // this.formConfig[0].defaultSelect = response.data.list[0].id
// this.$set(this.formConfig[0], 'defaultSelect', response.data.list[0].id)
// });
// });
// },
// 设置表头和横坐标
setHeader() {
const month = this.tempTtime.getMonth() + 1
let arr = [
{
prop: 'proName',
label: '产品名称',
fixed: 'left'
},
{
prop: 'specifications',
label: '产品规格',
fixed: 'left'
},
{
prop: 'sum',
label: '合计',
fixed: 'left'
},
{
label: this.tempTtime.getFullYear() + '年' + month + '月',
align: 'center',
children: []
}
]
for (let d = 1; d <= this.day; d ++) {
arr[3].children.push({
prop: 'value' + d, label: month + '-' + d
})
// 横坐标
this.xData.push(month + '-' + d)
}
this.tableProps = arr
},
getData() {
this.urlOptions.getDataListURL(this.listQuery).then(res => {
//构造数据
this.tableData = []
if (Object.values(res.data.coreProductionLineMonthVOS).length > 0) {
this.setHeader()
let yAllData = [], proNameList = []
Object.values(res.data.coreProductionLineMonthVOS).forEach(pro => {
// 一条产品的数据
let yData = []
const tempData = {
proName: pro[0].proName,
specifications: pro[0].specifications,
sum: 0
}
proNameList.push(pro[0].proName)
pro.forEach(item => {
// 产品下的各时间点的数据
// 截取日
const day = parseTime(item.recordTime).slice(8, 10) < 10 ? parseTime(item.recordTime).slice(9, 10) : parseTime(item.recordTime).slice(8, 10)
// console.log('!1', day < 10)
tempData['value' + day] = item.countSum
tempData.sum += item.countSum
yData[day] = item.countSum
// yData.push(item.countSum)
})
this.tableData.push(tempData)
yAllData.push(yData)
})
this.$nextTick(() => {
this.$refs.lineChart.initChart(this.xData, yAllData, proNameList)
})
}
// this.total = response.data.total;
// this.dataListLoading = false;
});
},
buttonClick(val) {
switch (val.btnName) {
case 'search':
// this.listQuery.recordTime = val.time ? new Date(val.time).getTime() : undefined
if (val.time) {
this.tempTtime = new Date(val.time)
switch (this.tempTtime.getMonth() + 1) {
case 1, 3, 5, 7, 8, 10, 12:
this.day = 31;
break;
case 2:
this.day = 28;
break;
case 4, 6, 9, 11:
this.day = 30;
break;
}
this.listQuery.recordTime = [
val.time,
parseTime(new Date(this.tempTtime.getFullYear(), this.tempTtime.getMonth(), this.day, 23, 59, 59))
]
this.getData()
} else {
this.$message({
message: '请选择时间',
type: 'warning'
});
}
break;
case 'reset':
this.$refs.searchBarForm.resetForm();
this.listQuery = {
pageSize: 10,
pageNo: 1,
total: 1,
};
this.getDataList();
break;
default:
console.log(val);
}
},
},
};
</script>