fix:修整采购统计

This commit is contained in:
shijing 2025-04-28 14:27:35 +08:00
parent c3c63afc2d
commit 8aa9dfe98b
1 changed files with 75 additions and 64 deletions

View File

@ -41,28 +41,25 @@
<el-header>
<div class="right-panel">
<h2>采购统计</h2>
<el-select
<xtSelect
:apiObj="apiObjMaterial"
v-model="materialIn"
clearable
filterable
v-model:label="materialName"
v-model:obj="materialItem"
@change="materialInChange"
>
<el-option
v-for="item in inmOption"
:key="item.id"
:label="item.full_name"
:value="item.id"
>
</el-option>
</el-select>
<el-table-column type="index" width="50" />
<!-- <el-table-column label="物料编号" prop="number"></el-table-column> -->
<el-table-column label="名称" prop="name"></el-table-column>
<el-table-column label="规格" prop="specification"></el-table-column>
<el-table-column label="型号" prop="model"></el-table-column>
<el-table-column label="库存" prop="count"></el-table-column>
</xtSelect>
</div>
</el-header>
<el-row>
<el-col>
<div
id="bachart1"
style="width: 100%; height: 300px"
></div>
<div id="bachart1" style="width: 100%; height: 300px"></div>
</el-col>
<el-card
shadow="never"
@ -227,6 +224,7 @@ export default {
tableData1: [],
tableData2: [],
materialIn: "",
materialName: "",
firstWeekNum: 1,
endWeekNum: 1,
product: "",
@ -234,20 +232,10 @@ export default {
outData: [],
inmOption: [],
outOption: [],
monthList: [
"一月",
"二月",
"三月",
"四月",
"五月",
"六月",
"七月",
"八月",
"九月",
"十月",
"十一月",
"十二月",
],
monthList: ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],
materialItem:{},
apiObjMaterial:this.$API.mtm.material.list,
queryMaterial:{type__in : "30,40,50,60,70"}
};
},
mounted() {
@ -279,12 +267,11 @@ export default {
},
methods: {
setChart(name, option = null) {
var myChart = echarts.getInstanceByDom(
document.getElementById(name)
);
if (myChart == undefined) {
myChart = echarts.init(document.getElementById(name), "T");
var myChart = echarts.getInstanceByDom(document.getElementById(name));
if (myChart != null) {
myChart.dispose(); //
}
myChart = echarts.init(document.getElementById(name), "T");
if (option == null) {
option = Object.assign({}, this.basicOption);
}
@ -306,7 +293,15 @@ export default {
console.log(value);
this.queryDate = "";
},
materialInChange() {
materialInChange(data) {
let that = this;
console.log(that.materialItem);
console.log(that.materialItem.id);
that.materialIn = that.materialItem.id;
let option = deepCopy(that.basicOption);
option.xAxis.data = that.xAxisData;
console.log(option);
that.setChart("bachart1",option);
this.getInmData();
},
//
@ -317,21 +312,12 @@ export default {
obj.type__in = "30,40,50,60,70";
that.$API.mtm.material.list.req(obj).then((res) => {
that.inmOption = res;
// that.materialIn = res[1].id;
// let arr = [];
// res.forEach(item=>{
// if(item.type==30){
// arr.push(item)
// }
// });
// that.getInmData();
});
},
//
getInmData() {
let that = this;
let option = deepCopy(that.basicOption);
option.xAxis.data = that.xAxisData;
that.tableData1 = [];
let exec = that.queryType == "月" ? "saleOutWeek" : "saleOutMonth";
let obj = {
query: {
@ -342,26 +328,16 @@ export default {
},
};
that.$API.bi.dataset.exec.req(exec, obj).then((res) => {
console.log("getInmData", res);
option.series.data = [];
if (res.data2.ds0) {
let data = res.data2.ds0;
that.tableData1 = data;
if (data.length > 0) {
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;
}
if (res.data2.ds0&&res.data2.ds0.length>0) {
that.tableData1 = res.data2.ds0;
that.setChartData(res.data2.ds0);
}else{
console.log('无数据')
let option = deepCopy(that.basicOption);
option.xAxis.data = that.xAxisData;
console.log(option);
that.setChart("bachart1",option);
}
that.setChart("bachart1", option);
});
},
getTable() {
@ -378,7 +354,9 @@ export default {
that.tableData2 = [];
if (res.data2.ds0) {
let data = res.data2.ds0;
that.tableData1 = data;
that.tableData2 = data;
that.setChartData(data);
}
});
},
@ -421,6 +399,39 @@ export default {
that.getInmData();
}
},
setChartData(data){
let that = this;
let option = deepCopy(that.basicOption);
option.xAxis.data = that.xAxisData;
option.series=[];
let materials = [],seriesData = [];
data.forEach((item) => {
if(materials.indexOf(item.物料名) == -1){
materials.push(item.物料名);
}
})
materials.forEach((item) => {
let obj = {};
obj.name = item;
obj.type = "bar";
obj.stack = "Ad";
obj.barWidth = "15px";
obj.data = [0,0,0,0,0,0,0,0,0,0,0,0];
seriesData.push(obj);
})
data.forEach((item) => {
let index = 0;let indexY = 0;
if (that.queryType == "月") {
index = item. - that.firstWeekNum;
} else {
index = item. - 1;
}
indexY = materials.indexOf(item.物料名);
seriesData[indexY].data[index] = item.数量;
});
option.series = seriesData;
that.setChart("bachart1", option);
},
handleExport(val) {
this.exportLoading = true;
let id = "#exportDiv" + val;