fix:采购统计默认不请求柱状图数据

This commit is contained in:
shijing 2024-03-26 11:11:43 +08:00
parent 98ac2b691b
commit 4b66cea211
1 changed files with 360 additions and 255 deletions

View File

@ -2,47 +2,56 @@
<el-container> <el-container>
<el-header> <el-header>
<div class="right-panel"> <div class="right-panel">
<el-select v-model="queryType" clearable @change="queryTypeChange"> <el-select v-model="queryType" @change="queryTypeChange">
<el-option v-for="item in typeOptions" <el-option
:key="item" v-for="item in typeOptions"
:label="item" :key="item"
:value="item" :label="item"
:value="item"
> >
</el-option> </el-option>
</el-select> </el-select>
<el-date-picker <el-date-picker
v-if="queryType=='月'" v-if="queryType == '月'"
v-model="queryDate" v-model="queryDate"
type="month" type="month"
placeholder="查询月期" placeholder="查询月期"
value-format="YYYY-MM" value-format="YYYY-MM"
style="width:100%"
> >
</el-date-picker> </el-date-picker>
<el-date-picker <el-date-picker
v-if="queryType=='年'" v-if="queryType == '年'"
v-model="queryDate" v-model="queryDate"
type="year" type="year"
placeholder="查询年份" placeholder="查询年份"
value-format="YYYY" value-format="YYYY"
style="width:100%"
> >
</el-date-picker> </el-date-picker>
<el-button type="primary" icon="el-icon-search" @click="handleQuery"></el-button> <el-button
type="primary"
icon="el-icon-search"
@click="handleQuery"
></el-button>
</div> </div>
</el-header> </el-header>
<el-main id="elMain"> <el-main id="elMain">
<el-row :gutter="15"> <el-row :gutter="15">
<el-col :lg="12"> <el-col :lg="12">
<el-card shadow="never" style="margin-bottom: 8px;"> <el-card shadow="never" style="margin-bottom: 8px">
<el-header> <el-header>
<div class="right-panel"> <div class="right-panel">
<h2>采购统计</h2> <h2>采购统计</h2>
<el-select v-model="materialIn" clearable @change="materialInChange"> <el-select
<el-option v-for="item in inmOption" v-model="materialIn"
:key="item.id" clearable
:label="item.full_name" filterable
:value="item.id" @change="materialInChange"
>
<el-option
v-for="item in inmOption"
:key="item.id"
:label="item.full_name"
:value="item.id"
> >
</el-option> </el-option>
</el-select> </el-select>
@ -50,17 +59,40 @@
</el-header> </el-header>
<el-row> <el-row>
<el-col> <el-col>
<div id="bachart1" style="width:100%;height:300px;"></div> <div
id="bachart1"
style="width: 100%; height: 300px"
></div>
</el-col> </el-col>
<el-card shadow="never" style="width: 100%;position: relative;margin-top: 20px;"> <el-card
<el-button @click="handleExport('1')" class="tables" type="primary">导出</el-button> shadow="never"
<el-table :data="tableData1" id="exportDiv1" :height="tableHeight"> style="
width: 100%;
position: relative;
margin-top: 20px;
"
>
<el-button
@click="handleExport('1')"
class="tables"
type="primary"
>导出</el-button
>
<el-table
:data="tableData1"
id="exportDiv1"
:height="tableHeight"
>
<el-table-column type="index" width="50" /> <el-table-column type="index" width="50" />
<el-table-column label="日期" prop="date"> <el-table-column label="日期" prop="date">
<template #default="scope"> <template #default="scope">
<span>{{ scope.row. }}-</span> <span>{{ scope.row. }}-</span>
<span v-if="scope.row.周">{{ scope.row.周 }}</span> <span v-if="scope.row.周">{{
<span v-if="scope.row.月">{{ scope.row.月 }}</span> scope.row.
}}</span>
<span v-if="scope.row.月">{{
scope.row.
}}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="名称" prop="物料"> <el-table-column label="名称" prop="物料">
@ -73,23 +105,37 @@
</el-card> </el-card>
</el-col> </el-col>
<el-col :lg="12"> <el-col :lg="12">
<el-card shadow="never" style="margin-bottom: 8px;"> <el-card shadow="never" style="margin-bottom: 8px">
<el-container> <el-container>
<el-header> <el-header>
<div class="right-panel"> <div class="right-panel">
<h2>采购统计总表</h2> <h2>采购统计总表</h2>
</div> </div>
</el-header> </el-header>
<el-main style="width: 100%;position: relative;"> <el-main style="width: 100%; position: relative">
<el-button @click="handleExport('2')" class="tables" type="primary">导出</el-button> <el-button
@click="handleExport('2')"
<scTable :data="tableData2" id="exportDiv2" :height="rightHeight" hideDo> class="tables"
type="primary"
>导出</el-button
>
<scTable
:data="tableData2"
id="exportDiv2"
:height="rightHeight"
hideDo
>
<el-table-column type="index" width="50" /> <el-table-column type="index" width="50" />
<el-table-column label="日期" prop="date"> <el-table-column label="日期" prop="date">
<template #default="scope"> <template #default="scope">
<span>{{ scope.row. }}-</span> <span>{{ scope.row. }}-</span>
<span v-if="scope.row.周">{{ scope.row.周 }}</span> <span v-if="scope.row.周">{{
<span v-if="scope.row.月">{{ scope.row.月 }}</span> scope.row.
}}</span>
<span v-if="scope.row.月">{{
scope.row.
}}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="名称" prop="物料"> <el-table-column label="名称" prop="物料">
@ -107,243 +153,302 @@
</template> </template>
<script> <script>
import * as echarts from "echarts"; import * as echarts from "echarts";
import T from '@/components/scEcharts/echarts-theme-T.js'; import T from "@/components/scEcharts/echarts-theme-T.js";
echarts.registerTheme('T', T); echarts.registerTheme("T", T);
import scEcharts from '@/components/scEcharts'; import scEcharts from "@/components/scEcharts";
function deepCopy(obj) { function deepCopy(obj) {
return JSON.parse(JSON.stringify(obj)); return JSON.parse(JSON.stringify(obj));
} }
export default { export default {
name: 'chart', name: "chart",
components: { components: {
scEcharts scEcharts,
}, },
data() { data() {
return { return {
queryType:'月', queryType: "月",
queryDate:'', queryDate: "",
start_date:'', start_date: "",
end_date:'', end_date: "",
currentYear:'', currentYear: "",
currentMonth:'', currentMonth: "",
xAxisOrigin:[], xAxisOrigin: [],
xAxisData:[], xAxisData: [],
typeOptions:['月','年'], typeOptions: ["月", "年"],
basicOption: { basicOption: {
backgroundColor: 'transparent', backgroundColor: "transparent",
title: { title: {
text: '', text: "",
},
grid: {
top: '80px'
},
tooltip: {
trigger: 'axis'
},
xAxis: {
type: 'category',
data: []
},
yAxis: {
type: 'value'
},
lenged:[],
series: {
data: [0, 0, 0, 0, 0, 0, 0],
stack: 'Ad',
type: 'bar',
barWidth: '15px',
}
}, },
tableHeight: 0, grid: {
rightHeight:0, top: "80px",
tableData1:[], },
tableData2:[], tooltip: {
materialIn:'', trigger: "axis",
firstWeekNum:1, },
endWeekNum:1, xAxis: {
product:'', type: "category",
inmData:[], data: ["第1周", "第2周", "第3周", "第4周", "第5周"],
outData:[], },
inmOption:[], yAxis: {
outOption: [], type: "value",
monthList:['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'] },
lenged: [],
series: {
data: [0, 0, 0, 0, 0, 0, 0],
stack: "Ad",
type: "bar",
barWidth: "15px",
},
},
tableHeight: 0,
rightHeight: 0,
tableData1: [],
tableData2: [],
materialIn: "",
firstWeekNum: 1,
endWeekNum: 1,
product: "",
inmData: [],
outData: [],
inmOption: [],
outOption: [],
monthList: [
"一月",
"二月",
"三月",
"四月",
"五月",
"六月",
"七月",
"八月",
"九月",
"十月",
"十一月",
"十二月",
],
};
},
mounted() {
let that = this;
let date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let days = new Date(year, month, 0).getDate();
that.currentYear = year;
that.currentMonth = month;
that.start_date = year + "-" + month + "-01";
that.end_date =
year + "-" + month + "-" + new Date(year, month, 0).getDate();
let month1 = month;
if (month1 < 10) {
month1 = "0" + month1;
}
that.queryDate = year + "-" + month1;
that.firstWeekNum = that.getWeekOfYear(new Date(that.start_date));
that.endWeekNum = that.getWeekOfYear(new Date(that.end_date));
// console.log('that.firstWeekNum',that.firstWeekNum)
// console.log('that.endWeekNum',that.endWeekNum)
let duration = that.endWeekNum - that.firstWeekNum + 1;
for (let i = 1; i <= duration; i++) {
that.xAxisOrigin.push("第" + i + "周");
}
that.xAxisData = that.xAxisOrigin;
let height = document.getElementById("elMain").clientHeight;
let chartheight = document.getElementById("bachart1").clientHeight;
that.rightHeight = height - 115;
that.tableHeight = height - 140 - chartheight;
that.setChart("bachart1", that.basicOption);
this.getInmOption();
this.getTable();
},
methods: {
setChart(name, option = null) {
var myChart = echarts.getInstanceByDom(
document.getElementById(name)
);
if (myChart == undefined) {
myChart = echarts.init(document.getElementById(name), "T");
}
if (option == null) {
option = Object.assign({}, this.basicOption);
}
setTimeout(() => {
try {
myChart.setOption(option);
} catch (error) {}
}, 500);
},
getWeekOfYear(date) {
var target = new Date(
date.getFullYear(),
date.getMonth(),
date.getDate()
); //
var firstDayOfYear = new Date(target.getFullYear(), 0, 1); //
if (target.getTime() == firstDayOfYear.getTime()) {
return 1;
} else {
return Math.ceil(
(target -
firstDayOfYear +
8 * (firstDayOfYear.getTimezoneOffset() / 480)) /
604800000
);
} }
}, },
mounted(){ queryTypeChange(value) {
let that =this; console.log(value);
let date = new Date(); this.queryDate = "";
let year = date.getFullYear();
let month = date.getMonth()+1;
let days = new Date(year, month, 0).getDate();
that.currentYear = year;
that.currentMonth = month;
that.start_date =year+'-'+month+'-01';
that.end_date = year+'-'+month+'-'+new Date(year, month, 0).getDate();
let month1 = month;
if(month1<10){month1='0'+month1}
that.queryDate = year+'-'+month1;
that.firstWeekNum = that.getWeekOfYear(new Date(that.start_date));
that.endWeekNum = that.getWeekOfYear(new Date(that.end_date));
// console.log('that.firstWeekNum',that.firstWeekNum)
// console.log('that.endWeekNum',that.endWeekNum)
let duration = that.endWeekNum - that.firstWeekNum + 1;
for(let i =1;i<=duration;i++ ){
that.xAxisOrigin.push('第'+i+'周');
}
that.xAxisData = that.xAxisOrigin;
let height= document.getElementById('elMain').clientHeight;
let chartheight = document.getElementById('bachart1').clientHeight;
that.rightHeight = height - 115;
that.tableHeight = height-140-chartheight;
this.getInmOption();
}, },
methods:{ materialInChange() {
setChart(name, option = null) { this.getInmData();
var myChart = echarts.getInstanceByDom(document.getElementById(name)); },
if (myChart == undefined) { //
myChart = echarts.init(document.getElementById(name), 'T'); getInmOption() {
} let that = this;
if (option == null) { let obj = {};
option = Object.assign({}, this.basicOption) obj.page = 0;
} obj.type__in = "30,40,50,60,70";
setTimeout(() => { that.$API.mtm.material.list.req(obj).then((res) => {
try { that.inmOption = res;
myChart.setOption(option); // that.materialIn = res[1].id;
} catch (error) { } // let arr = [];
}, 500) // res.forEach(item=>{
}, // if(item.type==30){
getWeekOfYear(date) { // arr.push(item)
var target = new Date(date.getFullYear(), date.getMonth(), date.getDate()); // // }
var firstDayOfYear = new Date(target.getFullYear(), 0, 1); // // });
if(target.getTime()==firstDayOfYear.getTime()){ // that.getInmData();
return 1; });
}else{ },
return Math.ceil((target - firstDayOfYear + 8 * (firstDayOfYear.getTimezoneOffset() / 480)) / 604800000); //
} getInmData() {
}, let that = this;
queryTypeChange(value){ let option = deepCopy(that.basicOption);
console.log(value) option.xAxis.data = that.xAxisData;
this.queryDate = ''; let exec = that.queryType == "月" ? "saleOutWeek" : "saleOutMonth";
}, let obj = {
materialInChange(){ query: {
this.getInmData(); start_date: that.start_date,
}, end_date: that.end_date,
// mio_type: "pur_in",
getInmOption(){ material_id: that.materialIn,
let that = this; },
let obj = {}; };
obj.page=0; that.$API.bi.dataset.exec.req(exec, obj).then((res) => {
obj.type__in = '30,40,50,60,70'; console.log("getInmData", res);
that.$API.mtm.material.list.req( obj).then((res) => { let data = res.data2.ds0;
that.inmOption = res; that.tableData1 = data;
that.materialIn = res[1].id; if (data.length > 0) {
let arr = []; option.series.data = [];
res.forEach(item=>{ let seriesData = [];
if(item.type==30){ data.forEach((item) => {
arr.push(item) if (that.queryType == "月") {
let index = item. - that.firstWeekNum;
seriesData[index] = item.数量;
} else {
let index = item. - 1;
seriesData[index] = item.数量;
} }
}); });
that.outOption = arr; option.series.data = seriesData;
that.materialOut = arr[1].id; that.setChart("bachart1", option);
that.getInmData(); } else {
}) that.setChart("bachart1", option);
},
//
getInmData(){
let that = this;
let option = deepCopy(that.basicOption);
option.xAxis.data = that.xAxisData;
let exec = that.queryType=='月'?'saleOutWeek':'saleOutMonth';
let obj = {
query: { start_date: that.start_date, end_date: that.end_date, mio_type: "pur_in",material_id:that.materialIn },
};
that.$API.bi.dataset.exec.req(exec, obj).then((res) => {
console.log('getInmData',res);
let data = res.data2.ds0;
that.tableData1 = data;
if(data.length>0){
option.series.data = [];
let seriesData = [];
data.forEach(item=>{
if(that.queryType=='月'){
let index = item.-that.firstWeekNum;
seriesData[index]=item.数量;
}else{
let index = item.-1;
seriesData[index]=item.数量;
}
})
option.series.data = seriesData;
that.setChart("bachart1", option);
}else{
that.setChart("bachart1", option);
}
})
let obj2 = {
query: { start_date: that.start_date, end_date: that.end_date, mio_type: "pur_in"}
} }
that.$API.bi.dataset.exec.req(exec, obj2).then((res) => { });
if (res.data2.ds0) {
let data = res.data2.ds0;
that.tableData2 = data;
} else {
that.tableData2 = [];
}
})
},
handleQuery(){
let that = this;
if(this.queryType=='月'){
if(this.queryDate!==''&&this.queryDate!==null){
this.start_date =this.queryDate+'-01';
let arr = this.queryDate.split('-');
this.end_date = this.queryDate+'-'+new Date(arr[0], arr[1], 0).getDate();
this.firstWeekNum = this.getWeekOfYear(new Date(this.start_date));
this.endWeekNum = this.getWeekOfYear(new Date(this.end_date));
let duration = this.endWeekNum - this.firstWeekNum + 1;
let xAxisData = [];
for(let i =1;i<=duration;i++ ){
xAxisData.push('第'+i+'周');
}
that.xAxisData = xAxisData;
}else{
this.start_date =this.currentYear+'-'+this.currentMonth+'-01';
this.end_date = this.currentYear+'-'+this.currentMonth+'-'+new Date(this.currentYear, this.currentMonth, 0).getDate();
let date = new Date(this.start_date);
this.firstWeekNum = this.getWeekOfYear(date);
this.xAxisData = this.xAxisOrigin;
}
}else{
if(this.queryDate!==''&&this.queryDate!==null){
this.start_date = this.queryDate+'-01-01';
this.end_date = this.queryDate+'-12-31';
}else{
this.start_date = this.currentYear+'-01-01';
this.end_date = this.currentYear+'-12-31';
}
that.xAxisData = that.monthList;
}
this.getInmData();
},
handleExport(val) {
this.exportLoading = true;
let id = '#exportDiv' + val;
let name = val == '1' ? '采购统计' : '采购统计总表';
this.$XLSX(id, name);
this.exportLoading = false;
},
}, },
} getTable() {
let that = this;
let obj = {
query: {
start_date: that.start_date,
end_date: that.end_date,
mio_type: "pur_in",
},
};
let exec = that.queryType == "月" ? "saleOutWeek" : "saleOutMonth";
that.$API.bi.dataset.exec.req(exec, obj).then((res) => {
if (res.data2.ds0) {
let data = res.data2.ds0;
that.tableData2 = data;
} else {
that.tableData2 = [];
}
});
},
handleQuery() {
let that = this;
if (that.queryType == "月") {
if (that.queryDate !== "" && that.queryDate !== null) {
that.start_date = that.queryDate + "-01";
let arr = that.queryDate.split("-");
that.end_date =
that.queryDate +
"-" +
new Date(arr[0], arr[1], 0).getDate();
that.firstWeekNum = that.getWeekOfYear(
new Date(that.start_date)
);
that.endWeekNum = that.getWeekOfYear(
new Date(that.end_date)
);
let duration = that.endWeekNum - that.firstWeekNum + 1;
let xAxisData = [];
for (let i = 1; i <= duration; i++) {
xAxisData.push("第" + i + "周");
}
that.xAxisData = xAxisData;
} else {
that.start_date =
that.currentYear + "-" + that.currentMonth + "-01";
that.end_date =
that.currentYear +
"-" +
that.currentMonth +
"-" +
new Date(
that.currentYear,
that.currentMonth,
0
).getDate();
let date = new Date(that.start_date);
that.firstWeekNum = that.getWeekOfYear(date);
that.xAxisData = that.xAxisOrigin;
}
} else {
if (that.queryDate !== "" && that.queryDate !== null) {
that.start_date = that.queryDate + "-01-01";
that.end_date = that.queryDate + "-12-31";
} else {
that.start_date = that.currentYear + "-01-01";
that.end_date = that.currentYear + "-12-31";
}
that.xAxisData = that.monthList;
}
that.getTable();
if (that.materialIn !== "" && that.materialIn !== null) {
that.getInmData();
}
},
handleExport(val) {
this.exportLoading = true;
let id = "#exportDiv" + val;
let name = val == "1" ? "采购统计" : "采购统计总表";
this.$XLSX(id, name);
this.exportLoading = false;
},
},
};
</script> </script>
<style scoped> <style scoped>
.tables { .tables {
position: absolute; position: absolute;
top: 4px; top: 4px;
right: 6px; right: 6px;
z-index: 10; z-index: 10;
} }
</style> </style>