diff --git a/src/views/statistics/material_statistics.vue b/src/views/statistics/material_statistics.vue index 89e1d1be..1a2ba481 100644 --- a/src/views/statistics/material_statistics.vue +++ b/src/views/statistics/material_statistics.vue @@ -41,28 +41,25 @@

采购统计

- - - - + + + + + + +
-
+
{ 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;